2 # Copyright (C) 1996-2008, 2009 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
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.
28 TEXTDOMAINDIR
=@TEXTDOMAINDIR@
35 while test $# -gt 0; do
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.
43 printf $
"Written by %s and %s.
44 " "Roland McGrath" "Ulrich Drepper"
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
56 echo $
"For bug reporting instructions, please see:
57 <http://www.gnu.org/software/libc/bugs.html>.
61 -d |
--d |
--da |
--dat |
--data |
--data- |
--data-r |
--data-re | \
62 --data-rel |
--data-relo |
--data-reloc |
--data-relocs)
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)
73 -v |
--verb |
--verbo |
--verbos |
--verbose)
77 -u |
--u |
--un |
--unu |
--unus |
--unuse |
--unused)
82 echo >&2 $
"ldd: option \`$1' is ambiguous"
85 --) # Stop option processing.
89 echo >&2 'ldd:' $
"unrecognized option" "\`$1'"
90 echo >&2 $
"Try \`ldd --help' for more information."
101 # Maybe extra code for non-ELF binaries.
105 add_env
="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
106 add_env
="$add_env LD_VERBOSE=$verbose"
107 if test "$unused" = yes; then
108 add_env
="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
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.
115 if set -o pipefail
2> /dev
/null
; then
117 eval $add_env '"$@"' |
cat
127 echo >&2 'ldd:' $
"missing file arguments"
128 echo >&2 $
"Try \`ldd --help' for more information."
141 # We don't list the file name when there is only one.
142 test $single_file = t ||
echo "${file}:"
149 if test ! -e "$file"; then
150 echo "ldd: ${file}:" $
"No such file or directory" >&2
152 elif test ! -f "$file"; then
153 echo "ldd: ${file}:" $
"not regular file" >&2
155 elif test -r "$file"; then
156 test -x "$file" ||
echo 'ldd:' $
"\
157 warning: you do not have execution permission for" "\`$file'" >&2
160 for rtld
in ${RTLDLIST}; do
161 if test -x $rtld; then
162 verify_out
=`${rtld} --verify "$file"`
165 [02]) RTLD
=${rtld}; break;;
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.
177 try_trace
"$RTLD" "$file"
180 [ $rc = 0 ] || result
=1
183 # This can be a non-ELF binary or no binary at all.
185 echo $
" not a dynamic executable"
190 try_trace
"$RTLD" "$file" || result
=1
193 echo 'ldd:' ${RTLD} $
"exited with unknown exit code" "($ret)" >&2
198 echo 'ldd:' $
"error: you do not have read permission for" "\`$file'" >&2