From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Enable the undefined behavior sanitizer (ubsan) if it's available or the builder requests it. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- 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..a5b2c65 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=yesdefault to enable autoprobe. +AC_ARG_ENABLE(ubsan, +[ --enable-ubsan=[yes/no] Enable Undefined Behavior Sanitizer (UBSAN) [default=yes]],, + 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" = "yesdefault"; 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) + ]) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html