Skip to content

Commit 7ff7a80

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. In these cases (or in the case that __libc_start_main is now at a different version), the test should print a warning, but exit with "0" to report a pass.
1 parent 85b83d0 commit 7ff7a80

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

tests/Makefile.am

+2-1
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

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
9+
SYMBOL_TO_REMOVE=__libc_start_main
10+
VERSION_TO_REMOVE=GLIBC_2.34a
11+
12+
readelfData=$(readelf -V ${SCRATCH}/main 2>&1)
13+
14+
if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") -lt 2 ]; then
15+
# We expect this to appear at least twice: once for the symbol entry,
16+
# and once for verneed entry.
17+
echo "Warning: Couldn't find expected versioned symbol."
18+
echo "This is probably because you're either not using glibc, or"
19+
echo "${SYMBOL_TO_REMOVE} is no longer at version ${VERSION_TO_REMOVE}"
20+
echo "Reporting a pass anyway, as the test result is invalid."
21+
exit 0
22+
fi
23+
24+
../src/patchelf --clear-symbol-version ${SYMBOL_TO_REMOVE} ${SCRATCH}/main
25+
26+
readelfData=$(readelf -V ${SCRATCH}/main 2>&1)
27+
28+
if [ $(echo "$readelfData" | grep --count "$VERSION_TO_REMOVE") -ne 0 ]; then
29+
# We expect this to appear at least twice: once for the symbol entry,
30+
# and once for verneed entry.
31+
echo "The symbol version ${SYMBOL_TO_REMOVE} remained behind!"
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)