ldd is a unix utility to list dynamic dependencies of a program or library. i.e. given a program or library, it will display what other libraries it requires to run and what libraries they depend on to run, etc.
In order to obtain this information on Linux systems, the dynamic linker is actually run and it starts preparing the program to run without actually running it. ldd is actually just a script on most modern Linux systems which just calls the appropriate dynamic linker (on 64 bit systems there may be two - e.g. /lib64/ld-linux-x86-64.so.2 as well as /lib/ld-linux.so.2).
For example, the following two commands will produce the same results on a 32 bit Linux system:
/lib/ld-linux.so.2 --list /bin/bash and
ldd /bin/bash
But what about if you want to quickly check the library dependencies of a cross-compiled program? Then this simple utility will help you. Instead of trying to execute the program, it examines the file and extracts the names of the libraries it requires. It does this by extracting ELF file DT_NEEDED and INTERP fields.
There are two disadvantages to this technique:
- The load address cannot be obtained as there is no interaction with the kernel to obtain this
- Runtime loaded libraries (opened with dlopen) will not be reported
However, for a simple check this utility is useful. At MathEmbedded.com we use it to create minimal application-specific root filesystems. Starting with a set of embedded applications, we can extract which libraries they need and add only these libraries to a new root filesystem. This minimises the root filesystem size and stops unnecessary programs being included in the root filesystem therefore increasing system security and auditability.