Weak symbols not overriden

Ian Lance Taylor iant@google.com
Fri Mar 18 01:36:00 GMT 2011


Pan ruochen <panruochen@gmail.com> writes:

> I found weak symbols wouldn't be overriden by the strong symbols with
> same names.

This case, involving shared libraries, actually has nothing to do with
either gcc or the binutils.  It's the dynamic linker that matters here,
and that is part of the C library.  You didn't say, but I'm guessing
that you are using GNU/Linux and glibc.  By default, the glibc dynamic
linker uses the first definition it finds even if it is weak.  That is
because overriding a weak symbol is rare, and would require the dynamic
linker to search all the remaining shared libraries.

You can get the behaviour you want by defining the environment variable
LD_DYNAMIC_WEAK.

Ian



More information about the Binutils mailing list