]>
Commit | Line | Data |
---|---|---|
b122c703 RM |
1 | #! /bin/sh |
2 | ||
b0df72f4 | 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 | ||
b122c703 RM |
22 | # This is the `ldd' command, which lists what shared libraries are |
23 | # used by given dynamically-linked executables. It works by invoking the | |
f0e44959 UD |
24 | # run-time dynamic linker as a command and setting the environment |
25 | # variable LD_TRACE_LOADED_OBJECTS to a non-empty value. | |
b122c703 RM |
26 | |
27 | RTLD=@RTLD@ | |
c84142e8 UD |
28 | warn= |
29 | bind_now= | |
f0e44959 UD |
30 | |
31 | while test $# -gt 0; do | |
32 | case "$1" in | |
ce37fa88 | 33 | --vers | --versi | --versio | --version) |
84384f5b | 34 | echo 'ldd (GNU libc) @VERSION@ |
9eb2730e | 35 | Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. |
84384f5b | 36 | This is free software; see the source for copying conditions. There is NO |
ce37fa88 UD |
37 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
38 | Written by Roland McGrath and Ulrich Drepper.' | |
9eb2730e UD |
39 | exit 0 |
40 | ;; | |
fd26970f | 41 | --h | --he | --hel | --help) |
df4ef2ab | 42 | echo "ldd [OPTION]... FILE... |
fd26970f UD |
43 | --help print this help and exit |
44 | --version print version information and exit | |
45 | -d, --data-relocs process data relocations | |
46 | -r, --function-relocs process data and function relocations | |
ce37fa88 | 47 | -v, --verbose print all information |
af6f3906 | 48 | Report bugs using the \`glibcbug' script to <bugs@gnu.org>." |
9eb2730e UD |
49 | exit 0 |
50 | ;; | |
fd26970f UD |
51 | -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \ |
52 | --data-rel | --data-relo | --data-reloc | --data-relocs) | |
c84142e8 | 53 | warn=yes |
9eb2730e UD |
54 | shift |
55 | ;; | |
fd26970f UD |
56 | -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \ |
57 | --function | --function- | --function-r | --function-re | --function-rel | \ | |
58 | --function-relo | --function-reloc | --function-relocs) | |
c84142e8 UD |
59 | warn=yes |
60 | bind_now=yes | |
9eb2730e UD |
61 | shift |
62 | ;; | |
ce37fa88 UD |
63 | -v | --verb | --verbo | --verbos | --verbose) |
64 | verbose=yes | |
9eb2730e UD |
65 | shift |
66 | ;; | |
ce37fa88 UD |
67 | --v | --ve | --ver) |
68 | echo >&2 "ldd: option \`$1' is ambiguous" | |
9eb2730e UD |
69 | exit 1 |
70 | ;; | |
6d52618b | 71 | --) # Stop option processing. |
9eb2730e UD |
72 | shift; break |
73 | ;; | |
fd26970f UD |
74 | -*) |
75 | echo >&2 "\ | |
76 | ldd: unrecognized option \`$1' | |
77 | Try \`ldd --help' for more information." | |
9eb2730e UD |
78 | exit 1 |
79 | ;; | |
f0e44959 | 80 | *) |
9eb2730e UD |
81 | break |
82 | ;; | |
f0e44959 UD |
83 | esac |
84 | done | |
b122c703 | 85 | |
cb343854 UD |
86 | nonelf () |
87 | { | |
88 | # Maybe extra code for non-ELF binaries. | |
89 | return 1; | |
90 | } | |
91 | ||
2f6d1f1b | 92 | add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" |
ce37fa88 | 93 | add_env="$add_env LD_VERBOSE=$verbose" |
b122c703 RM |
94 | case $# in |
95 | 0) | |
f0e44959 UD |
96 | echo >&2 "\ |
97 | ldd: missing file arguments | |
98 | Try \`ldd --help' for more information." | |
9eb2730e UD |
99 | exit 1 |
100 | ;; | |
b122c703 RM |
101 | 1) |
102 | # We don't list the file name when there is only one. | |
d17e960c | 103 | case "$1" in |
9eb2730e UD |
104 | */*) file="$1" |
105 | ;; | |
106 | *) file="./$1" | |
107 | ;; | |
d17e960c | 108 | esac |
8145a974 | 109 | if test ! -f "$file"; then |
7cc27f44 | 110 | echo "ldd: ${file}: no such file" |
fd26970f | 111 | exit 1 |
61965e9b | 112 | else |
7cc27f44 UD |
113 | if test -r "$file"; then |
114 | test -x "$file" || | |
115 | echo "ldd: warning: you do not have execution permission for \`$file'" | |
2f6d1f1b UD |
116 | ${RTLD} --verify "$file" |
117 | case $? in | |
118 | 0) | |
119 | eval $add_env exec '"$file"' || exit 1 | |
120 | ;; | |
121 | 1) | |
cb343854 | 122 | nonelf $file || |
7cc27f44 UD |
123 | echo ' not a dynamic executable' |
124 | exit 1 | |
2f6d1f1b UD |
125 | ;; |
126 | 2) | |
127 | eval $add_env exec \${RTLD} '"$file"' || exit 1 | |
128 | ;; | |
129 | *) | |
130 | echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2 | |
131 | exit 1 | |
132 | ;; | |
133 | esac | |
fd26970f | 134 | else |
7cc27f44 | 135 | echo "ldd: error: you do not have read permission for \`$file'" |
fd26970f UD |
136 | exit 1 |
137 | fi | |
61965e9b | 138 | fi |
9eb2730e UD |
139 | exit |
140 | ;; | |
b122c703 RM |
141 | *) |
142 | set -e # Bail out immediately if ${RTLD} loses on any argument. | |
fd26970f | 143 | result=0 |
b122c703 RM |
144 | for file; do |
145 | echo "${file}:" | |
d17e960c | 146 | case "$file" in |
9eb2730e UD |
147 | */*) : |
148 | ;; | |
149 | *) file="./$file" | |
150 | ;; | |
d17e960c | 151 | esac |
8145a974 | 152 | if test ! -f "$file"; then |
7cc27f44 | 153 | echo "ldd: ${file}: no such file" |
fd26970f | 154 | result=1 |
61965e9b | 155 | else |
7cc27f44 UD |
156 | if test -r "$file"; then |
157 | test -x "$file" || echo "\ | |
158 | ldd: warning: you do not have execution permission for \`$file'" | |
2f6d1f1b UD |
159 | ${RTLD} --verify "$file" |
160 | case $? in | |
161 | 0) | |
162 | eval $add_env '"$file"' || result=1 | |
163 | ;; | |
164 | 1) | |
cb343854 | 165 | nonelf $file || |
7cc27f44 UD |
166 | echo ' not a dynamic executable' |
167 | result=1 | |
2f6d1f1b UD |
168 | ;; |
169 | 2) | |
170 | eval $add_env ${RTLD} '"$file"' || result=1 | |
171 | ;; | |
172 | *) | |
173 | echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2 | |
174 | exit 1 | |
175 | ;; | |
176 | esac | |
fd26970f | 177 | else |
7cc27f44 | 178 | echo "ldd: error: you do not have read permission for \`$file'" |
fd26970f UD |
179 | result=1 |
180 | fi | |
61965e9b | 181 | fi |
b122c703 RM |
182 | done |
183 | esac | |
184 | ||
fd26970f | 185 | exit $result |