Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoguim committed Feb 20, 2023
1 parent 62dcdd2 commit 86fa688
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
19 changes: 18 additions & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ check_DATA = libbig-dynstr.debug
# - with libtool, it is difficult to control options
# - with libtool, it is not possible to compile convenience *dynamic* libraries :-(
check_PROGRAMS += libfoo.so libfoo-scoped.so libbar.so libbar-scoped.so libsimple.so libbuildid.so libtoomanystrtab.so \
phdr-corruption.so
phdr-corruption.so many-syms-main libmany-syms.so

libbuildid_so_SOURCES = simple.c
libbuildid_so_LDFLAGS = $(LDFLAGS_sharedlib) -Wl,--build-id
Expand Down Expand Up @@ -138,6 +138,14 @@ too_many_strtab_SOURCES = too-many-strtab.c too-many-strtab2.s
libtoomanystrtab_so_SOURCES = too-many-strtab.c too-many-strtab2.s
libtoomanystrtab_so_LDFLAGS = $(LDFLAGS_sharedlib)

many_syms_main_SOURCES = many-syms-main.c
many_syms_main_LDFLAGS = $(LDFLAGS_local)
many_syms_main_LDADD = -lmany-syms $(AM_LDADD)
many_syms_main_DEPENDENCIES = libmany-syms.so
many_syms_main_CFLAGS = -pie
libmany_syms_so_SOURCES = many-syms.c
libmany_syms_so_LDFLAGS = $(LDFLAGS_sharedlib)

no_rpath_SOURCES = no-rpath.c
# no -fpic for no-rpath.o
no_rpath_CFLAGS =
Expand All @@ -149,3 +157,12 @@ contiguous_note_sections_CFLAGS = -pie
phdr_corruption_so_SOURCES = void.c phdr-corruption.ld
phdr_corruption_so_LDFLAGS = -nostdlib -shared -Wl,-T$(srcdir)/phdr-corruption.ld
phdr_corruption_so_CFLAGS =

many-syms.c:
i=1; while [ $$i -le 2000 ]; do echo "void f$$i() {};"; i=$$(($$i + 1)); done > $@

many-syms-main.c:
echo "int main() {" > $@
i=1; while [ $$i -le 2000 ]; do echo "void f$$i(); f$$i();"; i=$$(($$i + 1)); done >> $@
echo "}" >> $@

22 changes: 9 additions & 13 deletions tests/rename-dynamic-symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ PATCHELF=$(readlink -f "../src/patchelf")
rm -rf ${SCRATCH}
mkdir -p ${SCRATCH}

# Use the c++ standard library used by patchelf for our testing
# It helps exercising a large number of symbols, versioning and validate
# the feature in a more real scenario
full_lib_name=$(ldd ${PATCHELF} | awk '/ => / { print $3 }' | grep "c++" | head -n 1)
echo "The library used in this test is: ${full_lib_name}"
full_main_name="${PWD}/many-syms-main"
full_lib_name="${PWD}/libmany-syms.so"
chmod -w $full_lib_name $full_main_name

lib_name="$(basename $full_lib_name)"
suffix="_special_suffix"

cd ${SCRATCH}
Expand Down Expand Up @@ -71,18 +68,17 @@ diff orig_rel map_rel_r > diff_orig_rel_map_rel_r || exit 1
# 4. Run patchelf with the modified dependencies
###############################################################################

# Create the map
echo "# Create the map"
list_symbols --defined-only $full_lib_name | cut -d@ -f1 | sort -u | awk "{printf \"%s %s${suffix}\n\",\$1,\$1}" > map

# Copy all dependencies
echo "# Copy all dependencies"
mkdir env
cd env
patchelf_dependencies="$(ldd ${PATCHELF} | awk '/ => / { print $3 }')"
cp ${PATCHELF} $patchelf_dependencies .
cp $full_lib_name $full_main_name .

# Apply renaming
echo "# Apply renaming"
chmod +w *
${PATCHELF} --rename-dynamic-symbols ../map *

# Run the patched tool and libraries
env LD_BIND_NOW=1 LD_LIBRARY_PATH=. ./patchelf --version
echo "# Run the patched tool and libraries"
env LD_BIND_NOW=1 LD_LIBRARY_PATH=${PWD} ./many-syms-main

0 comments on commit 86fa688

Please sign in to comment.