]> granicus.if.org Git - sysstat/commitdiff
Add Link Time Optimization (LTO) support
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 30 Jan 2021 17:26:11 +0000 (18:26 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 30 Jan 2021 17:26:11 +0000 (18:26 +0100)
Add new configuration option (--enable-lto) to make it possible to
compile sysstat with link time optimizations.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
Makefile.in
build/lto [new file with mode: 0644]
configure
configure.in
do_test
iconfig

index d110e4a85ecb93462c630e4059ee2913a93d997e..30eb9264a7d9778f68068d2ebe2ffe3a1af77a48 100644 (file)
@@ -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 (file)
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).
+
index 9617e10b774187ebbb223d7c57419ee4328a5484..5a8194cbd72ee383d490e08bde3c2027ae4fd21b 100755 (executable)
--- 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; }
index efe7978010636e001dd5f1a5783f0285bcd3d24e..ffa303b66b715378b2981877258d7f979ecb99ca 100644 (file)
@@ -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 8b20579299779a15bea029456d13f600ff709174..d09db3e60e8799fbe49333b69a338d8d8dcd1b19 100755 (executable)
--- 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 52b71c949f1aa891ea0038f6244a6da3c3e0432b..23afaf363c97cb65b8d0689d8031f4f0ccb73030 100755 (executable)
--- 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}