如何查看一个动态链接库中的依赖的其他动态链接库是绝对地址引用还是名字引用?

╰─➤  ldd libx264-2881b7ff.so.164                        
        linux-vdso.so.1 (0x00007fff1bec0000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9f37919000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9f37d5c000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9f37d57000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9f37600000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9f37d77000)

比如上面的输出,哪些是「绝对」,哪些是「相对」呢?

我觉得 /lib64/ld-linux-x86-64.so.2 (0x00007f9f37d77000) 是绝对

linux-vdso.so.1 (0x00007fff1bec0000) 是相对

但是类似 libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9f37d5c000) 这样的算绝对还是相对引用呢?这里的 => 表示什么含义呢?


我有一个问题,就是「如果没有 / ,那么就按找一个特定的方式在在磁盘上寻找这个文件。这个时候,ldd 会用 => 显示寻找的结果。」,我安装了一个 pyav,通过 pip install av 安装,然后我查看 av 的一个动态链接库

ldd _core.cpython-310-x86_64-linux-gnu.so ,发现这个动态链接库里面的 => 都是指向 /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs 里面的某个文件,我不清楚这个「特定的方式」是什么?

(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av  
╰─➤  ldd _core.cpython-310-x86_64-linux-gnu.so                                    
        linux-vdso.so.1 (0x00007ffc8db53000)
        libavformat-20d4e1d0.so.59.27.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000)
        libavcodec-8a88085f.so.59.37.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavcodec-8a88085f.so.59.37.100 (0x00007fcffff37000)
        libavdevice-ed40abdd.so.59.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavdevice-ed40abdd.so.59.7.100 (0x00007fcffff18000)
        libavutil-1701948d.so.57.28.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavutil-1701948d.so.57.28.100 (0x00007fcfffd3a000)
        libavfilter-2d5314ec.so.8.44.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavfilter-2d5314ec.so.8.44.100 (0x00007fcfff8e9000)
        libswscale-a6aee226.so.6.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libswscale-a6aee226.so.6.7.100 (0x00007fcfff846000)
        libswresample-b868a3ce.so.4.7.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libswresample-b868a3ce.so.4.7.100 (0x00007fcfff824000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcfff7f5000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcfff603000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcfff4b4000)
        libxml2-47a785fa.so.2.9.13 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxml2-47a785fa.so.2.9.13 (0x00007fcfff328000)
        libbluray-69850b93.so.2.1.2 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libbluray-69850b93.so.2.1.2 (0x00007fcfff2d3000)
        libgmp-dbb9f291.so.10.4.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libgmp-dbb9f291.so.10.4.1 (0x00007fcfff25a000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fcfff23e000)
        libgnutls-58994bd7.so.30.31.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libgnutls-58994bd7.so.30.31.0 (0x00007fcfff005000)
        libvpx-c1705a7a.so.7.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvpx-c1705a7a.so.7.0.0 (0x00007fcffedf0000)
        liblzma-f3a5963b.so.5.2.5 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/liblzma-f3a5963b.so.5.2.5 (0x00007fcffedc5000)
        libdav1d-df61568f.so.5.1.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libdav1d-df61568f.so.5.1.1 (0x00007fcffebff000)
        libopencore-amrwb-9db94aa9.so.0.0.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopencore-amrwb-9db94aa9.so.0.0.3 (0x00007fcffebe9000)
        libaom-e9efed4a.so.3.2.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libaom-e9efed4a.so.3.2.0 (0x00007fcffe4a9000)
        libmp3lame-3ecc6556.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libmp3lame-3ecc6556.so.0.0.0 (0x00007fcffe415000)
        libopencore-amrnb-393dbae2.so.0.0.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopencore-amrnb-393dbae2.so.0.0.3 (0x00007fcffe3e7000)
        libopenjp2-0d101c52.so.2.4.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopenjp2-0d101c52.so.2.4.0 (0x00007fcffe363000)
        libopus-70bda348.so.0.8.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libopus-70bda348.so.0.8.0 (0x00007fcffe307000)
        libspeex-b6a53f7a.so.1.5.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libspeex-b6a53f7a.so.1.5.1 (0x00007fcffe2eb000)
        libtheoraenc-276df146.so.1.1.2 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtheoraenc-276df146.so.1.1.2 (0x00007fcffe2a9000)
        libtheoradec-f01ee89e.so.1.1.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtheoradec-f01ee89e.so.1.1.4 (0x00007fcffe287000)
        libtwolame-72d74ef7.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libtwolame-72d74ef7.so.0.0.0 (0x00007fcffe25e000)
        libvorbis-f4a9a6fd.so.0.4.9 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvorbis-f4a9a6fd.so.0.4.9 (0x00007fcffe221000)
        libvorbisenc-0d9d5bdf.so.2.0.12 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libvorbisenc-0d9d5bdf.so.2.0.12 (0x00007fcffe170000)
        libx264-2881b7ff.so.164 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libx264-2881b7ff.so.164 (0x00007fcffde4d000)
        libx265-d8690e8d.so.199 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libx265-d8690e8d.so.199 (0x00007fcffcbc1000)
        libxvidcore-d29bca61.so.4.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxvidcore-d29bca61.so.4.3 (0x00007fcffcab3000)
        libxcb-65da195c.so.1.1.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-65da195c.so.1.1.0 (0x00007fcffc880000)
        libxcb-shm-7a199f70.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-shm-7a199f70.so.0.0.0 (0x00007fcffc679000)
        libxcb-shape-25c2b258.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-shape-25c2b258.so.0.0.0 (0x00007fcffc472000)
        libxcb-xfixes-9be3ba6f.so.0.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libxcb-xfixes-9be3ba6f.so.0.0.0 (0x00007fcffc262000)
        libpostproc-9d3ac700.so.56.6.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libpostproc-9d3ac700.so.56.6.100 (0x00007fcffc240000)
        libass-8499ab98.so.9.1.3 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libass-8499ab98.so.9.1.3 (0x00007fcffc1fe000)
        libfontconfig-99ba2620.so.1.12.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfontconfig-99ba2620.so.1.12.0 (0x00007fcffc1aa000)
        libfreetype-19bd6cfb.so.6.17.1 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfreetype-19bd6cfb.so.6.17.1 (0x00007fcffc0f9000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd0014fe000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fcffc0f1000)
        libunistring-aeeab030.so.2.1.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libunistring-aeeab030.so.2.1.0 (0x00007fcffbf6a000)
        libnettle-cb75a9d6.so.8.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libnettle-cb75a9d6.so.8.4 (0x00007fcffbf1f000)
        libhogweed-5d799758.so.6.4 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libhogweed-5d799758.so.6.4 (0x00007fcffbece000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fcffbcec000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fcffbccf000)
        libogg-bbd52b06.so.0.8.5 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libogg-bbd52b06.so.0.8.5 (0x00007fcffbcc3000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fcffbcb9000)
        libXau-00ec42fe.so.6.0.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libXau-00ec42fe.so.6.0.0 (0x00007fcffbab4000)
        libfribidi-baef595b.so.0.4.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libfribidi-baef595b.so.0.4.0 (0x00007fcffba91000)
        libharfbuzz-d40f381a.so.0.40100.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libharfbuzz-d40f381a.so.0.40100.0 (0x00007fcffb97d000)
        libuuid-f64cda11.so.1.3.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libuuid-f64cda11.so.1.3.0 (0x00007fcffb777000)
        libpng16-1f529098.so.16.37.0 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libpng16-1f529098.so.16.37.0 (0x00007fcffb746000)

比如其中的 libavformat-20d4e1d0.so.59.27.100 => /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000)
这个是按照什么规定让 libavformat-20d4e1d0.so.59.27.100 指向 /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000) 的呢?按理来说,/home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/ 不应该存在于系统的默认搜索路径中吧?而且我也没有添加类似 LD_LIBRARY_PATH、LD_PRELOAD、LD_LIBRARYN、LD_DEBUG、LD_BIND_NOW 的环境变量

(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av  
╰─➤  printenv | grep LD_                                                                                                                                                                                                                                                 1 ↵

(svddb_sdk) ╭─pon@admini ~/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av  

如果使用 readelf 查看,就是下面这样

─➤  readelf -d _core.cpython-310-x86_64-linux-gnu.so                                                                                                                                                                                                                    1 ↵

Dynamic section at offset 0x2d000 contains 33 entries:
  Tag        Type                         Name/Value
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../av.libs]
 0x0000000000000001 (NEEDED)             Shared library: [libavformat-20d4e1d0.so.59.27.100]
 0x0000000000000001 (NEEDED)             Shared library: [libavcodec-8a88085f.so.59.37.100]
 0x0000000000000001 (NEEDED)             Shared library: [libavdevice-ed40abdd.so.59.7.100]
 0x0000000000000001 (NEEDED)             Shared library: [libavutil-1701948d.so.57.28.100]
 0x0000000000000001 (NEEDED)             Shared library: [libavfilter-2d5314ec.so.8.44.100]
 0x0000000000000001 (NEEDED)             Shared library: [libswscale-a6aee226.so.6.7.100]
 0x0000000000000001 (NEEDED)             Shared library: [libswresample-b868a3ce.so.4.7.100]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x3000
 0x000000000000000d (FINI)               0x63c4
 0x0000000000000019 (INIT_ARRAY)         0x8cd8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x8ce0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0xb358
 0x0000000000000005 (STRTAB)             0x12250
 0x0000000000000006 (SYMTAB)             0xa8d8
 0x000000000000000a (STRSZ)              2479 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000003 (PLTGOT)             0x9000
 0x0000000000000002 (PLTRELSZ)           2016 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x1e40
 0x0000000000000007 (RELA)               0x17b0
 0x0000000000000008 (RELASZ)             1680 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000006ffffffe (VERNEED)            0x16b0
 0x000000006fffffff (VERNEEDNUM)         8
 0x000000006ffffff0 (VERSYM)             0x15ce
 0x000000006ffffff9 (RELACOUNT)          44
 0x0000000000000000 (NULL)               0x0
阅读 2k
4 个回答

ldd 列出来的始终都是绝对路径。

你误解 linux-vdso.so 了是“相对路径”可能是因为它开头没带着 / 吧。这是因为它在内核里,是个虚拟的文件(VDSO 全称就是 Virtual Dynamic Shared Object ,虚拟动态共享对象),并不在文件系统里。


至于怎么看这我不太了解,帮你艾特搞 C 的吧 @fefe

ldd

ldd 会实际加载一个 elf 文件,并把加载过程中用到的跟找到的 so 都显示出来。

=> 左边就是它用到了哪个 so ,右边就是它在磁盘上什么地方找到了这个 so 。

elf 会记录需要的动态库,然后 dynamic linker 会使用一个特定的规则在磁盘上寻找这些动态连接库。ldd 会递归地展示所有需要的跟找的的动态库。

linux-vdso.so.1 是一个虚拟文件,不在磁盘上,好像是用来解决内核跟 libc 兼容性问题的

而 /lib64/ld-linux-x86-64.so.2 ,就是 denamic linker 本身。你可直接运行它,然后它就可以告诉你它是干什么的:

$ /lib64/ld-linux-x86-64.so.2
Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]
You have invoked `ld.so', the helper program for shared library executables.
This program usually lives in the file `/lib/ld.so', and special directives
in executable files using ELF shared libraries tell the system's program
loader to load the helper program from this file.  This helper program loads
the shared libraries needed by the program executable, prepares the program
to run, and runs it.  You may invoke this helper program directly from the
command line to load and run an ELF executable file; this is like executing
that file itself, but always uses this helper program from the file you
specified, instead of the helper program file specified in the executable
file you run.  This is mostly of use for maintainers to test new versions
of this helper program; chances are you did not intend to run this program.

根据 ld.so

When resolving shared object dependencies, the dynamic linker
first inspects each dependency string to see if it contains a
slash (this can occur if a shared object pathname containing
slashes was specified at link time). If a slash is found, then
the dependency string is interpreted as a (relative or absolute)
pathname, and the shared object is loaded using that pathname.)

If a shared object dependency does not contain a slash, then it
is searched for in the following order:

(1) Using the directories specified in the DT_RPATH dynamic
section attribute of the binary if present and DT_RUNPATH
attribute does not exist. Use of DT_RPATH is deprecated.

(2) Using the environment variable LD_LIBRARY_PATH, unless the
executable is being run in secure-execution mode (see
below), in which case this variable is ignored.

(3) Using the directories specified in the DT_RUNPATH dynamic
section attribute of the binary if present. Such
directories are searched only to find those objects required
by DT_NEEDED (direct dependencies) entries and do not apply
to those objects' children, which must themselves have their
own DT_RUNPATH entries. This is unlike DT_RPATH, which is
applied to searches for all children in the dependency tree.

