Skip to content

Commit 860c04d

Browse files
committed
Add test
1 parent 8b32fae commit 860c04d

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

tests/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ src_TESTS = \
4949
modify-execstack.sh \
5050
rename-dynamic-symbols.sh \
5151
overlapping-segments-after-rounding.sh \
52+
shared-rpath.sh \
5253
empty-note.sh
5354

5455
build_TESTS = \
@@ -121,7 +122,7 @@ check_DATA = libbig-dynstr.debug
121122
# - with libtool, it is difficult to control options
122123
# - with libtool, it is not possible to compile convenience *dynamic* libraries :-(
123124
check_PROGRAMS += libfoo.so libfoo-scoped.so libbar.so libbar-scoped.so libsimple.so libsimple-execstack.so libbuildid.so libtoomanystrtab.so \
124-
phdr-corruption.so many-syms-main libmany-syms.so liboveralign.so
125+
phdr-corruption.so many-syms-main libmany-syms.so liboveralign.so libshared-rpath.so
125126

126127
libbuildid_so_SOURCES = simple.c
127128
libbuildid_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,--build-id
@@ -148,6 +149,9 @@ libsimple_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,-z,noexecstack
148149
liboveralign_so_SOURCES = simple.c
149150
liboveralign_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,-z,max-page-size=0x10000
150151

152+
libshared_rpath_so_SOURCES = shared-rpath.c
153+
libshared_rpath_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,-rpath=a_symbol_name
154+
151155
libsimple_execstack_so_SOURCES = simple.c
152156
libsimple_execstack_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,-z,execstack
153157

tests/shared-rpath.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
int a_symbol_name;
2+
int foo() { return a_symbol_name; }

tests/shared-rpath.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#! /bin/sh -e
2+
3+
PATCHELF=$(readlink -f "../src/patchelf")
4+
SCRATCH="scratch/$(basename "$0" .sh)"
5+
READELF=${READELF:-readelf}
6+
7+
LIB_NAME="${PWD}/libshared-rpath.so"
8+
9+
rm -rf "${SCRATCH}"
10+
mkdir -p "${SCRATCH}"
11+
cd "${SCRATCH}"
12+
13+
has_x() {
14+
strings "$1" | grep -c "XXXXXXXX"
15+
}
16+
17+
nm -D "${LIB_NAME}" | grep a_symbol_name
18+
previous_cnt="$(strings "${LIB_NAME}" | grep -c a_symbol_name)"
19+
20+
echo "#### Number of a_symbol_name strings in the library: $previous_cnt"
21+
22+
echo "#### Rename the rpath to something larger than the original"
23+
# Pathelf should detect that the rpath string is shared with the symbol name string and avoid
24+
# tainting the string with Xs
25+
"${PATCHELF}" --set-rpath a_very_big_rpath_that_is_larger_than_original --output liblarge-rpath.so "${LIB_NAME}"
26+
27+
echo "#### Checking symbol is still there"
28+
nm -D liblarge-rpath.so | grep a_symbol_name
29+
30+
echo "#### Checking there are no Xs"
31+
[ "$(has_x liblarge-rpath.so)" -eq 0 ] || exit 1
32+
33+
current_cnt="$(strings liblarge-rpath.so | grep -c a_symbol_name)"
34+
echo "#### Number of a_symbol_name strings in the modified library: $current_cnt"
35+
[ "$current_cnt" -eq "$previous_cnt" ] || exit 1
36+
37+
echo "#### Rename the rpath to something shorter than the original"
38+
# Pathelf should detect that the rpath string is shared with the symbol name string and avoid
39+
# overwriting the existing string
40+
"${PATCHELF}" --set-rpath shrt_rpth --output libshort-rpath.so "${LIB_NAME}"
41+
42+
echo "#### Checking symbol is still there"
43+
nm -D libshort-rpath.so | grep a_symbol_name
44+
45+
echo "#### Number of a_symbol_name strings in the modified library: $current_cnt"
46+
current_cnt="$(strings libshort-rpath.so | grep -c a_symbol_name)"
47+
[ "$current_cnt" -eq "$previous_cnt" ] || exit 1
48+
49+
echo "#### Now liblarge-rpath.so should have its own rpath, so it should be allowed to taint it"
50+
"${PATCHELF}" --set-rpath a_very_big_rpath_that_is_larger_than_original__even_larger --output liblarge-rpath2.so liblarge-rpath.so
51+
[ "$(has_x liblarge-rpath2.so)" -eq 1 ] || exit 1

0 commit comments

Comments
 (0)