[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <151992864742.32479.14836279048550708063.stgit@magnolia>
Date: Thu, 01 Mar 2018 10:24:07 -0800
From: "Darrick J. Wong" <darrick.wong@...cle.com>
To: tytso@....edu, darrick.wong@...cle.com
Cc: djwong@...nel.org, linux-ext4@...r.kernel.org
Subject: [PATCH 6/7] misc: enable gcc/clang address sanitizer if the builder
wants it
From: Darrick J. Wong <darrick.wong@...cle.com>
Enable AddressSanitizer to look for memory usage errors if the builder
asks for it and it's available.
Signed-off-by: Darrick J. Wong <darrick.wong@...cle.com>
---
MCONFIG.in | 4 ++--
configure | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 28 ++++++++++++++++++++++++++++
debian/rules | 3 ++-
4 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/MCONFIG.in b/MCONFIG.in
index 4234ff0..1344511 100644
--- a/MCONFIG.in
+++ b/MCONFIG.in
@@ -81,8 +81,8 @@ SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
@ifNotGNUmake@ CHECK_CMD=true
@ifNotGNUmake@ CPPCHECK_CMD=true
-SANITIZER_CFLAGS = @lto_cflags@ @ubsan_cflags@
-SANITIZER_LDFLAGS = @lto_ldflags@ @ubsan_ldflags@
+SANITIZER_CFLAGS = @lto_cflags@ @ubsan_cflags@ @addrsan_cflags@
+SANITIZER_LDFLAGS = @lto_ldflags@ @ubsan_ldflags@ @addrsan_ldflags@
CC = @CC@
BUILD_CC = @BUILD_CC@
diff --git a/configure b/configure
index 1893678..fec933a 100755
--- a/configure
+++ b/configure
@@ -653,6 +653,9 @@ E2SCRUB_CMT
UNIX_CMT
CYGWIN_CMT
LINUX_CMT
+addrsan_ldflags
+addrsan_cflags
+have_addrsan
ubsan_ldflags
ubsan_cflags
have_ubsan
@@ -912,6 +915,7 @@ with_libintl_prefix
enable_fuse2fs
enable_lto
enable_ubsan
+enable_addrsan
with_multiarch
with_udev_rules_dir
with_crond_dir
@@ -1592,6 +1596,7 @@ Optional Features:
--disable-fuse2fs do not build fuse2fs
--enable-lto enable link time optimization
--enable-ubsan enable undefined behavior sanitizer
+ --enable-addrsan enable address sanitizer
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -13915,6 +13920,53 @@ fi
if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
as_fn_error $? "UBSAN not supported by compiler." "$LINENO" 5
fi
+# Check whether --enable-addrsan was given.
+if test "${enable_addrsan+set}" = set; then :
+ enableval=$enable_addrsan;
+else
+ enable_addrsan=no
+fi
+
+if test "$enable_addrsan" = "yes" || test "$enable_addrsan" = "probe"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking if C compiler supports ADDRSAN" >&5
+$as_echo_n "checking if C compiler supports ADDRSAN... " >&6; }
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ ADDRSAN_FLAGS="-fsanitize=address"
+ CFLAGS="$CFLAGS $ADDRSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $ADDRSAN_FLAGS"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ addrsan_cflags=$ADDRSAN_FLAGS
+ addrsan_ldflags=$ADDRSAN_FLAGS
+ have_addrsan=yes
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+
+
+
+fi
+if test "$enable_addrsan" = "yes" && test "$have_addrsan" != "yes"; then
+ as_fn_error $? "ADDRSAN not supported by compiler." "$LINENO" 5
+fi
LINUX_CMT="#"
CYGWIN_CMT="#"
UNIX_CMT=
diff --git a/configure.ac b/configure.ac
index 9ec01c5..f93f572 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1356,6 +1356,34 @@ if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
AC_MSG_ERROR([UBSAN not supported by compiler.])
fi
dnl
+dnl Enable ADDRSAN for all packages
+dnl
+AC_ARG_ENABLE([addrsan],
+[ --enable-addrsan enable address sanitizer],,
+enable_addrsan=no)
+if test "$enable_addrsan" = "yes" || test "$enable_addrsan" = "probe"; then
+ AC_MSG_CHECKING([if C compiler supports ADDRSAN])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ ADDRSAN_FLAGS="-fsanitize=address"
+ CFLAGS="$CFLAGS $ADDRSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $ADDRSAN_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [addrsan_cflags=$ADDRSAN_FLAGS]
+ [addrsan_ldflags=$ADDRSAN_FLAGS]
+ [have_addrsan=yes],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_addrsan)
+ AC_SUBST(addrsan_cflags)
+ AC_SUBST(addrsan_ldflags)
+fi
+if test "$enable_addrsan" = "yes" && test "$have_addrsan" != "yes"; then
+ AC_MSG_ERROR([ADDRSAN not supported by compiler.])
+fi
+dnl
dnl OS-specific uncomment control
dnl
LINUX_CMT="#"
diff --git a/debian/rules b/debian/rules
index 600b751..f4135e8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -164,7 +164,8 @@ endif
BACKTRACE_CONF_FLAGS ?= $(shell if ${debdir}/scripts/test-backtrace ; then echo --disable-backtrace ; fi)
-COMMON_CONF_FLAGS = --enable-lto --disable-ubsan --disable-e2initrd-helper \
+COMMON_CONF_FLAGS = --enable-lto --disable-ubsan --disable-addrsan \
+ --disable-e2initrd-helper \
--infodir=/usr/share/info --enable-symlink-install \
--with-multiarch=$(DEB_HOST_MULTIARCH) \
$(BACKTRACE_CONF_FLAGS) $(UTIL_CONF_FLAGS)
Powered by blists - more mailing lists