]> sourceware.org Git - glibc.git/blame - elf/ldd.sh.in
Update.
[glibc.git] / elf / ldd.sh.in
CommitLineData
b122c703
RM
1#! /bin/sh
2
b0df72f4 3# Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
84384f5b
UD
4# This file is part of the GNU C Library.
5
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.
10
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.
15
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.
20
21
b122c703
RM
22# This is the `ldd' command, which lists what shared libraries are
23# used by given dynamically-linked executables. It works by invoking the
f0e44959
UD
24# run-time dynamic linker as a command and setting the environment
25# variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
b122c703
RM
26
27RTLD=@RTLD@
c84142e8
UD
28warn=
29bind_now=
f0e44959
UD
30
31while test $# -gt 0; do
32 case "$1" in
ce37fa88 33 --vers | --versi | --versio | --version)
84384f5b 34 echo 'ldd (GNU libc) @VERSION@
9eb2730e 35Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
84384f5b 36This is free software; see the source for copying conditions. There is NO
ce37fa88
UD
37warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
38Written by Roland McGrath and Ulrich Drepper.'
9eb2730e
UD
39 exit 0
40 ;;
fd26970f 41 --h | --he | --hel | --help)
df4ef2ab 42 echo "ldd [OPTION]... FILE...
fd26970f
UD
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
ce37fa88 47 -v, --verbose print all information
af6f3906 48Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
9eb2730e
UD
49 exit 0
50 ;;
fd26970f
UD
51 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
52 --data-rel | --data-relo | --data-reloc | --data-relocs)
c84142e8 53 warn=yes
9eb2730e
UD
54 shift
55 ;;
fd26970f
UD
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)
c84142e8
UD
59 warn=yes
60 bind_now=yes
9eb2730e
UD
61 shift
62 ;;
ce37fa88
UD
63 -v | --verb | --verbo | --verbos | --verbose)
64 verbose=yes
9eb2730e
UD
65 shift
66 ;;
ce37fa88
UD
67 --v | --ve | --ver)
68 echo >&2 "ldd: option \`$1' is ambiguous"
9eb2730e
UD
69 exit 1
70 ;;
6d52618b 71 --) # Stop option processing.
9eb2730e
UD
72 shift; break
73 ;;
fd26970f
UD
74 -*)
75 echo >&2 "\
76ldd: unrecognized option \`$1'
77Try \`ldd --help' for more information."
9eb2730e
UD
78 exit 1
79 ;;
f0e44959 80 *)
9eb2730e
UD
81 break
82 ;;
f0e44959
UD
83 esac
84done
b122c703 85
2f6d1f1b 86add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
ce37fa88 87add_env="$add_env LD_VERBOSE=$verbose"
b122c703
RM
88case $# in
890)
f0e44959
UD
90 echo >&2 "\
91ldd: missing file arguments
92Try \`ldd --help' for more information."
9eb2730e
UD
93 exit 1
94 ;;
b122c703
RM
951)
96 # We don't list the file name when there is only one.
d17e960c 97 case "$1" in
9eb2730e
UD
98 */*) file="$1"
99 ;;
100 *) file="./$1"
101 ;;
d17e960c 102 esac
8145a974 103 if test ! -f "$file"; then
7cc27f44 104 echo "ldd: ${file}: no such file"
fd26970f 105 exit 1
61965e9b 106 else
7cc27f44
UD
107 if test -r "$file"; then
108 test -x "$file" ||
109 echo "ldd: warning: you do not have execution permission for \`$file'"
2f6d1f1b
UD
110 ${RTLD} --verify "$file"
111 case $? in
112 0)
113 eval $add_env exec '"$file"' || exit 1
114 ;;
115 1)
7cc27f44
UD
116 echo ' not a dynamic executable'
117 exit 1
2f6d1f1b
UD
118 ;;
119 2)
120 eval $add_env exec \${RTLD} '"$file"' || exit 1
121 ;;
122 *)
123 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
124 exit 1
125 ;;
126 esac
fd26970f 127 else
7cc27f44 128 echo "ldd: error: you do not have read permission for \`$file'"
fd26970f
UD
129 exit 1
130 fi
61965e9b 131 fi
9eb2730e
UD
132 exit
133 ;;
b122c703
RM
134*)
135 set -e # Bail out immediately if ${RTLD} loses on any argument.
fd26970f 136 result=0
b122c703
RM
137 for file; do
138 echo "${file}:"
d17e960c 139 case "$file" in
9eb2730e
UD
140 */*) :
141 ;;
142 *) file="./$file"
143 ;;
d17e960c 144 esac
8145a974 145 if test ! -f "$file"; then
7cc27f44 146 echo "ldd: ${file}: no such file"
fd26970f 147 result=1
61965e9b 148 else
7cc27f44
UD
149 if test -r "$file"; then
150 test -x "$file" || echo "\
151ldd: warning: you do not have execution permission for \`$file'"
2f6d1f1b
UD
152 ${RTLD} --verify "$file"
153 case $? in
154 0)
155 eval $add_env '"$file"' || result=1
156 ;;
157 1)
7cc27f44
UD
158 echo ' not a dynamic executable'
159 result=1
2f6d1f1b
UD
160 ;;
161 2)
162 eval $add_env ${RTLD} '"$file"' || result=1
163 ;;
164 *)
165 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
166 exit 1
167 ;;
168 esac
fd26970f 169 else
7cc27f44 170 echo "ldd: error: you do not have read permission for \`$file'"
fd26970f
UD
171 result=1
172 fi
61965e9b 173 fi
b122c703
RM
174 done
175esac
176
fd26970f 177exit $result
This page took 0.068407 seconds and 5 git commands to generate.