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