[BUG] ld behavior varies for C++ static initializer depending on .a or .o input

Zack Weinberg zack@codesourcery.com
Sun Apr 13 23:07:00 GMT 2003


Ian Lance Taylor <ian@airs.com> writes:

> Hal Black <black@ieee.org> writes:
>> Yes.  That's the desired behavior.  If a developer were to develop a
>> library with a static initializer with side-effects, it would be
>> something that should be called whenever that library was used.
>
> No Unix linker has ever worked that way.
>
> Basically, you misunderstand how ld and ar work.  If you feel that you
> have been misled by existing documentation, please let us know so that
> we can fix it.

I'd like to point out that while this is true for static (.a)
libraries, it is not true for shared (.so) libraries -- the linker
generates DT_NEEDED entries for every shared library on the command
line, whether or not they satisfy undefined symbols.  Personally I
consider this a bug.

zw



More information about the Binutils mailing list