Updated to fedora-glibc-20041210T0634
[glibc.git] / elf / ldd.bash.in
blob5dbf88cdc894f97dabfefd2530dc768e5aca6556
1 #! @BASH@
2 # Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
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.
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
13 # Lesser General Public License for more details.
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.
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.
26 # We should be able to find the translation right at the beginning.
27 TEXTDOMAIN=libc
28 TEXTDOMAINDIR=@TEXTDOMAINDIR@
30 RTLDLIST=@RTLD@
31 warn=
32 bind_now=
33 verbose=
35 while test $# -gt 0; do
36 case "$1" in
37 --vers | --versi | --versio | --version)
38 echo 'ldd (GNU libc) @VERSION@'
39 printf $"Copyright (C) %s Free Software Foundation, Inc.
40 This is free software; see the source for copying conditions. There is NO
41 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
42 " "2004"
43 printf $"Written by %s and %s.
44 " "Roland McGrath" "Ulrich Drepper"
45 exit 0
47 --h | --he | --hel | --help)
48 echo $"Usage: ldd [OPTION]... FILE...
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
53 -u, --unused print unused direct dependencies
54 -v, --verbose print all information
55 For bug reporting instructions, please see:
56 <http://www.gnu.org/software/libc/bugs.html>."
57 exit 0
59 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
60 --data-rel | --data-relo | --data-reloc | --data-relocs)
61 warn=yes
62 shift
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)
67 warn=yes
68 bind_now=yes
69 shift
71 -v | --verb | --verbo | --verbos | --verbose)
72 verbose=yes
73 shift
75 -u | --u | --un | --unu | --unus | --unuse | --unused)
76 unused=yes
77 bind_now=yes
78 shift
80 --v | --ve | --ver)
81 echo >&2 $"ldd: option \`$1' is ambiguous"
82 exit 1
84 --) # Stop option processing.
85 shift; break
87 -*)
88 echo >&2 'ldd:' $"unrecognized option" "\`$1'"
89 echo >&2 $"Try \`ldd --help' for more information."
90 exit 1
93 break
95 esac
96 done
98 nonelf ()
100 # Maybe extra code for non-ELF binaries.
101 return 1;
104 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
105 add_env="$add_env LD_VERBOSE=$verbose"
106 if test "$unused" = yes; then
107 add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
110 # The following use of cat is needed to make ldd work in SELinux
111 # environments where the executed program might not have permissions
112 # to write to the console/tty. But only bash 3.x supports the pipefail
113 # option, and we don't bother to handle the case for older bash versions.
114 if set -o pipefail 2> /dev/null; then
115 try_trace() {
116 eval $add_env '"$@"' | cat
118 else
119 try_trace() {
120 eval $add_env '"$@"'
124 case $# in
126 echo >&2 'ldd:' $"missing file arguments"
127 echo >&2 $"Try \`ldd --help' for more information."
128 exit 1
131 single_file=t
134 single_file=f
136 esac
138 result=0
139 for file do
140 # We don't list the file name when there is only one.
141 test $single_file = t || echo "${file}:"
142 case $file in
143 */*) :
145 *) file=./$file
147 esac
148 if test ! -f "$file"; then
149 echo "ldd: ${file}:" $"No such file or directory" >&2
150 result=1
151 elif test -r "$file"; then
152 test -x "$file" || echo 'ldd:' $"\
153 warning: you do not have execution permission for" "\`$file'" >&2
154 RTLD=
155 for rtld in ${RTLDLIST}; do
156 if test -x $rtld; then
157 verify_out=`${rtld} --verify "$file"`
158 ret=$?
159 case $ret in
160 [02]) RTLD=${rtld}; break;;
161 esac
163 done
164 if test -z "${RTLD}"; then
165 set ${RTLDLIST}
166 RTLD=$1
167 verify_out=`${RTLD} --verify "$file"`
168 ret=$?
170 case $ret in
172 # If the program exits with exit code 5, it means the process has been
173 # invoked with __libc_enable_secure. Fall back to running it through
174 # the dynamic linker.
175 try_trace "$file"
176 rc=$?
177 if [ $rc = 5 ]; then
178 try_trace "$RTLD" "$file"
179 rc=$?
181 [ $rc = 0 ] || result=1
184 # This can be a non-ELF binary or no binary at all.
185 nonelf "$file" || {
186 echo $" not a dynamic executable"
187 result=1
191 try_trace "$RTLD" "$file" || result=1
194 echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
195 exit 1
197 esac
198 else
199 echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
200 result=1
202 done
204 exit $result
205 # Local Variables:
206 # mode:ksh
207 # End: