Okay some time ago there was an article somewhere talking about the mythical –as-needed flag for GNU ld, that allows to link inside a binary only the actual libraries used by that binary. It shown up a lot of noise and lot of people tried to use it on Gentoo, with mixed results. The timeframe was the one of binutils 2.15.9x .
Today, I wanted to take another look to that, my own old report on that was not completely clean: we had known issues with GNOME-related packages, and KDE ones weren’t having that much impact without things like –dont-add-needed that was breaking badly a lot of libraries such as the ones related to gnupg (bad idea to use that flag without caring where it gets enabled… for unieject, you can use it, but many packages does not really behave well with that).
Okay, so what changed in the mean time? binutils 2.16 were released quite a few months ago, and 2.16.9x is now available (and I’m using it), so there’s that change first. GCC 4 is now final and almost stable for everyday use. But the reason I was tempted by –as-needed was to limit the quantity of software that was being broken by dbus changing soname and then breaking linking: pmount command does not use hal nor dbus, but it was broken, too (pmount-hal is another story, but I don’t use it), lot of libraries/plugins in k3b were linking to dbus also if it wasn’t probably needed, and so on. Using –as-needed, the amount of breakage could be limited. The speed improvement side-effect is not bad, anyway 🙂
I put it in LDFLAGS, thought on that a bit, and started merging simple applications: unieject, rtorrent, pmount… the result wasn’t so bad. I tried k3b that’s a lot more complex, and the result was interesting, a lot. It was able to drop a good deal of NEEDED lines in k3b executable: 13 vs 48. Seems like this new version of ld does have effect with KDE 🙂
The first problem came with vlc that was failing to find libfaad2, I fixed that in faad2 (without revbump, so if you want to use it, rebuild it by yourself after a sync, make sure it uses the patchset 3), and the configure finished right, but then ld was segfaulting when linking wxGTK. I put a filter in vlc ebuild to get rid of –as-needed when using wxwindows.
Of course, all this is unsupported and I take the pieces for my own breakage if something does not work anymore, so please don’t start filling bugs on bugzilla if you try this and something does not work. At least for my packages (but I think this would be true for everyone), patches to fix a package to support –as-needed are welcome. Fixes are always good 🙂
We’ll see how it continues this time…
Update: As it was reported in the comments, there’s already forum topic about the flag (and I actually knew of it, there’s also my reply there). It lists a series of applications that fails to build when using –as-needed. Some of them, like gtk2 (that i remember failing), speex or openjade/docbook-sgml-utils, seems to be working now, not sure if it’s because of fixed code in the apps, or binutils be bett
I’m currently trying a couple more I have installed in my system. The startup time for the applications I already rebuilt, also if they lost prelinking, dropped in a visible way. KMail above all, but also tvtime.
Some applications like tvtime also dropped completely the link (direct and indirect) on libSM and libICE.