Update.
[glibc.git] / elf / ldd.sh.in
blob2447a90a3e594642b2ed011376976f4c057581a8
1 #! /bin/sh
3 # Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB. If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
22 # This is the `ldd' command, which lists what shared libraries are
23 # used by given dynamically-linked executables. It works by invoking the
24 # run-time dynamic linker as a command and setting the environment
25 # variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
27 RTLD=@RTLD@
28 warn=
29 bind_now=
31 while test $# -gt 0; do
32 case "$1" in
33 --vers | --versi | --versio | --version)
34 echo 'ldd (GNU libc) @VERSION@
35 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
36 This is free software; see the source for copying conditions. There is NO
37 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38 Written by Roland McGrath and Ulrich Drepper.'
39 exit 0
41 --h | --he | --hel | --help)
42 echo "ldd [OPTION]... FILE...
43 --help print this help and exit
44 --version print version information and exit
45 -d, --data-relocs process data relocations
46 -r, --function-relocs process data and function relocations
47 -v, --verbose print all information
48 Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
49 exit 0
51 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
52 --data-rel | --data-relo | --data-reloc | --data-relocs)
53 warn=yes
54 shift
56 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
57 --function | --function- | --function-r | --function-re | --function-rel | \
58 --function-relo | --function-reloc | --function-relocs)
59 warn=yes
60 bind_now=yes
61 shift
63 -v | --verb | --verbo | --verbos | --verbose)
64 verbose=yes
65 shift
67 --v | --ve | --ver)
68 echo >&2 "ldd: option \`$1' is ambiguous"
69 exit 1
71 --) # Stop option processing.
72 shift; break
74 -*)
75 echo >&2 "\
76 ldd: unrecognized option \`$1'
77 Try \`ldd --help' for more information."
78 exit 1
81 break
83 esac
84 done
86 nonelf ()
88 # Maybe extra code for non-ELF binaries.
89 return 1;
92 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
93 add_env="$add_env LD_VERBOSE=$verbose"
94 case $# in
96 echo >&2 "\
97 ldd: missing file arguments
98 Try \`ldd --help' for more information."
99 exit 1
102 # We don't list the file name when there is only one.
103 case "$1" in
104 */*) file="$1"
106 *) file="./$1"
108 esac
109 if test ! -f "$file"; then
110 echo "ldd: ${file}: no such file"
111 exit 1
112 else
113 if test -r "$file"; then
114 test -x "$file" ||
115 echo "ldd: warning: you do not have execution permission for \`$file'"
116 verify_out=`${RTLD} --verify "$file"`
117 case $? in
119 eval $add_env exec '"$file"' || exit 1
122 nonelf $file ||
123 echo ' not a dynamic executable'
124 exit 1
127 eval $add_env exec \${RTLD} '"$file"' || exit 1
130 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
131 exit 1
133 esac
134 else
135 echo "ldd: error: you do not have read permission for \`$file'"
136 exit 1
139 exit
142 set -e # Bail out immediately if ${RTLD} loses on any argument.
143 result=0
144 for file; do
145 echo "${file}:"
146 case "$file" in
147 */*) :
149 *) file="./$file"
151 esac
152 if test ! -f "$file"; then
153 echo "ldd: ${file}: no such file"
154 result=1
155 else
156 if test -r "$file"; then
157 test -x "$file" || echo "\
158 ldd: warning: you do not have execution permission for \`$file'"
159 verify_out=`${RTLD} --verify "$file"`
160 case $? in
162 eval $add_env '"$file"' || result=1
165 nonelf $file ||
166 echo ' not a dynamic executable'
167 result=1
170 eval $add_env ${RTLD} '"$file"' || result=1
173 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
174 exit 1
176 esac
177 else
178 echo "ldd: error: you do not have read permission for \`$file'"
179 result=1
182 done
183 esac
185 exit $result