]> git.ipfire.org Git - thirdparty/glibc.git/blame - elf/ldd.sh.in
update from main archive 970209
[thirdparty/glibc.git] / elf / ldd.sh.in
CommitLineData
b122c703
RM
1#! /bin/sh
2
df4ef2ab 3# Copyright (C) 1996, 1997 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@
fd26970f 28RELOCS=
f0e44959
UD
29
30while test $# -gt 0; do
31 case "$1" in
fd26970f 32 --v | --ve | --ver | --vers | --versi | --versio | --version)
84384f5b 33 echo 'ldd (GNU libc) @VERSION@
df4ef2ab 34Copyright (C) 1996, 1997 Free Software Foundation, Inc.
84384f5b
UD
35This is free software; see the source for copying conditions. There is NO
36warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
37 exit 0 ;;
fd26970f 38 --h | --he | --hel | --help)
df4ef2ab 39 echo "ldd [OPTION]... FILE...
fd26970f
UD
40 --help print this help and exit
41 --version print version information and exit
42 -d, --data-relocs process data relocations
43 -r, --function-relocs process data and function relocations
df4ef2ab 44Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
84384f5b 45 exit 0 ;;
fd26970f
UD
46 -d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
47 --data-rel | --data-relo | --data-reloc | --data-relocs)
48 RELOCS='--data-relocs'
49 shift ;;
50 -r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
51 --function | --function- | --function-r | --function-re | --function-rel | \
52 --function-relo | --function-reloc | --function-relocs)
53 RELOCS='--function-relocs'
54 shift ;;
6d52618b 55 --) # Stop option processing.
f0e44959 56 shift; break ;;
fd26970f
UD
57 -*)
58 echo >&2 "\
59ldd: unrecognized option \`$1'
60Try \`ldd --help' for more information."
61 exit 1 ;;
f0e44959
UD
62 *)
63 break ;;
64 esac
65done
b122c703
RM
66
67case $# in
680)
f0e44959
UD
69 echo >&2 "\
70ldd: missing file arguments
71Try \`ldd --help' for more information."
b122c703
RM
72 exit 1 ;;
731)
74 # We don't list the file name when there is only one.
d17e960c
RM
75 case "$1" in
76 /*) file="$1" ;;
77 *) file="./$1" ;;
78 esac
8145a974 79 if test ! -f "$file"; then
7cc27f44 80 echo "ldd: ${file}: no such file"
fd26970f 81 exit 1
61965e9b 82 else
7cc27f44
UD
83 if test -r "$file"; then
84 test -x "$file" ||
85 echo "ldd: warning: you do not have execution permission for \`$file'"
86 if ${RTLD} --verify "$file"; then
87 LD_TRACE_LOADED_OBJECTS=1 exec ${RTLD} ${RELOCS} "$file" || exit 1
88 else
89 echo ' not a dynamic executable'
90 exit 1
91 fi
fd26970f 92 else
7cc27f44 93 echo "ldd: error: you do not have read permission for \`$file'"
fd26970f
UD
94 exit 1
95 fi
61965e9b 96 fi
b122c703
RM
97 exit ;;
98*)
99 set -e # Bail out immediately if ${RTLD} loses on any argument.
fd26970f 100 result=0
b122c703
RM
101 for file; do
102 echo "${file}:"
d17e960c 103 case "$file" in
f0e44959 104 /*) : ;;
d17e960c
RM
105 *) file="./$file" ;;
106 esac
8145a974 107 if test ! -f "$file"; then
7cc27f44 108 echo "ldd: ${file}: no such file"
fd26970f 109 result=1
61965e9b 110 else
7cc27f44
UD
111 if test -r "$file"; then
112 test -x "$file" || echo "\
113ldd: warning: you do not have execution permission for \`$file'"
114 if ${RTLD} --verify "$file"; then
115 LD_TRACE_LOADED_OBJECTS=1 ${RTLD} ${RELOCS} "$file" || result=1
116 else
117 echo ' not a dynamic executable'
118 result=1
119 fi
fd26970f 120 else
7cc27f44 121 echo "ldd: error: you do not have read permission for \`$file'"
fd26970f
UD
122 result=1
123 fi
61965e9b 124 fi
b122c703
RM
125 done
126esac
127
fd26970f 128exit $result