This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++] GCC tree linkage types


On Fri, Nov 07, 2003 at 10:11:48AM -0600, Chris Lattner wrote:
> On Fri, 7 Nov 2003, Daniel Jacobowitz wrote:
> 
> > As Ian said, they will be implicitly defined to zero if no definition
> > is present.
> >
> > extern int foo_func() __attribute__((weak));
> > ...
> >   if (foo_func != 0)
> >     return foo_func ();
> > ...
> >
> > There are a number of uses for this.  For instance, glibc uses it to
> > call pthread locking functions iff the threading library is available
> > at runtime.
> 
> Can't the same effect be had like this:
> 
> libc:
> 
> bool has_foo_feature() __attribute__((weak)) { return false; }
> 
> libfoo:
> 
> bool has_foo_feature() { return true; }
> 
> If they link to libfoo, they will automatically get the new definition of
> has_foo_feature... without needing undefined weak symbols.

No.

Weak symbols are not overridden by later strong symbols during dynamic
linking, only during static linking.  On GNU/Linux, until some point (a
year-ish ago?  Less?) this would have worked; it causes the dynamic
linker to be quite inefficient however, since a weak def would cause it
to keep searching.

It's also more expensive at use time; it involves a function call
instead of a GOT load.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]