]> git.ipfire.org Git - thirdparty/glibc.git/blob - elf/ldd.sh.in
16d3fd8b7948ced4bc245c22e26fbfa74f68cefc
[thirdparty/glibc.git] / elf / ldd.sh.in
1 #! /bin/sh
2
3 # This is the `ldd' command, which lists what shared libraries are
4 # used by given dynamically-linked executables. It works by invoking the
5 # run-time dynamic linker as a command and setting the environment
6 # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
7
8 RTLD=@RTLD@
9 usage="\
10 ldd [OPTION]... FILE...
11 --help print this help and exit
12 --version print version information and exit
13 Report bugs to <bug-glibc@prep.ai.mit.edu>."
14
15 while test $# -gt 0; do
16 case "$1" in
17 --v*)
18 echo 'ldd (GNU libc) @VERSION@'; exit 0 ;;
19 --h*)
20 echo "$usage"; exit 0 ;;
21 --) # Stop option prcessing
22 shift; break ;;
23 *)
24 break ;;
25 esac
26 done
27
28 case $# in
29 0)
30 echo >&2 "\
31 ldd: missing file arguments
32 Try \`ldd --help' for more information."
33 exit 1 ;;
34 1)
35 # We don't list the file name when there is only one.
36 case "$1" in
37 /*) file="$1" ;;
38 *) file="./$1" ;;
39 esac
40 if test ! -f "$file"; then
41 echo "${file}: no such file"
42 elif ${RTLD} --verify "$file"; then
43 LD_TRACE_LOADED_OBJECTS=1 exec ${RTLD} "$file" && exit 1
44 else
45 echo ' not a dynamic executable'
46 fi
47 exit ;;
48 *)
49 set -e # Bail out immediately if ${RTLD} loses on any argument.
50 for file; do
51 echo "${file}:"
52 case "$file" in
53 /*) : ;;
54 *) file="./$file" ;;
55 esac
56 if test ! -f "$file"; then
57 echo "$file: no such file"
58 elif ${RTLD} --verify "$file"; then
59 LD_TRACE_LOADED_OBJECTS=1 ${RTLD} "$file"
60 else
61 echo ' not a dynamic executable'
62 fi
63 done
64 esac
65
66 exit 0