diff --git a/Misc/NEWS.d/next/Build/2026-09-11-19-37-05.gh-issue-101525.DGIpL3.rst b/Misc/NEWS.d/next/Build/2026-09-11-19-37-05.gh-issue-101525.DGIpL3.rst new file mode 100644 index 00000000000000..f7394954ecda89 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-09-11-19-37-05.gh-issue-101525.DGIpL3.rst @@ -0,0 +1,2 @@ +When using :option:`--enable-bolt`, enable safe identical code folding on +BOLT versions new enough to support it (LLVM 20+). diff --git a/configure b/configure index 1115be256afb49..63444fcf8ea08a 100755 --- a/configure +++ b/configure @@ -9739,6 +9739,63 @@ printf "%s\n" "\"Found merge-fdata\"" >&6; } else as_fn_error $? "merge-fdata is required for a --enable-bolt build but could not be found." "$LINENO" 5 fi + + py_bolt_icf_flag="-icf=safe" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${LLVM_BOLT} supports safe identical code folding" >&5 +printf %s "checking whether ${LLVM_BOLT} supports safe identical code folding... " >&6; } +if test ${py_cv_bolt_icf_safe+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + CFLAGS="$CFLAGS_NODIST" + LDFLAGS="$LDFLAGS_NODIST" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + py_cv_bolt_icf_safe=no + ${LLVM_BOLT} -icf=safe -o conftest.bolt conftest$EXEEXT >&5 2>&1 && py_cv_bolt_icf_safe=yes +else case e in #( + e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} +as_fn_error $? "could not compile empty test program +See 'config.log' for more details" "$LINENO" 5; } ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + + + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $py_cv_bolt_icf_safe" >&5 +printf "%s\n" "$py_cv_bolt_icf_safe" >&6; } + if test "$py_cv_bolt_icf_safe" = no; then + py_bolt_icf_flag="" + fi fi @@ -9780,7 +9837,7 @@ printf "%s\n" "$BOLT_INSTRUMENT_FLAGS" >&6; } printf %s "checking BOLT_APPLY_FLAGS... " >&6; } if test -z "${BOLT_APPLY_FLAGS}" then - BOLT_APPLY_FLAGS=" ${BOLT_COMMON_FLAGS} -reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions -icf=0 -inline-all -split-eh -reorder-functions-use-hot-size -peepholes=none -jump-tables=aggressive -inline-ap -indirect-call-promotion=all -dyno-stats -use-gnu-stack -frame-opt=hot " + BOLT_APPLY_FLAGS=" ${BOLT_COMMON_FLAGS} -reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions ${py_bolt_icf_flag} -inline-all -split-eh -reorder-functions-use-hot-size -peepholes=none -jump-tables=aggressive -inline-ap -indirect-call-promotion=all -dyno-stats -use-gnu-stack -frame-opt=hot " fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $BOLT_APPLY_FLAGS" >&5 diff --git a/configure.ac b/configure.ac index 902a822e43a42f..fa3fa639d1b68d 100644 --- a/configure.ac +++ b/configure.ac @@ -2230,6 +2230,27 @@ if test "$Py_BOLT" = 'true' ; then else AC_MSG_ERROR([merge-fdata is required for a --enable-bolt build but could not be found.]) fi + + py_bolt_icf_flag="-icf=safe" + AC_CACHE_CHECK( + [whether ${LLVM_BOLT} supports safe identical code folding], + [py_cv_bolt_icf_safe], + [ + WITH_SAVE_ENV([ + CFLAGS="$CFLAGS_NODIST" + LDFLAGS="$LDFLAGS_NODIST" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([], [])], + [py_cv_bolt_icf_safe=no + ${LLVM_BOLT} -icf=safe -o conftest.bolt conftest$EXEEXT >&AS_MESSAGE_LOG_FD 2>&1 dnl + && py_cv_bolt_icf_safe=yes], + [AC_MSG_FAILURE([could not compile empty test program])]) + ]) + ] + ) + if test "$py_cv_bolt_icf_safe" = no; then + py_bolt_icf_flag="" + fi fi dnl Enable BOLT of libpython if built and used by the python3 binary. @@ -2289,7 +2310,7 @@ then -reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions - -icf=0 + ${py_bolt_icf_flag} -inline-all -split-eh -reorder-functions-use-hot-size