linux - 进程如何在 Linux 中找到动态共享库?

标签 linux process elf dynamic-loading

我正在阅读 APUE并查看以下内容:

Several more segment types exist in an a.out, containing the symbol table, debugging information, linkage tables for dynamic shared libraries, and the like. These additional sections don’t get loaded as part of the program’s image executed by a process.

但是,如果动态共享库的链接表没有加载到程序镜像中,进程如何找到必要的 .so

最佳答案

  1. 动态链接器通过在链接过程中添加到程序头的 .interp (PT_INTERP) 部分加载为程序解释器。

  2. 动态链接器读取 DT_NEEDED ELF 标记(在静态链接期间添加)以找出它需要解析哪些共享库。

  3. 最后,关于解析库 deps,来自 ld.so(8):

When resolving library dependencies, the dynamic linker first inspects each dependency string to see if it contains a slash (this can occur if a library 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 library is loaded using that pathname.

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

  • (ELF only) 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.

  • Using the environment variable LD_LIBRARY_PATH. Except if the executable is a set-user-ID/set-group-ID binary, in which case it is ignored.

  • (ELF only) Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present.

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

  • In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped.

关于linux - 进程如何在 Linux 中找到动态共享库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24902698/

相关文章:

c++ - 使用 boost::filesystem 时无法链接

java - 在 Windows 7 中运行进程并获取其 ID

android - 获取正在运行的进程列表并终止特定进程

c - 存储在.data 或.bss 段中的静态或全局数据是否应该在程序执行前加载?

linux - 如何从 awk 语句添加时间格式 hh :mm. ss

linux - linux系统中euid、suid、ruid的区别

php - 使用 PHP exec 命令和 scp 复制

python - 如何使用python保存内存、pid和进程

c - 有没有办法将 Linux 共享库加载到特定的内存位置?

c++ - 访问 C++ 程序的代码段