]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
enable UBSAN if the builder wants it
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 8 Mar 2018 20:15:29 +0000 (12:15 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 8 Aug 2018 15:16:09 +0000 (11:16 -0400)
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>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
MCONFIG.in
config/ltmain.sh [new symlink]
configure
configure.ac
debian/rules

index f06933d45f0b140acf9a55e9e6af8529bdf48b1e..4234ff0819dffdc9218544650c772bd42fd7e043 100644 (file)
@@ -81,8 +81,8 @@ SYSTEMD_SYSTEM_UNIT_DIR = @systemd_system_unit_dir@
 @ifNotGNUmake@ CHECK_CMD=true
 @ifNotGNUmake@ CPPCHECK_CMD=true
 
-SANITIZER_CFLAGS = @lto_cflags@
-SANITIZER_LDFLAGS = @lto_ldflags@
+SANITIZER_CFLAGS = @lto_cflags@ @ubsan_cflags@
+SANITIZER_LDFLAGS = @lto_ldflags@ @ubsan_ldflags@
 
 CC = @CC@
 BUILD_CC = @BUILD_CC@
diff --git a/config/ltmain.sh b/config/ltmain.sh
new file mode 120000 (symlink)
index 0000000..8cff389
--- /dev/null
@@ -0,0 +1 @@
+/usr/share/libtool/build-aux/ltmain.sh
\ No newline at end of file
index ef9bb99809e08c75d4f896c834dcbf656e2a6989..c0f8c4bd7ccc38cf1c368b82bcd8efd8e92e3fdb 100755 (executable)
--- a/configure
+++ b/configure
@@ -653,6 +653,9 @@ E2SCRUB_CMT
 UNIX_CMT
 CYGWIN_CMT
 LINUX_CMT
+ubsan_ldflags
+ubsan_cflags
+have_ubsan
 lto_ldflags
 lto_cflags
 have_lto
@@ -909,6 +912,7 @@ with_included_gettext
 with_libintl_prefix
 enable_fuse2fs
 enable_lto
+enable_ubsan
 with_multiarch
 with_udev_rules_dir
 with_crond_dir
@@ -1588,6 +1592,7 @@ Optional Features:
   --disable-rpath         do not hardcode runtime library paths
   --disable-fuse2fs      do not build fuse2fs
   --enable-lto           enable link time optimization
+  --enable-ubsan         enable undefined behavior sanitizer
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
 if test "$enable_lto" = "yes" && test "$have_lto" != "yes"; then
        as_fn_error $? "LTO not supported by compiler." "$LINENO" 5
 fi
+# Check whether --enable-ubsan was given.
+if test "${enable_ubsan+set}" = set; then :
+  enableval=$enable_ubsan;
+else
+  enable_ubsan=no
+fi
+
+if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking if C compiler supports UBSAN" >&5
+$as_echo_n "checking if C compiler supports UBSAN... " >&6; }
+       OLD_CFLAGS="$CFLAGS"
+       OLD_LDFLAGS="$LDFLAGS"
+       UBSAN_FLAGS="-fsanitize=undefined"
+       CFLAGS="$CFLAGS $UBSAN_FLAGS"
+       LDFLAGS="$LDFLAGS $UBSAN_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; }
+               ubsan_cflags=$UBSAN_FLAGS
+               ubsan_ldflags=$UBSAN_FLAGS
+               have_ubsan=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_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
+       as_fn_error $? "UBSAN not supported by compiler." "$LINENO" 5
+fi
 LINUX_CMT="#"
 CYGWIN_CMT="#"
 UNIX_CMT=
index 062323bb15912e19e226b4f8d64c71f8f9a9f7ea..1d23858b7de08af099b41b2afe35bf0be376811c 100644 (file)
@@ -1330,6 +1330,34 @@ if test "$enable_lto" = "yes" && test "$have_lto" != "yes"; then
        AC_MSG_ERROR([LTO not supported by compiler.])
 fi
 dnl
+dnl Enable UBSAN for all packages
+dnl
+AC_ARG_ENABLE([ubsan],
+[  --enable-ubsan        enable undefined behavior sanitizer],,
+enable_ubsan=no)
+if test "$enable_ubsan" = "yes" || test "$enable_ubsan" = "probe"; then
+       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)
+fi
+if test "$enable_ubsan" = "yes" && test "$have_ubsan" != "yes"; then
+       AC_MSG_ERROR([UBSAN not supported by compiler.])
+fi
+dnl
 dnl OS-specific uncomment control
 dnl
 LINUX_CMT="#"
index 8be679a204d7cac1af2cf3b8737680606ba872cf..6c5f7503895ef8e3af94c2ce559d5ae47029793a 100755 (executable)
@@ -164,7 +164,7 @@ endif
 
 BACKTRACE_CONF_FLAGS ?= $(shell if ${debdir}/scripts/test-backtrace ; then echo --disable-backtrace ; fi)
 
-COMMON_CONF_FLAGS = --enable-lto --disable-e2initrd-helper \
+COMMON_CONF_FLAGS = --enable-lto --disable-ubsan --disable-e2initrd-helper \
        --infodir=/usr/share/info  --enable-symlink-install \
        --with-multiarch=$(DEB_HOST_MULTIARCH) \
        $(BACKTRACE_CONF_FLAGS) $(UTIL_CONF_FLAGS)