Fix typo.
[glibc/history.git] / elf / ldd.sh.in
blob908a26e2693ee640a401036c642c387d7ee88e5a
1 #! /bin/sh
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 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 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 ;;
40 --h | --he | --hel | --help)
41 echo "ldd [OPTION]... FILE...
42 --help print this help and exit
43 --version print version information and exit
44 -d, --data-relocs process data relocations
45 -r, --function-relocs process data and function relocations
46 -v, --verbose print all information
47 Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
48 exit 0 ;;
49 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
50 --data-rel | --data-relo | --data-reloc | --data-relocs)
51 warn=yes
52 shift ;;
53 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
54 --function | --function- | --function-r | --function-re | --function-rel | \
55 --function-relo | --function-reloc | --function-relocs)
56 warn=yes
57 bind_now=yes
58 shift ;;
59 -v | --verb | --verbo | --verbos | --verbose)
60 verbose=yes
61 shift ;;
62 --v | --ve | --ver)
63 echo >&2 "ldd: option \`$1' is ambiguous"
64 exit 1 ;;
65 --) # Stop option processing.
66 shift; break ;;
67 -*)
68 echo >&2 "\
69 ldd: unrecognized option \`$1'
70 Try \`ldd --help' for more information."
71 exit 1 ;;
73 break ;;
74 esac
75 done
77 add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
78 add_env="$add_env LD_VERBOSE=$verbose"
79 case $# in
81 echo >&2 "\
82 ldd: missing file arguments
83 Try \`ldd --help' for more information."
84 exit 1 ;;
86 # We don't list the file name when there is only one.
87 case "$1" in
88 /*) file="$1" ;;
89 *) file="./$1" ;;
90 esac
91 if test ! -f "$file"; then
92 echo "ldd: ${file}: no such file"
93 exit 1
94 else
95 if test -r "$file"; then
96 test -x "$file" ||
97 echo "ldd: warning: you do not have execution permission for \`$file'"
98 ${RTLD} --verify "$file"
99 case $? in
101 eval $add_env exec '"$file"' || exit 1
104 echo ' not a dynamic executable'
105 exit 1
108 eval $add_env exec \${RTLD} '"$file"' || exit 1
111 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
112 exit 1
114 esac
115 else
116 echo "ldd: error: you do not have read permission for \`$file'"
117 exit 1
120 exit ;;
122 set -e # Bail out immediately if ${RTLD} loses on any argument.
123 result=0
124 for file; do
125 echo "${file}:"
126 case "$file" in
127 /*) : ;;
128 *) file="./$file" ;;
129 esac
130 if test ! -f "$file"; then
131 echo "ldd: ${file}: no such file"
132 result=1
133 else
134 if test -r "$file"; then
135 test -x "$file" || echo "\
136 ldd: warning: you do not have execution permission for \`$file'"
137 ${RTLD} --verify "$file"
138 case $? in
140 eval $add_env '"$file"' || result=1
143 echo ' not a dynamic executable'
144 result=1
147 eval $add_env ${RTLD} '"$file"' || result=1
150 echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2
151 exit 1
153 esac
154 else
155 echo "ldd: error: you do not have read permission for \`$file'"
156 result=1
159 done
160 esac
162 exit $result