In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "introduction and use of Ldd commands under Linux". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "introduction and usage of Ldd commands under Linux".
Linux Ldd parameter description:
-- version prints the version number of ldd
-v-- verbose prints all information, such as version information including symbols
-d-- data-relocs performs symbolic redeployment and reports missing targets (ELF format only)
-r-- function-relocs redeploys target objects and functions and reports missing target objects and functions (ELF format only)
-- help usage information
If the library name given on the command line contains'/', the libc5 version of the program will use it as the library name; otherwise, it will search for the library in the standard location. Run a shared library in the current directory with the prefix ". /".
Error:
Ldd cannot work on shared libraries in a.out format.
Ldd does not work on very old a.out programs that were created prior to the release of compilers that support ldd. If you use ldd on this type of program, the program will try to run argc = 0, and the results are unpredictable.
For example:
Ldd / bin/bash
But ldd itself is not a program, but just 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, the function of ldd is to set the values of some environment variables)
Such as: LD_TRACE_LOADED_OBJECTS
As long as the value is set to be non-empty.
$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)
By revoking the environment variable, ls can return to 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
The environment variable enabled by ldd by default is: LD_TRACE_LOADED_OBJECTS=1
The other variables (and values) correspond to some 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 a necessary environment variable, others depend on the specific situation.
The essence of the ldd command is to execute: / lib/ld-linux.so.*
We can find from the above (ls / usr): / lib/ld-linux.so.2 (0xb7fad000).
$ls-l / lib/ld-linux.so.*
Lrwxrwxrwx 1 root root 9 2009-09-05 22:54 / lib/ld-linux.so.2-> ld-2.9.so
The newly compiled file may be: / lib/ld.so. If it's libc5, it's / lib/ld-linux.so.1, and 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 that the above is equivalent to ldd ls.
The shared library files available to ldd are actually files built by reading the ldconfig command (/ etc/ld.so.cache).
The default shared library file search / lib takes precedence over / usr/lib, and there are only two directories. If you want to add other paths, you need to configure the relevant files through the ldconfig command.
Ld-linux.so typically searches for shared libraries in the following order:
1. DT_RPATH or DT_RUNPATH segment
2. Environment variable LD_LIBRARY_PATH
3. The path in the / etc/ld.so.cache file, but if the executable adds the-z nodeflib option when connecting, it is skipped.
4. Default paths / lib and / usr/lib, but skip if-z nodeflib is added.
The following are the supplements of other netizens:
1. First of all, ldd is not an executable program, but just a shell script
2. Ldd can display the dependency of the executable module, the principle is by setting a series of environment variables, as follows: LD_TRACE_LOADED_OBJECTS, LD_WARN, LD_BIND_NOW, LD_LIBRARY_VERSION, LD_VERBOSE and so on. When the LD_TRACE_LOADED_OBJECTS environment variable is not empty, any executable program will only display the dependency of the module when it is running, and the program will not actually execute. Or you can test it at the shell terminal, as follows:
(1) export LD_TRACE_LOADED_OBJECTS=1
(2) execute any program, such as ls, to see the running result of the program.
3. Ldd shows the working principle of dependency of executable module, which is realized by ld-linux.so (loader of elf dynamic library). We know that the ld-linux.so module works before the executable module program and gains control, so when the above environment variables are set, ld-linux.so chooses the dependency that displays the executable module.
4. You can actually execute the ld-linux.so module directly, such as: / lib/ld-linux.so.2-- list program (this is equivalent to ldd program) ldd command usage (extracted from ldd-- help)
Name ldd-print dependency of the shared library
Outline ldd [options]. File.
Describes the shared libraries that ldd outputs for each program or shared library specified on the command line.
Option
-- version
Print the version number of ldd
-v-- verbose
Print all information, such as version information including symbols
-d-- data-relocs
Perform symbolic redeployment and report missing target objects (ELF format only)
-r-- function-relocs
Redeploy target objects and functions and report missing target objects and functions (ELF format only)
-- help usage information
The standard version of ldd is provided with glibc2. Libc5 is previously available in older versions and still exists in some systems. The long option is not supported in libc5 versions. On the other hand, the glibc2 version does not support the-V option and only provides the equivalent-- version option.
If the library name given on the command line contains'/', the libc5 version of the program will use it as the library name; otherwise, it will search for the library in the standard location. Run a shared library in the current directory with the prefix ". /".
Ldd cannot work on shared libraries in a.out format.
Ldd does not work on very old a.out programs that were created prior to the release of compilers that support ldd. If you use ldd on this type of program, the program will try to run argc = 0, and the results are unpredictable.
At this point, I believe you have a deeper understanding of the "introduction and use of Ldd commands under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.