Update.
[platform/upstream/glibc.git] / elf / ldd.bash.in
1 #! @BASH@
2
3 # Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
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
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.
26
27 # We should be able to find the translation right at the beginning.
28 TEXTDOMAIN=libc
29 TEXTDOMAINDIR=@TEXTDOMAINDIR@
30
31 RTLD=@RTLD@
32 warn=
33 bind_now=
34 verbose=
35
36 while test $# -gt 0; do
37   case "$1" in
38   --vers | --versi | --versio | --version)
39     echo 'ldd (GNU libc) @VERSION@'
40     echo $"Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
41 This is free software; see the source for copying conditions.  There is NO
42 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
43 Written by Roland McGrath and Ulrich Drepper."
44     exit 0
45     ;;
46   --h | --he | --hel | --help)
47     echo $"ldd [OPTION]... FILE...
48       --help              print this help and exit
49       --version           print version information and exit
50   -d, --data-relocs       process data relocations
51   -r, --function-relocs   process data and function relocations
52   -v, --verbose           print all information
53 Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
54     exit 0
55     ;;
56   -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
57   --data-rel | --data-relo | --data-reloc | --data-relocs)
58     warn=yes
59     shift
60     ;;
61   -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
62   --function | --function- | --function-r | --function-re | --function-rel | \
63   --function-relo | --function-reloc | --function-relocs)
64     warn=yes
65     bind_now=yes
66     shift
67     ;;
68   -v | --verb | --verbo | --verbos | --verbose)
69     verbose=yes
70     shift
71     ;;
72   --v | --ve | --ver)
73     echo >&2 $"ldd: option \`$1' is ambiguous"
74     exit 1
75     ;;
76   --)           # Stop option processing.
77     shift; break
78     ;;
79   -*)
80     echo >&2 'ldd:' $"unrecognized option" "\`$1'"
81     echo >&2 $"Try \`ldd --help' for more information."
82     exit 1
83     ;;
84   *)
85     break
86     ;;
87   esac
88 done
89
90 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
91 add_env="$add_env LD_VERBOSE=$verbose"
92 case $# in
93 0)
94   echo >&2 'ldd:' $"missing file arguments"
95   echo >&2 $"Try \`ldd --help' for more information."
96   exit 1
97   ;;
98 1)
99   # We don't list the file name when there is only one.
100   case "$1" in
101   */*) file="$1"
102        ;;
103   *) file="./$1"
104      ;;
105   esac
106   if test ! -f "$file"; then
107     echo "ldd: ${file}:" $"no such file"
108     exit 1
109   elif test -r "$file"; then
110     test -x "$file" ||
111     echo 'ldd:' $"warning: you do not have execution permission for" "\`$file'"
112     ${RTLD} --verify "$file"
113     case $? in
114     0)
115       eval $add_env exec '"$file"' || exit 1
116       ;;
117     1)
118       echo $"   not a dynamic executable"
119       exit 1
120       ;;
121     2)
122       eval $add_env exec \${RTLD} '"$file"' || exit 1
123       ;;
124     *)
125       echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($?)" >&2
126       exit 1
127       ;;
128     esac
129   else
130     echo 'ldd:' $"error: you do not have read permission for" "\`$file'"
131     exit 1
132   fi
133   exit
134   ;;
135 *)
136   result=0
137   for file; do
138     echo "${file}:"
139     case "$file" in
140     */*) :
141          ;;
142     *) file="./$file"
143        ;;
144     esac
145     if test ! -f "$file"; then
146       echo "ldd: ${file}:" $"no such file"
147       result=1
148     elif test -r "$file"; then
149       test -x "$file" || echo 'ldd:' $"\
150 warning: you do not have execution permission for" "\`$file'"
151       ${RTLD} --verify "$file"
152       case $? in
153       0)
154         eval $add_env '"$file"' || result=1
155         ;;
156       1)
157         echo $" not a dynamic executable"
158         result=1
159         ;;
160       2)
161         eval $add_env ${RTLD} '"$file"' || result=1
162         ;;
163       *)
164         echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($?)" >&2
165         exit 1
166         ;;
167       esac
168     else
169       echo 'ldd:' $"error: you do not have read permission for" "\`$file'"
170       result=1
171     fi
172   done
173 esac
174
175 exit $result
176 # Local Variables:
177 #  mode:ksh
178 # End: