From 7a9feaf14ca023d9a2d5f1e6460056e17cda72c5 Mon Sep 17 00:00:00 2001 From: mayeut Date: Tue, 3 Dec 2024 22:58:15 +0100 Subject: [PATCH] fix some tests when running under QEMU In some cases, ldd can fail on the original binary. In that case it is also observed that running with an explicit interpreter will fail. https://gitlab.com/qemu-project/qemu/-/issues/1763 --- tests/replace-add-needed.sh | 10 +++++++++- tests/set-interpreter-long.sh | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/replace-add-needed.sh b/tests/replace-add-needed.sh index 701cb953..1282f4f8 100755 --- a/tests/replace-add-needed.sh +++ b/tests/replace-add-needed.sh @@ -11,7 +11,15 @@ cp libbar.so "${SCRATCH}"/ cd "${SCRATCH}" -libcldd=$(ldd ./simple | awk '/ => / { print $3 }' | grep -E "(libc(-[0-9.]*)*.so|ld-musl)") +# QEMU & ldd are not playing well together in certain cases +if ldd ./simple >/dev/null 2>&1; then + libcldd=$(ldd ./simple | awk '/ => / { print $3 }' | grep -E "(libc(-[0-9.]*)*.so|ld-musl)") +elif [ -f /lib64/libc.so.6 ]; then + libcldd=/lib64/libc.so.6 +else + echo "ldd ./simple failed" + exit 1 +fi # We have to set the soname on these libraries ${PATCHELF} --set-soname libbar.so ./libbar.so diff --git a/tests/set-interpreter-long.sh b/tests/set-interpreter-long.sh index f1e0d2f9..bb692aeb 100755 --- a/tests/set-interpreter-long.sh +++ b/tests/set-interpreter-long.sh @@ -6,7 +6,8 @@ SCRATCH=scratch/$(basename "$0" .sh) oldInterpreter=$(../src/patchelf --print-interpreter ./simple) echo "current interpreter is $oldInterpreter" -if test "$(uname)" = Linux; then +# QEMU & ldd/ld.so are not playing well together in certain cases +if test "$(uname)" = Linux && ldd ./simple >/dev/null 2>&1; then echo "running with explicit interpreter..." "$oldInterpreter" ./simple fi @@ -28,7 +29,7 @@ echo "running with new interpreter..." ln -s "$oldInterpreter" "$newInterpreter" "${SCRATCH}"/simple -if test "$(uname)" = Linux; then +if test "$(uname)" = Linux && ldd ./simple >/dev/null 2>&1; then echo "running with explicit interpreter..." "$oldInterpreter" "${SCRATCH}/simple" fi