This Time Self-Hosted
dark mode light mode Search

Why can’t we use –as-needed on Gentoo/FreeBSD?

Gentoo/FreeBSD logo by Marius Morawski

Here it is again one of my informative blog posts, for future memento and for asking comments about this.

Yesterday I was talking yesterday with drizzt about --as-needed having trouble on Gentoo/FreeBSD, I tried, and I’ve seen that on 2.17 it worked fine. So I thought with myself “Why don’t enable it?” and so I did..

The first package I merged was a KDE theme, and it didn’t find Qt. I tried another and again the same problem, so I decided looking at the problem, and here it is the description.

The -pthread flag used to link against libpthread on Linux and FreeBSD, has a particular meaning on FreeBSD. Basically, if the result is an executable is added to the NEEDED lines, but when generating a shared object, that is not added.

One might think of a GCC bug, either the Gentoo one, or in general. But actually, there’s a reason for that. There are more than one pthread implementation in FreeBSD: one can use -lthr to use libthr threads rather than pthread. When using -pthread option, no library is linked when creating a shared object, so that when one create a final executable, that might come out of a totally another package, the threading library can be chosen freely. Unfortunately, this entirely breaks when using --as-needed.

So, for now, I have to say that --as-needed is not supposed to work on Gentoo/FreeBSD, until I can find a way to work this around. The easy part would be to use -Wl,--no-as-needed -pthread -Wl,--as-needed as PTHREAD_LIBS, but I don’t think we ever planned on adding support for that anytime soon. Sigh.

Then there’s the other trouble, with the non-linked libraries in freebsd-lib due to the way they are built in standard FreeBSD (there aren’t the deps built at the time yet).

I suppose that adding support for --as-needed on Gentoo/FreeBSD would be a major hassle, and now I understand why KDE decided not to enable it on FreeBSD by default.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.