[Python-checkins] gh-96761: Fix build process of the clang compiler for _bootstrap_python (gh-96945)
corona10
webhook-mailer at python.org
Thu Sep 22 22:00:59 EDT 2022
https://github.com/python/cpython/commit/83d84e67cd203cc75687152e57572895f56245fa
commit: 83d84e67cd203cc75687152e57572895f56245fa
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2022-09-23T11:00:44+09:00
summary:
gh-96761: Fix build process of the clang compiler for _bootstrap_python (gh-96945)
Co-authored-by: Matthias Goergens <matthias.goergens at gmail.com>
files:
A Misc/NEWS.d/next/Build/2022-09-20-12-43-44.gh-issue-96761.IF29kR.rst
M configure
M configure.ac
diff --git a/Misc/NEWS.d/next/Build/2022-09-20-12-43-44.gh-issue-96761.IF29kR.rst b/Misc/NEWS.d/next/Build/2022-09-20-12-43-44.gh-issue-96761.IF29kR.rst
new file mode 100644
index 000000000000..18f75ac48910
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-09-20-12-43-44.gh-issue-96761.IF29kR.rst
@@ -0,0 +1,2 @@
+Fix the build process of clang compiler for :program:`_bootstrap_python` if
+LTO optimization is applied. Patch by Matthias Görgens and Dong-hee Na.
diff --git a/configure b/configure
index 08ec2161cba0..0e9f72faa7b1 100755
--- a/configure
+++ b/configure
@@ -7640,7 +7640,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PROFILE_TASK" >&5
$as_echo "$PROFILE_TASK" >&6; }
-# Make llvm-relatec checks work on systems where llvm tools are not installed with their
+# Make llvm-related checks work on systems where llvm tools are not installed with their
# normal names in the default $PATH (ie: Ubuntu). They exist under the
# non-suffixed name in their versioned llvm directory.
@@ -7705,7 +7705,42 @@ fi
if test "$Py_LTO" = 'true' ; then
case $CC in
*clang*)
- LDFLAGS_NOLTO="-fno-lto"
+ LDFLAGS_NOLTO="-fno-lto"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -flto=thin" >&5
+$as_echo_n "checking whether C compiler accepts -flto=thin... " >&6; }
+if ${ax_cv_check_cflags___flto_thin+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+
+ ax_check_save_flags=$CFLAGS
+ CFLAGS="$CFLAGS -flto=thin"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ ax_cv_check_cflags___flto_thin=yes
+else
+ ax_cv_check_cflags___flto_thin=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ CFLAGS=$ax_check_save_flags
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___flto_thin" >&5
+$as_echo "$ax_cv_check_cflags___flto_thin" >&6; }
+if test "x$ax_cv_check_cflags___flto_thin" = xyes; then :
+ LDFLAGS_NOLTO="-flto=thin"
+else
+ LDFLAGS_NOLTO="-flto"
+fi
+
if test -n "$ac_tool_prefix"; then
# Extract the first word of "${ac_tool_prefix}llvm-ar", so it can be a program name with args.
diff --git a/configure.ac b/configure.ac
index 7d2e83cac819..a4f3b0ab8466 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1774,7 +1774,7 @@ then
fi
AC_MSG_RESULT($PROFILE_TASK)
-# Make llvm-relatec checks work on systems where llvm tools are not installed with their
+# Make llvm-related checks work on systems where llvm tools are not installed with their
# normal names in the default $PATH (ie: Ubuntu). They exist under the
# non-suffixed name in their versioned llvm directory.
@@ -1828,8 +1828,10 @@ esac
if test "$Py_LTO" = 'true' ; then
case $CC in
*clang*)
- dnl flag to disable lto during linking
LDFLAGS_NOLTO="-fno-lto"
+ dnl Clang linker requires -flto in order to link objects with LTO information.
+ dnl Thin LTO is faster and works for object files with full LTO information, too.
+ AX_CHECK_COMPILE_FLAG([-flto=thin],[LDFLAGS_NOLTO="-flto=thin"],[LDFLAGS_NOLTO="-flto"])
AC_SUBST(LLVM_AR)
AC_PATH_TOOL(LLVM_AR, llvm-ar, '', ${llvm_path})
AC_SUBST(LLVM_AR_FOUND)
More information about the Python-checkins
mailing list