Skip to content

Commit e47b96c

Browse files
authored
gh-89536: Use ThinLTO policy if possible (gh-96766)
1 parent 16c33a9 commit e47b96c

File tree

5 files changed

+99
-6
lines changed

5 files changed

+99
-6
lines changed

Doc/using/configure.rst

+3
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

+4
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ Build Changes
453453
``va_start()`` is no longer called with a single parameter.
454454
(Contributed by Kumar Aditya in :gh:`93207`.)
455455

456+
* CPython now uses the ThinLTO option as the default link time optimization policy
457+
if the Clang compiler accepts the flag.
458+
(Contributed by Dong-hee Na in :gh:`89536`.)
459+
456460

457461
C API Changes
458462
=============
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

+79-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

+11-3
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)