Issue
ldd fails to find a dll that is present in the rpath definition. Some others libraries are found (check /./../lib/*)
Here the output of ldd (we can see that 2 dlls are found in ../lib, but not libexpat.so.0):
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# ldd ./ade_admin
linux-vdso.so.1 => (0x00007ffeb9796000)
libadeversion.so => /DT/local/ADE-trunk4/build-ADE-Desktop-efault/bin/./../lib/libadeversion.so
(0x00007f31abaef000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f31ab8ca000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
(0x00007f31ab6ac000)
libaprutil-1.so.0 => /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/**./../lib/libaprutil-1.so.0**
(0x00007f31ab58c000)
libapr-1.so.0 => /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/**./../lib/libapr-1.so.0**
(0x00007f31ab460000)
libavahi-client.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007f31ab24d000)
libavahi-common.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007f31ab041000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f31aae3d000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(0x00007f31aaab5000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f31aa7ac000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f31aa595000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f31aa1cc000)
/lib64/ld-linux-x86-64.so.2 (0x0000560d30a76000)
**libexpat.so.0 => not found**
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1
(0x00007f31a9fc4000) [...]
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# file ../lib/libexpat.so.0
../lib/libexpat.so.0: ELF 64-bit LSB shared
object, x86-64, version 1 (SYSV), dynamically linked,
BuildID[sha1]=762de704943d03033d01a9725216d6b05d0740f5, not stripped
Here the rpath:
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin#
readelf -d ade_admin | grep 'R.*PATH' 16: 0x000000000000001d (RUNPATH)
Library runpath: **[${ORIGIN}/../lib]**
Now the killer fact: It works with clang 3.8, but fails with gcc 6.3 (ubuntu 16.10)
Obviously adding an LD_LIBRARY_PATH=../lib make it works again, but the goal of rpath was to avoid to set it
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# export **LD_LIBRARY_PATH=../lib**
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# ldd ./ade_admin
linux-vdso.so.1 => (0x00007ffea23b6000)
libadeversion.so => ../lib/libadeversion.so (0x00007f78c6474000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f78c624f000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f78c6031000)
libaprutil-1.so.0 => ../lib/libaprutil-1.so.0 (0x00007f78c5f11000)
libapr-1.so.0 => ../lib/libapr-1.so.0 (0x00007f78c5de5000)
libavahi-client.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007f78c5bd2000)
libavahi-common.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007f78c59c6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f78c57c2000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f78c543a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f78c5131000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f78c4f1a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f78c4b51000)
/lib64/ld-linux-x86-64.so.2 (0x0000559fdceab000)
libexpat.so.0 => .**./lib/libexpat.so.0** (0x00007f78c492a000)
Any idea ?
Solution
I just find the explanation: clang put in the [NEEDED] section of the elf binary ALL libraries (even libraries not explicitely included by myself, but referenced by the [NEEDED] section of the library that I include
example from gcc:
readelf -d my_prog
Dynamic section at offset 0x9cb548 contains 46 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libadeversion.so]
0x0000000000000001 (NEEDED) Shared library: [libuuid.so.1]
0x0000000000000001 (NEEDED) Shared library: [libsqlite3.so]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libaprutil-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libapr-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libavahi-client.so.3]
0x0000000000000001 (NEEDED) Shared library: [libavahi-common.so.3]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libaio.so.1]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [lib_adm64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_dict64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_rdm64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_dbr64.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [${ORIGIN}/../lib/:$ORIGIN/../lib/:../lib/]
from clang:
readelf -d my_prog
Dynamic section at offset 0xa7bae8 contains 54 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libadeversion.so]
0x0000000000000001 (NEEDED) Shared library: [libuuid.so.1]
0x0000000000000001 (NEEDED) Shared library: [libsqlite3.so]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libaprutil-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libexpat.so.0]
0x0000000000000001 (NEEDED) Shared library: [libapr-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libavahi-client.so.3]
0x0000000000000001 (NEEDED) Shared library: [libavahi-common.so.3]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libaio.so.1]
0x0000000000000001 (NEEDED) Shared library: [libcrypt.so.1]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [lib_adm64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_dict64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_rdm64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_rpc64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_sql64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_rdbc64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_rm64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_ncp64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_cmp64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_repfltr64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_expat64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_cncp64.so]
0x0000000000000001 (NEEDED) Shared library: [lib_dbr64.so]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000001d (RUNPATH) Library runpath: [${ORIGIN}/../lib/:$ORIGIN/../lib/:../lib/]
And one dll include the missing one libexpat:
readelf -d ../lib/libaprutil-1.so.0
Dynamic section at offset 0x1e698 contains 29 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: **[libexpat.so.0]**
0x0000000000000001 (NEEDED) Shared library: [libapr-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libuuid.so.1]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libcrypt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000e (SONAME) Library soname: [libaprutil-1.so.0]
but RUNPATH is only used by the binary not by the dll (that can have is own RUNPATH too).
2 solutions: - add a RUNPATH in libaprutil-1.so.0 to force to include library from "." - add explicitely all missing dll in my build
Hope it help
Answered By - rafal98 Answer Checked By - Willingham (WPSolving Volunteer)