http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56446
Bug #: 56446 Summary: Generate one fewer relocation when calling a checked weakref function Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: thi...@kde.org When you have code like: static int f() __attribute__((weakref("foo"))); void g() { int (*ptr)() = f; if (ptr) ptr(); } which is typical for weakref functions, when compiled in PIC/PIE mode, gcc sees through the variable and generates: cmpq $0, f@GOTPCREL(%rip) je .L1 xorl %eax, %eax jmp f@PLT .L1: ret That means there will be two GOT entries for the "foo" symbol: one in the actual GOT and one in the .plt.got (lazily initialised). Since the actual GOT needs to have the address filled in at load time, there's no gain in lazy initialisation -- in fact, there's a loss. GCC could do exactly what the code is suggesting and load the actual address onto a register and then use it. This would save one relocation, the indirect PLT jumps and the loss in the lazy resolution.