Hans de Goede wrote:
How about using ld --as-needed, AFAIK that has come up before and would
be a great improvement!
Whats holding us back from linking with --as-needed by default?
Well, one, libtool will actively defeat your attempts to use it, since
it doesn't think linker arguments are positional, so it sorts
-Wl,--as-needed (and -Wl,* in general) to the end, _after_ all the
libraries you could possibly want to have specified as optional. Which
means the libtool developers are either clueless or malicious.
No, I'm not interested in fixing libtool, other than by replacement.
In general though, since --as-needed is positional, it's not as simple
as "just turn it on by default", because you have to do it between all
the convenience libraries you ar'd up during the build, and all the
installed system libraries you might possibly want to link against.
Even if you do that, there's no guarantee the app isn't doing something
weird like using the result of dlopen(NULL) to dlsym with, in which case
the altered search scope can affect runtime behaviour.
It's fine to add it if you're willing to fix what breaks _and_ you're
not using libtool.
- ajax