Files
patchelf/tests/replace-add-needed.sh
Farid Zakaria d02a3ecdd7 Code clarity and test working with musl
Made changes according to feedback from @Mic92 such as moving the
`rewriteSections` inline into every method.

Improved `replace-add-needed.sh` to work with musl libc
2021-12-21 06:05:13 -08:00

35 lines
775 B
Bash
Executable File

#! /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}/
cd ${SCRATCH}
libcldd=$(ldd ./simple | awk '/ => / { print $3 }' | grep .so | head -n 1)
# 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