public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/56446] New: Generate one fewer relocation when calling a checked weakref function
@ 2013-02-25 19:40 thiago at kde dot org
  2013-02-25 19:48 ` [Bug tree-optimization/56446] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: thiago at kde dot org @ 2013-02-25 19:40 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: thiago@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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-06-12 13:53 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-25 19:40 [Bug c/56446] New: Generate one fewer relocation when calling a checked weakref function thiago at kde dot org
2013-02-25 19:48 ` [Bug tree-optimization/56446] " pinskia at gcc dot gnu.org
2013-02-25 22:22 ` [Bug tree-optimization/56446] [4.6/4.7/4.8 Regression] " steven at gcc dot gnu.org
2013-02-25 22:27 ` thiago at kde dot org
2013-02-25 22:28 ` thiago at kde dot org
2013-02-26 10:10 ` rguenth at gcc dot gnu.org
2013-02-26 10:11 ` rguenth at gcc dot gnu.org
2013-02-26 10:26 ` jakub at gcc dot gnu.org
2013-02-27  9:44 ` [Bug target/56446] " rguenth at gcc dot gnu.org
2013-03-13 19:52 ` [Bug target/56446] " steven at gcc dot gnu.org
2013-04-12 15:43 ` jakub at gcc dot gnu.org
2013-05-23 13:15 ` hubicka at gcc dot gnu.org
2014-06-12 13:53 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).