# Author: Alecsandru Patrascu diff -r 136adbcefa5f Makefile.pre.in --- a/Makefile.pre.in Sun Jan 03 18:00:31 2016 -0800 +++ b/Makefile.pre.in Mon Jan 04 17:01:35 2016 +0200 @@ -75,13 +75,13 @@ OPT= @OPT@ BASECFLAGS= @BASECFLAGS@ BASECPPFLAGS= @BASECPPFLAGS@ -CONFIGURE_CFLAGS= @CFLAGS@ +CONFIGURE_CFLAGS= @CFLAGS@ @LTOFLAGS@ # CFLAGS_NODIST is used for building the interpreter and stdlib C extensions. # Use it when a compiler flag should _not_ be part of the distutils CFLAGS # once Python is installed (Issue #21121). -CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@ -CONFIGURE_CPPFLAGS= @CPPFLAGS@ -CONFIGURE_LDFLAGS= @LDFLAGS@ +CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@ @LTOFLAGS@ +CONFIGURE_CPPFLAGS= @CPPFLAGS@ @LTOFLAGS@ +CONFIGURE_LDFLAGS= @LDFLAGS@ @LTOFLAGS@ # Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the # command line to append to these values without stomping the pre-set # values. diff -r 136adbcefa5f configure --- a/configure Sun Jan 03 18:00:31 2016 -0800 +++ b/configure Mon Jan 04 17:01:35 2016 +0200 @@ -673,6 +673,7 @@ LLVM_PROF_MERGER PGO_PROF_USE_FLAG PGO_PROF_GEN_FLAG +LTOFLAGS ABIFLAGS LN MKDIR_P @@ -807,6 +808,7 @@ enable_shared enable_profiling with_pydebug +with_lto with_hash_algorithm with_address_sanitizer with_libs @@ -1487,6 +1489,7 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-lto Enable Link Time Optimizations. Disabled by default. --with-hash-algorithm=[fnv|siphash24] select hash algorithm --with-address-sanitizer @@ -6560,6 +6563,48 @@ fi +# Enable LTO flags + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5 +$as_echo_n "checking for --with-lto... " >&6; } + +# Check whether --with-lto was given. +if test "${with_lto+set}" = set; then : + withval=$with_lto; +if test "$withval" != no +then + Py_LTO='true' + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +else + Py_LTO='false' + { $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 + +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. diff -r 136adbcefa5f configure.ac --- a/configure.ac Sun Jan 03 18:00:31 2016 -0800 +++ b/configure.ac Mon Jan 04 17:01:35 2016 +0200 @@ -1235,6 +1235,39 @@ fi], [AC_MSG_RESULT(no)]) +# Enable LTO flags +AC_SUBST(LTOFLAGS) +AC_MSG_CHECKING(for --with-lto) +AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimizations. Disabled by default.]), +[ +if test "$withval" != no +then + Py_LTO='true' + AC_MSG_RESULT(yes); +else + Py_LTO='false' + AC_MSG_RESULT(no); +fi], +[AC_MSG_RESULT(no)]) +if test "$Py_LTO" = 'true' ; then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac +fi + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG)