From: Sebastien GODARD Date: Sat, 30 Jan 2021 17:26:11 +0000 (+0100) Subject: Add Link Time Optimization (LTO) support X-Git-Tag: v12.5.3~9^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8292f9047cdfb503094db7ad5630514fa42d4b86;p=sysstat Add Link Time Optimization (LTO) support Add new configuration option (--enable-lto) to make it possible to compile sysstat with link time optimizations. Signed-off-by: Sebastien GODARD --- diff --git a/Makefile.in b/Makefile.in index d110e4a..30eb926 100644 --- a/Makefile.in +++ b/Makefile.in @@ -160,6 +160,19 @@ ifdef REQUIRE_NLS DFLAGS += $(REQUIRE_NLS) endif +ifndef LTO +LTO = @LTO@ +endif +ifndef GCC_AR +GCC_AR = @GCC_AR@ +endif +ifeq ($(LTO),y) +AR = $(GCC_AR) +CFLAGS += -flto +LD = gcc +LDFLAGS += $(CFLAGS) +endif + ifndef INSTALL_CRON INSTALL_CRON = @INSTALL_CRON@ endif diff --git a/build/lto b/build/lto new file mode 100644 index 0000000..8cba628 --- /dev/null +++ b/build/lto @@ -0,0 +1,7 @@ + +Link Time Optimization (LTO) gives the compiler the opportunity to optimize +as a single module all the different compilation units that make up a single +executable. The downside is an increased compile time. +Answer y to compile sysstat commands with link time optimizations. +The default answer is n (no). + diff --git a/configure b/configure index 9617e10..5a8194c 100755 --- a/configure +++ b/configure @@ -651,6 +651,8 @@ COMPRESSAFTER compressafter HISTORY history +LTO +GCC_AR NLS LFINTL SYSCONFIG_FILE @@ -757,6 +759,7 @@ enable_pcp enable_sensors enable_largefile enable_nls +enable_lto enable_file_attr enable_compress_manpg enable_clean_sa_dir @@ -1403,6 +1406,7 @@ Optional Features: --disable-sensors disable sensors support --disable-largefile omit support for large files --disable-nls disable National Language Support + --enable-lto enable Link Time Optimization --disable-file-attr do not set attributes on files being installed --disable-compress-manpg do not compress sysstat manual pages @@ -5107,6 +5111,7 @@ echo . # --disable-stripping do not strip object files # --enable-copy-only only copy files when installing sysstat # --enable-use-crond use standard cron daemon +# --enable-lto compile with Link Time Optimizations # # Some influential environment variables: # rcdir directory where startup scripts are installed @@ -5370,6 +5375,66 @@ if test $NLS = "y" && test $LACKING_GETTEXT = "y"; then fi +# Link Time Optimization +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Link Time Optimization support" >&5 +$as_echo_n "checking Link Time Optimization support... " >&6; } +# Check whether --enable-lto was given. +if test "${enable_lto+set}" = set; then : + enableval=$enable_lto; AUX_LTO=$enableval +else + AUX_LTO=no +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $AUX_LTO" >&5 +$as_echo "$AUX_LTO" >&6; } +LTO="n" +if test $AUX_LTO = "yes"; then + # 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_prog_GCC_AR+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$GCC_AR"; then + ac_cv_prog_GCC_AR="$GCC_AR" # Let the user override the test. +else +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_prog_GCC_AR="gcc-ar" + $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 + +fi +fi +GCC_AR=$ac_cv_prog_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 + + + if test x$GCC_AR != x"gcc-ar"; then + echo "WARNING: gcc-ar command not found! Disabling LTO support" + AUX_LTO="no" + else + LTO="y" + fi +fi + + # Data history to keep by sa2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking number of daily data files to keep" >&5 $as_echo_n "checking number of daily data files to keep... " >&6; } diff --git a/configure.in b/configure.in index efe7978..ffa303b 100644 --- a/configure.in +++ b/configure.in @@ -244,6 +244,7 @@ echo . # --disable-stripping do not strip object files # --enable-copy-only only copy files when installing sysstat # --enable-use-crond use standard cron daemon +# --enable-lto compile with Link Time Optimizations # # Some influential environment variables: # rcdir directory where startup scripts are installed @@ -451,6 +452,25 @@ if test $NLS = "y" && test $LACKING_GETTEXT = "y"; then fi AC_SUBST(NLS) +# Link Time Optimization +AC_MSG_CHECKING(Link Time Optimization support) +AC_ARG_ENABLE(lto, + AC_HELP_STRING([--enable-lto], + [enable Link Time Optimization]), + AUX_LTO=$enableval,AUX_LTO=no) +AC_MSG_RESULT($AUX_LTO) +LTO="n" +if test $AUX_LTO = "yes"; then + AC_CHECK_PROG(GCC_AR, gcc-ar, gcc-ar) + if test x$GCC_AR != x"gcc-ar"; then + echo "WARNING: gcc-ar command not found! Disabling LTO support" + AUX_LTO="no" + else + LTO="y" + fi +fi +AC_SUBST(LTO) + # Data history to keep by sa2 AC_MSG_CHECKING(number of daily data files to keep) AC_ARG_VAR([history],[number of daily data files to keep (default value is 7)]) diff --git a/do_test b/do_test index 8b20579..d09db3e 100755 --- a/do_test +++ b/do_test @@ -3,6 +3,10 @@ if [ "$1" = "conf" ] then make distclean ./configure sa_lib_dir=. sar_dir=. conf_dir=. conf_file=sysstat.sysconfig sa_dir=tests --enable-debuginfo +elif [ "$1" = "conflto" ] +then + make distclean + ./configure sa_lib_dir=. sar_dir=. conf_dir=. conf_file=sysstat.sysconfig sa_dir=tests --enable-debuginfo --enable-lto elif [ "$1" = "comp" ] then make TFLAGS="-DTEST" diff --git a/iconfig b/iconfig index 52b71c9..23afaf3 100755 --- a/iconfig +++ b/iconfig @@ -64,6 +64,15 @@ else echo "Parameter --disable-nls is NOT set" fi +# Link Time Optimization support +LTO=`${ASK} 'Compile with Link Time Optimizations (LTO)? (y/n)' "--enable-lto" "lto"` +if [ "${LTO}" = "y" ]; then + LTO="--enable-lto " +else + LTO="" + echo "Parameter --enable-lto is NOT set" +fi + # Sensors support SENSORS=`${ASK} 'Disable sensors support? (y/n)' "--disable-sensors" "sensors"` if [ "${SENSORS}" = "y" ]; then @@ -228,7 +237,7 @@ fi echo echo -n "./configure ${PREFIX}${SA_LIB_DIR}${SA_DIR}${SYSCONFIG_DIR}${SYSCONFIG_FILE} \ -${CLEAN_SA_DIR}${NLS}${HISTORY}${DELAY_RANGE}${COMPRESSAFTER}${MAN}${IGNORE_FILE_ATTR} \ +${CLEAN_SA_DIR}${NLS}${LTO}${HISTORY}${DELAY_RANGE}${COMPRESSAFTER}${MAN}${IGNORE_FILE_ATTR} \ ${CRON}${USE_CROND}${RCDIR}" if [ "${SADC_OPT}" != "" ]; then @@ -238,7 +247,7 @@ echo "${COMPRESSMANPG}${INSTALL_DOC}${DEBUGINFO}${SENSORS}${PCP}${STRIP}${COPY_O echo ./configure ${PREFIX}${SA_LIB_DIR}${SA_DIR}${SYSCONFIG_DIR}${SYSCONFIG_FILE} \ -${CLEAN_SA_DIR}${NLS} \ +${CLEAN_SA_DIR}${NLS}${LTO} \ ${HISTORY}${DELAY_RANGE}${COMPRESSAFTER}${MAN}${IGNORE_FILE_ATTR}${CRON}${USE_CROND}${RCDIR} \ sadc_options="${SADC_OPT}" ${COMPRESSMANPG}${INSTALL_DOC}${DEBUGINFO}${SENSORS} \ ${PCP}${STRIP}${COPY_ONLY}