Update.
[glibc.git] / elf / ldd.bash.in
blob48d5c90fd512616b9c97ddd53d734ffb4559484e
1 #! @BASH@
3 # Copyright (C) 1996, 1997 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 # We should be able to find the translation right at the beginning.
28 TEXTDOMAIN=libc
29 TEXTDOMAINDIR=@TEXTDOMAINDIR@
31 RTLD=@RTLD@
32 warn=
33 bind_now=
35 while test $# -gt 0; do
36 case "$1" in
37 --v | --ve | --ver | --vers | --versi | --versio | --version)
38 echo $"ldd (GNU libc) @VERSION@
39 Copyright (C) 1996, 1997 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 exit 0 ;;
43 --h | --he | --hel | --help)
44 echo $"ldd [OPTION]... FILE...
45 --help print this help and exit
46 --version print version information and exit
47 -d, --data-relocs process data relocations
48 -r, --function-relocs process data and function relocations
49 Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
50 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 ;;
55 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
56 --function | --function- | --function-r | --function-re | --function-rel | \
57 --function-relo | --function-reloc | --function-relocs)
58 warn=yes
59 bind_now=yes
60 shift ;;
61 --) # Stop option processing.
62 shift; break ;;
63 -*)
64 echo >&2 $"ldd: unrecognized option" "\`$1'"
65 echo >&2 $"Try \`ldd --help' for more information."
66 exit 1 ;;
68 break ;;
69 esac
70 done
72 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
73 case $# in
75 echo >&2 $"ldd: missing file arguments"
76 echo >&2 $"Try \`ldd --help' for more information."
77 exit 1 ;;
79 # We don't list the file name when there is only one.
80 case "$1" in
81 /*) file="$1" ;;
82 *) file="./$1" ;;
83 esac
84 if test ! -f "$file"; then
85 echo "ldd: ${file}:" $"no such file"
86 exit 1
87 elif test -r "$file"; then
88 test -x "$file" ||
89 echo $"ldd: warning: you do not have execution permission for" "\`$file'"
90 ${RTLD} --verify "$file"
91 case $? in
93 eval $add_env exec '"$file"' || exit 1
96 echo $" not a dynamic executable"
97 exit 1
100 eval $add_env exec \${RTLD} '"$file"' || exit 1
103 echo $"ldd: ${RTLD} exited with unknown exit code ($?)" >&2
104 exit 1
106 esac
107 else
108 echo $"ldd: error: you do not have read permission for" "\`$file'"
109 exit 1
111 exit ;;
113 result=0
114 for file; do
115 echo "${file}:"
116 case "$file" in
117 /*) : ;;
118 *) file="./$file" ;;
119 esac
120 if test ! -f "$file"; then
121 echo "ldd: ${file}:" $"no such file"
122 result=1
123 elif test -r "$file"; then
124 test -x "$file" || echo $"\
125 ldd: warning: you do not have execution permission for" "\`$file'"
126 ${RTLD} --verify "$file"
127 case $? in
129 eval $add_env '"$file"' || result=1
132 echo $" not a dynamic executable"
133 result=1
136 eval $add_env ${RTLD} '"$file"' || result=1
139 echo $"ldd: ${RTLD} exited with unknown exit code ($?)" >&2
140 exit 1
142 esac
143 else
144 echo $"ldd: error: you do not have read permission for" "\`$file'"
145 result=1
147 done
148 esac
150 exit $result
151 # Local Variables:
152 # mode:ksh
153 # End: