[Gllug] pimping my elf

Nix nix at esperi.org.uk
Sun Jun 18 11:50:43 UTC 2006


On Wed, 14 Jun 2006, Alex Sayle stated:
> it looks a bit like <somepath>/bar/<version>/{lib,include,share} so
> we can have multiple libbar's co-existing.

I do this, roughly, using GNU stow. epkg, DEPOT, STORE and other systems
do much the same (with ever-increasing degrees of flexibility and
byzantineness).

> For simplicity we then take bar/<version>/lib/libbar.so.<version> and
> install into a central LIB directory. For some historic reason when
> we do this the libraries are renamed to libbar-<version>.so.

The first part should be a matter of course, with every active thing in
the installed tree being symlinked into the stow tree (/usr/local or
whatever). Arrange for apps to look into the stow tree instead of the
installed tree for everything, and you're home free.

(Aside; KDE needs a tiny patch for this or its menus get all mangled.
So does AmaroK. Available on request; I'll push them upstream when I
get around to upgrading KDE from 3.$ANCIENT.)

But renaming the libraries is somewhere between dangerous and lunatic and
*really* shouldn't happen.

The transformations I apply to install-time trees pre-stowing are:

 - gzip manpages and transform the names in .so links in them (that's the
   groff .so command used as a sort of strange symlink/#include replacement,
   not shared libraries!)

 - gzip info pages and install-info them into the info/dir file

 - similar with XML and SGML catalogs

 - move certain things onto the root filesystem (which I don't manage with
   stow) and repoint symlinks to any shared libraries I so move

 - strip every binary with --strip-unneeded (note that `binary' here includes
   shared objects but does *not* include object files! Strip the object
   files in a gcc install and you've just wrecked your compiler)

 - eliminate the libtool dependency library stuff, which is only needed for 
   static libs (which I don't use):

[[ -d lib ]] && find lib -name "*.la" -print0 | xargs -0r sed -i 's/^dependency_libs='"'"'.*'"'"'$/dependency_libs='"''"'/; /^libdir=/s,packages\.bin/[^/]*/[^/]*/usr/,,'

 - zap .a files which have corresponding .so's (I'll never use the .a's)


Post-stowing, I run ldconfig, and scan for missing symbols or non-PIC
code in libraries (which stymie prelinking).


Note that at no point here are libraries hex-edited! The soname of a
library is part of its published ABI and should *not* be changed.  You
can rename the library all you like and ldconfig will create appropriate
symlinks for you if they're missing (although because those symlinks
aren't stowed, I'd recommend against it; it'll cause you problems when
next you upgrade when the symlinks break).

> this name change can be an issue and rather than going against the grain
> I'd like to get it working as is. So, here's the question, does anyone
> know a non hexedit or binary sed hackery way to change link targets  in a an elf binary.

You could do it with libelf, but it would be annoying. Among other
things, if the new name is longer than the old you may have quite a lot
of work to do if the DT_NEEDED tag value needs expanding.

There's never a need to do this unless the library doesn't bother to
maintain its sonames properly (and virtually all of them do), and by
doing this you *destroy* any chance of interoperability with other Linux
systems. ELF handles this stuff for you; don't make your life difficult
by shooting it in the foot.

I have ~1200 packages with libraries in on the systems I maintain with
GNU stow (the only nonstowed stuff on those systems outside of the root
filesystem is GNU libc). I've never *once* had to edit sonames. Sometimes
I have to create a temporary installation of just the shared library
parts of a package if its ABI is breaking and I want to maintain the
old library until dependent code is updated, but that's the most that's
necessary.

> 0x00000001 (NEEDED)                     Shared library: [libbar.so.4.2]
> 
> to
> 
> 0x00000001 (NEEDED)                     Shared library: [libbar-4.2.so]
> 
> with out re-linking the whole thing.
> 
> any marvellous ideas ?

libelf, and pray. Hard.

-- 
`Voting for any American political party is fundamentally
 incomprehensible.' --- Vadik
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list