[PATCH] gold/aarch64: Fix adrp distance check
Vladislav Khmelevsky
och95@yandex.ru
Sat Jun 25 17:52:59 GMT 2022
The offset between destination and location is a signed number,
currently the offset is treated as unsigned number, thus mathematical
shifting of negative value is performed incorrectly.
---
gold/aarch64.cc | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index d2b0747ffdc..e3ab5f10faa 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -1182,7 +1182,9 @@ class Reloc_stub : public Stub_base<size, big_endian>
aarch64_valid_for_adrp_p(AArch64_address location, AArch64_address dest)
{
typedef AArch64_relocate_functions<size, big_endian> Reloc;
- int64_t adrp_imm = (Reloc::Page(dest) - Reloc::Page(location)) >> 12;
+ int64_t offset
+ = static_cast<int64_t> (Reloc::Page (dest) - Reloc::Page (location));
+ int64_t adrp_imm = offset < 0 ? ~(~offset >> 12) : offset >> 12;
return adrp_imm >= MIN_ADRP_IMM && adrp_imm <= MAX_ADRP_IMM;
}
--
2.25.1
More information about the Binutils
mailing list