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