All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@redhat.com, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 08/10] misc: enable gcc/clang address sanitizer
Date: Thu, 26 Oct 2017 15:15:43 -0700	[thread overview]
Message-ID: <150905614361.28563.9247533518481627005.stgit@magnolia> (raw)
In-Reply-To: <150905608689.28563.9670731739870415773.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

Enable AddressSanitizer to look for memory usage errors if requested.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 configure.ac            |   13 +++++++++++++
 debian/rules            |    4 ++--
 include/builddefs.in    |    4 ++--
 m4/package_sanitizer.m4 |   20 ++++++++++++++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)


diff --git a/configure.ac b/configure.ac
index a5b2c65..b101e05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -78,6 +78,12 @@ AC_ARG_ENABLE(ubsan,
 	enable_ubsan=no)
 AC_SUBST(enable_ubsan)
 
+# Enable ADDRSAN; set enable_addrsan=yesdefault to enable autoprobe.
+AC_ARG_ENABLE(addrsan,
+[ --enable-addrsan=[yes/no] Enable Address Sanitizer (ADDRSAN) [default=yes]],,
+	enable_addrsan=no)
+AC_SUBST(enable_addrsan)
+
 #
 # If the user specified a libdir ending in lib64 do not append another
 # 64 to the library names.
@@ -161,6 +167,13 @@ if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
         AC_MSG_ERROR([UBSAN not supported by compiler.])
 fi
 
+if test "$enable_addrsan" = "yes" || test "$enable_addrsan" = "yesdefault"; then
+        AC_PACKAGE_CHECK_ADDRSAN
+fi
+if test "$enable_addrsan" = "yes" && test "$have_addrsan" != "yes"; then
+        AC_MSG_ERROR([ADDRSAN not supported by compiler.])
+fi
+
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([char *])
 AC_TYPE_UMODE_T
diff --git a/debian/rules b/debian/rules
index 9dcaf52..6b6f45b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -20,9 +20,9 @@ stdenv = @GZIP=-q; export GZIP;
 
 options = export DEBUG=-DNDEBUG DISTRIBUTION=debian \
 	  INSTALL_USER=root INSTALL_GROUP=root \
-	  LOCAL_CONFIGURE_OPTIONS="--enable-readline=yes --enable-blkid=yes --disable-ubsan" ;
+	  LOCAL_CONFIGURE_OPTIONS="--enable-readline=yes --enable-blkid=yes --disable-ubsan --disable-addrsan" ;
 diopts  = $(options) \
-	  export OPTIMIZER=-Os LOCAL_CONFIGURE_OPTIONS="--enable-gettext=no --disable-ubsan" ;
+	  export OPTIMIZER=-Os LOCAL_CONFIGURE_OPTIONS="--enable-gettext=no --disable-ubsan --disable-addrsan" ;
 checkdir = test -f debian/rules
 
 build: built
diff --git a/include/builddefs.in b/include/builddefs.in
index 6b9d6c2..7c78d4b 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -155,8 +155,8 @@ ifeq ($(HAVE_GETFSMAP),yes)
 PCFLAGS+= -DHAVE_GETFSMAP
 endif
 
-SANITIZER_CFLAGS += @ubsan_cflags@
-SANITIZER_LDFLAGS += @ubsan_ldflags@
+SANITIZER_CFLAGS += @addrsan_cflags@ @ubsan_cflags@
+SANITIZER_LDFLAGS += @addrsan_ldflags@ @ubsan_ldflags@
 
 GCFLAGS = $(DEBUG) \
 	  -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\"  \
diff --git a/m4/package_sanitizer.m4 b/m4/package_sanitizer.m4
index a6673f3..06031ad 100644
--- a/m4/package_sanitizer.m4
+++ b/m4/package_sanitizer.m4
@@ -17,3 +17,23 @@ AC_DEFUN([AC_PACKAGE_CHECK_UBSAN],
     AC_SUBST(ubsan_cflags)
     AC_SUBST(ubsan_ldflags)
   ])
+
+AC_DEFUN([AC_PACKAGE_CHECK_ADDRSAN],
+  [ 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)
+  ])


  parent reply	other threads:[~2017-10-26 22:15 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-26 22:14 [PATCH 00/10] xfsprogs: 4.14 rollup Darrick J. Wong
2017-10-26 22:14 ` [PATCH 01/10] db: increase metadump's default overly long extent discard threshold Darrick J. Wong
2017-10-27  0:03   ` Eric Sandeen
2017-10-27  0:12     ` Darrick J. Wong
2017-10-26 22:15 ` [PATCH 02/10] xfsprogs: explicitly cast troublesome types to match printf format specifiers Darrick J. Wong
2017-10-27  0:06   ` Eric Sandeen
2017-10-26 22:15 ` [PATCH 03/10] xfs_io: add new error injection knobs to inject command Darrick J. Wong
2017-10-27  0:09   ` Eric Sandeen
2017-10-26 22:15 ` [PATCH 04/10] xfs_repair: fix bag memory overwrite problems Darrick J. Wong
2017-10-27  0:49   ` Eric Sandeen
2017-10-26 22:15 ` [PATCH 05/10] xfs_repair: clear DAX flag from non-file inodes Darrick J. Wong
2017-10-27  2:01   ` Eric Sandeen
2017-10-26 22:15 ` [PATCH 06/10] xfs_repair: fix cowextsize field checking and repairing Darrick J. Wong
2017-10-27  2:06   ` Eric Sandeen
2017-10-27 16:17     ` Darrick J. Wong
2017-10-27 16:27       ` Eric Sandeen
2017-10-26 22:15 ` [PATCH 07/10] misc: enable ubsan if it's available Darrick J. Wong
2017-10-26 22:23   ` [PATCH v2] misc: enable ubsan if the builder wants it Darrick J. Wong
2017-10-26 22:15 ` Darrick J. Wong [this message]
2017-10-26 22:24   ` [PATCH v2 08/10] misc: enable gcc/clang address sanitizer Darrick J. Wong
2017-10-26 22:15 ` [PATCH 09/10] misc: enable thread Darrick J. Wong
2017-10-26 22:24   ` [PATCH v2 09/10] misc: enable thread sanitizer if requested Darrick J. Wong
2017-10-26 22:15 ` [PATCH 10/10] misc: fix ubsan warnings Darrick J. Wong
2017-10-27 13:48   ` Eric Sandeen
2017-10-27 16:14     ` Darrick J. Wong
2017-10-27 16:24       ` Eric Sandeen
2017-10-27 16:19   ` [PATCH v2 " Darrick J. Wong
2017-10-26 22:32 ` [PATCH 00/10] xfsprogs: 4.14 rollup Goldwyn Rodrigues
2017-10-27  0:01   ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150905614361.28563.9247533518481627005.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.