Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot force rpath #94

Closed
mknln opened this issue Apr 15, 2016 · 1 comment · Fixed by #137
Closed

Cannot force rpath #94

mknln opened this issue Apr 15, 2016 · 1 comment · Fixed by #137

Comments

@mknln
Copy link

mknln commented Apr 15, 2016

I'm having trouble setting the RPATH on a binary when it already has a RUNPATH, even when the --force-rpath option is employed. Test case:

cp `which ls` .
readelf -d ./ls | egrep -i "runpath|rpath"

Displays nothing, as ls by default appears to have no rpath or runpath.

patchelf --set-rpath ~/libs ./ls
readelf -d ./ls | egrep -i "runpath|rpath"

Now it displays 0x000000000000001d (RUNPATH) Library runpath: [/home/mpn/libs]. OK, fine!

Next do:

patchelf --force-rpath --set-rpath ~/libs ./ls
readelf -d ./ls | egrep -i "runpath|rpath"

Expected result: It will display an RPATH for the binary
Actual result: It still displays only a RUNPATH for the binary

My current workaround has been to delete the existing RUNPATH using chrpath -d (using --set-rpath "" with patchelf doesn't appear to do it, as that looks rather to set RUNPATH to an empty string instead), and then to use --force-rpath with patchelf. Force-rpath does appear to work when there is no RUNPATH present.

@speleo3
Copy link
Contributor

speleo3 commented Oct 20, 2017

I just ran into the same issue. The behavior of --force-rpath feels very random. I would expect that the flag doesn't depend at all on the previous values of RUNPATH or RPATH, namely:

  • without --force-rpath: modified file has RUNPATH
  • with --force-rpath: modified file has RPATH

But instead, I get this:

patchelf --remove-rpath
patchelf --set-rpath foo
  RUNPATH              foo
patchelf --force-rpath --set-rpath foo
  RUNPATH              foo                        <-- unexpected (expect RPATH)
patchelf --force-rpath --set-rpath bar
  RUNPATH              bar                        <-- unexpected (expect RPATH)
patchelf --remove-rpath
patchelf --force-rpath --set-rpath foo
  RPATH                foo
patchelf --set-rpath foo
  RPATH                foo                        <-- unexpected (expect RUNPATH)
patchelf --set-rpath bar
  RUNPATH              bar

The outcome is only predictable after --remove-rpath.

Output generated with this script:

#!/bin/bash
doit() {
    echo patchelf $*
    filename=libm.so.6
    patchelf $* $filename
    objdump -x $filename | grep PATH
}
doit --remove-rpath
doit --set-rpath foo
doit --force-rpath --set-rpath foo
doit --force-rpath --set-rpath bar
doit --remove-rpath
doit --force-rpath --set-rpath foo
doit --set-rpath foo
doit --set-rpath bar

sergiusens added a commit to sergiusens/snapcraft that referenced this issue Apr 18, 2018
Given NixOS/patchelf#94 we may find ourselves
in a situation where given an elf file with an existing RUNPATH, a
proper RPATH may not be set.

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
sergiusens added a commit to sergiusens/snapcraft that referenced this issue Apr 18, 2018
Given NixOS/patchelf#94 we may find ourselves
in a situation where given an elf file with an existing RUNPATH, a
proper RPATH may not be set.

Resolve canonical#2071

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
sergiusens added a commit to canonical/snapcraft that referenced this issue Apr 18, 2018
Given NixOS/patchelf#94 we may find ourselves
in a situation where given an elf file with an existing RUNPATH, a
proper RPATH may not be set.

Resolve #2071

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants