[英]ldd shows .so not found but RUNPATH contains the lib
I'm trying to get some binaries running on NixOS, and I ran into a weird situation when trying to get ldd
to find libpython2.7.so.1.0
and other libs.我试图让一些二进制文件在 NixOS 上运行,当我试图让
ldd
找到libpython2.7.so.1.0
和其他库时遇到了一个奇怪的情况。
$ ldd lldb
./lldb: /nix/store/5rjfisjzz6vgwmgf7zx25yd9p6rfs0zy-ncurses-6.2-abi5-compat/lib/libtinfo.so.5: no version information available (required by ./lldb)
./lldb: /nix/store/5rjfisjzz6vgwmgf7zx25yd9p6rfs0zy-ncurses-6.2-abi5-compat/lib/libtinfo.so.5: no version information available (required by /nix/store/nn8pr7xzam0rz7fq95x9dpi087xazsnv-theos/share/theos/toolchain/linux/iphone/usr/bin/./../lib/liblldb.so.10git)
linux-vdso.so.1 (0x00007ffd57b80000)
libpthread.so.0 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/libpthread.so.0 (0x00007f921e821000)
liblldb.so.10git => /nix/store/nn8pr7xzam0rz7fq95x9dpi087xazsnv-theos/share/theos/toolchain/linux/iphone/usr/bin/./../lib/liblldb.so.10git (0x00007f9215c3c000)
libz.so.1 => /nix/store/1l4r0r4ab3v3a3ppir4jwiah3icalk9d-zlib-1.2.11/lib/libz.so.1 (0x00007f9215c1f000)
librt.so.1 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/librt.so.1 (0x00007f9215c12000)
libdl.so.2 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/libdl.so.2 (0x00007f9215c0d000)
libtinfo.so.5 => /nix/store/5rjfisjzz6vgwmgf7zx25yd9p6rfs0zy-ncurses-6.2-abi5-compat/lib/libtinfo.so.5 (0x00007f9215ba7000)
libm.so.6 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/libm.so.6 (0x00007f9215a66000)
libstdc++.so.6 => /nix/store/c9f15p1kwm0mw5p13wsnvd1ixrhbhb12-gcc-10.3.0-lib/lib/libstdc++.so.6 (0x00007f9215891000)
libgcc_s.so.1 => /nix/store/c9f15p1kwm0mw5p13wsnvd1ixrhbhb12-gcc-10.3.0-lib/lib/libgcc_s.so.1 (0x00007f9215875000)
libc.so.6 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/libc.so.6 (0x00007f92156b0000)
/nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/ld-linux-x86-64.so.2 => /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib64/ld-linux-x86-64.so.2 (0x00007f921e843000)
libpython2.7.so.1.0 => not found
libncurses.so.5 => not found
libform.so.5 => not found
libpanel.so.5 => not found
libuuid.so.1 => not found
libedit.so.2 => not found
libxml2.so.2 => not found
There are quite a few missing, but let's focus on libpython2.7.so.1.0
.有很多缺失,但让我们关注
libpython2.7.so.1.0
。 When we check the RUNPATH
of ld64
,当我们检查
ld64
的RUNPATH
时,
$ readelf -d ld64 | rg RUNPATH
0x000000000000001d (RUNPATH) Library runpath: [/nix/store/c9f15p1kwm0mw5p13wsnvd1ixrhbhb12-gcc-10.3.0-lib/lib:/nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib:/nix/store/xvyzi7cr0icnyavi5pm9rywjc4d8l7sx-libedit-20210714-3.1/lib:/nix/store/yxflij8cg4fgnzqmda91jx4d94jvkjf5-util-linux-2.37.2-lib/lib:/nix/store/370lxynzkmwrk8685jx9p2vgh7h0xp2h-libxml2-2.9.12/lib:/nix/store/5rjfisjzz6vgwmgf7zx25yd9p6rfs0zy-ncurses-6.2-abi5-compat/lib:/nix/store/nvx0l614cv661i5zz6w3j3y2w1xzppv1-python-2.7.18/lib:/nix/store/7344a20iqaja6i2qdz2xrgzy28rgnz5p-util-linux-2.37.2-lib/lib:/nix/store/1l4r0r4ab3v3a3ppir4jwiah3icalk9d-zlib-1.2.11/lib:$ORIGIN/../lib]
it contains /nix/store/nvx0l614cv661i5zz6w3j3y2w1xzppv1-python-2.7.18/lib
, which has our desired lib,它包含
/nix/store/nvx0l614cv661i5zz6w3j3y2w1xzppv1-python-2.7.18/lib
,其中包含我们想要的库,
$ file /nix/store/nvx0l614cv661i5zz6w3j3y2w1xzppv1-python-2.7.18/lib/libpython2.7.so.1.0
/nix/store/nvx0l614cv661i5zz6w3j3y2w1xzppv1-python-2.7.18/lib/libpython2.7.so.1.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
I'm not sure how this is possible.我不确定这怎么可能。 The executable is also 64-bit, as we can see here:
可执行文件也是 64 位的,我们可以在这里看到:
$ file lldb
lldb: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/z56jcx3j1gfyk4sv7g8iaan0ssbdkhz1-glibc-2.33-56/lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, not stripped
I'm not sure how this is possible.
我不确定这怎么可能。
There is a big difference between RUNPATH
and RPATH
: the former applies only to the binary itself (in this case, only to the lldb
binary), the latter applies to the binary and all its dependencies . RUNPATH
和RPATH
之间有很大的区别:前者仅适用于二进制文件本身(在这种情况下,仅适用于lldb
二进制文件),后者适用于二进制文件及其所有依赖项。
Effectively using RUNPATH
forces all binaries participating in the (dynamic) link to be linked correctly (to specify their own RUNPATH
so that every one of their (recursive) dependencies is found).有效地使用
RUNPATH
会强制所有参与(动态)链接的二进制文件正确链接(指定它们自己的RUNPATH
以便找到它们的每一个(递归)依赖项)。
What you observe is possible if:如果出现以下情况,您观察到的情况是可能的:
lldb
does not itself depend on libpython.2.7.so.1.0
and lldb
本身不依赖于libpython.2.7.so.1.0
和lldb
s dependencies does depend on on libpython.2.7.so.1.0
and lldb
的依赖项之一确实依赖于libpython.2.7.so.1.0
和RUNPATH
in which libpython.2.7.so.1.0
can be found.libpython.2.7.so.1.0
的RUNPATH
。 You can verify that 1) is true with readelf -d./lldb | grep libpython
您可以使用
readelf -d./lldb | grep libpython
验证 1) 是否正确。 readelf -d./lldb | grep libpython
(I predict there will be no output). readelf -d./lldb | grep libpython
(我预测不会有输出)。
If 1) is true, we know that 2 is true because libpython
shows up in ldd
output.如果 1) 为真,我们知道 2 为真,因为
libpython
出现在ldd
output 中。 You can find which of lldb
s direct dependencies this is by going through them one by one (you can see them in the output from readelf -d lldb | grep NEEDED
).您可以通过一一浏览它们来找到
lldb
的哪些直接依赖项(您可以在readelf -d lldb | grep NEEDED
的 output 中看到它们)。
Once you found a dependency which needs libpython
, you can confirm 3) by using readelf -d $direct_dependency | grep R.*PATH
找到需要
libpython
的依赖项后,您可以使用readelf -d $direct_dependency | grep R.*PATH
确认 3) readelf -d $direct_dependency | grep R.*PATH
. readelf -d $direct_dependency | grep R.*PATH
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.