Skip to content

Commit

Permalink
Add a test for --clear-symbol-version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sulix committed Jul 30, 2022
1 parent 85b83d0 commit 2d3122c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions tests/clear-symver.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d3122c

Please sign in to comment.