Skip to content

Commit b8513fe

Browse files
committed
arm64-gen: fix address calculation for large symbol offsets
When accessing a global symbol with an addend > 0xffffff, the AArch64 backend incorrectly encoded an 'add xr, xt, #0' (Add Immediate) instead of 'add xr, xr, xt' (Add Register). This resulted in the base address of the symbol being overwritten by the offset value rather than being summed with it. Fixes the issue where (sym + 0x1000000) would resolve to 0x1000000 instead of the correct memory address.
1 parent 11118be commit b8513fe

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arm64-gen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static void arm64_sym(int r, Sym *sym, unsigned long addend)
476476
int t = r ? 0 : 1;
477477
o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
478478
arm64_movimm(t, addend & ~0xfffffful); // use xt for addent
479-
o(0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
479+
o(0x8B000000 | (t << 16) | (r << 5) | r); /* add xr, xr, xt */
480480
o(0xf84107e0 | t); /* ldr xt, [sp], #16 */
481481
}
482482
}

0 commit comments

Comments
 (0)