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.
This commit is contained in:
Dylan Fei
2025-12-28 21:32:58 +08:00
parent 11118be717
commit b8513fe895

View File

@@ -476,7 +476,7 @@ static void arm64_sym(int r, Sym *sym, unsigned long addend)
int t = r ? 0 : 1;
o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */
arm64_movimm(t, addend & ~0xfffffful); // use xt for addent
o(0x91000000 | r | (t << 5)); /* add xr, xt, #0 */
o(0x8B000000 | (t << 16) | (r << 5) | r); /* add xr, xr, xt */
o(0xf84107e0 | t); /* ldr xt, [sp], #16 */
}
}