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