From b8513fe895436cece82121dde7c3405ecc556963 Mon Sep 17 00:00:00 2001 From: Dylan Fei Date: Sun, 28 Dec 2025 21:32:58 +0800 Subject: [PATCH] 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. --- arm64-gen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arm64-gen.c b/arm64-gen.c index 2038aeba..f076b480 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -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 */ } }