]>
Commit | Line | Data |
---|---|---|
f0e44959 | 1 | #! @BASH@ |
11bf311e | 2 | # Copyright (C) 1996-2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
84384f5b UD |
3 | # This file is part of the GNU C Library. |
4 | ||
5 | # The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | # modify it under the terms of the GNU Lesser General Public |
7 | # License as published by the Free Software Foundation; either | |
8 | # version 2.1 of the License, or (at your option) any later version. | |
84384f5b UD |
9 | |
10 | # The GNU C Library is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | # Lesser General Public License for more details. |
84384f5b | 14 | |
41bdb6e2 AJ |
15 | # You should have received a copy of the GNU Lesser General Public |
16 | # License along with the GNU C Library; if not, write to the Free | |
17 | # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | # 02111-1307 USA. | |
84384f5b UD |
19 | |
20 | ||
f0e44959 UD |
21 | # This is the `ldd' command, which lists what shared libraries are |
22 | # used by given dynamically-linked executables. It works by invoking the | |
23 | # run-time dynamic linker as a command and setting the environment | |
24 | # variable LD_TRACE_LOADED_OBJECTS to a non-empty value. | |
25 | ||
84384f5b UD |
26 | # We should be able to find the translation right at the beginning. |
27 | TEXTDOMAIN=libc | |
28 | TEXTDOMAINDIR=@TEXTDOMAINDIR@ | |
29 | ||
3a8599b2 | 30 | RTLDLIST=@RTLD@ |
c84142e8 UD |
31 | warn= |
32 | bind_now= | |
ce37fa88 | 33 | verbose= |
f0e44959 UD |
34 | |
35 | while test $# -gt 0; do | |
36 | case "$1" in | |
ce37fa88 | 37 | --vers | --versi | --versio | --version) |
1f205a47 | 38 | echo 'ldd (GNU libc) @VERSION@' |
8e597a18 | 39 | printf $"Copyright (C) %s Free Software Foundation, Inc. |
84384f5b | 40 | This is free software; see the source for copying conditions. There is NO |
ce37fa88 | 41 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11bf311e | 42 | " "2007" |
8e597a18 UD |
43 | printf $"Written by %s and %s. |
44 | " "Roland McGrath" "Ulrich Drepper" | |
9eb2730e UD |
45 | exit 0 |
46 | ;; | |
fd26970f | 47 | --h | --he | --hel | --help) |
43fc8f18 | 48 | echo $"Usage: ldd [OPTION]... FILE... |
fd26970f UD |
49 | --help print this help and exit |
50 | --version print version information and exit | |
51 | -d, --data-relocs process data relocations | |
52 | -r, --function-relocs process data and function relocations | |
7a11603d | 53 | -u, --unused print unused direct dependencies |
ce37fa88 | 54 | -v, --verbose print all information |
d40eb37a UD |
55 | For bug reporting instructions, please see: |
56 | <http://www.gnu.org/software/libc/bugs.html>." | |
9eb2730e UD |
57 | exit 0 |
58 | ;; | |
fd26970f UD |
59 | -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \ |
60 | --data-rel | --data-relo | --data-reloc | --data-relocs) | |
c84142e8 | 61 | warn=yes |
9eb2730e UD |
62 | shift |
63 | ;; | |
fd26970f UD |
64 | -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \ |
65 | --function | --function- | --function-r | --function-re | --function-rel | \ | |
66 | --function-relo | --function-reloc | --function-relocs) | |
c84142e8 UD |
67 | warn=yes |
68 | bind_now=yes | |
9eb2730e UD |
69 | shift |
70 | ;; | |
ce37fa88 UD |
71 | -v | --verb | --verbo | --verbos | --verbose) |
72 | verbose=yes | |
9eb2730e UD |
73 | shift |
74 | ;; | |
7a11603d UD |
75 | -u | --u | --un | --unu | --unus | --unuse | --unused) |
76 | unused=yes | |
77 | shift | |
366ca3ac | 78 | ;; |
ce37fa88 | 79 | --v | --ve | --ver) |
d705269e | 80 | echo >&2 $"ldd: option \`$1' is ambiguous" |
9eb2730e UD |
81 | exit 1 |
82 | ;; | |
6d52618b | 83 | --) # Stop option processing. |
9eb2730e UD |
84 | shift; break |
85 | ;; | |
fd26970f | 86 | -*) |
51702635 | 87 | echo >&2 'ldd:' $"unrecognized option" "\`$1'" |
fd26970f | 88 | echo >&2 $"Try \`ldd --help' for more information." |
9eb2730e UD |
89 | exit 1 |
90 | ;; | |
f0e44959 | 91 | *) |
9eb2730e UD |
92 | break |
93 | ;; | |
f0e44959 UD |
94 | esac |
95 | done | |
96 | ||
cb343854 UD |
97 | nonelf () |
98 | { | |
99 | # Maybe extra code for non-ELF binaries. | |
100 | return 1; | |
101 | } | |
102 | ||
2f6d1f1b | 103 | add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" |
ce37fa88 | 104 | add_env="$add_env LD_VERBOSE=$verbose" |
7a11603d | 105 | if test "$unused" = yes; then |
366ca3ac | 106 | add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\"" |
7a11603d | 107 | fi |
f57a3c94 RM |
108 | |
109 | # The following use of cat is needed to make ldd work in SELinux | |
110 | # environments where the executed program might not have permissions | |
111 | # to write to the console/tty. But only bash 3.x supports the pipefail | |
112 | # option, and we don't bother to handle the case for older bash versions. | |
113 | if set -o pipefail 2> /dev/null; then | |
114 | try_trace() { | |
115 | eval $add_env '"$@"' | cat | |
116 | } | |
117 | else | |
118 | try_trace() { | |
119 | eval $add_env '"$@"' | |
120 | } | |
121 | fi | |
122 | ||
f0e44959 UD |
123 | case $# in |
124 | 0) | |
51702635 | 125 | echo >&2 'ldd:' $"missing file arguments" |
fd26970f | 126 | echo >&2 $"Try \`ldd --help' for more information." |
9eb2730e UD |
127 | exit 1 |
128 | ;; | |
f0e44959 | 129 | 1) |
ed1ac6a2 UD |
130 | single_file=t |
131 | ;; | |
132 | *) | |
133 | single_file=f | |
134 | ;; | |
135 | esac | |
136 | ||
137 | result=0 | |
138 | for file do | |
f0e44959 | 139 | # We don't list the file name when there is only one. |
ed1ac6a2 UD |
140 | test $single_file = t || echo "${file}:" |
141 | case $file in | |
142 | */*) : | |
9eb2730e | 143 | ;; |
ed1ac6a2 | 144 | *) file=./$file |
9eb2730e | 145 | ;; |
f0e44959 | 146 | esac |
7cd67fd8 | 147 | if test ! -e "$file"; then |
ed1ac6a2 UD |
148 | echo "ldd: ${file}:" $"No such file or directory" >&2 |
149 | result=1 | |
7cd67fd8 UD |
150 | elif test ! -f "$file"; then |
151 | echo "ldd: ${file}:" $"not regular file" >&2 | |
152 | result=1 | |
7cc27f44 | 153 | elif test -r "$file"; then |
ed1ac6a2 | 154 | test -x "$file" || echo 'ldd:' $"\ |
df777c40 | 155 | warning: you do not have execution permission for" "\`$file'" >&2 |
3a8599b2 | 156 | RTLD= |
34e21278 | 157 | ret=1 |
3a8599b2 UD |
158 | for rtld in ${RTLDLIST}; do |
159 | if test -x $rtld; then | |
160 | verify_out=`${rtld} --verify "$file"` | |
161 | ret=$? | |
162 | case $ret in | |
163 | [02]) RTLD=${rtld}; break;; | |
164 | esac | |
165 | fi | |
166 | done | |
3a8599b2 | 167 | case $ret in |
2f6d1f1b | 168 | 0) |
f57a3c94 RM |
169 | # If the program exits with exit code 5, it means the process has been |
170 | # invoked with __libc_enable_secure. Fall back to running it through | |
171 | # the dynamic linker. | |
172 | try_trace "$file" | |
173 | rc=$? | |
174 | if [ $rc = 5 ]; then | |
175 | try_trace "$RTLD" "$file" | |
176 | rc=$? | |
177 | fi | |
178 | [ $rc = 0 ] || result=1 | |
2f6d1f1b UD |
179 | ;; |
180 | 1) | |
cb343854 | 181 | # This can be a non-ELF binary or no binary at all. |
ed1ac6a2 UD |
182 | nonelf "$file" || { |
183 | echo $" not a dynamic executable" | |
184 | result=1 | |
185 | } | |
2f6d1f1b UD |
186 | ;; |
187 | 2) | |
f57a3c94 | 188 | try_trace "$RTLD" "$file" || result=1 |
2f6d1f1b UD |
189 | ;; |
190 | *) | |
3a8599b2 | 191 | echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2 |
2f6d1f1b UD |
192 | exit 1 |
193 | ;; | |
194 | esac | |
7cc27f44 | 195 | else |
df777c40 | 196 | echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2 |
ed1ac6a2 | 197 | result=1 |
f0e44959 | 198 | fi |
ed1ac6a2 | 199 | done |
f0e44959 | 200 | |
fd26970f | 201 | exit $result |
84384f5b UD |
202 | # Local Variables: |
203 | # mode:ksh | |
204 | # End: |