[BUG] ld behavior varies for C++ static initializer depending on .a or .o input
Ian Lance Taylor
ian@airs.com
Sun Apr 13 22:55:00 GMT 2003
Hal Black <black@ieee.org> writes:
> > It means that including any class with a static initializer in a .a
> > file would mean that that class would be included in all programs
> > linked with that .a file.
>
> 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.
Also, while this is not the reason for not making the change, it turns
out that it is not an efficient change to make. It would require the
linker to examine every object in every archive, which obviates the
entire point of having archives in the first place. Again, this
inefficiency, while severe, is not the reason for not making the
change; the reason for not making the change is that ld and ar
implement behaviour which has not changed for decades, and should not
be changed now.
Ian
More information about the Binutils
mailing list