From 34c06ccc4c6c21935b46302935f3df24b00daa2c Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Thu, 13 Feb 2025 22:06:00 +0800 Subject: gh-130048: Reintroduce full LTO as default on Clang (GH-130049) --- Doc/using/configure.rst | 3 + Doc/whatsnew/3.14.rst | 4 + .../2025-02-12-19-51-19.gh-issue-130048.kHNkzP.rst | 1 + configure | 94 +--------------------- configure.ac | 14 +--- 5 files changed, 14 insertions(+), 102 deletions(-) create mode 100644 Misc/NEWS.d/next/Build/2025-02-12-19-51-19.gh-issue-130048.kHNkzP.rst diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst index 72912ce..e7116d5 100644 --- a/Doc/using/configure.rst +++ b/Doc/using/configure.rst @@ -575,6 +575,9 @@ also be used to improve performance. .. versionchanged:: 3.12 Use ThinLTO as the default optimization policy on Clang if the compiler accepts the flag. + .. versionchanged:: next + Revert to using full LTO as the default optimization policy on Clang. + .. option:: --enable-bolt Enable usage of the `BOLT post-link binary optimizer diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index ece5afd..8e4b617 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -1279,6 +1279,10 @@ Build changes * GNU Autoconf 2.72 is now required to generate :file:`configure`. (Contributed by Erlend Aasland in :gh:`115765`.) +* CPython now uses Full LTO as the default link time optimization policy + on Clang. This reverts an earlier change in CPython 3.12. + (Contributed by Ken Jin in :gh:`130049`.) + .. _whatsnew314-pep761: PEP 761: Discontinuation of PGP signatures diff --git a/Misc/NEWS.d/next/Build/2025-02-12-19-51-19.gh-issue-130048.kHNkzP.rst b/Misc/NEWS.d/next/Build/2025-02-12-19-51-19.gh-issue-130048.kHNkzP.rst new file mode 100644 index 0000000..2344325 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2025-02-12-19-51-19.gh-issue-130048.kHNkzP.rst @@ -0,0 +1 @@ +CPython now uses Full LTO as the default link time optimization policy on Clang. This reverts an earlier change in CPython 3.12. diff --git a/configure b/configure index 453b012..bebc8bc 100755 --- a/configure +++ b/configure @@ -8766,55 +8766,8 @@ printf "%s\n" "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;} # Any changes made here should be reflected in the GCC+Darwin case below if test $Py_LTO_POLICY = default then - # Check that ThinLTO is accepted. - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -flto=thin" >&5 -printf %s "checking whether C compiler accepts -flto=thin... " >&6; } -if test ${ax_cv_check_cflags___flto_thin+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -flto=thin" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags___flto_thin=yes -else case e in #( - e) ax_cv_check_cflags___flto_thin=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___flto_thin" >&5 -printf "%s\n" "$ax_cv_check_cflags___flto_thin" >&6; } -if test "x$ax_cv_check_cflags___flto_thin" = xyes -then : - - LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" - LTOCFLAGS="-flto=thin" - -else case e in #( - e) - LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" - LTOCFLAGS="-flto" - - ;; -esac -fi - + LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" + LTOCFLAGS="-flto" else LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" LTOCFLAGS="-flto=${Py_LTO_POLICY}" @@ -8823,48 +8776,7 @@ fi *) if test $Py_LTO_POLICY = default then - # Check that ThinLTO is accepted - { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -flto=thin" >&5 -printf %s "checking whether C compiler accepts -flto=thin... " >&6; } -if test ${ax_cv_check_cflags___flto_thin+y} -then : - printf %s "(cached) " >&6 -else case e in #( - e) - ax_check_save_flags=$CFLAGS - CFLAGS="$CFLAGS -flto=thin" - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main (void) -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO" -then : - ax_cv_check_cflags___flto_thin=yes -else case e in #( - e) ax_cv_check_cflags___flto_thin=no ;; -esac -fi -rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - CFLAGS=$ax_check_save_flags ;; -esac -fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___flto_thin" >&5 -printf "%s\n" "$ax_cv_check_cflags___flto_thin" >&6; } -if test "x$ax_cv_check_cflags___flto_thin" = xyes -then : - LTOFLAGS="-flto=thin" -else case e in #( - e) LTOFLAGS="-flto" ;; -esac -fi - + LTOFLAGS="-flto" else LTOFLAGS="-flto=${Py_LTO_POLICY}" fi diff --git a/configure.ac b/configure.ac index 234ae90..e1e335a 100644 --- a/configure.ac +++ b/configure.ac @@ -1986,15 +1986,8 @@ if test "$Py_LTO" = 'true' ; then # Any changes made here should be reflected in the GCC+Darwin case below if test $Py_LTO_POLICY = default then - # Check that ThinLTO is accepted. - AX_CHECK_COMPILE_FLAG([-flto=thin],[ - LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" - LTOCFLAGS="-flto=thin" - ],[ - LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" - LTOCFLAGS="-flto" - ] - ) + LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" + LTOCFLAGS="-flto" else LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto" LTOCFLAGS="-flto=${Py_LTO_POLICY}" @@ -2003,8 +1996,7 @@ if test "$Py_LTO" = 'true' ; then *) if test $Py_LTO_POLICY = default then - # Check that ThinLTO is accepted - AX_CHECK_COMPILE_FLAG([-flto=thin],[LTOFLAGS="-flto=thin"],[LTOFLAGS="-flto"]) + LTOFLAGS="-flto" else LTOFLAGS="-flto=${Py_LTO_POLICY}" fi -- cgit v0.12