History

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.

Dylan Fei committed 10 months ago

Commit b8513fe1 parent 11118be1 file · +1 −1Browse files

Unified · Split

arm64-gen.c+1−1
@@ -476,7 +476,7 @@ static void arm64_sym(int r, Sym *sym, unsigned long addend) · 475 unmodified lines
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 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t