Skip to content

Commit 4f5c26d

Browse files
committed
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.
1 parent c73fed9 commit 4f5c26d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ src_TESTS = \
4141
phdr-corruption.sh \
4242
replace-needed.sh \
4343
replace-add-needed.sh \
44-
add-debug-tag.sh
44+
add-debug-tag.sh \
45+
clear-symver.sh
4546

4647
build_TESTS = \
4748
$(no_rpath_arch_TESTS)

tests/clear-symver.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /bin/sh -e
2+
SCRATCH=scratch/$(basename $0 .sh)
3+
4+
rm -rf ${SCRATCH}
5+
mkdir -p ${SCRATCH}
6+
7+
cp main ${SCRATCH}/
8+
RANDOM_PATH=$(pwd)/${SCRATCH}/$RANDOM
9+
10+
SYMBOL_TO_REMOVE=__libc_start_main
11+
VERSION_TO_REMOVE=GLIBC_2.34
12+
13+
readelfData=$(readelf -V ${SCRATCH}/main 2>&1)
14+
15+
if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") < 2 ]; then
16+
# We expect this to appear at least twice: once for the symbol entry,
17+
# and once for verneed entry.
18+
echo "Couldn't find expected versioned symbol. Are you building with glibc?"
19+
exit 1
20+
fi
21+
22+
../src/patchelf --clear-symbol-version ${SYMBOL_TO_REMOVE} ${SCRATCH}/main
23+
24+
readelfData=$(readelf -V ${SCRATCH}/main 2>&1)
25+
26+
if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") != 0 ]; then
27+
# We expect this to appear at least twice: once for the symbol entry,
28+
# and once for verneed entry.
29+
echo "The symbol version ${SYMBOL_TO_REMOVE} remained behind!"
30+
exit 1
31+
fi

0 commit comments

Comments
 (0)