On Tue, Nov 29, 2011 at 09:16:08PM +0900, Junichi Uekawa wrote: > At Fri, 11 Nov 2011 15:05:32 +0000, > Colin Watson wrote: > > cowdancer fails to build with a linker that defaults to --as-needed, as > > shown in this Ubuntu build log: > > > > > > https://launchpadlibrarian.net/83906438/buildlog_ubuntu-precise-i386.cowdancer_0.65_FAILEDTOBUILD.txt.gz > > > > This is because of incorrect link ordering: it puts libraries before the > > objects that use them rather than after. See: > > > > > > http://wiki.debian.org/ToolChain/DSOLinking#Only_link_with_needed_libraries > > > > The following patch fixes this. > > > > * Fix link order to list libraries after the objects that require them. > > * Use -pthread rather than -lpthread, since it should be a superset, it's > > what's recommended in pthread_create(3), and it isn't so sensitive to > > link order. > > Wow, the link order feels a bit backwards. Are you sure this isn't reversed?
Yes, I'm sure. This is how Unix linkers have behaved ever since I started working on Unix; it's just that GNU ld has historically been more tolerant than some others. However, this tolerance has a cost. Unix linkers traverse objects and libraries from left to right. Thus, the linker sees -ldl before it sees cowdancer.o. Traditionally, GNU ld inserted a DT_NEEDED reference to libdl.so upon seeing -ldl, regardless of whether it had yet seen any symbols that might be resolved using that library. However, this means that in practice many objects end up overlinked. This causes performance problems at startup; it causes safety problems because executables sometimes accidentally get linked against dependencies of the libraries they use which can result in multiple versions of the same library being linked into the same process when things change later; and it also means that we have to go through unnecessary library transitions. With --as-needed, the linker only inserts a DT_NEEDED reference if it satisfies an undefined symbol reference from an object it has seen up to that point. Over an entire distribution, this reduces run-time costs and improves safety, at the cost of needing to fix some build systems that have incorrectly relied on ld's traditional tolerant behaviour. Regards, -- Colin Watson [[email protected]] -- To UNSUBSCRIBE, email to [email protected] with a subject of "unsubscribe". Trouble? Contact [email protected]

