The ldd command is used to determine the dynamic library contained in an executable binary file.
Linux Ldd parameter description:
-- Version: prints the version number of ldd.
-V -- verbose prints all information, such as the version information of the symbol.
-D -- data-relocs: re-deploy the execution symbol and report the missing target object (only applicable to the ELF format)
-R -- function-relocs re-deploys the target object and function, and reports the missing target object and function (applicable only to the ELF format)
-- Help usage information
If the given library name in the command line contains '/', the libc5 version of this program uses it as the library name; otherwise, it searches for the library in the standard location. Run a shared library under the current directory with the prefix "./".
Error:
Ldd cannot work on a. out shared library.
Ldd cannot work on some very old a. out programs that have been created before the release of ldd compilers. If you use ldd in this type of program, the program will try the running mode of argc = 0, and the result is unpredictable.
For example:
Ldd/bin/bash
However, ldd is not a program, but a shell script:
$ Which ldd
/Usr/bin/ldd
$ File/usr/bin/ldd
/Usr/bin/ldd: Bourne-Again shell script text executable
The ldd command is actually implemented by setting some environment variables (that is, ldd only sets the values of some environment variables)
Example: LD_TRACE_LOADED_OBJECTS
You only need to set its valueNot emptyYou can.
$ Export LD_TRACE_LOADED_OBJECTS = 1
$ Ls/usr
Linux-gate.so.1 => (0xb7fac000)
Librt. so.1 =>/lib/tls/i686/cmov/librt. so.1 (0xb7f93000)
Libselinux. so.1 =>/lib/libselinux. so.1 (0xb7f79000)
Libacl. so.1 =>/lib/libacl. so.1 (0xb7f70000)
Libc. so.6 =>/lib/tls/i686/cmov/libc. so.6 (0xb7e0d000)
Libpthread. so.0 =>/lib/tls/i686/cmov/libpthread. so.0 (0xb7df4000)
/Lib/ld-linux.so.2 (0xb7fad000)
Libdl. so.2 =>/lib/tls/i686/cmov/libdl. so.2 (0xb7df0000)
Libattr. so.1 =>/lib/libattr. so.1 (0xb7dea000)
To cancel the environment variable, ls can resume normal use:
$ Unset LD_TRACE_LOADED_OBJECTS
$ Ls/usr/
Bin games include lib lib32 lib64 local sbin share src X11R6
More environment variables:
1. LD_TRACE_LOADED_OBJECTS
2. LD_WARN
3. LD_BIND_NOW
4. LD_LIBRARY_VERSION
5. LD_VERBOSE
6. LD_DEBUG
By default, the environment variable enabled by ldd is LD_TRACE_LOADED_OBJECTS = 1.
Other variables (and values) correspond to the following options:
-D, -- data-relocs-> LD_WARN = yes
-R, -- function-relocs-> LD_WARN and LD_BIND_NOW = yes
-U, -- unused-> LD_DEBUG = "unused"
-V, -- verbose-> LD_VERBOSE = yes
LD_TRACE_LOADED_OBJECTS is the necessary environment variable, and others depend on the actual situation.
The essence of the ldd command is to execute:/Lib/ld-linux.so .*
We can find from the above content (ls/usr):/lib/ld-linux.so.2 (0xb7fad000 ).
$ Ls-l/lib/ld-linux.so .*
Lrwxrwxrwx 1 root 9/lib/ld-linux.so.2-> ld-2.9.so
The compiled file may be/lib/ld. so. For libc5, it is/lib/ld-linux.so.1, while glibc2 should be/lib/ld-linux.so.2.
$/Lib/ld-linux.so.2 -- list/bin/ls
Linux-gate.so.1 => (0xb8050000)
Librt. so.1 =>/lib/tls/i686/cmov/librt. so.1 (0xb8037000)
Libselinux. so.1 =>/lib/libselinux. so.1 (0xb801d000)
Libacl. so.1 =>/lib/libacl. so.1 (0xb8014000)
Libc. so.6 =>/lib/tls/i686/cmov/libc. so.6 (0xb7eb1000)
Libpthread. so.0 =>/lib/tls/i686/cmov/libpthread. so.0 (0xb7e98000)
/Lib/ld-linux.so.2 (0xb8051000)
Libdl. so.2 =>/lib/tls/i686/cmov/libdl. so.2 (0xb7e94000)
Libattr. so.1 =>/lib/libattr. so.1 (0xb7e8e000)
We can see the aboveEquivalent to ldd ls.
The shared library files available for ldd are actually files (/etc/ld. so. cache) created by reading the ldconfig command ).
Default shared library file search/Lib takes precedence over/usr/libAnd only the two directories are available. To add other paths, use the ldconfig command to configure related files.
Typically, the ld-linux.so searches for shared libraries in the following order:
1. DT_RPATH or DT_RUNPATH
2. environment variable LD_LIBRARY_PATH
3. the path in the/etc/ld. so. cache file is skipped if the executable program adds the-z nodeflib option during connection.
4. the default path is/lib and/usr/lib. if-z nodeflib is added, skip this step.
The following is a supplement from other netizens:
1. ldd is not an executable program, but a shell script.
2. ldd can display the dependency of the executable module. The principle is to set a series of environment variables, such as LD_TRACE_LOADED_OBJECTS, LD_WARN, LD_BIND_NOW, LD_LIBRARY_VERSION, and LD_VERBOSE. When the LD_TRACE_LOADED_OBJECTS environment variable is not empty, when any executable program is running, it only displays the dependency of the module, and the program is not actually executed. Or you can test it on the shell terminal as follows:
(1) export LD_TRACE_LOADED_OBJECTS = 1
(2) execute any program, such as ls, and check the running result of the program.
3. ldd shows the dependency working principle of the executable module. its essence is realized by ld-linux.so (loader of elf dynamic library. We know that the ld-linux.so module will work prior to the executable module program and gain control, so when those environment variables above are set, the ld-linux.so selects the dependency that shows the executable module.
4. in fact, you can directly execute the ld-linux.so module, such as:/lib/ld-linux.so.2 -- list program (which is equivalent to ldd program) ldd command usage method (from ldd -- help)
Name ldd-print the dependency of the shared library
Outline ldd [option]... file...
Describes the shared libraries required for each program or shared library specified by ldd output on the command line.
Option
-- Version
Print the version number of ldd.
-V -- verbose
Print all information, such as the version information of the symbol.
-D -- data-relocs
Execute the symbol re-deployment and report the missing target object (only applicable to the ELF format)
-R -- function-relocs
Redeploy the target object and function and report the missing target object and function (applicable only to the ELF format)
-- Help usage information
The standard version of ldd is provided together with glibc2. Libc5 and earlier versions are available in some systems. Long options are not supported in libc5. On the other hand, glibc2 does not support the-V option, but only provides the equivalent -- version option.
If the given library name in the command line contains '/', the libc5 version of this program uses it as the library name; otherwise, it searches for the library in the standard location. Run a shared library under the current directory with the prefix "./".
Ldd cannot work on a. out shared library.
Ldd cannot work on some very old a. out programs that have been created before the release of ldd compilers. If you use ldd in this type of program, the program will try the running mode of argc = 0, and the result is unpredictable.