(4) From the cache file /etc/ld.so.cache, which contains a
compiled list of candidate shared objects previously found
in the augmented library path. If, however, the binary was
linked with the -z nodeflib linker option, shared objects in
the default paths are skipped. Shared objects installed in
hardware capability directories (see below) are preferred to
other shared objects.

(5) In the default path /lib, and then /usr/lib. (On some
64-bit architectures, the default paths for 64-bit shared
objects are /lib64, and then /usr/lib64.) If the binary was
linked with the -z nodeflib linker option, this step is
skipped.

动态库文件如有包含 / ,那么他就是相对或绝对路径(根据/的位置)。那么dynamic linker 会直接使用这个文件。

如果没有 / ,那么就按找一个特定的方式在在磁盘上寻找这个文件。这个时候,ldd 会用 => 显示寻找的结果。


第一条里的 DT_RPATH ,可以用 readelf -d 来看,在结果里找 RPATH 。

你的理解大体是没错的。不过ldd列出来的依赖不但包含了直接依赖,还包含了间接依赖。也就是依赖传递一并会列出来,如果你只想看到直接依赖,可以用readelf -d /path/to/your/file.

例如:

❯ ldd /usr/lib/libavcodec.so
    linux-vdso.so.1 (0x00007ffd94293000)
    libswresample.so.4 => /usr/lib/libswresample.so.4 (0x00007fb90a186000)
    libavutil.so.58 => /usr/lib/libavutil.so.58 (0x00007fb909f67000)
    libvpx.so.8 => /usr/lib/libvpx.so.8 (0x00007fb909ca0000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007fb909bb3000)
    libwebpmux.so.3 => /usr/lib/libwebpmux.so.3 (0x00007fb909ba6000)
    liblzma.so.5 => /usr/lib/liblzma.so.5 (0x00007fb909b73000)
    libdav1d.so.6 => /usr/lib/libdav1d.so.6 (0x00007fb909985000)
    libopencore-amrwb.so.0 => /usr/lib/libopencore-amrwb.so.0 (0x00007fb90996f000)
    librsvg-2.so.2 => /usr/lib/librsvg-2.so.2 (0x00007fb9094e7000)
    libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007fb909485000)
    libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007fb909339000)
    libcairo.so.2 => /usr/lib/libcairo.so.2 (0x00007fb909207000)
    libaom.so.3 => /usr/lib/libaom.so.3 (0x00007fb908963000)
    libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007fb908954000)
    libjxl.so.0.8 => /usr/lib/libjxl.so.0.8 (0x00007fb908580000)
    libjxl_threads.so.0.8 => /usr/lib/libjxl_threads.so.0.8 (0x00007fb90857a000)
    libmp3lame.so.0 => /usr/lib/libmp3lame.so.0 (0x00007fb908502000)
    libopencore-amrnb.so.0 => /usr/lib/libopencore-amrnb.so.0 (0x00007fb9084d9000)
    libopenjp2.so.7 => /usr/lib/libopenjp2.so.7 (0x00007fb90846a000)
    libopus.so.0 => /usr/lib/libopus.so.0 (0x00007fb90840c000)
    librav1e.so.0 => /usr/lib/librav1e.so.0 (0x00007fb9080f3000)
    libspeex.so.1 => /usr/lib/libspeex.so.1 (0x00007fb9080d6000)
    libSvtAv1Enc.so.1 => /usr/lib/libSvtAv1Enc.so.1 (0x00007fb8ffa75000)
    libtheoraenc.so.1 => /usr/lib/libtheoraenc.so.1 (0x00007fb8ffa3d000)
    libtheoradec.so.1 => /usr/lib/libtheoradec.so.1 (0x00007fb8ffa21000)
    libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0x00007fb8ff9f3000)
    libvorbisenc.so.2 => /usr/lib/libvorbisenc.so.2 (0x00007fb8ff948000)
...
❯ readelf -d /usr/lib/libavcodec.so

Dynamic section at offset 0xecb4f0 contains 60 entries:
  标记        类型                         名称/值
 0x0000000000000001 (NEEDED)             共享库:[libswresample.so.4]
 0x0000000000000001 (NEEDED)             共享库:[libavutil.so.58]
 0x0000000000000001 (NEEDED)             共享库:[libvpx.so.8]
 0x0000000000000001 (NEEDED)             共享库:[libm.so.6]
 0x0000000000000001 (NEEDED)             共享库:[libwebpmux.so.3]
 0x0000000000000001 (NEEDED)             共享库:[liblzma.so.5]
 0x0000000000000001 (NEEDED)             共享库:[libdav1d.so.6]
 0x0000000000000001 (NEEDED)             共享库:[libopencore-amrwb.so.0]
 0x0000000000000001 (NEEDED)             共享库:[librsvg-2.so.2]
 0x0000000000000001 (NEEDED)             共享库:[libgobject-2.0.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libglib-2.0.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libcairo.so.2]
 0x0000000000000001 (NEEDED)             共享库:[libaom.so.3]
 0x0000000000000001 (NEEDED)             共享库:[libgsm.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libjxl.so.0.8]
 0x0000000000000001 (NEEDED)             共享库:[libjxl_threads.so.0.8]
 0x0000000000000001 (NEEDED)             共享库:[libmp3lame.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libopencore-amrnb.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libopenjp2.so.7]
 0x0000000000000001 (NEEDED)             共享库:[libopus.so.0]
 0x0000000000000001 (NEEDED)             共享库:[librav1e.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libspeex.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libSvtAv1Enc.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libtheoraenc.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libtheoradec.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libvorbis.so.0]
 0x0000000000000001 (NEEDED)             共享库:[libvorbisenc.so.2]
 0x0000000000000001 (NEEDED)             共享库:[libwebp.so.7]
 0x0000000000000001 (NEEDED)             共享库:[libx264.so.164]
 0x0000000000000001 (NEEDED)             共享库:[libx265.so.199]
 0x0000000000000001 (NEEDED)             共享库:[libxvidcore.so.4]
 0x0000000000000001 (NEEDED)             共享库:[libz.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libva.so.2]
 0x0000000000000001 (NEEDED)             共享库:[libmfx.so.1]
 0x0000000000000001 (NEEDED)             共享库:[libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libavcodec.so.60]

「这个是按照什么规定让 libavformat-20d4e1d0.so.59.27.100 指向 /home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/libavformat-20d4e1d0.so.59.27.100 (0x00007fd001254000) 的呢?按理来说,/home/pon/.local/share/virtualenvs/svddb_sdk-qAt4tE2E/lib/python3.10/site-packages/av/./../av.libs/ 不应该存在于系统的默认搜索路径中吧?而且我也没有添加类似 LD_LIBRARY_PATH、LD_PRELOAD、LD_LIBRARYN、LD_DEBUG、LD_BIND_NOW 的环境变量」—— 这个问题我知道原因了,贴一下 chatGPT 的回答

在动态链接库(共享库)的输出中,=> 符号表示了共享库的依赖关系,指示共享库加载时从哪个具体路径加载依赖的库。对于你提供的输出:

  1. /lib64/ld-linux-x86-64.so.2 (0x00007f9f37d77000) 是一个绝对路径,它直接指向系统标准位置的 ld-linux-x86-64.so.2。
  2. linux-vdso.so.1 (0x00007fff1bec0000) 是一个相对路径。它通常是通过内核提供的虚拟动态共享对象(Virtual Dynamic Shared Object)加载的,因此不依赖于文件系统路径。
  3. 对于像 libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9f37d5c000) 这样的依赖项,libpthread.so.0 是相对于系统默认搜索路径(通常是 /lib/x86_64-linux-gnu/)的相对路径。虽然它以 / 开头,但它仍然是相对于默认搜索路径的路径。

在你的第二个问题中,RPATH 入口的存在解释了共享库如何找到它的依赖项。在你的输出中,存在以下 RPATH 条目:

0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/../av.libs]

这个条目告诉共享库,当它在运行时加载时,应该在 $ORIGIN/../av.libs 目录中查找它的依赖项。这里的 $ORIGIN 是一个特殊的标记,表示共享库所在的目录。因此,共享库在运行时会查找依赖项的路径,将其添加到加载路径中,以确保正确加载依赖项。

这是一种在共享库中指定依赖项查找路径的方式,通常用于使共享库能够找到与它一起分发的特定版本的依赖项,而不依赖于系统默认搜索路径或用户环境变量。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