Fix adrp distance check
authorVladislav Khmelevsky <och95@yandex.ru>
Fri, 11 Nov 2022 00:46:23 +0000 (16:46 -0800)
committerCary Coutant <ccoutant@gmail.com>
Fri, 11 Nov 2022 00:49:05 +0000 (16:49 -0800)
gold/
* aarch64.cc (aarch64_valid_for_adrp_p): Shift offset
as a signed number.

gold/aarch64.cc

index d1f5c3299b03a3bf82cdee9cb26ffb4780883a15..c5aa2c710da68bc998628617eedb3feb92e05c85 100644 (file)
@@ -1182,7 +1182,8 @@ 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 adrp_imm = Reloc::Page (dest) - Reloc::Page (location);
+    adrp_imm = adrp_imm < 0 ? ~(~adrp_imm >> 12) : adrp_imm >> 12;
     return adrp_imm >= MIN_ADRP_IMM && adrp_imm <= MAX_ADRP_IMM;
   }