Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fzakaria committed Dec 21, 2021
1 parent d306abe commit d66caff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ src_TESTS = \
basic-flags.sh \
set-empty-rpath.sh \
phdr-corruption.sh \
replace-needed.sh
replace-needed.sh \
replace-add-needed.sh

build_TESTS = \
$(no_rpath_arch_TESTS)
Expand Down
34 changes: 34 additions & 0 deletions tests/replace-add-needed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/sh -e
SCRATCH=scratch/$(basename $0 .sh)
PATCHELF=$(readlink -f "../src/patchelf")

rm -rf ${SCRATCH}
mkdir -p ${SCRATCH}

cp simple ${SCRATCH}/
cp libfoo.so ${SCRATCH}/
cp libbar.so ${SCRATCH}/


pushd ${SCRATCH}

libcldd=$(ldd ./simple | grep -oP "(?<=libc.so.6 => )[^ ]+")

# We have to set the soname on these libraries
${PATCHELF} --set-soname libbar.so ./libbar.so

# Add a libbar.so so we can rewrite it later
${PATCHELF} --add-needed libbar.so ./simple

${PATCHELF} --replace-needed libc.so.6 ${libcldd} \
--replace-needed libbar.so $(readlink -f ./libbar.so) \
--add-needed $(readlink -f ./libfoo.so) \
./simple

exitCode=0
./simple || exitCode=$?

if test "$exitCode" != 0; then
ldd ./simple
exit 1
fi

0 comments on commit d66caff

Please sign in to comment.