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.
Unified · Split
| @@ -476,7 +476,7 @@ static void arm64_sym(int r, Sym *sym, unsigned long addend) · 475 unmodified lines | ||
| 476 | 476 | int t = r ? 0 : 1; |
| 477 | 477 | o(0xf81f0fe0 | t); /* str xt, [sp, #-16]! */ |
| 478 | 478 | 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 */ | |
| 480 | 480 | o(0xf84107e0 | t); /* ldr xt, [sp], #16 */ |
| 481 | 481 | } |
| 482 | 482 | } |