Roumen Petrov <bugtr...@roumenpetrov.info> writes: > Urgh, article with very limited niche. First is only for shared libraries, > next unresolved externals in shared library, and finally requires > "advanced" loader.
Overlinking isn't about unresolved externals in shared libraries. It's about avoiding linking with shared libraries that *don't* resolve any external symbols. It doesn't require an advanced loader, just any reasonably modern shared library system; Solaris 2.6 from many years ago had the same issue. It is specific to systems where the linker is willing to encode dependencies to libraries (in NEEDED, for instance) that aren't actually required, but that's the default behavior of, say, GNU binutils. The standard problem is that liba depends on libb, and a binary depends on liba (but not libb). Libtool's default behavior in the presence of *.la files will link the binary with both liba and libb, even though it only needs to be linked with liba. This causes a lot of problems for the dependency management in a distribution if allowed to happen archive-wide, since it creates tons of unnecessary dependency edges that make dependency resolution and archive management much harder. Avoiding *.la files solves most of this. --as-needed helps when the upstream Makefiles are designed to support static linking (where all the libraries have to be listed), or where upstream just didn't pay attention to this or didn't consider overlinking to be a problem, but has been known to have bugs where it leaves out dependencies that actually are required. For the software I personally maintain, --enable-reduced-dependencies changes the behavior of Autoconf macros to not add the full transitive set of libraries and instead only link with the immediate dependencies. But I think I'm the only person who uses that convention. For newer software that uses pkg-config, pkg-config supports this inherently if the library maintainers write correct pkg-config files (which a lot of them don't). The article may have limited applicability in the grand picture of all systems and all ways of linking libraries, but it applies to pretty much every Linux distribution (and probably any other distribution of any kind of UNIX that uses shared libraries and package dependencies). So by quantity of Libtool installs and invocations, it's significant. -- Russ Allbery (ea...@eyrie.org) <https://www.eyrie.org/~eagle/>