https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88954
Bug ID: 88954 Summary: __attribute__((noplt)) doesn't work with function pointers Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: hjl.tools at gmail dot com Depends on: 67400 Target Milestone: --- Target: i386, x86-64 [hjl@gnu-cfl-1 noplt-3]$ make clean rm -f *.o *.so *.s [hjl@gnu-cfl-1 noplt-3]$ cat main.c void f_noplt(void) __attribute__((noplt)); void (*p_noplt)(void) = f_noplt; void g(void (*)(void)); int main() { g(p_noplt); // lazy: linker sets p_noplt to PLT address g(f_noplt); // lazy: linker sets mov immediate to PLT address f_noplt(); // non-lazy return 0; } [hjl@gnu-cfl-1 noplt-3]$ cat lib.c __attribute__((noplt)) void f_noplt(void) {} void g(void p(void)) {p();} [hjl@gnu-cfl-1 noplt-3]$ make CC=gcc gcc -O2 -fno-pic -c -o main.o main.c gcc -O2 -fno-pic -fPIC -c -o lib.o lib.c gcc -shared -o lib.so lib.o gcc -no-pie -o x main.o lib.so -Wl,-R,. ./x [hjl@gnu-cfl-1 noplt-3]$ readelf -rW x Relocation section '.rela.dyn' at offset 0x4c8 contains 3 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000403fe8 0000000400000006 R_X86_64_GLOB_DAT 0000000000401030 f_noplt + 0 0000000000403ff0 0000000100000006 R_X86_64_GLOB_DAT 0000000000000000 __libc_start_main@GLIBC_2.2.5 + 0 0000000000403ff8 0000000200000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 Relocation section '.rela.plt' at offset 0x510 contains 2 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000404018 0000000400000007 R_X86_64_JUMP_SLOT 0000000000401030 f_noplt + 0 This dynamic relocation shouldn't be here. 0000000000404020 0000000300000007 R_X86_64_JUMP_SLOT 0000000000000000 g + 0 [hjl@gnu-cfl-1 noplt-3]$ Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67400 [Bug 67400] -fno-plt doesn't work with function pointers