RPATH不再受间接依赖性的尊重

时间:2017-12-10 18:24:23

标签: linux gcc ld glibc ldd

我已经从Ubuntu 16.04升级到Ubuntu 17.10,这让我感动:

  • gcc:从gcc-5.4.0gcc-7.2.0
  • ld:从ld-2.26.1ld-2.29.1
  • glibc:从2.32.6

我正在构建一个带有硬编码RUNPATH的二进制文件,指向某些供应商提供的共享库的位置。

$ readelf -d /home/steve/src/krx/tests/krx.test | grep RUNPATH
 0x000000000000001d (RUNPATH)        Library runpath: [../library]

Ubuntu 16.04 上,RUNPATH允许我们找到这些库。

$ ldd ./krx.test
    ...
    libinisafeNet.so => ../library/libinisafeNet.so (0x00007f35c7754000)
    libiniCore.so => ../library/libiniCore.so (0x00007f35c5bea000)
    libiniPKI.so => ../library/libiniPKI.so (0x00007f35c5952000)
    libiniCrypto.so => ../library/libiniCrypto.so (0x00007f35c56e6000)

Ubuntu 17.10 上,它不再有效

$ ldd ./krx.test
    ...
    libinisafeNet.so => ../library/libinisafeNet.so (0x00007fb4acc38000)
    libiniCore.so => not found
    libiniPKI.so => not found
    libiniCrypto.so => not found

设置LD_LIBRARY_PATH 允许找到库

$ export LD_LIBRARY_PATH=../library
$ ldd ./krx.test 
    ...
    libinisafeNet.so => ../library/libinisafeNet.so (0x00007fa787659000)
    libiniCore.so => ../library/libiniCore.so (0x00007fa785a86000)
    libiniPKI.so => ../library/libiniPKI.so (0x00007fa7857ee000)
    libiniCrypto.so => ../library/libiniCrypto.so (0x00007fa785582000)

LD_DEBUG适用于Ubuntu 16.04

我设置LD_DEBUG=all并对我的二进制文件运行ldd

以下是libiniCore.so的摘录:

 30438:     file=libiniCore.so [0];  needed by ../library/libinisafeNet.so [0]
 30438:     find library=libiniCore.so [0]; searching
 30438:      search path=../library/tls/x86_64:../library/tls:../library/x86_64:../library          (RPATH from file ./krx.test)
 30438:       trying file=../library/tls/x86_64/libiniCore.so
 30438:       trying file=../library/tls/libiniCore.so
 30438:       trying file=../library/x86_64/libiniCore.so
 30438:       trying file=../library/libiniCore.so

图书馆已成功找到,从search path部分可以看出,它正在使用 RPATH from file ./krx.test

对于Ubuntu 17.10

LD_DEBUG

我设置LD_DEBUG=all并对我的二进制文件运行ldd

以下是libiniCore.so的摘录:(现在使用系统搜索路径,而不是krx.test RPATH

 20027:     file=libiniCore.so [0];  needed by ../library/libinisafeNet.so [0]
 20027:     find library=libiniCore.so [0]; searching
 20027:      search cache=/etc/ld.so.cache
 20027:      search path=/lib/x86_64-linux-gnu/tls/haswell/x86_64:/lib/x86_64-linux-gnu/tls/haswell:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls:/lib/x86_64-linux-gnu/haswell/x86_64:/lib/x86_64-linux-gnu/haswell:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64:/usr/lib/x86_64-linux-gnu/tls/haswell:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-gnu/haswell/x86_64:/usr/lib/x86_64-linux-gnu/haswell:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/haswell/x86_64:/lib/tls/haswell:/lib/tls/x86_64:/lib/tls:/lib/haswell/x86_64:/lib/haswell:/lib/x86_64:/lib:/usr/lib/tls/haswell/x86_64:/usr/lib/tls/haswell:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/haswell/x86_64:/usr/lib/haswell:/usr/lib/x86_64:/usr/lib            (system search path)
 20027:       trying file=/lib/x86_64-linux-gnu/tls/haswell/x86_64/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/tls/haswell/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/tls/x86_64/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/tls/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/haswell/x86_64/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/haswell/libiniCore.so
 20027:       trying file=/lib/x86_64-linux-gnu/x86_64/libiniCore.so
 ...          ...
 20027:       trying file=/lib/x86_64/libiniCore.so
 20027:       trying file=/lib/libiniCore.so
 20027:       trying file=/usr/lib/tls/haswell/x86_64/libiniCore.so
 20027:       trying file=/usr/lib/tls/haswell/libiniCore.so
 20027:       trying file=/usr/lib/tls/x86_64/libiniCore.so
 20027:       trying file=/usr/lib/tls/libiniCore.so
 20027:       trying file=/usr/lib/haswell/x86_64/libiniCore.so
 20027:       trying file=/usr/lib/haswell/libiniCore.so
 20027:       trying file=/usr/lib/x86_64/libiniCore.so
 20027:       trying file=/usr/lib/libiniCore.so

因此ld的行为似乎已发生变化,因为它是间接依赖krx.test - > libinisafeNet.so - > libiniCore.so)不再使用RPATH krx.test

问题:

  • 这是回归吗?
  • 解决这个问题的唯一方法(不更新ld.so.conf)也可以在我的共享库上设置RPATH吗?
  • 有没有办法在我的二进制文件上设置RPATH,以便它可以找到间接依赖项?

0 个答案:

没有答案