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

Reply via email to