rpm-build/scripts/ldd.in

80 lines
2.4 KiB
Plaintext
Raw Normal View History

2006-01-14 20:02:09 +03:00
#! /bin/sh
# Copyright (C) 1996-2004, 2005 Free Software Foundation, Inc.
# Copyright (C) 2006 Dmitry V. Levin <ldv@altlinux.org>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
. @RPMCONFIGDIR@/functions
undefined=
while test $# -gt 0; do
case "$1" in
--undefined)
undefined=1
shift
;;
--) # Stop option processing.
shift; break
;;
-*)
Fatal "unrecognized option: $1"
;;
*)
break
;;
esac
done
case $# in
[01]) Fatal 'insufficient arguments' ;;
2) ;;
*) Fatal 'too many arguments' ;;
esac
file="$1" && shift
rpath="$1" && shift
info="$(readelf -l "$file")" ||
Fatal "$file: unable to fetch ELF segment headers"
interp="$(printf '%s\n' "$info" |sed -ne 's,^[[:space:]]*\[Requesting program interpreter: \(/[^]]\+\)\]$,\1,p')" ||
2006-01-14 20:02:09 +03:00
Fatal "$file: program interpreter not specified"
2006-01-15 00:13:58 +03:00
if [ -z "$interp" ]; then
dump_ld_config='@RPMCONFIGDIR@/dump_ld_config'
info="$(readelf -l "$dump_ld_config")" ||
Fatal "$dump_ld_config: unable to fetch ELF segment headers"
interp="$(printf '%s\n' "$info" |sed -ne 's,^[[:space:]]*\[Requesting program interpreter: \(/[^]]\+\)\]$,\1,p')" ||
Fatal "$dump_ld_config: program interpreter not specified"
[ -n "$interp" ] ||
Fatal 'Unable to recognize ELF program interpreter'
2006-01-15 00:13:58 +03:00
fi
if [ -n "${RPM_BUILD_ROOT-}" ] && [ -f "$RPM_BUILD_ROOT$interp" -a -x "$RPM_BUILD_ROOT$interp" ]; then
2006-01-14 20:02:09 +03:00
rtld="$RPM_BUILD_ROOT$interp"
elif [ -f "$interp" -a -x "$interp" ]; then
rtld="$interp"
else
Fatal "$file: program interpreter $interp not found"
fi
verify_out="$("$rtld" --verify "$file")"
2006-01-14 20:35:47 +03:00
[ "$?" = 0 -o "$?" = 2 ] ||
Fatal "$file: trace failed"
2006-01-14 20:02:09 +03:00
2006-01-14 20:35:47 +03:00
LD_TRACE_LOADED_OBJECTS=1 LD_WARN="$undefined" LD_BIND_NOW="$undefined" LD_LIBRARY_VERSION="$verify_out" \
"$rtld" --library-path "$rpath" "$file" ||
Fatal "$file: trace failed"
2006-01-14 20:02:09 +03:00
exit 0