On Mon, 22 Jun 2015 16:13:57 +0000 (UTC) Grant Edwards <grant.b.edwa...@gmail.com> wrote:
> Is there any way to add a library to the list of libraries required by > an ELF dynamically linked executable? > > I have an executable (let's call it "foo") which was written and built > by somebody else [I don't have sources]. It requires the librt to run > on one particular platform, but librt isn't in the exeuctable's list > of libraries. [I'll skip the story of how it ended up this way. It > will be fixed with the next version of that application.] > > # foo > foo: can't resolve symbol 'shm_open' > > If I run it like this, it's fine: > > # LD_PRELOAD=/lib/librt.so.0 foo > > Is there any way to fix the ELF executable file to add librt.so.0 to > its list of libraries? > > I'm aware I can create a shell script that does this: > > #!/bin/sh > export LD_PRELOAD=/lib/librt.so.0 > exec foo > > What I'm wondering about is whether there is a way to fix the ELF > executable file itself so as to add librt.so.0 to its list of shared > libraries. I've found chrpath(1), but it only changes the search path > used to look for libraires, not the list of libraries themselves. > Perhaps elfsh[1] would do the trick. There's an example[2] that demonstrates editing the dynamic section, so you might be able to add an entry that way, though it's not as simple as an "addneeded" command. Although it sounds[3] like elfsh might not be very stable. Actually, scratch all that, NixOS's patchelf command[4] supports editing NEEDED entries now, that'll be the easiest way. Cheers, Bryan [1] http://www.eresi-project.org/wiki/TheELFsh [2] http://www.eresi-project.org/browser/trunk/testsuite/elf/elf-tests.esh [3] https://stackoverflow.com/a/2287737 [4] https://github.com/NixOS/patchelf
pgpPTP2uvQQRv.pgp
Description: OpenPGP digital signature