public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32511]  New: GCC inlines weak function
@ 2007-06-26  5:30 sabre at nondot dot org
  2010-07-12 13:46 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function jason at gcc dot gnu dot org
  0 siblings, 1 reply; 10+ messages in thread
From: sabre at nondot dot org @ 2007-06-26  5:30 UTC (permalink / raw)
  To: gcc-bugs

GCC generally doesn't inline weak functions, because their body may be
redefined by the linker: if the compiler inlined the call, the linker changing
the behavior of the function wouldn't change the inlined copy.  For example,
GCC does not inline this:

void bar () __attribute__((weak));
void bar () {}
void foo() { bar(); } 

However, GCC apparently overrides this if the inline keyword is added (and
potentially if the weak function is defined in a c++ class where it would be
implicit inline?).  As such, it cause the following to be inlined:

inline void bar () __attribute__((weak));
void bar () {}
void foo() { bar(); } 

However, again, this breaks the semantics of weak linkage.  If bar is redefined
at link-time, the inlined copy is not updated.  Because 'inline' is an
optimization request, not a requirement, it seems best for the compiler to
ignore the inline request in this case.

-Chris


-- 
           Summary: GCC inlines weak function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sabre at nondot dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32511


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

end of thread, other threads:[~2012-07-02  9:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-32511-4@http.gcc.gnu.org/bugzilla/>
2010-09-30 11:56 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function rguenth at gcc dot gnu.org
2010-09-30 19:17 ` jason at gcc dot gnu.org
2011-01-10 15:49 ` matz at gcc dot gnu.org
2011-01-10 15:53 ` rguenth at gcc dot gnu.org
2011-01-11 11:30 ` [Bug c/32511] [4.4/4.5 Regression] " rguenth at gcc dot gnu.org
2011-01-11 11:30 ` [Bug c/32511] [4.4/4.5/4.6 regression] " rguenth at gcc dot gnu.org
2012-01-12 20:25 ` [Bug c/32511] [4.4/4.5 Regression] " pinskia at gcc dot gnu.org
2012-03-13 15:02 ` [Bug c/32511] [4.5 " jakub at gcc dot gnu.org
2012-07-02  9:27 ` rguenth at gcc dot gnu.org
2007-06-26  5:30 [Bug c/32511] New: GCC inlines weak function sabre at nondot dot org
2010-07-12 13:46 ` [Bug c/32511] [4.4/4.5/4.6 regression] GCC rejects inline+weak function jason at gcc dot gnu dot 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).