From e522b14edc0ef742106771176f13c9a0b78818ca Mon Sep 17 00:00:00 2001 From: "Aaron D. Marasco" Date: Wed, 10 Jun 2020 09:35:06 -0400 Subject: Add libasan build option and test print-needed (cherry picked from commit 288eb61a173ce6f4cdf0be0d744c9c6b6b5598a4) --- configure.ac | 5 +++++ src/Makefile.am | 4 ++++ src/patchelf.cc | 3 +-- tests/Makefile.am | 1 + tests/plain-needed.sh | 4 ++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 tests/plain-needed.sh diff --git a/configure.ac b/configure.ac index c2e5e98..e762e1e 100644 --- a/configure.ac +++ b/configure.ac @@ -24,5 +24,10 @@ fi AC_DEFINE_UNQUOTED(PAGESIZE, ${PAGESIZE}) AC_MSG_RESULT([Setting page size to ${PAGESIZE}]) +AC_ARG_WITH([asan], + AS_HELP_STRING([--with-asan], [Link with libasan]) +) +AM_CONDITIONAL([WITH_ASAN], [test x"$with_asan" = xyes]) + AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile patchelf.spec]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index 7170cf3..b9aee08 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,9 @@ AM_CXXFLAGS = -Wall -std=c++11 -D_FILE_OFFSET_BITS=64 +if WITH_ASAN +AM_CXXFLAGS += -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1 +endif + bin_PROGRAMS = patchelf patchelf_SOURCES = patchelf.cc elf.h diff --git a/src/patchelf.cc b/src/patchelf.cc index 965686a..0d0f369 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -250,7 +250,6 @@ I ElfFile::rdi(I i) return r; } - /* Ugly: used to erase DT_RUNPATH when using --force-rpath. */ #define DT_IGNORE 0x00726e67 @@ -737,7 +736,7 @@ void ElfFile::rewriteSectionsLibrary() ET_DYN as does LD when linking with pie. If we move PT_PHDR, it has to stay in the first PT_LOAD segment or any subsequent ones if they're continuous in memory due to linux kernel constraints - (see BUGS). Since the end of the file would be after bss, we can't + (see BUGS). Since the end of the file would be after bss, we can't move PHDR there, we therefore choose to leave PT_PHDR where it is but move enough following sections such that we can add the extra PT_LOAD section to it. This PT_LOAD segment ensures the sections at the end of diff --git a/tests/Makefile.am b/tests/Makefile.am index 96339b3..d2d58b0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -23,6 +23,7 @@ src_TESTS = \ set-interpreter-long.sh set-rpath.sh no-rpath.sh big-dynstr.sh \ set-rpath-library.sh soname.sh shrink-rpath-with-allowed-prefixes.sh \ force-rpath.sh \ + plain-needed.sh \ output-flag.sh build_TESTS = \ diff --git a/tests/plain-needed.sh b/tests/plain-needed.sh new file mode 100755 index 0000000..36267fb --- /dev/null +++ b/tests/plain-needed.sh @@ -0,0 +1,4 @@ +#! /bin/sh +set -e +echo "Confirming main requires libfoo" +../src/patchelf --print-needed main | grep -q libfoo.so -- cgit v0.12