Files
glibc/elf/ldd.bash.in
T

172 lines
4.5 KiB
Plaintext
Raw Normal View History

1996-11-02 01:28:01 +00:00
#! @BASH@
2003-01-02 20:32:33 +00:00
# Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc.
1996-11-20 03:45:51 +00:00
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
1996-11-20 03:45:51 +00:00
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
# Lesser General Public License for more details.
1996-11-20 03:45:51 +00:00
2001-07-06 04:58:11 +00:00
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
1996-11-20 03:45:51 +00:00
1996-11-02 01:28:01 +00:00
# This is the `ldd' command, which lists what shared libraries are
# used by given dynamically-linked executables. It works by invoking the
# run-time dynamic linker as a command and setting the environment
# variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
1996-11-20 03:45:51 +00:00
# We should be able to find the translation right at the beginning.
TEXTDOMAIN=libc
TEXTDOMAINDIR=@TEXTDOMAINDIR@
1999-07-14 15:21:35 +00:00
RTLDLIST=@RTLD@
1997-02-15 04:31:36 +00:00
warn=
bind_now=
1997-06-13 22:46:42 +00:00
verbose=
1996-11-02 01:28:01 +00:00
while test $# -gt 0; do
case "$1" in
1997-06-13 22:46:42 +00:00
--vers | --versi | --versio | --version)
1997-05-21 01:48:59 +00:00
echo 'ldd (GNU libc) @VERSION@'
2003-01-02 20:32:33 +00:00
echo $"Copyright (C) 2003 Free Software Foundation, Inc.
1996-11-20 03:45:51 +00:00
This is free software; see the source for copying conditions. There is NO
1997-06-13 22:46:42 +00:00
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper."
1998-02-27 10:00:44 +00:00
exit 0
;;
1997-01-21 06:10:42 +00:00
--h | --he | --hel | --help)
1999-10-05 01:55:45 +00:00
echo $"Usage: ldd [OPTION]... FILE...
1997-01-21 06:10:42 +00:00
--help print this help and exit
--version print version information and exit
-d, --data-relocs process data relocations
-r, --function-relocs process data and function relocations
1997-06-13 22:46:42 +00:00
-v, --verbose print all information
1997-10-26 20:13:00 +00:00
Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
1998-02-27 10:00:44 +00:00
exit 0
;;
1997-01-21 06:10:42 +00:00
-d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
--data-rel | --data-relo | --data-reloc | --data-relocs)
1997-02-15 04:31:36 +00:00
warn=yes
1998-02-27 10:00:44 +00:00
shift
;;
1997-01-21 06:10:42 +00:00
-r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
--function | --function- | --function-r | --function-re | --function-rel | \
--function-relo | --function-reloc | --function-relocs)
1997-02-15 04:31:36 +00:00
warn=yes
bind_now=yes
1998-02-27 10:00:44 +00:00
shift
;;
1997-06-13 22:46:42 +00:00
-v | --verb | --verbo | --verbos | --verbose)
verbose=yes
1998-02-27 10:00:44 +00:00
shift
;;
1997-06-13 22:46:42 +00:00
--v | --ve | --ver)
1997-06-19 19:11:22 +00:00
echo >&2 $"ldd: option \`$1' is ambiguous"
1998-02-27 10:00:44 +00:00
exit 1
;;
1996-12-20 01:39:50 +00:00
--) # Stop option processing.
1998-02-27 10:00:44 +00:00
shift; break
;;
1997-01-21 06:10:42 +00:00
-*)
1997-05-07 15:31:21 +00:00
echo >&2 'ldd:' $"unrecognized option" "\`$1'"
1997-01-21 06:10:42 +00:00
echo >&2 $"Try \`ldd --help' for more information."
1998-02-27 10:00:44 +00:00
exit 1
;;
1996-11-02 01:28:01 +00:00
*)
1998-02-27 10:00:44 +00:00
break
;;
1996-11-02 01:28:01 +00:00
esac
done
1998-03-29 17:03:23 +00:00
nonelf ()
{
# Maybe extra code for non-ELF binaries.
return 1;
}
1997-02-25 05:18:05 +00:00
add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
1997-06-13 22:46:42 +00:00
add_env="$add_env LD_VERBOSE=$verbose"
1996-11-02 01:28:01 +00:00
case $# in
0)
1997-05-07 15:31:21 +00:00
echo >&2 'ldd:' $"missing file arguments"
1997-01-21 06:10:42 +00:00
echo >&2 $"Try \`ldd --help' for more information."
1998-02-27 10:00:44 +00:00
exit 1
;;
1996-11-02 01:28:01 +00:00
1)
1998-08-24 16:46:16 +00:00
single_file=t
;;
*)
single_file=f
;;
esac
result=0
for file do
1996-11-02 01:28:01 +00:00
# We don't list the file name when there is only one.
1998-08-24 16:46:16 +00:00
test $single_file = t || echo "${file}:"
case $file in
*/*) :
1998-02-27 10:00:44 +00:00
;;
1998-08-24 16:46:16 +00:00
*) file=./$file
1998-02-27 10:00:44 +00:00
;;
1996-11-02 01:28:01 +00:00
esac
if test ! -f "$file"; then
1998-08-24 16:46:16 +00:00
echo "ldd: ${file}:" $"No such file or directory" >&2
result=1
1997-02-10 03:19:57 +00:00
elif test -r "$file"; then
1998-08-24 16:46:16 +00:00
test -x "$file" || echo 'ldd:' $"\
1998-08-20 17:40:36 +00:00
warning: you do not have execution permission for" "\`$file'" >&2
1999-07-14 15:21:35 +00:00
RTLD=
for rtld in ${RTLDLIST}; do
if test -x $rtld; then
verify_out=`${rtld} --verify "$file"`
ret=$?
case $ret in
[02]) RTLD=${rtld}; break;;
esac
fi
done
if test -z "${RTLD}"; then
set ${RTLDLIST}
RTLD=$1
verify_out=`${RTLD} --verify "$file"`
ret=$?
fi
case $ret in
1997-02-25 05:18:05 +00:00
0)
1998-08-24 16:46:16 +00:00
eval $add_env '"$file"' || result=1
1997-02-25 05:18:05 +00:00
;;
1)
1998-03-29 17:03:23 +00:00
# This can be a non-ELF binary or no binary at all.
1998-08-24 16:46:16 +00:00
nonelf "$file" || {
echo $" not a dynamic executable"
result=1
}
1997-02-25 05:18:05 +00:00
;;
2)
1998-08-24 16:46:16 +00:00
eval $add_env \${RTLD} '"$file"' || result=1
1997-02-25 05:18:05 +00:00
;;
*)
1999-07-14 15:21:35 +00:00
echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
1997-02-25 05:18:05 +00:00
exit 1
;;
esac
1997-02-10 03:19:57 +00:00
else
1998-08-20 17:40:36 +00:00
echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
1998-08-24 16:46:16 +00:00
result=1
1996-11-02 01:28:01 +00:00
fi
1998-08-24 16:46:16 +00:00
done
1996-11-02 01:28:01 +00:00
1997-01-21 06:10:42 +00:00
exit $result
1996-11-20 03:45:51 +00:00
# Local Variables:
# mode:ksh
# End: