LD.SO(8) Linux Programmer’s Manual LD.SO(8) 名前 ld.so, ld-linux.so* - 動的なリンカ/ローダ 書式 動 的リンカは、動的にリンクされたプログラムやライブラリの実行によって間 接的に実行することができる (ELF の場合、動的リンカにコマンドラインオ プ ションを渡すことはできず、プログラムの .interp セクションに入っている動 的リンカが実行される)。また以下のように直接実行することもできる /lib/ld-linux.so.* [OPTIONS] [PROGRAM [ARGUMENTS]] 説明 プログラム ld.so と ld-linux.so* はプログラムに必要な共有ライブラリを見 つけてロードし、プログラムの実行を準備してから起動させる。 Linux のバイナリは、コンパイルの時に ld(1) に対して -static オプション が指定されていない限り、動的リンク (実行時リンク) が必要となる。 プログラム ld.so は a.out バイナリを扱う。これはずっと昔に使われてい た フ ォ ー マ ッ ト である。 ld-linux.so* (libc5 では /lib/ld-linux.so.1, glibc2 では /lib/ld-linux.so.2) は ELF バイナリを扱う。このフォーマット は 多くの人が最近何年も使っている。それ以外の点では両方とも同じように動 作し、同じサポート フ ァ イ ル と プ ロ グ ラ ム ldd(1), ldconfig(8), /etc/ld.so.conf を使用する。 プログラムで必要とされる共有ライブラリは、以下の順序で検索される。 o (ELF のみ) バイナリの動的セクション属性 DT_RPATH が存在し、 DT_RUN- PATH 属性が存在しない場合は、 DT_RPATH で指定されたディレクトリを 使 用する。 DT_RPATH の使用は推奨されない。 o 環 境 変数 LD_LIBRARY_PATH を用いる。ただし実行ファイルが set-user- ID/set-group-ID バイナリの場合、これは無視される。 o (ELF のみ) バイナリの動的セクション属性 DT_RUNPATH が存在す れ ば 、 DT_RUNPATH で指定されたディレクトリを使用する。 o キ ャ ッ シ ュ フ ァ イル /etc/ld.so.cache を探す。このファイルは、 (ld.so.conf で追加指定されたものも含めた) ライブラリ検索パスから見つ かったライブラリファイルの情報を集めたものである。ただしバイナリがリ ンカオプション -z nodeflib でリンクされている場合は、デフォルトの ラ イブラリパスにあるライブラリはスキップされる。 o デフォルトパスである /lib、次いで /usr/lib を用いる。バイナリがリン カオプション -z nodeflib でリンクされている場合、このステップはス キ ップされる。 $ORIGIN と rpath ld.so では、rpath 指定 (DT_RPATH や DT_RUNPATH) 中に $ORIGIN という文字 列 (${ORIGIN} も等価) を使うことができる。 $ORIGIN はアプリケーションの 実行ファイルが入っているディレクトリを表す。これを使って somedir/app に 置かれたアプリケーションを gcc -Wl,-rpath,’$ORIGIN/../lib’ でコンパイル すると、 somedir がディレクトリ階層のどこにあっても、アプリケーションは somedir/lib にある対応する共有ライブラリを見つけることができる。この 機 能 を使うと、特別なディレクトリではなく任意のディレクトリにインストール しても "ややこしい設定なしで" 独自の共有ライブラリを使えるアプリケー シ ョンを作成することができる。 オプション --list 全ての依存関係とその解決法をリストする。 --verify プログラムが動的にリンクされているかと、動的リンカがそのプログラ ムを扱えるかを検証する。 --library-path PATH LD_LIBRARY_PATH 環境変数の設定を上書きする (下記参照)。 --inhibit-rpath LIST LIST にあるオブジェクト名の RPATH と RUNPATH の情報を無視する 。 ld.so が set-user-ID か set-group-ID されている場合、このオプシ ョンは無視される。 環境変数 4 つの重要な環境変数がある。 LD_BIND_NOW (libc5; glibc 2.1.1 以降) 空文字列でない場合、動的リンカはプログ ラムの開始時に全てのシンボルを解決する。空文字列の場合、解決しな ければならない関数呼び出しが最初に参照された時点で解決する。デバ ッガを使っているときに役立つ。 LD_LIBRARY_PATH コ ロン区切りのディレクトリリスト。実行時に ELF ライブラリを検索 するディレクトリを指定する。 PATH 環境変数と同じように指定する。 LD_PRELOAD ス ペース区切りで ELF 共有ライブラリを指定する。これはユーザーが 指定でき、すべてのライブラリに先立ってロードされる。他の共有ライ ブ ラ リにある関数を選択的に置き換えるために用いることができる。 set-user-ID/set-group-ID された ELF バイナリに対して、標準的な検 索 パスにあるライブラリのうち set-user-ID されているものはロード しない。 LD_TRACE_LOADED_OBJECTS (ELF のみ) 空文字列でない場合、プログラムを普通に実行するので は なく、 ldd(1) を実行したときのように動的ライブラリの依存関係をリ スト表示させる。 そして、それほど知られていない環境変数もある。多くは廃れてしまったも の か内部でのみ使用される環境変数である。 LD_AOUT_LIBRARY_PATH (libc5) a.out バイナリにのみ使われる環境変数で、 LD_LIBRARY_PATH と同じ役割をする。 ld-linux.so.1 の 古 い バ ー ジ ョ ン で は LD_ELF_LIBRARY_PATH もサポートしていた。 LD_AOUT_PRELOAD (libc5) a.out バイナリにのみ使われる環境変数で、 LD_PRELOAD と同 じ役割をする。 ld-linux.so.1 の古いバージョンでは LD_ELF_PRELOAD もサポートしていた。 LD_BIND_NOT (glibc 2.1.95 以降) シンボルを解決した後、GOT (global offset ta- ble) と PLT (procedure linkage table) を更新しない。 LD_DEBUG (glibc 2.1 以降) 動的リンカの詳細なデバッグ情報を出力する。 all に 設 定した場合、全ての動的リンカが持つデバッグ情報を表示する。 help に設定した場合、この環境変数で指定されるカテゴリのヘルプ 情 報 を表示する。 glibc 2.3.4 以降、 set-user-ID/set-group-ID され たバイナリでは LD_DEBUG は無視される。 LD_DEBUG_OUTPUT (glibc 2.1 以降) LD_DEBUG の出力を書き込むファイル。デフォルトは 標 準 出力である。 set-user-ID/set-group-ID されたバイナリでは、 LD_DEBUG_OUTPUT は無視される。 LD_DYNAMIC_WEAK (glibc 2.1.19 以降) 上書きされる弱いシンボル (昔の glibc の挙 動 を 逆 にする)。セキュリティ上の理由から、glibc 2.3.4 以降、 set- user-ID/set-group-ID されたバイナリでは LD_DYNAMIC_WEAK は無視さ れる。 LD_HWCAP_MASK (glibc 2.1 以降) ハードウェア機能のマスク。 LD_KEEPDIR (a.out のみ)(libc5) ロードする a.out ライブラリの名前において、 ディレクトリを無視しない。このオプションは用いるべきではない。 LD_NOWARN (a.out のみ)(libc5) a.out ライブラリにおけるマイナーバージョン番 号の非互換に対する警告メッセージを抑制する。 LD_ORIGIN_PATH (glibc 2.1 以降) バイナリへのパス (set-user-ID されていないプロ グラムについて)。セキュリティ上の理由から、glibc 2.3.4 以 降 、 set-user-ID/set-group-ID されたバイナリでは LD_ORIGIN_PATH は無 視される。 LD_PROFILE (glibc 2.1 以降) プロファイルを行う共有オブジェクト。パス名か 共 有 オ ブ ジ ェクト名 (soname) で指定される。プロフィールの出力は "$LD_PROFILE_OUTPUT/$LD_PROFILE.profile" という名前のファイル に 書き込まれる。 LD_PROFILE_OUTPUT (glibc 2.1 以降) LD_PROFILE の出力が書き込まれるディレクトリ。こ の変数が定義されていないか、空の文字列が定義されている場合、デフ ォルト値は /var/tmp となる。 set-user-ID/set-group-ID されたプロ グラムでは、 LD_PROFILE_OUTPUT は無視される。出力ファイルは常 に /var/profile が使用される。 LD_SHOW_AUXV (glibc 2.1 以降) カーネルから渡される補助的な (パラメータの) 配 列を表示する。セキュリティ上の理由から、glibc 2.3.4 以降、 set- user-ID/set-group-ID されたバイナリでは LD_SHOW_AUXV は無視され る。 LD_USE_LOAD_BIAS デフォルトでは (つまり、この変数が定義されていない場合)、実行 フ ァ イルと prelink された共有オブジェクトでは、それらが依存するラ イブラリのベースアドレスが尊重される一方、 (prelink されて い な い) position-independent executables (PIEs) と他の共有オブジェク トでは依存するライブラリのベースアドレス は 尊 重 さ れ な い 。 LD_USE_LOAD_BIAS に値が定義された場合、実行ファイルと PIE のどち らでもベースアドレスが尊重される。 LD_USE_LOAD_BIAS が値 0 で 定 義 された場合、実行ファイルと PIE のどちらでもベースアドレスは尊 重されない。 set-user-ID や set-group-ID されたプログラムでは 、 この変数は無視される。 LD_VERBOSE (glibc 2.1 以降) 空文字列でない場合に、 (LD_TRACE_LOADED_OBJECTS を設定するか、 --list または --verify オプションを動的リンカに指 定することにより) プログラムについての情報を問い合わせると、プロ グラムのシンボルバージョン情報を表示する。 LD_WARN (ELF のみ)(glibc 2.1.3 以降) 空文字列でない場合、解決されてい な いシンボルがあれば警告を出す。 LDD_ARGV0 (libc5) ldd(1) の引き数がない場合に、 argv[0] として使われる値。 ファイル /lib/ld.so a.out の動的リンカ/ローダ /lib/ld-linux.so.{1,2} ELF の動的リンカ/ローダ /etc/ld.so.cache ライブラリを検索するディレクトリを集めたリストと、共有ライブラリ の候補の整列リストを含むファイル。 /etc/ld.so.preload プ ログラムの前にロードすべき ELF 共有ライブラリをスペースで区切 ったリストが書かれているファイル。 lib*.so* 共有ライブラリ 注意 ld.so の機能は libc のバージョン 4.4.3 以上を用いてコンパイルされた実行 フ ァイルで使用可能である。 ELF の機能は Linux 1.1.52 以降と libc5 以降 で使用可能である。 関連項目 ldd(1), ldconfig(8) GNU 2008-10-27 LD.SO(8)
LD.SO(8) Linux Programmer’s Manual LD.SO(8) NAME ld.so, ld-linux.so* - dynamic linker/loader SYNOPSIS The dynamic linker can be run either indirectly by running some dynami- cally linked program or library (in which case no command-line options to the dynamic linker can be passed and, in the ELF case, the dynamic linker which is stored in the .interp section of the program is exe- cuted) or directly by running: /lib/ld-linux.so.* [OPTIONS] [PROGRAM [ARGUMENTS]] DESCRIPTION The programs ld.so and ld-linux.so* find and load the shared libraries needed by a program, prepare the program to run, and then run it. Linux binaries require dynamic linking (linking at run time) unless the -static option was given to ld(1) during compilation. The program ld.so handles a.out binaries, a format used long ago; ld- linux.so* handles ELF (/lib/ld-linux.so.1 for libc5, /lib/ld-linux.so.2 for glibc2), which everybody has been using for years now. Otherwise both have the same behavior, and use the same support files and pro- grams ldd(1), ldconfig(8) and /etc/ld.so.conf. The shared libraries needed by the program are searched for in the fol- lowing order: o (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. o Using the environment variable LD_LIBRARY_PATH. Except if the exe- cutable is a set-user-ID/set-group-ID binary, in which case it is ignored. o (ELF only) Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present. o 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. o In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped. $ORIGIN and rpath ld.so understands the string $ORIGIN (or equivalently ${ORIGIN}) in an rpath specification (DT_RPATH or DT_RUNPATH) to mean the directory con- taining the application executable. Thus, an application located in somedir/app could be compiled with gcc -Wl,-rpath,'$ORIGIN/../lib' so that it finds an associated shared library in somedir/lib no matter where somedir is located in the directory hierarchy. This facilitates the creation of "turn-key" applications that do not need to be installed into special directories, but can instead be unpacked into any directory and still find their own shared libraries. OPTIONS --list List all dependencies and how they are resolved. --verify Verify that program is dynamically linked and this dynamic linker can handle it. --library-path PATH Override LD_LIBRARY_PATH environment variable setting (see below). --inhibit-rpath LIST Ignore RPATH and RUNPATH information in object names in LIST. This option is ignored if ld.so is set-user-ID or set-group-ID. ENVIRONMENT There are four important environment variables. LD_BIND_NOW (libc5; glibc since 2.1.1) If set to a non-empty string, causes the dynamic linker to resolve all symbols at program startup instead of deferring function call resolution to the point when they are first referenced. This is useful when using a debug- ger. LD_LIBRARY_PATH A colon-separated list of directories in which to search for ELF libraries at execution-time. Similar to the PATH environment variable. LD_PRELOAD A list of additional, user-specified, ELF shared libraries to be loaded before all others. The items of the list can be sepa- rated by spaces or colons. This can be used to selectively override functions in other shared libraries. The libraries are searched for using the rules given under DESCRIPTION. For set- user-ID/set-group-ID ELF binaries, preload pathnames containing slashes are ignored, and libraries in the standard search direc- tories are loaded only if the set-user-ID permission bit is enabled on the library file. LD_TRACE_LOADED_OBJECTS (ELF only) If set to a non-empty string, causes the program to list its dynamic library dependencies, as if run by ldd(1), instead of running normally. Then there are lots of more or less obscure variables, many obsolete or only for internal use. LD_AOUT_LIBRARY_PATH (libc5) Version of LD_LIBRARY_PATH for a.out binaries only. Old versions of ld-linux.so.1 also supported LD_ELF_LIBRARY_PATH. LD_AOUT_PRELOAD (libc5) Version of LD_PRELOAD for a.out binaries only. Old ver- sions of ld-linux.so.1 also supported LD_ELF_PRELOAD. LD_AUDIT (glibc since 2.4) A colon-separated list of user-specified, ELF shared objects to be loaded before all others in a separate linker namespace (i.e., one that does not intrude upon the nor- mal symbol bindings that would occur in the process). These libraries can be used to audit the operation of the dynamic linker. LD_AUDIT is ignored for set-user-ID/set-group-ID bina- ries. The dynamic linker will notify the audit libraries at so-called auditing checkpoints—for example, loading a new library, resolv- ing a symbol, or calling a symbol from another shared object—by calling an appropriate function within the audit library. For details, see rtld-audit(7). The auditing interface is largely compatible with that provided on Solaris, as described in its Linker and Libraries Guide, in the chapter Runtime Linker Audit- ing Interface. LD_BIND_NOT (glibc since 2.1.95) Do not update the GOT (global offset table) and PLT (procedure linkage table) after resolving a symbol. LD_DEBUG (glibc since 2.1) Output verbose debugging information about the dynamic linker. If set to all prints all debugging information it has, if set to help prints a help message about which cate- gories can be specified in this environment variable. Since glibc 2.3.4, LD_DEBUG is ignored for set-user-ID/set-group-ID binaries. LD_DEBUG_OUTPUT (glibc since 2.1) File where LD_DEBUG output should be fed into, default is standard output. LD_DEBUG_OUTPUT is ignored for set- user-ID/set-group-ID binaries. LD_DYNAMIC_WEAK (glibc since 2.1.91) Allow weak symbols to be overridden (reverting to old glibc behavior). For security reasons, since glibc 2.3.4, LD_DYNAMIC_WEAK is ignored for set-user-ID/set- group-ID binaries. LD_HWCAP_MASK (glibc since 2.1) Mask for hardware capabilities. LD_KEEPDIR (a.out only)(libc5) Don’t ignore the directory in the names of a.out libraries to be loaded. Use of this option is strongly discouraged. LD_NOWARN (a.out only)(libc5) Suppress warnings about a.out libraries with incompatible minor version numbers. LD_ORIGIN_PATH (glibc since 2.1) Path where the binary is found (for non-set- user-ID programs). For security reasons, since glibc 2.4, LD_ORIGIN_PATH is ignored for set-user-ID/set-group-ID binaries. LD_POINTER_GUARD (glibc since 2.4) Set to 0 to disable pointer guarding. Any other value enables pointer guarding, which is also the default. Pointer guarding is a security mechanism whereby some pointers to code stored in writable program memory (return addresses saved by setjmp(3) or function pointers used by various glibc internals) are mangled semi-randomly to make it more difficult for an attacker to hijack the pointers for use in the event of a buffer overrun or stack-smashing attack. LD_PROFILE (glibc since 2.1) Shared object to be profiled, specified either as a pathname or a soname. Profiling output is written to the file whose name is: "$LD_PROFILE_OUTPUT/$LD_PROFILE.profile". LD_PROFILE_OUTPUT (glibc since 2.1) Directory where LD_PROFILE output should be written. If this variable is not defined, or is defined as an empty string, then the default is /var/tmp. LD_PROFILE_OUTPUT is ignored for set-user-ID and set-group-ID programs, which always use /var/profile. LD_SHOW_AUXV (glibc since 2.1) Show auxiliary array passed up from the ker- nel. For security reasons, since glibc 2.3.5, LD_SHOW_AUXV is ignored for set-user-ID/set-group-ID binaries. LD_USE_LOAD_BIAS By default (i.e., if this variable is not defined) executables and prelinked shared objects will honor base addresses of their dependent libraries and (non-prelinked) position-independent executables (PIEs) and other shared objects will not honor them. If LD_USE_LOAD_BIAS is defined wit the value, both executables and PIEs will honor the base addresses. If LD_USE_LOAD_BIAS is defined with the value 0, neither executables nor PIEs will honor the base addresses. This variable is ignored by set-user- ID and set-group-ID programs. LD_VERBOSE (glibc since 2.1) If set to a non-empty string, output symbol versioning information about the program if querying information about the program (i.e., either LD_TRACE_LOADED_OBJECTS has been set, or --list or --verify options have been given to the dynamic linker). LD_WARN (ELF only)(glibc since 2.1.3) If set to a non-empty string, warn about unresolved symbols. LDD_ARGV0 (libc5) argv[0] to be used by ldd(1) when none is present. FILES /lib/ld.so a.out dynamic linker/loader /lib/ld-linux.so.{1,2} ELF dynamic linker/loader /etc/ld.so.cache File containing a compiled list of directories in which to search for libraries and an ordered list of candidate libraries. /etc/ld.so.preload File containing a whitespace separated list of ELF shared libraries to be loaded before the program. lib*.so* shared libraries NOTES The ld.so functionality is available for executables compiled using libc version 4.4.3 or greater. ELF functionality is available since Linux 1.1.52 and libc5. SEE ALSO ldd(1), rtld-audit(7), ldconfig(8) COLOPHON This page is part of release 3.22 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU 2009-01-12 LD.SO(8)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa