From patchwork Sun Dec 5 01:39:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 48509 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C92103858416 for ; Sun, 5 Dec 2021 01:39:59 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 38EC73858C2C for ; Sun, 5 Dec 2021 01:39:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38EC73858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x0b.wildebeest.org [172.31.17.141]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id D8ED0300064F; Sun, 5 Dec 2021 02:39:31 +0100 (CET) Received: by reform (Postfix, from userid 1000) id 83B512E8219C; Sun, 5 Dec 2021 02:39:30 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Subject: [PATCH] configure: Add --enable-sanitize-address Date: Sun, 5 Dec 2021 02:39:25 +0100 Message-Id: <20211205013925.278617-1-mark@klomp.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Cc: Mark Wielaard Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" --enable-sanitize-address makes sure that all code is compiled with -fsanitizer=address and all tests run against libasan. It can be combined with --enable-sanitize-undefined, but not with --enable-valgrind. In maintainer mode there is one program that causes leaks, i386_gendis, so disable leak detection for that program. One testcase, test_nlist, needs special linker flags, make sure it also uses -fsanitizer=address when using the address sanitizer. Signed-off-by: Mark Wielaard --- ChangeLog | 4 ++++ configure.ac | 25 +++++++++++++++++++++++++ libcpu/ChangeLog | 5 +++++ libcpu/Makefile.am | 10 +++++++++- tests/ChangeLog | 6 ++++++ tests/Makefile.am | 10 ++++++++-- 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d61b21c7..f00db17b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-12-04 Mark Wielaard + + * configure.ac: Add --enable-sanitize-address. + 2021-11-10 Mark Wielaard * configure.ac (AC_INIT): Set version to 0.186. diff --git a/configure.ac b/configure.ac index ff9581d2..48071165 100644 --- a/configure.ac +++ b/configure.ac @@ -307,10 +307,34 @@ esac AC_DEFINE_UNQUOTED(CHECK_UNDEFINED, $check_undefined_val, [Building with -fsanitize=undefined or not]) +AC_ARG_ENABLE([sanitize-address], + AS_HELP_STRING([--enable-sanitize-address], + [Use gcc address sanitizer]), + [use_address=$enableval], [use_address=no]) +if test "$use_address" = yes; then + old_CFLAGS="$CFLAGS" + old_CXXFLAGS="$CXXFLAGS" + old_LDFLAGS="$LDFLAGS" + # We want to fail immediately on first error, don't try to recover. + CFLAGS="$CFLAGS -fsanitize=address -fno-sanitize-recover" + CXXFLAGS="$CXXFLAGS -fsanitize=address -fno-sanitize-recover" + # Some compilers don't handle -fsanatize=address correctly with --no-undefined + LDFLAGS="-Wl,-z,defs -shared" + AC_LINK_IFELSE([AC_LANG_SOURCE([int main (int argc, char **argv) { return 0; }])], use_address=yes, use_address=no) + AS_IF([test "x$use_address" != xyes], + AC_MSG_WARN([gcc address sanitizer not available]) + CFLAGS="$old_CFLAGS" CXXFLAGS="$old_CXXFLAGS") + LDFLAGS="$old_LDFLAGS" +fi +AM_CONDITIONAL(USE_ADDRESS_SANITIZER, test "$use_address" = yes) + AC_ARG_ENABLE([valgrind], AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]), [use_valgrind=$enableval], [use_valgrind=no]) if test "$use_valgrind" = yes; then + if test "$use_address" = yes; then + AC_MSG_ERROR([cannot enable valgrind and sanitize address together]) + fi AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no) if test "$HAVE_VALGRIND" = "no"; then AC_MSG_ERROR([valgrind not found]) @@ -809,6 +833,7 @@ AC_MSG_NOTICE([ gcov support : ${use_gcov} run all tests under valgrind : ${use_valgrind} gcc undefined behaviour sanitizer : ${use_undefined} + gcc address sanitizer : ${use_address} use rpath in tests : ${tests_use_rpath} test biarch : ${utrace_cv_cc_biarch} ]) diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index 7cca9419..48fbba19 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,3 +1,8 @@ +2021-12-04 Mark Wielaard + + * Makefile.am (GENDIS_ENV): New variable, depends on + USE_ADDRESS_SANITIZER. + 2020-12-20 Dmitry V. Levin * .gitignore: New file. diff --git a/libcpu/Makefile.am b/libcpu/Makefile.am index 43844ecf..57d0a164 100644 --- a/libcpu/Makefile.am +++ b/libcpu/Makefile.am @@ -61,8 +61,16 @@ noinst_HEADERS += memory-access.h i386_parse.h i386_data.h noinst_PROGRAMS = i386_gendis$(EXEEXT) +# i386_gendis doesn't clean up, ignore leaks. +# It is just a build tool to generate source in maintainer mode. +if USE_ADDRESS_SANITIZER +GENDIS_ENV=env ASAN_OPTIONS=detect_leaks=0 +else +GENDIS_ENV= +endif + $(srcdir)/%_dis.h: %_defs i386_gendis$(EXEEXT) - $(AM_V_GEN)./i386_gendis$(EXEEXT) $< > $@T + $(AM_V_GEN) $(GENDIS_ENV) ./i386_gendis$(EXEEXT) $< > $@T $(AM_V_at)mv -f $@T $@ else diff --git a/tests/ChangeLog b/tests/ChangeLog index a5673f18..76cb974a 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2021-12-04 Mark Wielaard + + * Makefile.am (EXTRA_NLIST_CFLAGS): New variable depends on + USE_ADDRESS_SANITIZER. + (test_nlist_CFLAGS): Add EXTRA_NLIST_CFLAGS. + 2021-12-04 Mark Wielaard * varlocs.c (dwarf_encoding_string): Return "" instead diff --git a/tests/Makefile.am b/tests/Makefile.am index 2298a5ae..8acaeaf2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -87,7 +87,13 @@ endif # test_nlist checks its own symbol table, and expects various symbols # to be in the order as specified in the source file. Explicitly set -# minimal CFLAGS +# minimal CFLAGS. But add address sanitizer if in use. +if USE_ADDRESS_SANITIZER +EXTRA_NLIST_CFLAGS=-fsanitize=address +else +EXTRA_NLIST_CFLAGS= +endif + test-nlist$(EXEEXT): test-nlist.c $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) \ @@ -635,7 +641,7 @@ scnnames_LDADD = $(libelf) sectiondump_LDADD = $(libelf) showptable_LDADD = $(libelf) hash_LDADD = $(libelf) -test_nlist_CFLAGS =-g -O0 +test_nlist_CFLAGS =-g -O0 $(EXTRA_NLIST_CFLAGS) test_nlist_LDADD = $(libelf) msg_tst_LDADD = $(libelf) newscn_LDADD = $(libelf)