update from main archive 970124
[glibc.git] / elf / ldd.sh.in
blob4351578b6d7d47ff68a6a8935469852eef93347a
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 RELOCS=
30 while test $# -gt 0; do
31 case "$1" in
32 --v | --ve | --ver | --vers | --versi | --versio | --version)
33 echo 'ldd (GNU libc) @VERSION@
34 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
35 This is free software; see the source for copying conditions. There is NO
36 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.'
37 exit 0 ;;
38 --h | --he | --hel | --help)
39 echo "ldd [OPTION]... FILE...
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
44 Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>."
45 exit 0 ;;
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 ;;
55 --) # Stop option processing.
56 shift; break ;;
57 -*)
58 echo >&2 "\
59 ldd: unrecognized option \`$1'
60 Try \`ldd --help' for more information."
61 exit 1 ;;
63 break ;;
64 esac
65 done
67 case $# in
69 echo >&2 "\
70 ldd: missing file arguments
71 Try \`ldd --help' for more information."
72 exit 1 ;;
74 # We don't list the file name when there is only one.
75 case "$1" in
76 /*) file="$1" ;;
77 *) file="./$1" ;;
78 esac
79 if test ! -f "$file"; then
80 echo "${file}: no such file"
81 exit 1
82 else
83 test -x "$file" ||
84 echo "warning: you do not have execution permission for \`$file'"
85 if ${RTLD} --verify "$file"; then
86 LD_TRACE_LOADED_OBJECTS=1 exec ${RTLD} ${RELOCS} "$file" || exit 1
87 else
88 echo ' not a dynamic executable'
89 exit 1
92 exit ;;
94 set -e # Bail out immediately if ${RTLD} loses on any argument.
95 result=0
96 for file; do
97 echo "${file}:"
98 case "$file" in
99 /*) : ;;
100 *) file="./$file" ;;
101 esac
102 if test ! -f "$file"; then
103 echo "${file}: no such file"
104 result=1
105 else
106 test -x "$file" ||
107 echo "warning: you do not have execution permission for \`$file'"
108 if ${RTLD} --verify "$file"; then
109 LD_TRACE_LOADED_OBJECTS=1 ${RTLD} ${RELOCS} "$file" || result=1
110 else
111 echo ' not a dynamic executable'
112 result=1
115 done
116 esac
118 exit $result