Modify amd64 fixarg to fix calling constant addresses

On x86_64, direct calls are always PC-relative. This means that
in order to call an absolute address, the call must be indirect.

To accomplish this, update fixarg to introduce a temporary before
emitting.
This commit is contained in:
Richard McCormack 2026-01-07 06:23:46 -05:00 committed by Quentin Carbonneaux
parent 640c78d0da
commit cf06ce159d

View File

@ -96,6 +96,14 @@ fixarg(Ref *r, int k, Ins *i, Fn *fn)
a.offset.sym.id = intern(buf);
fn->mem[fn->nmem-1] = a;
}
else if (op == Ocall && r == &i->arg[0]
&& rtype(r0) == RCon && fn->con[r0.val].type != CAddr) {
/* use a temporary register so that we
* produce an indirect call
*/
r1 = newtmp("isel", Kl, fn);
emit(Ocopy, Kl, r1, r0, R);
}
else if (op != Ocopy && k == Kl && noimm(r0, fn)) {
/* load constants that do not fit in
* a 32bit signed integer into a