From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@redhat.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH v2] misc: enable ubsan if the builder wants it
Date: Thu, 26 Oct 2017 15:23:44 -0700 [thread overview]
Message-ID: <20171026222344.GC5483@magnolia> (raw)
In-Reply-To: <150905613758.28563.18393057548617924511.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Enable the undefined behavior sanitizer (ubsan) if the builder requests
it and it's available.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
configure.ac | 13 +++++++++++++
debian/rules | 4 ++--
include/builddefs.in | 6 ++++--
include/buildmacros | 2 +-
m4/Makefile | 1 +
m4/package_sanitizer.m4 | 19 +++++++++++++++++++
6 files changed, 40 insertions(+), 5 deletions(-)
create mode 100644 m4/package_sanitizer.m4
diff --git a/configure.ac b/configure.ac
index 4161c3b..5838e08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,6 +72,12 @@ AC_ARG_ENABLE(librt,
enable_librt=yes)
AC_SUBST(enable_librt)
+# Enable UBSAN; set enable_ubsan=probe below to enable autoprobe.
+AC_ARG_ENABLE(ubsan,
+[ --enable-ubsan=[yes/no] Enable Undefined Behavior Sanitizer (UBSAN) [default=no]],,
+ enable_ubsan=no)
+AC_SUBST(enable_ubsan)
+
#
# If the user specified a libdir ending in lib64 do not append another
# 64 to the library names.
@@ -148,6 +154,13 @@ if test "$enable_blkid" = yes; then
AC_HAVE_BLKID_TOPO
fi
+if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then
+ AC_PACKAGE_CHECK_UBSAN
+fi
+if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
+ AC_MSG_ERROR([UBSAN 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 c673380..9dcaf52 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" ;
+ LOCAL_CONFIGURE_OPTIONS="--enable-readline=yes --enable-blkid=yes --disable-ubsan" ;
diopts = $(options) \
- export OPTIMIZER=-Os LOCAL_CONFIGURE_OPTIONS="--enable-gettext=no" ;
+ export OPTIMIZER=-Os LOCAL_CONFIGURE_OPTIONS="--enable-gettext=no --disable-ubsan" ;
checkdir = test -f debian/rules
build: built
diff --git a/include/builddefs.in b/include/builddefs.in
index ec630bd..6b9d6c2 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -155,6 +155,8 @@ ifeq ($(HAVE_GETFSMAP),yes)
PCFLAGS+= -DHAVE_GETFSMAP
endif
+SANITIZER_CFLAGS += @ubsan_cflags@
+SANITIZER_LDFLAGS += @ubsan_ldflags@
GCFLAGS = $(DEBUG) \
-DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\" \
@@ -165,8 +167,8 @@ GCFLAGS += -DENABLE_GETTEXT
endif
BUILD_CFLAGS += $(GCFLAGS) $(PCFLAGS)
-# First, Global, Platform, Local CFLAGS
-CFLAGS += $(FCFLAGS) $(OPTIMIZER) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS)
+# First, Sanitizer, Global, Platform, Local CFLAGS
+CFLAGS += $(FCFLAGS) $(SANITIZER_CFLAGS) $(OPTIMIZER) $(GCFLAGS) $(PCFLAGS) $(LCFLAGS)
include $(TOPDIR)/include/buildmacros
diff --git a/include/buildmacros b/include/buildmacros
index a7c5d8a..178e2ed 100644
--- a/include/buildmacros
+++ b/include/buildmacros
@@ -9,7 +9,7 @@ BUILDRULES = $(TOPDIR)/include/buildrules
# $(CXXFILES), or $(HFILES) and is used to construct the manifest list
# during the "dist" phase (packaging).
-LDFLAGS += $(LOADERFLAGS) $(LLDFLAGS)
+LDFLAGS += $(SANITIZER_LDFLAGS) $(LOADERFLAGS) $(LLDFLAGS)
LTLDFLAGS += $(LOADERFLAGS)
LDLIBS = $(LLDLIBS) $(PLDLIBS) $(MALLOCLIB)
diff --git a/m4/Makefile b/m4/Makefile
index d282f0a..4706121 100644
--- a/m4/Makefile
+++ b/m4/Makefile
@@ -18,6 +18,7 @@ LSRCFILES = \
package_globals.m4 \
package_libcdev.m4 \
package_pthread.m4 \
+ package_sanitizer.m4 \
package_types.m4 \
package_utilies.m4 \
package_uuiddev.m4 \
diff --git a/m4/package_sanitizer.m4 b/m4/package_sanitizer.m4
new file mode 100644
index 0000000..a6673f3
--- /dev/null
+++ b/m4/package_sanitizer.m4
@@ -0,0 +1,19 @@
+AC_DEFUN([AC_PACKAGE_CHECK_UBSAN],
+ [ AC_MSG_CHECKING([if C compiler supports UBSAN])
+ OLD_CFLAGS="$CFLAGS"
+ OLD_LDFLAGS="$LDFLAGS"
+ UBSAN_FLAGS="-fsanitize=undefined"
+ CFLAGS="$CFLAGS $UBSAN_FLAGS"
+ LDFLAGS="$LDFLAGS $UBSAN_FLAGS"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+ [AC_MSG_RESULT([yes])]
+ [ubsan_cflags=$UBSAN_FLAGS]
+ [ubsan_ldflags=$UBSAN_FLAGS]
+ [have_ubsan=yes],
+ [AC_MSG_RESULT([no])])
+ CFLAGS="${OLD_CFLAGS}"
+ LDFLAGS="${OLD_LDFLAGS}"
+ AC_SUBST(have_ubsan)
+ AC_SUBST(ubsan_cflags)
+ AC_SUBST(ubsan_ldflags)
+ ])
next prev parent reply other threads:[~2017-10-26 22:23 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 ` Darrick J. Wong [this message]
2017-10-26 22:15 ` [PATCH 08/10] misc: enable gcc/clang address sanitizer Darrick J. Wong
2017-10-26 22:24 ` [PATCH v2 " 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=20171026222344.GC5483@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox