From patchwork Sat Mar 24 01:57:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 890371 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="U5HGRz/K"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 407NpW5cNnz9s08 for ; Sat, 24 Mar 2018 12:57:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751832AbeCXB5z (ORCPT ); Fri, 23 Mar 2018 21:57:55 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:33972 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751758AbeCXB5y (ORCPT ); Fri, 23 Mar 2018 21:57:54 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2O1vqR0047733; Sat, 24 Mar 2018 01:57:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=KdQeAX5z6b4LCD0jnrVWz4xwd0S5QiGCokozXwtRX4A=; b=U5HGRz/KYTlGtYpPOOPjTVKUdmIlT22fJQFA575ZWkzaDQXJrptvRWOewhXsY8ekh3Mv UqwuFJS9GUVOLqBzqAz4mYGncyCCV+mjJNlYlY/v4r3FCpWJ0P9EwXU90oUORY1lT7gn Vi0H6N7gb5SobcQLFN82ROTj4UpP68qYipJRVPifCzFDitNyw+5qqRX7o6kRd9fYCCki FejFCeq3uyDUgOFImTawV9UX+cmyMWU7Re1vADON6GEDEoTEbp0chqOkGzurxgRdsSsg 4kgH8LEjG5Y3yejwEjUeek8MNmqwRCsZurHDusFoC8nVXuO74dQo2UVjP583ZAlaoUm1 WQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2gwd8rr0gu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Mar 2018 01:57:51 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2O1voto007449 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Mar 2018 01:57:51 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2O1vo78023785; Sat, 24 Mar 2018 01:57:50 GMT Received: from localhost (/10.159.132.121) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Mar 2018 18:57:49 -0700 Subject: [PATCH 2/5] misc: enable UBSAN if the builder wants it From: "Darrick J. Wong" To: tytso@mit.edu, darrick.wong@oracle.com Cc: linux-ext4@vger.kernel.org Date: Fri, 23 Mar 2018 18:57:48 -0700 Message-ID: <152185666885.10571.2566613183664269112.stgit@magnolia> In-Reply-To: <152185665629.10571.4584627052866250686.stgit@magnolia> References: <152185665629.10571.4584627052866250686.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8841 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=9 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=969 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803240010 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Darrick J. Wong Enable the undefined behavior sanitizer (ubsan) if the builder requests it and it's available. Signed-off-by: Darrick J. Wong --- MCONFIG.in | 4 ++-- config/ltmain.sh | 1 + configure | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 28 ++++++++++++++++++++++++++++ debian/rules | 2 +- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 120000 config/ltmain.sh diff --git a/MCONFIG.in b/MCONFIG.in index f06933d..4234ff0 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@ -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 index 0000000..8cff389 --- /dev/null +++ b/config/ltmain.sh @@ -0,0 +1 @@ +/usr/share/libtool/build-aux/ltmain.sh \ No newline at end of file diff --git a/configure b/configure index 5947614..7632a4a 100755 --- 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] @@ -13865,6 +13870,53 @@ fi 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= diff --git a/configure.ac b/configure.ac index a605aad..981c6b0 100644 --- a/configure.ac +++ b/configure.ac @@ -1329,6 +1329,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="#" diff --git a/debian/rules b/debian/rules index 176ea78..600b751 100755 --- a/debian/rules +++ b/debian/rules @@ -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)