From 854df54e1839c8b96d1aaa9aeaa32c2ebbf535f8 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 13 Dec 2025 14:21:22 +0100 Subject: fix position independent loads of function symbols. For `extern int x[1];`, can use PCREL32 for &x. But for `extern int x(int)`, must use GOTREL, when not being called directly (that's PLT). Therefore the type of an external symbol (actually just whether it denotes a function) matters when deciding what kind of relocation to emit, so keep that information. --- x86_64/isel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'x86_64/isel.c') diff --git a/x86_64/isel.c b/x86_64/isel.c index 5d373f3..67a4358 100644 --- a/x86_64/isel.c +++ b/x86_64/isel.c @@ -310,7 +310,7 @@ fuseaddr(union ref *r, struct block *blk, int *curi) if (r->t != RTMP) return 0; if (!aadd(&addr, blk, curi, *r)) return 0; - if (isaddrcon(addr.base,0) && (ccopt.pic || (ccopt.pie && addr.index.bits))) { + if (isaddrcon(addr.base,0) && (ccopt.pic || (ccopt.pie && addr.index.bits) || conht[addr.base.i].isfunc)) { /* pic needs to load from GOT */ /* pie cannot encode RIP-relative address with index register */ /* first load symbol address into a temp register */ -- cgit v1.2.3