]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-145801: Use gcc -fprofile-update=atomic for PGO builds (#145802) (#145893)
authorVictor Stinner <vstinner@python.org>
Thu, 12 Mar 2026 23:17:00 +0000 (00:17 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Mar 2026 23:17:00 +0000 (23:17 +0000)
gh-145801: Use gcc -fprofile-update=atomic for PGO builds (#145802)

When Python build is optimized with GCC using PGO, use
-fprofile-update=atomic option to use atomic operations when updating
profile information. This option reduces the risk of gcov Data Files
(.gcda) corruption which can cause random GCC crashes.

(cherry picked from commit 08a018ebe0d673e9c352f790d2e4604d69604188)

Misc/NEWS.d/next/Build/2026-03-11-11-58-42.gh-issue-145801.iCXa3v.rst [new file with mode: 0644]
configure
configure.ac

diff --git a/Misc/NEWS.d/next/Build/2026-03-11-11-58-42.gh-issue-145801.iCXa3v.rst b/Misc/NEWS.d/next/Build/2026-03-11-11-58-42.gh-issue-145801.iCXa3v.rst
new file mode 100644 (file)
index 0000000..c5f3982
--- /dev/null
@@ -0,0 +1,4 @@
+When Python build is optimized with GCC using PGO, use
+``-fprofile-update=atomic`` option to use atomic operations when updating
+profile information. This option reduces the risk of gcov Data Files (.gcda)
+corruption which can cause random GCC crashes. Patch by Victor Stinner.
index 49b6795703ac687ecd0a29e2699f6c2490066764..9ddb712b5344d4ef0ac43725673c8bf2acc6fad6 100755 (executable)
--- a/configure
+++ b/configure
@@ -8990,7 +8990,44 @@ case "$CC_BASENAME" in
         fi
         ;;
       *)
-        PGO_PROF_GEN_FLAG="-fprofile-generate"
+        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fprofile-update=atomic" >&5
+printf %s "checking whether C compiler accepts -fprofile-update=atomic... " >&6; }
+if test ${ax_cv_check_cflags___fprofile_update_atomic+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS  -fprofile-update=atomic"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  ax_cv_check_cflags___fprofile_update_atomic=yes
+else $as_nop
+  ax_cv_check_cflags___fprofile_update_atomic=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___fprofile_update_atomic" >&5
+printf "%s\n" "$ax_cv_check_cflags___fprofile_update_atomic" >&6; }
+if test "x$ax_cv_check_cflags___fprofile_update_atomic" = xyes
+then :
+  PGO_PROF_GEN_FLAG="-fprofile-generate -fprofile-update=atomic"
+else $as_nop
+  PGO_PROF_GEN_FLAG="-fprofile-generate"
+fi
+
         PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction"
         LLVM_PROF_MERGER="true"
         LLVM_PROF_FILE=""
index 94776540d1b373ad2f92f107764528b6ee072b1a..d9acfce793e533e9d0682653f3fcfcf72d5da403 100644 (file)
@@ -2137,7 +2137,10 @@ case "$CC_BASENAME" in
         fi
         ;;
       *)
-        PGO_PROF_GEN_FLAG="-fprofile-generate"
+        AX_CHECK_COMPILE_FLAG(
+            [-fprofile-update=atomic],
+            [PGO_PROF_GEN_FLAG="-fprofile-generate -fprofile-update=atomic"],
+            [PGO_PROF_GEN_FLAG="-fprofile-generate"])
         PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction"
         LLVM_PROF_MERGER="true"
         LLVM_PROF_FILE=""