Skip to content

Commit b2cf251

Browse files
authored
bpo-44340: Add support for building with clang full/thin lto (GH-27231)
1 parent 635bfe8 commit b2cf251

File tree

5 files changed

+107
-33
lines changed

5 files changed

+107
-33
lines changed

Doc/using/configure.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ recommended for best performance.
171171

172172
.. versionadded:: 3.8
173173

174-
.. cmdoption:: --with-lto
174+
.. cmdoption:: --with-lto=[full|thin|no|yes]
175175

176176
Enable Link Time Optimization (LTO) in any build (disabled by default).
177177

@@ -180,6 +180,9 @@ recommended for best performance.
180180

181181
.. versionadded:: 3.6
182182

183+
.. versionadded:: 3.11
184+
To use ThinLTO feature, use ``--with-lto=thin`` on Clang.
185+
183186
.. cmdoption:: --with-computed-gotos
184187

185188
Enable computed gotos in evaluation loop (enabled by default on supported
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add support for building with clang thin lto via --with-lto=thin/full. Patch
2+
by Dong-hee Na and Brett Holman.

aclocal.m4

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
1+
# generated automatically by aclocal 1.16.3 -*- Autoconf -*-
22

3-
# Copyright (C) 1996-2018 Free Software Foundation, Inc.
3+
# Copyright (C) 1996-2020 Free Software Foundation, Inc.
44

55
# This file is free software; the Free Software Foundation
66
# gives unlimited permission to copy and/or distribute it,

configure

+54-18
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,8 @@ Optional Packages:
15451545
--with-trace-refs enable tracing references for debugging purpose
15461546
(default is no)
15471547
--with-assertions build with C assertions enabled (default is no)
1548-
--with-lto enable Link-Time-Optimization in any build (default
1548+
--with-lto=[full|thin|no|yes]
1549+
enable Link-Time-Optimization in any build (default
15491550
is no)
15501551
--with-hash-algorithm=[fnv|siphash24]
15511552
select hash algorithm for use in Python/pyhash.c
@@ -3039,27 +3040,27 @@ VERSION=3.11
30393040

30403041
SOVERSION=1.0
30413042

3042-
# The later defininition of _XOPEN_SOURCE disables certain features
3043+
# The later definition of _XOPEN_SOURCE disables certain features
30433044
# on Linux, so we need _GNU_SOURCE to re-enable them (makedev, tm_zone).
30443045

30453046
$as_echo "#define _GNU_SOURCE 1" >>confdefs.h
30463047

30473048

3048-
# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
3049+
# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
30493050
# certain features on NetBSD, so we need _NETBSD_SOURCE to re-enable
30503051
# them.
30513052

30523053
$as_echo "#define _NETBSD_SOURCE 1" >>confdefs.h
30533054

30543055

3055-
# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
3056+
# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
30563057
# certain features on FreeBSD, so we need __BSD_VISIBLE to re-enable
30573058
# them.
30583059

30593060
$as_echo "#define __BSD_VISIBLE 1" >>confdefs.h
30603061

30613062

3062-
# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
3063+
# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
30633064
# certain features on Mac OS X, so we need _DARWIN_C_SOURCE to re-enable
30643065
# them.
30653066

@@ -6585,16 +6586,36 @@ $as_echo_n "checking for --with-lto... " >&6; }
65856586
# Check whether --with-lto was given.
65866587
if test "${with_lto+set}" = set; then :
65876588
withval=$with_lto;
6588-
if test "$withval" != no
6589-
then
6590-
Py_LTO='true'
6591-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6592-
$as_echo "yes" >&6; };
6593-
else
6594-
Py_LTO='false'
6595-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6596-
$as_echo "no" >&6; };
6597-
fi
6589+
case "$withval" in
6590+
full)
6591+
Py_LTO='true'
6592+
Py_LTO_POLICY='full'
6593+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6594+
$as_echo "yes" >&6; }
6595+
;;
6596+
thin)
6597+
Py_LTO='true'
6598+
Py_LTO_POLICY='thin'
6599+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6600+
$as_echo "yes" >&6; }
6601+
;;
6602+
yes)
6603+
Py_LTO='true'
6604+
Py_LTO_POLICY='default'
6605+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6606+
$as_echo "yes" >&6; }
6607+
;;
6608+
no)
6609+
Py_LTO='false'
6610+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6611+
$as_echo "no" >&6; }
6612+
;;
6613+
*)
6614+
Py_LTO='false'
6615+
as_fn_error $? "unknown lto option: '$withval'" "$LINENO" 5
6616+
;;
6617+
esac
6618+
65986619
else
65996620
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
66006621
$as_echo "no" >&6; }
@@ -6732,15 +6753,30 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
67326753
case $ac_sys_system in
67336754
Darwin*)
67346755
# Any changes made here should be reflected in the GCC+Darwin case below
6735-
LTOFLAGS="-flto -Wl,-export_dynamic"
6736-
LTOCFLAGS="-flto"
6756+
if test $Py_LTO_POLICY = default
6757+
then
6758+
LTOFLAGS="-flto -Wl,-export_dynamic"
6759+
LTOCFLAGS="-flto"
6760+
else
6761+
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
6762+
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
6763+
fi
67376764
;;
67386765
*)
6739-
LTOFLAGS="-flto"
6766+
if test $Py_LTO_POLICY = default
6767+
then
6768+
LTOFLAGS="-flto"
6769+
else
6770+
LTOFLAGS="-flto=${Py_LTO_POLICY}"
6771+
fi
67406772
;;
67416773
esac
67426774
;;
67436775
*gcc*)
6776+
if test $Py_LTO_POLICY = thin
6777+
then
6778+
as_fn_error $? "thin lto is not supported under gcc compiler." "$LINENO" 5
6779+
fi
67446780
case $ac_sys_system in
67456781
Darwin*)
67466782
LTOFLAGS="-flto -Wl,-export_dynamic"

configure.ac

+45-12
Original file line numberDiff line numberDiff line change
@@ -1360,16 +1360,34 @@ fi
13601360

13611361
# Enable LTO flags
13621362
AC_MSG_CHECKING(for --with-lto)
1363-
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [enable Link-Time-Optimization in any build (default is no)]),
1363+
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto=@<:@full|thin|no|yes@:>@], [enable Link-Time-Optimization in any build (default is no)]),
13641364
[
1365-
if test "$withval" != no
1366-
then
1367-
Py_LTO='true'
1368-
AC_MSG_RESULT(yes);
1369-
else
1370-
Py_LTO='false'
1371-
AC_MSG_RESULT(no);
1372-
fi],
1365+
case "$withval" in
1366+
full)
1367+
Py_LTO='true'
1368+
Py_LTO_POLICY='full'
1369+
AC_MSG_RESULT(yes)
1370+
;;
1371+
thin)
1372+
Py_LTO='true'
1373+
Py_LTO_POLICY='thin'
1374+
AC_MSG_RESULT(yes)
1375+
;;
1376+
yes)
1377+
Py_LTO='true'
1378+
Py_LTO_POLICY='default'
1379+
AC_MSG_RESULT(yes)
1380+
;;
1381+
no)
1382+
Py_LTO='false'
1383+
AC_MSG_RESULT(no)
1384+
;;
1385+
*)
1386+
Py_LTO='false'
1387+
AC_MSG_ERROR([unknown lto option: '$withval'])
1388+
;;
1389+
esac
1390+
],
13731391
[AC_MSG_RESULT(no)])
13741392
if test "$Py_LTO" = 'true' ; then
13751393
case $CC in
@@ -1405,15 +1423,30 @@ if test "$Py_LTO" = 'true' ; then
14051423
case $ac_sys_system in
14061424
Darwin*)
14071425
# Any changes made here should be reflected in the GCC+Darwin case below
1408-
LTOFLAGS="-flto -Wl,-export_dynamic"
1409-
LTOCFLAGS="-flto"
1426+
if test $Py_LTO_POLICY = default
1427+
then
1428+
LTOFLAGS="-flto -Wl,-export_dynamic"
1429+
LTOCFLAGS="-flto"
1430+
else
1431+
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
1432+
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
1433+
fi
14101434
;;
14111435
*)
1412-
LTOFLAGS="-flto"
1436+
if test $Py_LTO_POLICY = default
1437+
then
1438+
LTOFLAGS="-flto"
1439+
else
1440+
LTOFLAGS="-flto=${Py_LTO_POLICY}"
1441+
fi
14131442
;;
14141443
esac
14151444
;;
14161445
*gcc*)
1446+
if test $Py_LTO_POLICY = thin
1447+
then
1448+
AC_MSG_ERROR([thin lto is not supported under gcc compiler.])
1449+
fi
14171450
case $ac_sys_system in
14181451
Darwin*)
14191452
LTOFLAGS="-flto -Wl,-export_dynamic"

0 commit comments

Comments
 (0)