]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/ldd.bash.in
Update copyright year
[thirdparty/glibc.git] / elf / ldd.bash.in
CommitLineData
f0e44959 1#! @BASH@
81fb02b0 2# Copyright (C) 1996-2011, 2012 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.
27TEXTDOMAIN=libc
28TEXTDOMAINDIR=@TEXTDOMAINDIR@
29
3a8599b2 30RTLDLIST=@RTLD@
c84142e8
UD
31warn=
32bind_now=
ce37fa88 33verbose=
f0e44959
UD
34
35while 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 40This is free software; see the source for copying conditions. There is NO
ce37fa88 41warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
81fb02b0 42" "2012"
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
cbbcaf23
UD
55"
56 echo $"For bug reporting instructions, please see:
57<http://www.gnu.org/software/libc/bugs.html>.
58"
9eb2730e
UD
59 exit 0
60 ;;
fd26970f
UD
61 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
62 --data-rel | --data-relo | --data-reloc | --data-relocs)
c84142e8 63 warn=yes
9eb2730e
UD
64 shift
65 ;;
fd26970f
UD
66 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
67 --function | --function- | --function-r | --function-re | --function-rel | \
68 --function-relo | --function-reloc | --function-relocs)
c84142e8
UD
69 warn=yes
70 bind_now=yes
9eb2730e
UD
71 shift
72 ;;
ce37fa88
UD
73 -v | --verb | --verbo | --verbos | --verbose)
74 verbose=yes
9eb2730e
UD
75 shift
76 ;;
7a11603d
UD
77 -u | --u | --un | --unu | --unus | --unuse | --unused)
78 unused=yes
79 shift
366ca3ac 80 ;;
ce37fa88 81 --v | --ve | --ver)
d705269e 82 echo >&2 $"ldd: option \`$1' is ambiguous"
9eb2730e
UD
83 exit 1
84 ;;
6d52618b 85 --) # Stop option processing.
9eb2730e
UD
86 shift; break
87 ;;
fd26970f 88 -*)
51702635 89 echo >&2 'ldd:' $"unrecognized option" "\`$1'"
fd26970f 90 echo >&2 $"Try \`ldd --help' for more information."
9eb2730e
UD
91 exit 1
92 ;;
f0e44959 93 *)
9eb2730e
UD
94 break
95 ;;
f0e44959
UD
96 esac
97done
98
cb343854
UD
99nonelf ()
100{
101 # Maybe extra code for non-ELF binaries.
102 return 1;
103}
104
2f6d1f1b 105add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
ce37fa88 106add_env="$add_env LD_VERBOSE=$verbose"
7a11603d 107if test "$unused" = yes; then
366ca3ac 108 add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
7a11603d 109fi
f57a3c94
RM
110
111# The following use of cat is needed to make ldd work in SELinux
112# environments where the executed program might not have permissions
113# to write to the console/tty. But only bash 3.x supports the pipefail
114# option, and we don't bother to handle the case for older bash versions.
115if set -o pipefail 2> /dev/null; then
116 try_trace() {
117 eval $add_env '"$@"' | cat
118 }
119else
120 try_trace() {
121 eval $add_env '"$@"'
122 }
123fi
124
f0e44959
UD
125case $# in
1260)
51702635 127 echo >&2 'ldd:' $"missing file arguments"
fd26970f 128 echo >&2 $"Try \`ldd --help' for more information."
9eb2730e
UD
129 exit 1
130 ;;
f0e44959 1311)
ed1ac6a2
UD
132 single_file=t
133 ;;
134*)
135 single_file=f
136 ;;
137esac
138
139result=0
140for file do
f0e44959 141 # We don't list the file name when there is only one.
ed1ac6a2
UD
142 test $single_file = t || echo "${file}:"
143 case $file in
144 */*) :
9eb2730e 145 ;;
ed1ac6a2 146 *) file=./$file
9eb2730e 147 ;;
f0e44959 148 esac
7cd67fd8 149 if test ! -e "$file"; then
ed1ac6a2
UD
150 echo "ldd: ${file}:" $"No such file or directory" >&2
151 result=1
7cd67fd8
UD
152 elif test ! -f "$file"; then
153 echo "ldd: ${file}:" $"not regular file" >&2
154 result=1
7cc27f44 155 elif test -r "$file"; then
ed1ac6a2 156 test -x "$file" || echo 'ldd:' $"\
df777c40 157warning: you do not have execution permission for" "\`$file'" >&2
3a8599b2 158 RTLD=
34e21278 159 ret=1
3a8599b2
UD
160 for rtld in ${RTLDLIST}; do
161 if test -x $rtld; then
162 verify_out=`${rtld} --verify "$file"`
561470e0 163 ret=$?
3a8599b2
UD
164 case $ret in
165 [02]) RTLD=${rtld}; break;;
166 esac
167 fi
168 done
3a8599b2 169 case $ret in
2f6d1f1b 170 0)
f57a3c94
RM
171 # If the program exits with exit code 5, it means the process has been
172 # invoked with __libc_enable_secure. Fall back to running it through
173 # the dynamic linker.
174 try_trace "$file"
175 rc=$?
176 if [ $rc = 5 ]; then
177 try_trace "$RTLD" "$file"
178 rc=$?
179 fi
180 [ $rc = 0 ] || result=1
2f6d1f1b
UD
181 ;;
182 1)
cb343854 183 # This can be a non-ELF binary or no binary at all.
ed1ac6a2
UD
184 nonelf "$file" || {
185 echo $" not a dynamic executable"
186 result=1
187 }
2f6d1f1b
UD
188 ;;
189 2)
f57a3c94 190 try_trace "$RTLD" "$file" || result=1
2f6d1f1b
UD
191 ;;
192 *)
3a8599b2 193 echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
2f6d1f1b
UD
194 exit 1
195 ;;
196 esac
7cc27f44 197 else
df777c40 198 echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
ed1ac6a2 199 result=1
f0e44959 200 fi
ed1ac6a2 201done
f0e44959 202
fd26970f 203exit $result
84384f5b
UD
204# Local Variables:
205# mode:ksh
206# End: