From 6e5e98ce774e728290680c46b44da86246f1d167 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Wed, 3 Jun 2020 13:15:33 +0200 Subject: Consistently use --force-rpath (fixes #94) --- src/patchelf.cc | 21 +++++++++++---------- tests/Makefile.am | 1 + tests/force-rpath.sh | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100755 tests/force-rpath.sh diff --git a/src/patchelf.cc b/src/patchelf.cc index d560587..80d40ab 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -1259,7 +1259,17 @@ void ElfFile::modifyRPath(RPathOp op, } - if (std::string(rpath ? rpath : "") == newRPath) return; + if (!forceRPath && dynRPath && !dynRunPath) { /* convert DT_RPATH to DT_RUNPATH */ + dynRPath->d_tag = DT_RUNPATH; + dynRunPath = dynRPath; + dynRPath = 0; + } else if (forceRPath && dynRunPath) { /* convert DT_RUNPATH to DT_RPATH */ + dynRunPath->d_tag = DT_RPATH; + dynRPath = dynRunPath; + dynRunPath = 0; + } else if (std::string(rpath ? rpath : "") == newRPath) { + return; + } changed = true; @@ -1273,15 +1283,6 @@ void ElfFile::modifyRPath(RPathOp op, debug("new rpath is '%s'\n", newRPath.c_str()); - if (!forceRPath && dynRPath && !dynRunPath) { /* convert DT_RPATH to DT_RUNPATH */ - dynRPath->d_tag = DT_RUNPATH; - dynRunPath = dynRPath; - dynRPath = 0; - } - - if (forceRPath && dynRPath && dynRunPath) { /* convert DT_RUNPATH to DT_RPATH */ - dynRunPath->d_tag = DT_IGNORE; - } if (newRPath.size() <= rpathSize) { strcpy(rpath, newRPath.c_str()); diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ad7f20..96339b3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,6 +22,7 @@ src_TESTS = \ plain-fail.sh plain-run.sh shrink-rpath.sh set-interpreter-short.sh \ set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh \ set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh \ + force-rpath.sh \ output-flag.sh build_TESTS = \ diff --git a/tests/force-rpath.sh b/tests/force-rpath.sh new file mode 100755 index 0000000..9256905 --- /dev/null +++ b/tests/force-rpath.sh @@ -0,0 +1,39 @@ +#! /bin/sh -e +SCRATCH=scratch/$(basename $0 .sh) + +rm -rf ${SCRATCH} +mkdir -p ${SCRATCH} + +SCRATCHFILE=${SCRATCH}/libfoo.so +cp libfoo.so $SCRATCHFILE + +doit() { + echo patchelf $* + ../src/patchelf $* $SCRATCHFILE +} + +expect() { + out=$(echo $(objdump -x $SCRATCHFILE | grep PATH)) + + if [ "$out" != "$*" ]; then + echo "Expected '$*' but got '$out'" + exit 1 + fi +} + +doit --remove-rpath +expect +doit --set-rpath foo +expect RUNPATH foo +doit --force-rpath --set-rpath foo +expect RPATH foo +doit --force-rpath --set-rpath bar +expect RPATH bar +doit --remove-rpath +expect +doit --force-rpath --set-rpath foo +expect RPATH foo +doit --set-rpath foo +expect RUNPATH foo +doit --set-rpath bar +expect RUNPATH bar -- cgit v0.12