summaryrefslogtreecommitdiff
path: root/tests/replace-add-needed.sh
diff options
context:
space:
mode:
authorFarid Zakaria <farid.m.zakaria@gmail.com>2021-12-20 17:28:34 -0800
committerFarid Zakaria <farid.m.zakaria@gmail.com>2021-12-20 17:34:26 -0800
commite268662c32464f3a09d3aecf069f906a562ab350 (patch)
tree835e514a4e01b312a36e4f84744dd2971a8972dc /tests/replace-add-needed.sh
parentd306abeb3549a574408fe8de490415f67f2a486e (diff)
downloadpatchelf-e268662c32464f3a09d3aecf069f906a562ab350.tar.gz
Add a unit test
Diffstat (limited to 'tests/replace-add-needed.sh')
-rwxr-xr-xtests/replace-add-needed.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/replace-add-needed.sh b/tests/replace-add-needed.sh
new file mode 100755
index 0000000..b486897
--- /dev/null
+++ b/tests/replace-add-needed.sh
@@ -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}/
+
+
+cd ${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