Linux 中共享对象的位置

Linux 中共享对象的位置

我想知道,.so文件信息在 Linux 中存储在哪里?我正在寻找libruby.so.2.6

当我在互联网上搜索时,ld.so首先用开始搜索LD_LIBRARY_PATH,然后它会查找ld.so.conf文件和缓存文件,然后是默认路径,如/lib/usr/local/lib

在我的例子中,ruby 安装在了/opt/puppetlabs/puppet/root/bin位置上,当我执行时,获得了asldd /opt/puppetlabs/puppet/root/bin的位置。libruby.so/opt/puppetlabs/puppet/lib/libruby.so.2.6

现在我能够获取共享对象的位置,但我想知道它从哪里获得详细信息?我检查了文件ld_library_pathld.so.conf可以找到该条目。有人能帮我获取这个详细信息吗?

答案1

的手册页ldd显示:

   In the usual case, ldd invokes the standard dynamic linker (see
   ld.so(8)) with the LD_TRACE_LOADED_OBJECTS environment variable set
   to 1.  This causes the dynamic linker to inspect the program's
   dynamic dependencies, and find (according to the rules described in
   ld.so(8)) and load the objects that satisfy those dependencies. 

的手册页ld给出了解释规则:

   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:

   o  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.

   o  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.

   o  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.

   o  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.

   o  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.

相关内容