make objdump/objcopy/readelf configurable and respect cross-compiling related prefixes

This commit is contained in:
Jörg Thalheim 2022-11-06 15:38:38 +01:00
parent c543a45f7f
commit b0599fe776
6 changed files with 17 additions and 13 deletions

View File

@ -6,6 +6,10 @@ AM_INIT_AUTOMAKE([1.11.1 -Wall -Werror dist-bzip2 foreign color-tests parallel-t
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AC_CHECK_TOOL([STRIP], [strip]) AC_CHECK_TOOL([STRIP], [strip])
# Those are only used in tests, hence we gracefully degrate if they are not found.
AC_CHECK_TOOL([OBJDUMP], [objdump], [objdump])
AC_CHECK_TOOL([OBJCOPY], [objcopy], [objcopy])
AC_CHECK_TOOL([READELF], [readelf], [readelf])
AM_PROG_CC_C_O AM_PROG_CC_C_O
AC_PROG_CXX AC_PROG_CXX

View File

@ -52,7 +52,7 @@ TESTS = $(src_TESTS) $(build_TESTS)
EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note EXTRA_DIST = no-rpath-prebuild $(src_TESTS) no-rpath-prebuild.sh invalid-elf endianness empty-note
TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 TESTS_ENVIRONMENT = PATCHELF_DEBUG=1 OBJDUMP=$(OBJDUMP) READELF=$(READELF)
$(no_rpath_arch_TESTS): no-rpath-prebuild.sh $(no_rpath_arch_TESTS): no-rpath-prebuild.sh
@ln -s $< $@ @ln -s $< $@

View File

@ -1,5 +1,6 @@
#! /bin/sh -e #! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh) SCRATCH=scratch/$(basename $0 .sh)
READELF=${READELF:-readelf}
rm -rf ${SCRATCH} rm -rf ${SCRATCH}
mkdir -p ${SCRATCH} mkdir -p ${SCRATCH}
@ -7,7 +8,7 @@ mkdir -p ${SCRATCH}
cp libsimple.so ${SCRATCH}/ cp libsimple.so ${SCRATCH}/
# check there is no DT_DEBUG tag # check there is no DT_DEBUG tag
debugTag=$(readelf -d ${SCRATCH}/libsimple.so) debugTag=$($READELF -d ${SCRATCH}/libsimple.so)
echo ".dynamic before: $debugTag" echo ".dynamic before: $debugTag"
if echo "$debugTag" | grep -q DEBUG; then if echo "$debugTag" | grep -q DEBUG; then
echo "failed --add-debug-tag test. Expected no line with (DEBUG), got: $debugTag" echo "failed --add-debug-tag test. Expected no line with (DEBUG), got: $debugTag"
@ -18,7 +19,7 @@ fi
../src/patchelf --add-debug-tag ${SCRATCH}/libsimple.so ../src/patchelf --add-debug-tag ${SCRATCH}/libsimple.so
# check there is DT_DEBUG tag # check there is DT_DEBUG tag
debugTag=$(readelf -d ${SCRATCH}/libsimple.so) debugTag=$($READELF -d ${SCRATCH}/libsimple.so)
echo ".dynamic before: $debugTag" echo ".dynamic before: $debugTag"
if ! echo "$debugTag" | grep -q DEBUG; then if ! echo "$debugTag" | grep -q DEBUG; then
echo "failed --add-debug-tag test. Expected line with (DEBUG), got: $debugTag" echo "failed --add-debug-tag test. Expected line with (DEBUG), got: $debugTag"

View File

@ -1,10 +1,6 @@
#! /bin/sh -e #! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh) SCRATCH=scratch/$(basename $0 .sh)
READELF=${READELF:-readelf}
if ! command -v readelf >/dev/null; then
echo "No readelf found; skip test"
exit 0
fi
rm -rf "${SCRATCH}" rm -rf "${SCRATCH}"
mkdir -p "${SCRATCH}" mkdir -p "${SCRATCH}"

View File

@ -1,5 +1,6 @@
#! /bin/sh -e #! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh) SCRATCH=scratch/$(basename $0 .sh)
OBJDUMP=${OBJDDUMP:-objdump}
rm -rf ${SCRATCH} rm -rf ${SCRATCH}
mkdir -p ${SCRATCH} mkdir -p ${SCRATCH}
@ -13,7 +14,7 @@ doit() {
} }
expect() { expect() {
out=$(echo $(objdump -x $SCRATCHFILE | grep PATH)) out=$(echo $($OBJDUMP -x $SCRATCHFILE | grep PATH))
if [ "$out" != "$*" ]; then if [ "$out" != "$*" ]; then
echo "Expected '$*' but got '$out'" echo "Expected '$*' but got '$out'"

View File

@ -1,12 +1,14 @@
#! /bin/sh -e #! /bin/sh -e
if ! objdump -p main | grep -q MIPS_RLD_MAP_REL; then SCRATCH=scratch/$(basename $0 .sh)
OBJDUMP=${OBJDUMP:-objdump}
OBJCOPY=${OBJCOPY:-objcopy}
if ! $OBJDUMP -p main | grep -q MIPS_RLD_MAP_REL; then
echo "No MIPS_RLD_MAP_REL dynamic section entry, skipping" echo "No MIPS_RLD_MAP_REL dynamic section entry, skipping"
exit 0 exit 0
fi fi
SCRATCH=scratch/$(basename $0 .sh)
rm -rf ${SCRATCH} rm -rf ${SCRATCH}
mkdir -p ${SCRATCH} mkdir -p ${SCRATCH}
mkdir -p ${SCRATCH}/libsA mkdir -p ${SCRATCH}/libsA
@ -17,7 +19,7 @@ cp libfoo.so ${SCRATCH}/libsA/
cp libbar.so ${SCRATCH}/libsB/ cp libbar.so ${SCRATCH}/libsB/
# break the main executable by removing .rld_map section # break the main executable by removing .rld_map section
objcopy --remove-section .rld_map ${SCRATCH}/main ${OBJCOPY} --remove-section .rld_map ${SCRATCH}/main
oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/main) oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/main)
if test -z "$oldRPath"; then oldRPath="/oops"; fi if test -z "$oldRPath"; then oldRPath="/oops"; fi