The thing I like most about Gentoo is the extraordinary flexibility that portage allows to make a system the way you want. Every once in awhile, I find something annoying however (this happens on every operating system, you’re hearing about this one because it was just the most recent). Today’s case in point: I found that several things depending on libselinux.so.1 despite my having “-selinux” in my global USE flags, and selinux disabled in the kernel. One of the packages that depends on that library is coreutils (which includes mv, cp, ln, and many other things you can’t afford to be without)
How did this happen? Because my /var/lib/portage/world file has a lot of packages in it that don’t really need to be there (they should be pulled in as dependancies of packages I do want, not in the way I have them.) When I was migrating to this box, instead of just looking at the few hundred packages in world, I grabbed a list of everything I’d compiled, and used that to build my new box. One result of that is that sys-libs/libselinux got compiled. (At least, I think that’s how it happened.) I noticed but didn’t think it was going to be a problem. However, for some ebuilds (coreutils being the most important to me), if the selinux header files are installed on the box, the configure script detects files like /usr/include/selinux/flask.h and proceeds to include selinux support. Then you will find that /bin/cp and many other critical utilities are linked against libselinux.so.1, so you can’t remove the sys-libs/libselinux, and since the USE flag has no effect other than changing RDEPEND in the ebuild, you’re stuck. Catch-22, almost.
Today I finally resolved to fix this, because I got annoyed, and because sys-libs/libselinux is hard-masked after my latest sync (as a result of the sync and having to update my profile with eselect).
The first part, fixing coreutils is pretty easy:
euse -D selinux
mv /usr/include/selinux /usr/include/selinux-save
emerge -av coreutils
emerge -C libselinux
rm -r /usr/include/selinux-save
Unfortunately, after that… you are still stuck. The coreutils will work, but I was left with a number of packages that revdep-rebuild reports as missing libselinux.so.1… furthermore they all die when trying to link against libselinux:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lselinux
Ah, portage, why are you so cruel to me? The above example is from gnome-terminal. Good thing I still use xterm.
Note: the next part could help, but it’s far easier to use lafilefixer these days.
So, what to do? I’m not kidding, this is basically it, in one line form:
find /usr/lib64 -name '*.la' -print | xargs grep selinux | cut -f1 -d: | sed -e 's#^./##g' | xargs equery b | awk '{print "="$1}' | sort -u | xargs emerge
Built that up a command at a time once I realized that the *.la files still contained references to the libselinux (-lselinux). Basically, it searches for all the .la files that contain references to selinux. .la files are just text files that control the linking process, either as part of libtool or the compile-time linker. My command above just uses some rather lame shell tricks to run emerge against all the packages those files belong too.
Even after that was complete, I still had libnss3.so.12 breakage to contend with, but at least revdep-rebuild was working at that point (not breaking on every ebuild it found missing libselinux.so.1). Frustrating.
I hope this saves someone some damn time, somewhere.