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])
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}
])
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
# 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) \
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)