[Bug middle-end/100593] [ELF] -fno-pic: Use GOT to take address of an external default visibility function

amonakov at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue May 18 09:16:56 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100593

--- Comment #7 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
Thanks. I agree that inferring address significance on the linker side is
problematic.

Thinking about your original request, I was about to say that it would be very
reasonable to do under -fno-plt flag, but then I found it was already
implemented for x86-64 in gcc-7 and for 32-bit x86 in gcc-8. Compiling

int f();
void *g()
{
  return f;
}

with -fno-pic -fno-plt yields

g:
        movq    f@GOTPCREL(%rip), %rax
        ret

(yields GOTPCRELX relocation) and

g:
        movl    f@GOT, %eax
        ret

on 32-bit (yields GOT32X relocation), so on x86 it's already implemented?


More information about the Gcc-bugs mailing list