Skip to content

Commit d66caff

Browse files
committed
Add a unit test
1 parent d306abe commit d66caff

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ src_TESTS = \
3939
basic-flags.sh \
4040
set-empty-rpath.sh \
4141
phdr-corruption.sh \
42-
replace-needed.sh
42+
replace-needed.sh \
43+
replace-add-needed.sh
4344

4445
build_TESTS = \
4546
$(no_rpath_arch_TESTS)

tests/replace-add-needed.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /bin/sh -e
2+
SCRATCH=scratch/$(basename $0 .sh)
3+
PATCHELF=$(readlink -f "../src/patchelf")
4+
5+
rm -rf ${SCRATCH}
6+
mkdir -p ${SCRATCH}
7+
8+
cp simple ${SCRATCH}/
9+
cp libfoo.so ${SCRATCH}/
10+
cp libbar.so ${SCRATCH}/
11+
12+
13+
pushd ${SCRATCH}
14+
15+
libcldd=$(ldd ./simple | grep -oP "(?<=libc.so.6 => )[^ ]+")
16+
17+
# We have to set the soname on these libraries
18+
${PATCHELF} --set-soname libbar.so ./libbar.so
19+
20+
# Add a libbar.so so we can rewrite it later
21+
${PATCHELF} --add-needed libbar.so ./simple
22+
23+
${PATCHELF} --replace-needed libc.so.6 ${libcldd} \
24+
--replace-needed libbar.so $(readlink -f ./libbar.so) \
25+
--add-needed $(readlink -f ./libfoo.so) \
26+
./simple
27+
28+
exitCode=0
29+
./simple || exitCode=$?
30+
31+
if test "$exitCode" != 0; then
32+
ldd ./simple
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)