]>
Commit | Line | Data |
---|---|---|
f0e44959 | 1 | #! @BASH@ |
3c5edd4d | 2 | # Copyright (C) 1996, 1997, 1998, 1999 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@' |
3c5edd4d | 39 | echo $"Copyright (C) 1999 Free Software Foundation, Inc. |
84384f5b | 40 | This is free software; see the source for copying conditions. There is NO |
ce37fa88 UD |
41 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
42 | Written by Roland McGrath and Ulrich Drepper." | |
9eb2730e UD |
43 | exit 0 |
44 | ;; | |
fd26970f | 45 | --h | --he | --hel | --help) |
43fc8f18 | 46 | echo $"Usage: ldd [OPTION]... FILE... |
fd26970f UD |
47 | --help print this help and exit |
48 | --version print version information and exit | |
49 | -d, --data-relocs process data relocations | |
50 | -r, --function-relocs process data and function relocations | |
ce37fa88 | 51 | -v, --verbose print all information |
af6f3906 | 52 | Report bugs using the \`glibcbug' script to <bugs@gnu.org>." |
9eb2730e UD |
53 | exit 0 |
54 | ;; | |
fd26970f UD |
55 | -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \ |
56 | --data-rel | --data-relo | --data-reloc | --data-relocs) | |
c84142e8 | 57 | warn=yes |
9eb2730e UD |
58 | shift |
59 | ;; | |
fd26970f UD |
60 | -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \ |
61 | --function | --function- | --function-r | --function-re | --function-rel | \ | |
62 | --function-relo | --function-reloc | --function-relocs) | |
c84142e8 UD |
63 | warn=yes |
64 | bind_now=yes | |
9eb2730e UD |
65 | shift |
66 | ;; | |
ce37fa88 UD |
67 | -v | --verb | --verbo | --verbos | --verbose) |
68 | verbose=yes | |
9eb2730e UD |
69 | shift |
70 | ;; | |
ce37fa88 | 71 | --v | --ve | --ver) |
d705269e | 72 | echo >&2 $"ldd: option \`$1' is ambiguous" |
9eb2730e UD |
73 | exit 1 |
74 | ;; | |
6d52618b | 75 | --) # Stop option processing. |
9eb2730e UD |
76 | shift; break |
77 | ;; | |
fd26970f | 78 | -*) |
51702635 | 79 | echo >&2 'ldd:' $"unrecognized option" "\`$1'" |
fd26970f | 80 | echo >&2 $"Try \`ldd --help' for more information." |
9eb2730e UD |
81 | exit 1 |
82 | ;; | |
f0e44959 | 83 | *) |
9eb2730e UD |
84 | break |
85 | ;; | |
f0e44959 UD |
86 | esac |
87 | done | |
88 | ||
cb343854 UD |
89 | nonelf () |
90 | { | |
91 | # Maybe extra code for non-ELF binaries. | |
92 | return 1; | |
93 | } | |
94 | ||
2f6d1f1b | 95 | add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" |
ce37fa88 | 96 | add_env="$add_env LD_VERBOSE=$verbose" |
f0e44959 UD |
97 | case $# in |
98 | 0) | |
51702635 | 99 | echo >&2 'ldd:' $"missing file arguments" |
fd26970f | 100 | echo >&2 $"Try \`ldd --help' for more information." |
9eb2730e UD |
101 | exit 1 |
102 | ;; | |
f0e44959 | 103 | 1) |
ed1ac6a2 UD |
104 | single_file=t |
105 | ;; | |
106 | *) | |
107 | single_file=f | |
108 | ;; | |
109 | esac | |
110 | ||
111 | result=0 | |
112 | for file do | |
f0e44959 | 113 | # We don't list the file name when there is only one. |
ed1ac6a2 UD |
114 | test $single_file = t || echo "${file}:" |
115 | case $file in | |
116 | */*) : | |
9eb2730e | 117 | ;; |
ed1ac6a2 | 118 | *) file=./$file |
9eb2730e | 119 | ;; |
f0e44959 UD |
120 | esac |
121 | if test ! -f "$file"; then | |
ed1ac6a2 UD |
122 | echo "ldd: ${file}:" $"No such file or directory" >&2 |
123 | result=1 | |
7cc27f44 | 124 | elif test -r "$file"; then |
ed1ac6a2 | 125 | test -x "$file" || echo 'ldd:' $"\ |
df777c40 | 126 | warning: you do not have execution permission for" "\`$file'" >&2 |
3a8599b2 UD |
127 | RTLD= |
128 | for rtld in ${RTLDLIST}; do | |
129 | if test -x $rtld; then | |
130 | verify_out=`${rtld} --verify "$file"` | |
131 | ret=$? | |
132 | case $ret in | |
133 | [02]) RTLD=${rtld}; break;; | |
134 | esac | |
135 | fi | |
136 | done | |
137 | if test -z "${RTLD}"; then | |
138 | set ${RTLDLIST} | |
139 | RTLD=$1 | |
140 | verify_out=`${RTLD} --verify "$file"` | |
141 | ret=$? | |
142 | fi | |
143 | case $ret in | |
2f6d1f1b | 144 | 0) |
ed1ac6a2 | 145 | eval $add_env '"$file"' || result=1 |
2f6d1f1b UD |
146 | ;; |
147 | 1) | |
cb343854 | 148 | # This can be a non-ELF binary or no binary at all. |
ed1ac6a2 UD |
149 | nonelf "$file" || { |
150 | echo $" not a dynamic executable" | |
151 | result=1 | |
152 | } | |
2f6d1f1b UD |
153 | ;; |
154 | 2) | |
ed1ac6a2 | 155 | eval $add_env \${RTLD} '"$file"' || result=1 |
2f6d1f1b UD |
156 | ;; |
157 | *) | |
3a8599b2 | 158 | echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2 |
2f6d1f1b UD |
159 | exit 1 |
160 | ;; | |
161 | esac | |
7cc27f44 | 162 | else |
df777c40 | 163 | echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2 |
ed1ac6a2 | 164 | result=1 |
f0e44959 | 165 | fi |
ed1ac6a2 | 166 | done |
f0e44959 | 167 | |
fd26970f | 168 | exit $result |
84384f5b UD |
169 | # Local Variables: |
170 | # mode:ksh | |
171 | # End: |