Weak symbols and inline
Paul Smith
paul@mad-scientist.net
Thu Feb 27 18:53:00 GMT 2014
Hi all; I'm using C++ built with GCC 4.8.2 / binutils 2.23.2 on a
GNU/Linux system.
When I create a global function marked "inline" I see, using nm, that a
weak symbol ("W") is added to the object file for that function.
For link-order reasons, I would prefer that the inlined function not
generate any (external) symbol; in particular I do NOT want this object
to be pulled in from a static library just because it happens to appear
first in the archive order. I have another object in the archive which
declares a global symbol ("T" in nm) and I want that one linked instead.
I don't see an __attribute__ setting that specifically controls this (I
can force a symbol to be weak, but that's not what I want).
I did discover that if I use __attribute__((always_inline)) then it does
what I want and doesn't add a weak symbol into the object.
Is that an approved usage of this attribute? It doesn't appear to be
explicitly documented so I'm concerned that it's just a side-effect that
can't be counted on going forward.
Is there a better solution?
More information about the Gcc-help
mailing list