`

rpath - runtime search path

阅读更多

RPath is a very interesting topic which can instruct the binary to find the right location of libraries and dependencies.

GNU ld.so has some rules in regarding how to use the rpath to find the right dependencies (basically it has attribute or environment which direct the runtime to look for directories for things within).

 

You may find some explaination from this wikipedia link: http://en.wikipedia.org/wiki/Rpath 

GNU ld.so

The dynamic linker of the GNU C Library and its derivative Embedded GLIBC implement a rather complicated algorithm for searching for shared libraries. The basic search order is:[1]

  1. The (colon-separated) paths in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist.
  2. The (colon-separated) paths in the environment variable LD_LIBRARY_PATH, unless the executable is a setuid/setgidbinary, in which case it is ignored. LD_LIBRARY_PATH can be overridden by calling the dynamic linker with the option --library-path (e.g. /lib/ld-linux.so.2 --library-path $HOME/mylibs myprogram).
  3. The (colon-separated) paths in the DT_RUNPATH dynamic section attribute of the binary if present.
  4. Lookup based on the ldconfig cache file (often located at /etc/ld.so.cache) which contains a compiled list of candidate libraries previously found in the augmented library path (set by /etc/ld.so.conf). If, however, the binary was linked with the-z nodeflib linker option, libraries in the default library paths are skipped.
  5. In the trusted default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped.

Notes:

  • The option --inhibit-rpath LIST of the dynamic linker instructs it to ignore DT_RPATH and DT_RUNPATH attributes of the object names in LIST.
  • Libraries specified by the environment variable LD_PRELOAD and then those listed in /etc/ld.so.preload are loaded before the search begins. A preload can thus be used to replace some (or all) of the requested library's normal functionalities, or it can simply be used to supply a library that would otherwise not be found.
  • Static libraries are searched and linked into the ELF file at link time and are not linked at run time.

[edit]The role of GNU ld

The GNU Linker (GNU ld) implements a feature which it calls "new-dtags": [2]

If the new-dtags feature is enabled in the linker (at run time using --enable-new-dtags), GNU ld, besides setting the DT_RPATHattribute, also sets the DT_RUNPATH attribute to the same string. At run time, if the dynamic linker finds a DT_RUNPATH attribute, it ignores the value of the DT_RPATH attribute, with the effect that LD_LIBRARY_PATH is checked next and the paths in theDT_RUNPATH attribute are only searched after it.

This means that in such configurations, the paths in LD_LIBRARY_PATH are searched before those given at link time using -rpath if--enable-new-dtags was active.

Instead of specifying the -rpath to the linker, the environment variable LD_RUN_PATH can be set to the same effect.

分享到:
评论

相关推荐

    patchelf:一个用于修改ELF可执行文件的动态链接器和RPATH的小实用程序

    PatchELF是用于修改现有ELF可执行文件和库的简单实用程序。 特别是,它可以执行以下操作: ... 例如,如果可执行文件引用一个库libfoo.so ,并且具有RPATH /lib:/usr/lib:/foo/lib ,而libfoo.so只能在/

    05-rpath解决so动态库依赖1

    1. 赖库程动态库或可执件,是何找赖的库的是下录顺来• the RPATH binary header (set at build-time) of the l

    shengqianfu-php:省钱付php-fpm源代码编译配置

    第三步:编译php ./configure --enable-fpm --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable- mbregex --enable-mbstring --enable-ftp --...

    rPath简化定制Linux.pdf

    rPath简化定制Linux.pdf

    php-7.3.0.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --...

    php-7.0.27.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd ...

    php-7.1.29.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd ...

    php-5.6.29.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd ...

    php-7.2.20.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /i nclude --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd ...

    php-7.3.7.tar.gz

    -with-config-file-path=/usr/local/php/etc --with-mysql-sock=/var/run/mysql/mysql.sock --with-mcrypt=/usr /include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd -...

    Debenu Quick PDF Library for Mac 10.12

    The dylib for Debenu Quick PDF Library has a dependency on the Delphi restributable (libcgunwind.1.0.dylib) and both the .dylib files use @rpath for their install_path. Both dyblib files must use the ...

    Git-2.21.0-64-bit.zip

    replaced with the new default to pass -Wl,-rpath,/path/to/dir, which is the more recent GCC uses. Those who need to build with an old GCC can still use "CC_LD_DYNPATH=-R" * Prepare use of ...

    php-7.2.26.tar.xz

    --with-config-file-path=/usr/local/php/etc \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --...

    nginx的php模块ngx_php.zip

     --with-ld-opt="-Wl,-rpath,$PHP_LIB" \  --add-module=/path/to/ngx_php/dev/ngx_devel_kit \  --add-module=/path/to/ngx_php 概要 user www www; worker_processes 4; events {  worker_connections ...

    rpath:node.js 中的递归路径遍历

    路径递归路径遍历安装 $ npm install --save rpath用法 var rpath = require ( 'rpath' ) ;var allPaths = rpath ....rpath ( '/path/to/rpath' , false , function ( allPaths ) { console . log ( allPaths ) ;} ) ;

    qt帮助文档 qt-help

    [-nomake ] [-R ] [-l ] [-no-rpath] [-rpath] [-continue] [-verbose] [-v] [-silent] [-no-nis] [-nis] [-no-cups] [-cups] [-no-iconv] [-iconv] [-no-pch] [-pch] [-no-dbus] [-dbus] [-dbus-linked] [-no-...

    Git-2.23.0/win64/32/mac 多文件

    替换为新的默认值以传递-Wl,-rpath,/ path / to / dir, 这是最近GCC的用途。那些需要建立的人 旧的GCC仍然可以使用“CC_LD_DYNPATH = -R” *准备在拓扑步行器中使用可达性指数 在一个范围(A..B)。 *一...

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    全志R16平台编译linux系统V1.0.txt 2017/4/11 13:36 (编译请使用编译android的lichee的选项编译生成的.config文件,不然直接编译会报错!!...rootroot@cm-System-Product-Name:/home/wwt/linux_r16$ tar zxvf ...

    gmssl.tar.gz

    ubuntu20编译Gmssl时,“version OPENSSL_1_1_0d not defined”问题的...修改Gmssl的Makefile文件,在CFLAGS赋值时添加-Wl,-rpath=$(LIBRPATH),LIB_LDFLAGS赋值LIB_LDFLAGS=-Wl,-rpath=$(LIBRPATH) -znodelete -m64。

    CentOS7.2.1511 gcc4.8.5 通过编译的 tfs2.2.16

    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, ...

Global site tag (gtag.js) - Google Analytics