Fix isblank / isascii / toascii namespace (bug 17635).
[glibc.git] / elf / ldd.bash.in
blob7fb6c157a02a9d087120c9aa6352563566da0c3c
1 #! @BASH@
2 # Copyright (C) 1996-2015 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, see
17 # <http://www.gnu.org/licenses/>.
20 # This is the `ldd' command, which lists what shared libraries are
21 # used by given dynamically-linked executables. It works by invoking the
22 # run-time dynamic linker as a command and setting the environment
23 # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
25 # We should be able to find the translation right at the beginning.
26 TEXTDOMAIN=libc
27 TEXTDOMAINDIR=@TEXTDOMAINDIR@
29 RTLDLIST=@RTLD@
30 warn=
31 bind_now=
32 verbose=
34 while test $# -gt 0; do
35 case "$1" in
36 --vers | --versi | --versio | --version)
37 echo 'ldd @PKGVERSION@@VERSION@'
38 printf $"Copyright (C) %s Free Software Foundation, Inc.
39 This is free software; see the source for copying conditions. There is NO
40 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
41 " "2015"
42 printf $"Written by %s and %s.
43 " "Roland McGrath" "Ulrich Drepper"
44 exit 0
46 --h | --he | --hel | --help)
47 echo $"Usage: ldd [OPTION]... FILE...
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
52 -u, --unused print unused direct dependencies
53 -v, --verbose print all information
55 printf $"For bug reporting instructions, please see:\\n%s.\\n" \
56 "@REPORT_BUGS_TO@"
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 shift
79 --v | --ve | --ver)
80 echo >&2 $"ldd: option \`$1' is ambiguous"
81 exit 1
83 --) # Stop option processing.
84 shift; break
86 -*)
87 echo >&2 'ldd:' $"unrecognized option" "\`$1'"
88 echo >&2 $"Try \`ldd --help' for more information."
89 exit 1
92 break
94 esac
95 done
97 nonelf ()
99 # Maybe extra code for non-ELF binaries.
100 return 1;
103 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
104 add_env="$add_env LD_VERBOSE=$verbose"
105 if test "$unused" = yes; then
106 add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
109 # The following command substitution is needed to make ldd work in SELinux
110 # environments where the RTLD might not have permission to write to the
111 # terminal. The extra "x" character prevents the shell from trimming trailing
112 # newlines from command substitution results. This function is defined as a
113 # subshell compound list (using "(...)") to prevent parameter assignments from
114 # affecting the calling shell execution environment.
115 try_trace() (
116 output=$(eval $add_env '"$@"' 2>&1; rc=$?; printf 'x'; exit $rc)
117 rc=$?
118 printf '%s' "${output%x}"
119 return $rc
122 case $# in
124 echo >&2 'ldd:' $"missing file arguments"
125 echo >&2 $"Try \`ldd --help' for more information."
126 exit 1
129 single_file=t
132 single_file=f
134 esac
136 result=0
137 for file do
138 # We don't list the file name when there is only one.
139 test $single_file = t || echo "${file}:"
140 case $file in
141 */*) :
143 *) file=./$file
145 esac
146 if test ! -e "$file"; then
147 echo "ldd: ${file}:" $"No such file or directory" >&2
148 result=1
149 elif test ! -f "$file"; then
150 echo "ldd: ${file}:" $"not regular file" >&2
151 result=1
152 elif test -r "$file"; then
153 test -x "$file" || echo 'ldd:' $"\
154 warning: you do not have execution permission for" "\`$file'" >&2
155 RTLD=
156 ret=1
157 for rtld in ${RTLDLIST}; do
158 if test -x $rtld; then
159 verify_out=`${rtld} --verify "$file"`
160 ret=$?
161 case $ret in
162 [02]) RTLD=${rtld}; break;;
163 esac
165 done
166 case $ret in
168 # If the program exits with exit code 5, it means the process has been
169 # invoked with __libc_enable_secure. Fall back to running it through
170 # the dynamic linker.
171 try_trace "$file"
172 rc=$?
173 if [ $rc = 5 ]; then
174 try_trace "$RTLD" "$file"
175 rc=$?
177 [ $rc = 0 ] || result=1
180 # This can be a non-ELF binary or no binary at all.
181 nonelf "$file" || {
182 echo $" not a dynamic executable"
183 result=1
187 try_trace "$RTLD" "$file" || result=1
190 echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
191 exit 1
193 esac
194 else
195 echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
196 result=1
198 done
200 exit $result
201 # Local Variables:
202 # mode:ksh
203 # End: