Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 653586

Summary: app-misc/pax-utils: lddtree: Incomplete support for relative DT_RPATH / DT_RUNPATH
Product: Gentoo Linux Reporter: Arfrever Frehtes Taifersar Arahesis <arfrever.fta>
Component: Current packagesAssignee: SpanKY <vapier>
Status: RESOLVED FIXED    
Severity: normal CC: toolchain
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
Package list:
Runtime testing required: ---

Description Arfrever Frehtes Taifersar Arahesis 2018-04-20 01:51:14 UTC
$ mkdir -p /tmp/tests
$ cd /tmp/tests
$ mkdir dir
$ gcc -shared -fPIC -o libA.so -x c - < /dev/null
$ gcc -shared -fPIC -o dir/libB.so -x c - < /dev/null
$ gcc -o test1 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath, -Wl,-rpath,dir
$ gcc -o test2 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,. -Wl,-rpath,dir
$ gcc -o test3 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,dir/.. -Wl,-rpath,dir
$ gcc -o test4 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,'$ORIGIN' -Wl,-rpath,'$ORIGIN/dir'
$ gcc -o test5 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,'${ORIGIN}' -Wl,-rpath,'${ORIGIN}/dir'
$ gcc -o test6 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,'$ORIGIN/dir/..' -Wl,-rpath,'$ORIGIN/dir'
$ gcc -o test7 -x c - <<< "int main() {}" -L. -Ldir -lA -lB -Wl,-rpath,'${ORIGIN}/dir/..' -Wl,-rpath,'${ORIGIN}/dir'
$ 


DT_RUNPATH is set correctly:

$ scanelf -r test*
 TYPE   RPATH FILE 
ET_DYN :dir test1 
ET_DYN .:dir test2 
ET_DYN dir/..:dir test3 
ET_DYN $ORIGIN:$ORIGIN/dir test4 
ET_DYN ${ORIGIN}:${ORIGIN}/dir test5
ET_DYN $ORIGIN/dir/..:$ORIGIN/dir test6 
ET_DYN ${ORIGIN}/dir/..:${ORIGIN}/dir test7
$ 


All executables actually work:

$ ./test1
$ ./test2
$ ./test3
$ ./test4
$ ./test5
$ ./test6
$ ./test7
$ 


ldd tool (from sys-libs/glibc) finds libraries:

$ ldd test*
test1:
        linux-vdso.so.1 (0x00007ffcfad86000)
        libA.so (0x00007f349ae13000)
        libB.so => dir/libB.so (0x00007f349ac11000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f349a846000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f349b217000)
test2:
        linux-vdso.so.1 (0x00007ffed2344000)
        libA.so => ./libA.so (0x00007f639a872000)
        libB.so => dir/libB.so (0x00007f639a670000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f639a2a5000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f639ac76000)
test3:
        linux-vdso.so.1 (0x00007ffdc0d30000)
        libA.so => dir/../libA.so (0x00007f8146b1b000)
        libB.so => dir/libB.so (0x00007f8146919000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f814654e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f8146f1f000)
test4:
        linux-vdso.so.1 (0x00007ffc6f560000)
        libA.so => /tmp/tests/./libA.so (0x00007f2d1b9fe000)
        libB.so => /tmp/tests/./dir/libB.so (0x00007f2d1b7fc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2d1b431000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2d1be02000)
test5:
        linux-vdso.so.1 (0x00007ffcd198d000)
        libA.so => /tmp/tests/./libA.so (0x00007f0ef81b0000)
        libB.so => /tmp/tests/./dir/libB.so (0x00007f0ef7fae000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0ef7be3000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f0ef85b4000)
test6:
        linux-vdso.so.1 (0x00007ffde2ff3000)
        libA.so => /tmp/tests/./dir/../libA.so (0x00007fb9112bf000)
        libB.so => /tmp/tests/./dir/libB.so (0x00007fb9110bd000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fb910cf2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb9116c3000)
test7:
        linux-vdso.so.1 (0x00007fff8f190000)
        libA.so => /tmp/tests/./dir/../libA.so (0x00007f4749724000)
        libB.so => /tmp/tests/./dir/libB.so (0x00007f4749522000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f4749157000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4749b28000)
$


Following results with app-misc/pax-utils-1.2.3-r1:


lddtree (Python implementation, lddtree.py in pax-utils repository) supports '' (empty path), but not '.', supports '$ORIGIN', but not '${ORIGIN}' and does not support other relative paths:

$ lddtree test*
test1 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => /tmp/tests/libA.so
    libB.so => None
    libc.so.6 => /lib64/libc.so.6
test2 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => None
    libB.so => None
    libc.so.6 => /lib64/libc.so.6
test3 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => None
    libB.so => None
    libc.so.6 => /lib64/libc.so.6
test4 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => /tmp/tests/libA.so
    libB.so => /tmp/tests/dir/libB.so
    libc.so.6 => /lib64/libc.so.6
test5 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => None
    libB.so => None
    libc.so.6 => /lib64/libc.so.6
test6 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => /tmp/tests/libA.so
    libB.so => /tmp/tests/dir/libB.so
    libc.so.6 => /lib64/libc.so.6
test7 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => None
    libB.so => None
    libc.so.6 => /lib64/libc.so.6
$ 


lddtree (BASH implementation, lddtree.sh in pax-utils repository) does not support '' (empty path), supports '.', supports alone '$ORIGIN', but not '$ORIGIN/...', does not support '${ORIGIN}':

lddtree test*
test1 => ./test1 (interpreter => /lib64/ld-linux-x86-64.so.2)
scanelf: rpath_security_checks(): Security problem NULL DT_RUNPATH in ./test1
scanelf: rpath_security_checks(): Maybe? sec problem with DT_RUNPATH='dir' in ./test1
    libA.so => not found
scanelf: rpath_security_checks(): Security problem NULL DT_RUNPATH in ./test1
scanelf: rpath_security_checks(): Maybe? sec problem with DT_RUNPATH='dir' in ./test1
    libB.so => dir/libB.so
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test2 => ./test2 (interpreter => /lib64/ld-linux-x86-64.so.2)
scanelf: rpath_security_checks(): Security problem with relative DT_RUNPATH '.:dir' in ./test2
scanelf: rpath_security_checks(): Maybe? sec problem with DT_RUNPATH='dir' in ./test2
    libA.so => ./libA.so
    libB.so => dir/libB.so
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test3 => ./test3 (interpreter => /lib64/ld-linux-x86-64.so.2)
scanelf: rpath_security_checks(): Maybe? sec problem with DT_RUNPATH='dir/..:dir' in ./test3
scanelf: rpath_security_checks(): Maybe? sec problem with DT_RUNPATH='dir' in ./test3
    libA.so => dir/../libA.so
    libB.so => dir/libB.so
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test4 => ./test4 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => ./libA.so
    libB.so => not found
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test5 => ./test5 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => not found
    libB.so => not found
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test6 => ./test6 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => ./dir/../libA.so
    libB.so => not found
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
test7 => ./test7 (interpreter => /lib64/ld-linux-x86-64.so.2)
    libA.so => not found
    libB.so => not found
    libc.so.6 => /lib64/libc.so.6
        ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2
$
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2018-04-20 06:12:01 UTC

*** This bug has been marked as a duplicate of bug 589434 ***
Comment 2 Arfrever Frehtes Taifersar Arahesis 2018-04-20 08:59:53 UTC
All problems in lddtree.py and at least one problem lddtree.sh are unrelated to scanelf.
Comment 3 Larry the Git Cow gentoo-dev 2021-04-16 15:08:23 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=8d2fa4fe36cf525bc5a16ec176d0fbe79cfab8e6

commit 8d2fa4fe36cf525bc5a16ec176d0fbe79cfab8e6
Author:     Mike Frysinger <vapier@chromium.org>
AuthorDate: 2021-04-16 15:06:08 +0000
Commit:     Mike Frysinger <vapier@gentoo.org>
CommitDate: 2021-04-16 15:06:08 +0000

    lddtree: add --cwd option
    
    Rather than rely on ambient environmental settings (the cwd), allow
    users to override the cwd explicitly when processing paths.
    
    Bug: https://bugs.gentoo.org/653586
    Signed-off-by: Mike Frysinger <vapier@gentoo.org>

 lddtree.py | 50 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=080a59e801e121ebadc3e1e170e57ca27de15876

commit 080a59e801e121ebadc3e1e170e57ca27de15876
Author:     Mike Frysinger <vapier@chromium.org>
AuthorDate: 2021-04-16 14:49:56 +0000
Commit:     Mike Frysinger <vapier@gentoo.org>
CommitDate: 2021-04-16 14:49:56 +0000

    lddtree: handle relative ldpaths
    
    Tweak the ldpath logic to handle all relative paths relative to the
    cwd instead of the root.  Such ELFs are uncommon and weird, but not
    invalid, so might as well.
    
    Bug: https://bugs.gentoo.org/653586
    Signed-off-by: Mike Frysinger <vapier@gentoo.org>

 lddtree.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=583af0f01ece9c63042a8a12bac11aaa53faa19b

commit 583af0f01ece9c63042a8a12bac11aaa53faa19b
Author:     Mike Frysinger <vapier@chromium.org>
AuthorDate: 2021-04-16 14:37:46 +0000
Commit:     Mike Frysinger <vapier@gentoo.org>
CommitDate: 2021-04-16 14:37:46 +0000

    lddtree: handle ${ORIGIN} like $ORIGIN
    
    Bug: https://bugs.gentoo.org/653586
    Signed-off-by: Mike Frysinger <vapier@gentoo.org>

 lddtree.py | 2 ++
 lddtree.sh | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
Comment 4 SpanKY gentoo-dev 2021-04-16 15:09:30 UTC
lddtree.py should handle ${ORIGIN} & relative paths now

i made a minor fix for ${ORIGIN} to lddtree.sh, but not really planning on investing a lot in that file.  feel free to attach a patch if you think it'd be easy and we can review, but eh.