ldd
List shared library dependencies of executables
TLDR
Display shared library dependencies of a binary
Display all information about dependencies
Display unused direct dependencies
Report missing data objects and perform data relocations
Report missing data objects and functions, and perform relocations for both
SYNOPSIS
ldd [option]... file...
PARAMETERS
-h, --help
Display this help message and exit
-V, --version
Print version information and exit
-v, --verbose
Verbose mode: print all details, including symbol versioning
-u, --unused
Print unused direct dependencies
-r, --function-relocs
Print relocation processing information for functions
-d, --data-relocs
Print relocation processing for data objects
-R, --text-relocs
Print relocation processing for text/code
--list
Equivalent to -r -d -R (list all relocations)
-I, --ignore-missing
Ignore missing libraries and continue
DESCRIPTION
The ldd command displays the shared libraries required by an ELF executable, shared object, or core dump file. It is invaluable for diagnosing linking issues, verifying dependencies for portability, and understanding runtime library needs.
ldd achieves this by invoking the dynamic linker/loader (ld.so or ld-linux.so) with the environment variable LD_TRACE_LOADED_OBJECTS set to 1. This simulates program execution but traces library loading instead of running the main code. Output shows each library, its full path, and memory address, e.g., libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8b2c000000).
Use cases include checking for missing libraries before deployment, identifying version mismatches, or auditing dependencies in containers. It works on dynamically linked ELF binaries but fails on static executables (showing 'not a dynamic executable') or non-ELF files. For verbose details like symbol versions or relocations, use options like -v.
CAVEATS
ldd executes untrusted binaries via the dynamic linker, posing a security risk if the file contains malicious code. Avoid using on untrusted inputs. Does not support a.out binaries or fully static executables. Combining certain relocation flags (-r/-d/-R) with -u is invalid.
OUTPUT EXAMPLE
/bin/ls
linux-vdso.so.1 (0x00007ffc12345000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f8b2c123000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8b2c000000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8b2c600000)
ALTERNATIVES FOR STATIC ANALYSIS
For safer inspection without execution, use readelf -d file | grep NEEDED or objdump -p file | grep NEEDED to list required libraries statically.
HISTORY
Introduced with GNU C Library (glibc) in the early 1990s alongside ELF support. Evolved with glibc versions to add relocation tracing (glibc 2.3+), verbose symbol info, and security mitigations. Widely used on Linux systems; BSD variants exist as ldd or lddtree.


