From patchwork Thu Dec 7 18:48:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 845773 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; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="nfBEnKSp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yt4Jc5Xrgz9s82 for ; Fri, 8 Dec 2017 05:49:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751010AbdLGStE (ORCPT ); Thu, 7 Dec 2017 13:49:04 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:59938 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750929AbdLGStD (ORCPT ); Thu, 7 Dec 2017 13:49:03 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.21/8.16.0.21) with SMTP id vB7ImnCP084836; Thu, 7 Dec 2017 18:49:00 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=KgoP1Gq7KZV73Yoh8LpudEoKjb2rLF0/WgjUa2tA8Uc=; b=nfBEnKSpNOFb0NGwaZuEPACa8l/fWrOmAwypXptyqBK3DwGNmAYnv/cC+4wvCmSRA42I ZOQQMZrB04nivN410MPyK8VVU3t+VRB4o8FOEer2D6lWZlRm6tMK9KCDQGscSwsQAkFf vDC2ORAskM/3OFyp04n6hku6R8hIaR5chClt6Wg8MFs44xRzEQmFfv2FICa/jVvnplSy Y6UwRyL/zGlpSUYmwow29tnVHNWCvLd2k55gqmbl6uoZ3YUzwACv+YLNksJAvHEzpKZO vyIpQetx5aBSIAdtF+k25Nm6iOp+duTRQg3teOc/Xkux8UoVUoTZPCCwfE0xySnTEKZ0 ow== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2eqb8j8019-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Dec 2017 18:49:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vB7ImxDI029156 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Dec 2017 18:48:59 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vB7Imxv3026185; Thu, 7 Dec 2017 18:48:59 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 07 Dec 2017 10:48:58 -0800 Subject: [PATCH 4/4] misc: enable link time optimization, if requested From: "Darrick J. Wong" To: tytso@mit.edu, darrick.wong@oracle.com Cc: adilger@dilger.ca, linux-ext4@vger.kernel.org Date: Thu, 07 Dec 2017 10:48:48 -0800 Message-ID: <151267252874.1350.6941160583740966622.stgit@magnolia> In-Reply-To: <151267250365.1350.7799938074608034424.stgit@magnolia> References: <151267250365.1350.7799938074608034424.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8738 signatures=668644 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=9 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1712070275 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Darrick J. Wong Enable link time optimization (LTO) if the builder requests it. The extra link optimization results in smaller binaries. Signed-off-by: Darrick J. Wong --- MCONFIG.in | 16 +++---- configure | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 35 +++++++++++++++ debian/rules | 2 - 4 files changed, 183 insertions(+), 9 deletions(-) diff --git a/MCONFIG.in b/MCONFIG.in index aa7d0d1..a396935 100644 --- a/MCONFIG.in +++ b/MCONFIG.in @@ -82,19 +82,19 @@ UDEVRULESDIR = @udevrulesdir@ CC = @CC@ BUILD_CC = @BUILD_CC@ -CFLAGS = @CFLAGS@ -CFLAGS_SHLIB = @CFLAGS_SHLIB@ -CFLAGS_STLIB = @CFLAGS_STLIB@ +CFLAGS = @lto_cflags@ @CFLAGS@ +CFLAGS_SHLIB = @lto_cflags@ @CFLAGS_SHLIB@ +CFLAGS_STLIB = @lto_cflags@ @CFLAGS_STLIB@ CPPFLAGS = @INCLUDES@ ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) ALL_CFLAGS_SHLIB = $(CPPFLAGS) $(CFLAGS_SHLIB) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) ALL_CFLAGS_STLIB = $(CPPFLAGS) $(CFLAGS_STLIB) $(CFLAGS_WARN) @DEFS@ $(LOCAL_CFLAGS) -LDFLAGS = @LDFLAGS@ -LDFLAGS_SHLIB = @LDFLAGS_SHLIB@ +LDFLAGS = @lto_ldflags@ @LDFLAGS@ +LDFLAGS_SHLIB = @lto_ldflags@ @LDFLAGS_SHLIB@ ALL_LDFLAGS = $(LDFLAGS) @LDFLAG_DYNAMIC@ -LDFLAGS_STATIC = @LDFLAGS_STATIC@ -BUILD_CFLAGS = @BUILD_CFLAGS@ -BUILD_LDFLAGS = @BUILD_LDFLAGS@ +LDFLAGS_STATIC = @lto_ldflags@ @LDFLAGS_STATIC@ +BUILD_CFLAGS = @lto_cflags@ @BUILD_CFLAGS@ +BUILD_LDFLAGS = @lto_ldflags@ @BUILD_LDFLAGS@ RDYNAMIC = @RDYNAMIC@ LINK_BUILD_FLAGS = @LINK_BUILD_FLAGS@ LINK_INSTALL_FLAGS = @LINK_INSTALL_FLAGS@ diff --git a/configure b/configure index cca0c23..26a027e 100755 --- a/configure +++ b/configure @@ -649,6 +649,11 @@ E2SCRUB_CMT UNIX_CMT CYGWIN_CMT LINUX_CMT +lto_ldflags +lto_cflags +have_lto +gcc_ranlib +gcc_ar UNI_DIFF_OPTS SEM_INIT_LIB FUSE_CMT @@ -898,6 +903,7 @@ with_libiconv_prefix with_included_gettext with_libintl_prefix enable_fuse2fs +enable_lto with_multiarch ' ac_precious_vars='build_alias @@ -1569,6 +1575,7 @@ Optional Features: --disable-threads build without multithread safety --disable-rpath do not hardcode runtime library paths --disable-fuse2fs do not build fuse2fs + --enable-lto enable link time optimization Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -13703,6 +13710,138 @@ $as_echo "#define HAVE_EXT2_IOCTLS 1" >>confdefs.h ;; esac +# Check whether --enable-lto was given. +if test "${enable_lto+set}" = set; then : + enableval=$enable_lto; +else + enable_lto=probe +fi + +if test "$enable_lto" = "yes" || test "$enable_lto" = "probe"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if C compiler supports LTO" >&5 +$as_echo_n "checking if C compiler supports LTO... " >&6; } + OLD_CFLAGS="$CFLAGS" + OLD_LDFLAGS="$LDFLAGS" + LTO_FLAGS="-flto -ffat-lto-objects" + CFLAGS="$CFLAGS $LTO_FLAGS" + LDFLAGS="$LDFLAGS $LTO_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; } + lto_cflags=$LTO_FLAGS + lto_ldflags=$LTO_FLAGS + # Extract the first word of "gcc-ar", so it can be a program name with args. +set dummy gcc-ar; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_gcc_ar+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $gcc_ar in + [\\/]* | ?:[\\/]*) + ac_cv_path_gcc_ar="$gcc_ar" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_gcc_ar="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +gcc_ar=$ac_cv_path_gcc_ar +if test -n "$gcc_ar"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_ar" >&5 +$as_echo "$gcc_ar" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + # Extract the first word of "gcc-ranlib", so it can be a program name with args. +set dummy gcc-ranlib; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_gcc_ranlib+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $gcc_ranlib in + [\\/]* | ?:[\\/]*) + ac_cv_path_gcc_ranlib="$gcc_ranlib" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_gcc_ranlib="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +gcc_ranlib=$ac_cv_path_gcc_ranlib +if test -n "$gcc_ranlib"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_ranlib" >&5 +$as_echo "$gcc_ranlib" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +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 + if test -x "$gcc_ar" && test -x "$gcc_ranlib"; then + have_lto=yes + AR="${gcc_ar}" + RANLIB="${gcc_ranlib}" + fi + CFLAGS="${OLD_CFLAGS}" + LDFLAGS="${OLD_LDFLAGS}" + + + +fi +if test "$enable_lto" = "yes" && test "$have_lto" != "yes"; then + echo "MUGGA \"${enable_lto}\" OR \"${have_lto}\"" + as_fn_error $? "LTO not supported by compiler." "$LINENO" 5 +fi LINUX_CMT="#" CYGWIN_CMT="#" UNIX_CMT= diff --git a/configure.ac b/configure.ac index 28172bd..e44d040 100644 --- a/configure.ac +++ b/configure.ac @@ -1293,6 +1293,41 @@ linux*) ;; esac dnl +dnl Enable LTO for all packages +dnl +AC_ARG_ENABLE([lto], +[ --enable-lto enable link time optimization],, +enable_lto=probe) +if test "$enable_lto" = "yes" || test "$enable_lto" = "probe"; then + AC_MSG_CHECKING([if C compiler supports LTO]) + OLD_CFLAGS="$CFLAGS" + OLD_LDFLAGS="$LDFLAGS" + LTO_FLAGS="-flto -ffat-lto-objects" + CFLAGS="$CFLAGS $LTO_FLAGS" + LDFLAGS="$LDFLAGS $LTO_FLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM([])], + [AC_MSG_RESULT([yes])] + [lto_cflags=$LTO_FLAGS] + [lto_ldflags=$LTO_FLAGS] + [AC_PATH_PROG(gcc_ar, gcc-ar,,)] + [AC_PATH_PROG(gcc_ranlib, gcc-ranlib,,)], + [AC_MSG_RESULT([no])]) + if test -x "$gcc_ar" && test -x "$gcc_ranlib"; then + have_lto=yes + AR="${gcc_ar}" + RANLIB="${gcc_ranlib}" + fi + CFLAGS="${OLD_CFLAGS}" + LDFLAGS="${OLD_LDFLAGS}" + AC_SUBST(have_lto) + AC_SUBST(lto_cflags) + AC_SUBST(lto_ldflags) +fi +if test "$enable_lto" = "yes" && test "$have_lto" != "yes"; then + echo "MUGGA \"${enable_lto}\" OR \"${have_lto}\"" + AC_MSG_ERROR([LTO not supported by compiler.]) +fi +dnl dnl OS-specific uncomment control dnl LINUX_CMT="#" diff --git a/debian/rules b/debian/rules index 841715d..3a22c35 100755 --- a/debian/rules +++ b/debian/rules @@ -147,7 +147,7 @@ endif BACKTRACE_CONF_FLAGS ?= $(shell if ${debdir}/scripts/test-backtrace ; then echo --disable-backtrace ; fi) -COMMON_CONF_FLAGS = --disable-e2initrd-helper \ +COMMON_CONF_FLAGS = --enable-lto --disable-e2initrd-helper \ --infodir=/usr/share/info --enable-symlink-install \ --with-multiarch=$(DEB_HOST_MULTIARCH) \ $(BACKTRACE_CONF_FLAGS) $(UTIL_CONF_FLAGS)