* sysdeps/mach/hurd/dl-sysdep.c (__writev): Does use assert on FD
[glibc.git] / elf / ldd.bash.in
blobaeceae85923fc099799f5f680d4844def12983f8
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 -v, --verbose print all information
54 For bug reporting instructions, please see:
55 <http://www.gnu.org/software/libc/bugs.html>."
56 exit 0
58 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
59 --data-rel | --data-relo | --data-reloc | --data-relocs)
60 warn=yes
61 shift
63 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
64 --function | --function- | --function-r | --function-re | --function-rel | \
65 --function-relo | --function-reloc | --function-relocs)
66 warn=yes
67 bind_now=yes
68 shift
70 -v | --verb | --verbo | --verbos | --verbose)
71 verbose=yes
72 shift
74 --v | --ve | --ver)
75 echo >&2 $"ldd: option \`$1' is ambiguous"
76 exit 1
78 --) # Stop option processing.
79 shift; break
81 -*)
82 echo >&2 'ldd:' $"unrecognized option" "\`$1'"
83 echo >&2 $"Try \`ldd --help' for more information."
84 exit 1
87 break
89 esac
90 done
92 nonelf ()
94 # Maybe extra code for non-ELF binaries.
95 return 1;
98 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
99 add_env="$add_env LD_VERBOSE=$verbose"
100 case $# in
102 echo >&2 'ldd:' $"missing file arguments"
103 echo >&2 $"Try \`ldd --help' for more information."
104 exit 1
107 single_file=t
110 single_file=f
112 esac
114 result=0
115 for file do
116 # We don't list the file name when there is only one.
117 test $single_file = t || echo "${file}:"
118 case $file in
119 */*) :
121 *) file=./$file
123 esac
124 if test ! -f "$file"; then
125 echo "ldd: ${file}:" $"No such file or directory" >&2
126 result=1
127 elif test -r "$file"; then
128 test -x "$file" || echo 'ldd:' $"\
129 warning: you do not have execution permission for" "\`$file'" >&2
130 RTLD=
131 for rtld in ${RTLDLIST}; do
132 if test -x $rtld; then
133 verify_out=`${rtld} --verify "$file"`
134 ret=$?
135 case $ret in
136 [02]) RTLD=${rtld}; break;;
137 esac
139 done
140 if test -z "${RTLD}"; then
141 set ${RTLDLIST}
142 RTLD=$1
143 verify_out=`${RTLD} --verify "$file"`
144 ret=$?
146 case $ret in
148 eval $add_env '"$file"' || result=1
151 # This can be a non-ELF binary or no binary at all.
152 nonelf "$file" || {
153 echo $" not a dynamic executable"
154 result=1
158 eval $add_env \${RTLD} '"$file"' || result=1
161 echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
162 exit 1
164 esac
165 else
166 echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
167 result=1
169 done
171 exit $result
172 # Local Variables:
173 # mode:ksh
174 # End: