]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44340: Add support for building with clang full/thin lto (GH-27231)
authorDong-hee Na <donghee.na@python.org>
Mon, 19 Jul 2021 10:52:56 +0000 (19:52 +0900)
committerGitHub <noreply@github.com>
Mon, 19 Jul 2021 10:52:56 +0000 (19:52 +0900)
Doc/using/configure.rst
Misc/NEWS.d/next/Build/2021-07-19-01-09-56.bpo-44340.JNeOf4.rst [new file with mode: 0644]
aclocal.m4
configure
configure.ac

index b1d1623a38cbeea1df30825bf2673e7d2aa94c19..a545d5a9372ac01c942262b30213537283e86b9c 100644 (file)
@@ -171,7 +171,7 @@ recommended for best performance.
 
    .. versionadded:: 3.8
 
-.. cmdoption:: --with-lto
+.. cmdoption:: --with-lto=[full|thin|no|yes]
 
    Enable Link Time Optimization (LTO) in any build (disabled by default).
 
@@ -180,6 +180,9 @@ recommended for best performance.
 
    .. versionadded:: 3.6
 
+   .. versionadded:: 3.11
+      To use ThinLTO feature, use ``--with-lto=thin`` on Clang.
+
 .. cmdoption:: --with-computed-gotos
 
    Enable computed gotos in evaluation loop (enabled by default on supported
diff --git a/Misc/NEWS.d/next/Build/2021-07-19-01-09-56.bpo-44340.JNeOf4.rst b/Misc/NEWS.d/next/Build/2021-07-19-01-09-56.bpo-44340.JNeOf4.rst
new file mode 100644 (file)
index 0000000..cf19eb6
--- /dev/null
@@ -0,0 +1,2 @@
+Add support for building with clang thin lto via --with-lto=thin/full. Patch
+by Dong-hee Na and Brett Holman.
index 1133004b86a216ce7edf4cc479f95d0215b8b30b..987bfdf215ccb4cfad31e8faa5d663f44d196c4d 100644 (file)
@@ -1,6 +1,6 @@
-# generated automatically by aclocal 1.16.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.16.3 -*- Autoconf -*-
 
-# Copyright (C) 1996-2018 Free Software Foundation, Inc.
+# Copyright (C) 1996-2020 Free Software Foundation, Inc.
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
index 1756d25d16fa47cc315e1910586c293ce918c3ce..050f183601114391b1d8260d6660b7f51c2b6628 100755 (executable)
--- a/configure
+++ b/configure
@@ -1545,7 +1545,8 @@ Optional Packages:
   --with-trace-refs       enable tracing references for debugging purpose
                           (default is no)
   --with-assertions       build with C assertions enabled (default is no)
-  --with-lto              enable Link-Time-Optimization in any build (default
+  --with-lto=[full|thin|no|yes]
+                          enable Link-Time-Optimization in any build (default
                           is no)
   --with-hash-algorithm=[fnv|siphash24]
                           select hash algorithm for use in Python/pyhash.c
@@ -3039,27 +3040,27 @@ VERSION=3.11
 
 SOVERSION=1.0
 
-# The later defininition of _XOPEN_SOURCE disables certain features
+# The later definition of _XOPEN_SOURCE disables certain features
 # on Linux, so we need _GNU_SOURCE to re-enable them (makedev, tm_zone).
 
 $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
 
 
-# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
+# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
 # certain features on NetBSD, so we need _NETBSD_SOURCE to re-enable
 # them.
 
 $as_echo "#define _NETBSD_SOURCE 1" >>confdefs.h
 
 
-# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
+# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
 # certain features on FreeBSD, so we need __BSD_VISIBLE to re-enable
 # them.
 
 $as_echo "#define __BSD_VISIBLE 1" >>confdefs.h
 
 
-# The later defininition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
+# The later definition of _XOPEN_SOURCE and _POSIX_C_SOURCE disables
 # certain features on Mac OS X, so we need _DARWIN_C_SOURCE to re-enable
 # them.
 
@@ -6585,16 +6586,36 @@ $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
+case "$withval" in
+    full)
+        Py_LTO='true'
+        Py_LTO_POLICY='full'
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        ;;
+    thin)
+        Py_LTO='true'
+        Py_LTO_POLICY='thin'
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        ;;
+    yes)
+        Py_LTO='true'
+        Py_LTO_POLICY='default'
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+        ;;
+    no)
+        Py_LTO='false'
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+        ;;
+    *)
+        Py_LTO='false'
+        as_fn_error $? "unknown lto option: '$withval'" "$LINENO" 5
+        ;;
+esac
+
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
@@ -6732,15 +6753,30 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
       case $ac_sys_system in
         Darwin*)
           # Any changes made here should be reflected in the GCC+Darwin case below
-          LTOFLAGS="-flto -Wl,-export_dynamic"
-          LTOCFLAGS="-flto"
+          if test $Py_LTO_POLICY = default
+          then
+            LTOFLAGS="-flto -Wl,-export_dynamic"
+            LTOCFLAGS="-flto"
+          else
+            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
+            LTOCFLAGS="-flto=${Py_LTO_POLICY}"
+          fi
           ;;
         *)
-          LTOFLAGS="-flto"
+          if test $Py_LTO_POLICY = default
+          then
+            LTOFLAGS="-flto"
+          else
+            LTOFLAGS="-flto=${Py_LTO_POLICY}"
+          fi
           ;;
       esac
       ;;
     *gcc*)
+      if test $Py_LTO_POLICY = thin
+      then
+        as_fn_error $? "thin lto is not supported under gcc compiler." "$LINENO" 5
+      fi
       case $ac_sys_system in
         Darwin*)
           LTOFLAGS="-flto -Wl,-export_dynamic"
index 11dd84f12c6692d24cf1c87f1831868cab4fd9f4..aaff79f720e3c40bc83d181f69d7853f2ba9cc65 100644 (file)
@@ -1360,16 +1360,34 @@ fi
 
 # Enable LTO flags
 AC_MSG_CHECKING(for --with-lto)
-AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [enable Link-Time-Optimization in any build (default is no)]),
+AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto=@<:@full|thin|no|yes@:>@], [enable Link-Time-Optimization in any build (default is no)]),
 [
-if test "$withval" != no
-then
-  Py_LTO='true'
-  AC_MSG_RESULT(yes);
-else
-  Py_LTO='false'
-  AC_MSG_RESULT(no);
-fi],
+case "$withval" in
+    full)
+        Py_LTO='true'
+        Py_LTO_POLICY='full'
+        AC_MSG_RESULT(yes)
+        ;;
+    thin)
+        Py_LTO='true'
+        Py_LTO_POLICY='thin'
+        AC_MSG_RESULT(yes)
+        ;;
+    yes)
+        Py_LTO='true'
+        Py_LTO_POLICY='default'
+        AC_MSG_RESULT(yes)
+        ;;
+    no)
+        Py_LTO='false'
+        AC_MSG_RESULT(no)
+        ;;
+    *)
+        Py_LTO='false'
+        AC_MSG_ERROR([unknown lto option: '$withval'])
+        ;;
+esac
+],
 [AC_MSG_RESULT(no)])
 if test "$Py_LTO" = 'true' ; then
   case $CC in
@@ -1405,15 +1423,30 @@ if test "$Py_LTO" = 'true' ; then
       case $ac_sys_system in
         Darwin*)
           # Any changes made here should be reflected in the GCC+Darwin case below
-          LTOFLAGS="-flto -Wl,-export_dynamic"
-          LTOCFLAGS="-flto"
+          if test $Py_LTO_POLICY = default
+          then
+            LTOFLAGS="-flto -Wl,-export_dynamic"
+            LTOCFLAGS="-flto"
+          else
+            LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
+            LTOCFLAGS="-flto=${Py_LTO_POLICY}"
+          fi
           ;;
         *)
-          LTOFLAGS="-flto"
+          if test $Py_LTO_POLICY = default
+          then
+            LTOFLAGS="-flto"
+          else
+            LTOFLAGS="-flto=${Py_LTO_POLICY}"
+          fi
           ;;
       esac
       ;;
     *gcc*)
+      if test $Py_LTO_POLICY = thin
+      then
+        AC_MSG_ERROR([thin lto is not supported under gcc compiler.])
+      fi
       case $ac_sys_system in
         Darwin*)
           LTOFLAGS="-flto -Wl,-export_dynamic"