public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
From: Bryan Gardiner <bog@khumba.net>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] [OT] How to add library to dynamically linked executable?
Date: Mon, 22 Jun 2015 10:34:50 -0700	[thread overview]
Message-ID: <20150622103450.61931ae2@mion> (raw)
In-Reply-To: <mm9c85$tre$1@ger.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1850 bytes --]

On Mon, 22 Jun 2015 16:13:57 +0000 (UTC)
Grant Edwards <grant.b.edwards@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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

  parent reply	other threads:[~2015-06-22 17:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-22 16:13 [gentoo-user] [OT] How to add library to dynamically linked executable? Grant Edwards
2015-06-22 17:16 ` Matti Nykyri
2015-06-22 23:57   ` [gentoo-user] " walt
2015-06-23  0:31     ` Grant Edwards
2015-06-22 17:34 ` Bryan Gardiner [this message]
2015-06-22 18:59   ` Grant Edwards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150622103450.61931ae2@mion \
    --to=bog@khumba.net \
    --cc=gentoo-user@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox