From 2d3122c2162808d943600b23ea57caa01d8a79fb Mon Sep 17 00:00:00 2001 From: David Gow Date: Mon, 11 Apr 2022 14:48:10 +0800 Subject: [PATCH] Add a test for --clear-symbol-version This test removes the __libc_start_main@GLIBC_2.34 symbol, which should be the only GLIBC_2.34 symbol in 'main' when built with recent (i.e., > 2.34) glibc. Because it is the only symbol, the entry in .gnu.version_r should also be removed. Because this is a symbol version test, it's unlikely to work on musl or anything else which doesn't use glibc symbol versions. --- tests/Makefile.am | 3 ++- tests/clear-symver.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 tests/clear-symver.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index bbea1ba4..adbe3605 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -41,7 +41,8 @@ src_TESTS = \ phdr-corruption.sh \ replace-needed.sh \ replace-add-needed.sh \ - add-debug-tag.sh + add-debug-tag.sh \ + clear-symver.sh build_TESTS = \ $(no_rpath_arch_TESTS) diff --git a/tests/clear-symver.sh b/tests/clear-symver.sh new file mode 100755 index 00000000..7a85a3c0 --- /dev/null +++ b/tests/clear-symver.sh @@ -0,0 +1,31 @@ +#! /bin/sh -e +SCRATCH=scratch/$(basename $0 .sh) + +rm -rf ${SCRATCH} +mkdir -p ${SCRATCH} + +cp main ${SCRATCH}/ +RANDOM_PATH=$(pwd)/${SCRATCH}/$RANDOM + +SYMBOL_TO_REMOVE=__libc_start_main +VERSION_TO_REMOVE=GLIBC_2.34 + +readelfData=$(readelf -V ${SCRATCH}/main 2>&1) + +if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") < 2 ]; then + # We expect this to appear at least twice: once for the symbol entry, + # and once for verneed entry. + echo "Couldn't find expected versioned symbol. Are you building with glibc?" + exit 1 +fi + +../src/patchelf --clear-symbol-version ${SYMBOL_TO_REMOVE} ${SCRATCH}/main + +readelfData=$(readelf -V ${SCRATCH}/main 2>&1) + +if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") != 0 ]; then + # We expect this to appear at least twice: once for the symbol entry, + # and once for verneed entry. + echo "The symbol version ${SYMBOL_TO_REMOVE} remained behind!" + exit 1 +fi