Skip to content

Commit 029f8e6

Browse files
committed
pythongh-89536: Use thinLTO policy if possible
1 parent 53a54b7 commit 029f8e6

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

Doc/using/configure.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ also be used to improve performance.
232232
.. versionadded:: 3.11
233233
To use ThinLTO feature, use ``--with-lto=thin`` on Clang.
234234

235+
.. versionchanged:: 3.12
236+
Use ThinLTO as the default optimization policy on Clang if the compiler accepts the flag.
237+
235238
.. cmdoption:: --enable-bolt
236239

237240
Enable usage of the `BOLT post-link binary optimizer

Doc/whatsnew/3.12.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ Build Changes
439439
``va_start()`` is no longer called with a single parameter.
440440
(Contributed by Kumar Aditya in :gh:`93207`.)
441441

442+
* CPython now uses the ThinLTO option as the default policy if the Clang compiler accepts the flag.
443+
(Contributed by Dong-hee Na in :gh:`89536`.)
442444

443445
C API Changes
444446
=============
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CPython now uses the ThinLTO option as the default policy if the Clang
2+
compiler accepts the flag. Patch by Dong-hee Na.

configure

Lines changed: 79 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,8 +1863,15 @@ if test "$Py_LTO" = 'true' ; then
18631863
# Any changes made here should be reflected in the GCC+Darwin case below
18641864
if test $Py_LTO_POLICY = default
18651865
then
1866-
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
1867-
LTOCFLAGS="-flto"
1866+
# Check that ThinLTO is accepted.
1867+
AX_CHECK_COMPILE_FLAG([-flto=thin],[
1868+
LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
1869+
LTOCFLAGS="-flto=thin"
1870+
],[
1871+
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
1872+
LTOCFLAGS="-flto"
1873+
]
1874+
)
18681875
else
18691876
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
18701877
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
@@ -1873,7 +1880,8 @@ if test "$Py_LTO" = 'true' ; then
18731880
*)
18741881
if test $Py_LTO_POLICY = default
18751882
then
1876-
LTOFLAGS="-flto"
1883+
# Check that ThinLTO is accepted
1884+
AX_CHECK_COMPILE_FLAG([-flto=thin],[LTOFLAGS="-flto=thin"],[LTOFLAGS="-flto"])
18771885
else
18781886
LTOFLAGS="-flto=${Py_LTO_POLICY}"
18791887
fi

0 commit comments

Comments
 (0)