Skip to content

Commit 241a541

Browse files
committed
gh-101525: Check whether to skip functions with computed gotos during BOLT runs
With LLVM >= 21.1.0 BOLT can handle computed gotos in PIC compiled code. Check for the LLVM version during configure to determine if we can safely skip those functions.
1 parent d6da34f commit 241a541

File tree

2 files changed

+53
-7
lines changed

2 files changed

+53
-7
lines changed

configure

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,23 @@ if test "$Py_BOLT" = 'true' ; then
21292129
AC_MSG_ERROR([llvm-bolt is required for a --enable-bolt build but could not be found.])
21302130
fi
21312131

2132+
# Check BOLT version to determine if we need to skip functions with computed gotos.
2133+
AC_MSG_CHECKING([llvm-bolt version])
2134+
llvm_bolt_version=$("${LLVM_BOLT}" --version 2>/dev/null | grep -oE '[[0-9]]+\.[[0-9]]+\.[[0-9]]+' | head -1)
2135+
AC_MSG_RESULT([${llvm_bolt_version}])
2136+
2137+
# Parse version
2138+
llvm_bolt_major=$(echo "${llvm_bolt_version}" | cut -d. -f1)
2139+
llvm_bolt_minor=$(echo "${llvm_bolt_version}" | cut -d. -f2)
2140+
2141+
bolt_need_skip_computed_goto="yes"
2142+
if test -n "${llvm_bolt_major}" && test "${llvm_bolt_major}" -ge 21; then
2143+
if test "${llvm_bolt_major}" -gt 21 || test "${llvm_bolt_minor}" -ge 1; then
2144+
bolt_need_skip_computed_goto="no"
2145+
AC_MSG_RESULT([LLVM ${llvm_bolt_version} supports computed gotos])
2146+
fi
2147+
fi
2148+
21322149
AC_SUBST([MERGE_FDATA])
21332150
AC_PATH_TOOL([MERGE_FDATA], [merge-fdata], [''], [${llvm_path}])
21342151
if test -n "${MERGE_FDATA}" -a -x "${MERGE_FDATA}"
@@ -2158,15 +2175,18 @@ then
21582175
[BOLT_COMMON_FLAGS],
21592176
[m4_normalize("
21602177
[-update-debug-sections]
2161-
2162-
dnl At least LLVM 19.x doesn't support computed gotos in PIC compiled code.
2163-
dnl Exclude functions containing computed gotos.
2164-
dnl TODO this may be fixed in LLVM 20.x via https://github.com/llvm/llvm-project/pull/120267.
2165-
dnl GCC's LTO creates .lto_priv.0 clones of these functions.
2166-
[-skip-funcs=_PyEval_EvalFrameDefault,sre_ucs1_match/1,sre_ucs2_match/1,sre_ucs4_match/1,sre_ucs1_match.lto_priv.0/1,sre_ucs2_match.lto_priv.0/1,sre_ucs4_match.lto_priv.0/1]
21672178
")]
21682179
)
2180+
2181+
dnl BOLT versions before LLVM 21.1.0 don't support computed gotos in PIC compiled code.
2182+
dnl Exclude functions containing computed gotos for older versions.
2183+
dnl Fixed in LLVM 21.1.0+ via https://github.com/llvm/llvm-project/pull/120267
2184+
dnl GCC's LTO creates .lto_priv.0 clones of these functions.
2185+
if test "${bolt_need_skip_computed_goto}" = "yes"; then
2186+
BOLT_COMMON_FLAGS="${BOLT_COMMON_FLAGS} -skip-funcs=_PyEval_EvalFrameDefault,sre_ucs1_match/1,sre_ucs2_match/1,sre_ucs4_match/1,sre_ucs1_match.lto_priv.0/1,sre_ucs2_match.lto_priv.0/1,sre_ucs4_match.lto_priv.0/1"
2187+
fi
21692188
fi
2189+
AC_MSG_RESULT([$BOLT_COMMON_FLAGS])
21702190

21712191
AC_ARG_VAR(
21722192
[BOLT_INSTRUMENT_FLAGS],

0 commit comments

Comments
 (0)