Skip to content

Commit 7e07d97

Browse files
committed
test: add test for --remove-needed-version
1 parent aaecc8c commit 7e07d97

File tree

8 files changed

+120
-3
lines changed

8 files changed

+120
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Makefile
3333
/tests/contiguous-note-sections
3434
/tests/simple-pie
3535
/tests/simple-execstack
36+
/tests/symver
3637

3738
.direnv/
3839
.vscode/

tests/Makefile.am

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
LIBS =
22

3-
check_PROGRAMS = simple-pie simple simple-execstack main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections
3+
check_PROGRAMS = simple-pie simple simple-execstack main too-many-strtab main-scoped big-dynstr no-rpath contiguous-note-sections \
4+
symver
45

56
no_rpath_arch_TESTS = \
67
no-rpath-amd64.sh \
@@ -51,7 +52,8 @@ src_TESTS = \
5152
overlapping-segments-after-rounding.sh \
5253
shared-rpath.sh \
5354
short-first-segment.sh \
54-
empty-note.sh
55+
empty-note.sh \
56+
remove-needed-version.sh
5557

5658
build_TESTS = \
5759
$(no_rpath_arch_TESTS)
@@ -123,7 +125,8 @@ check_DATA = libbig-dynstr.debug
123125
# - with libtool, it is difficult to control options
124126
# - with libtool, it is not possible to compile convenience *dynamic* libraries :-(
125127
check_PROGRAMS += libfoo.so libfoo-scoped.so libbar.so libbar-scoped.so libsimple.so libsimple-execstack.so libbuildid.so libtoomanystrtab.so \
126-
phdr-corruption.so many-syms-main libmany-syms.so liboveralign.so libshared-rpath.so
128+
phdr-corruption.so many-syms-main libmany-syms.so liboveralign.so libshared-rpath.so \
129+
libsymver.so libsymver-old.so
127130

128131
libbuildid_so_SOURCES = simple.c
129132
libbuildid_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,--build-id
@@ -180,6 +183,18 @@ phdr_corruption_so_SOURCES = void.c phdr-corruption.ld
180183
phdr_corruption_so_LDFLAGS = -nostdlib -shared -Wl,-T$(srcdir)/phdr-corruption.ld
181184
phdr_corruption_so_CFLAGS =
182185

186+
libsymver_so_SOURCES = libsymver.c
187+
libsymver_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,--version-script=libsymver.map
188+
libsymver_so_CFLAGS = $(AM_CFLAGS)
189+
libsymver_old_so_SOURCES = libsymver-old.c
190+
libsymver_old_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,--version-script=libsymver-old.map
191+
libsymver_old_so_CFLAGS = $(AM_CFLAGS)
192+
symver_SOURCES = symver.c
193+
symver_LDFLAGS = $(LDFLAGS_local)
194+
symver_LDADD = -lsymver $(AM_LDADD)
195+
symver_DEPENDENCIES = libsymver.so libsymver-old.so
196+
symver_CFLAGS = $(AM_CFLAGS)
197+
183198
many-syms.c:
184199
i=1; while [ $$i -le 2000 ]; do echo "void f$$i() {};"; i=$$(($$i + 1)); done > $@
185200

tests/libsymver-old.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
3+
__asm__(".symver foo_v1, foo@@V1");
4+
5+
void foo_v1() {
6+
printf("foo_v1\n");
7+
}
8+
9+
void bar() {
10+
printf("bar_unver\n");
11+
}

tests/libsymver-old.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
V1 {
2+
global: foo;
3+
local: foo_v1;
4+
};

tests/libsymver.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
3+
__asm__(".symver foo_v1, foo@V1");
4+
__asm__(".symver foo_v2, foo@@V2");
5+
6+
void foo_v1() {
7+
printf("foo_v1\n");
8+
}
9+
10+
void foo_v2() {
11+
printf("foo_v2\n");
12+
}
13+
14+
15+
// version defined in version script
16+
void bar() {
17+
printf("bar_ver\n");
18+
}

tests/libsymver.map

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
V1 {
2+
global: foo;
3+
local: foo_v1;
4+
};
5+
V2 {
6+
global: foo;
7+
local: foo_v2;
8+
};
9+
VER {
10+
global: bar;
11+
};

tests/remove-needed-version.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#! /bin/sh -e
2+
SCRATCH="scratch/$(basename "$0" .sh)"
3+
PATCHELF="$(readlink -f "../src/patchelf")"
4+
READELF="${READELF:-readelf}"
5+
MAIN=symver
6+
LIBNEW=libsymver.so
7+
LIBOLD=libsymver-old.so
8+
9+
10+
rm -rf "$SCRATCH"
11+
mkdir -p "$SCRATCH"
12+
13+
cp $MAIN $LIBNEW $LIBOLD "${SCRATCH}/"
14+
15+
cd "$SCRATCH"
16+
17+
fail() {
18+
echo $1
19+
"$READELF" -a -W $MAIN
20+
"$READELF" -a -W $LIBNEW
21+
"$READELF" -a -W $LIBOLD
22+
exit $2
23+
}
24+
25+
# sanity check
26+
exit_code=0
27+
LD_LIBRARY_PATH="$PWD" ./${MAIN} || exit_code=$?
28+
if [ $exit_code -ne 0 ]; then
29+
fail "basic check" $exit_code
30+
fi
31+
32+
# replace with old version
33+
mv $LIBOLD $LIBNEW
34+
35+
# should NOT run before patch
36+
exit_code=0
37+
LD_LIBRARY_PATH="$PWD" ./${MAIN} || exit_code=$?
38+
if [ $exit_code -eq 0 ]; then
39+
fail "patch check" 1
40+
fi
41+
42+
${PATCHELF} --remove-needed-version $LIBNEW V2 \
43+
--remove-needed-version $LIBNEW VER $MAIN || fail "patchelf" -1
44+
45+
# should run after removing version
46+
exit_code=0
47+
LD_LIBRARY_PATH="$PWD" ./${MAIN} || exit_code=$?
48+
if [ $exit_code -ne 0 ]; then
49+
fail "patch check" $exit_code
50+
fi

tests/symver.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
void foo();
2+
void bar();
3+
4+
int main() {
5+
foo();
6+
bar();
7+
}

0 commit comments

Comments
 (0)