Skip to content

Commit 288cbac

Browse files
miss-islingtonFidget-Spinnervstinner
authored
[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 (GH-148334) (GH-148349)
gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 (GH-148334) (cherry picked from commit e007631) Co-authored-by: Ken Jin <kenjin@python.org> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 429c1d3 commit 288cbac

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

Doc/using/configure.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,12 @@ Compiler flags
15061506

15071507
.. versionadded:: 3.7
15081508

1509+
.. envvar:: CFLAGS_CEVAL
1510+
1511+
Flags used to compile ``Python/ceval.c``.
1512+
1513+
.. versionadded:: 3.14.5
1514+
15091515
.. envvar:: CCSHARED
15101516

15111517
Compiler flags used to build a shared library.

Makefile.pre.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
126126
PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
127127
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
128128
CFLAGS_ALIASING=@CFLAGS_ALIASING@
129+
# Compilation flags only for ceval.c.
130+
CFLAGS_CEVAL=@CFLAGS_CEVAL@
129131

130132

131133
# Machine-dependent subdirectories
@@ -3142,6 +3144,9 @@ regen-jit:
31423144
Python/dtoa.o: Python/dtoa.c
31433145
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
31443146

3147+
Python/ceval.o: Python/ceval.c
3148+
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_CEVAL) -o $@ $<
3149+
31453150
# Run reindent on the library
31463151
.PHONY: reindent
31473152
reindent:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix high stack consumption in Python's interpreter loop on Clang 22 by setting function limits for inlining when building with computed gotos.

configure

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7244,6 +7244,34 @@ if test "$have_glibc_memmove_bug" = yes; then
72447244
for memmove and bcopy.])
72457245
fi
72467246

7247+
AC_MSG_CHECKING([if we need to manually block large inlining in ceval.c])
7248+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
7249+
int main(void) {
7250+
// See gh-148284: Clang 22 seems to have interactions with inlining
7251+
// and the stackref buffer which cause 40 kB of stack usage on x86-64
7252+
// in buggy versions of _PyEval_EvalFrameDefault() in computed goto
7253+
// interpreter. The normal usage seen is normally 1-2 kB.
7254+
#if defined(__clang__) && (__clang_major__ == 22)
7255+
return 1;
7256+
#else
7257+
return 0;
7258+
#endif
7259+
}
7260+
]])],
7261+
[block_huge_inlining_in_ceval=no],
7262+
[block_huge_inlining_in_ceval=yes],
7263+
[block_huge_inlining_in_ceval=undefined])
7264+
AC_MSG_RESULT([$block_huge_inlining_in_ceval])
7265+
7266+
if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" = yes; then
7267+
# gh-148284: Suppress inlining of functions whose stack size exceeds
7268+
# 512 bytes. This number should be tuned to follow the C stack
7269+
# consumption in _PyEval_EvalFrameDefault() on computed goto
7270+
# interpreter.
7271+
CFLAGS_CEVAL="$CFLAGS_CEVAL -finline-max-stacksize=512"
7272+
fi
7273+
AC_SUBST([CFLAGS_CEVAL])
7274+
72477275
if test "$ac_cv_gcc_asm_for_x87" = yes; then
72487276
# Some versions of gcc miscompile inline asm:
72497277
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491

0 commit comments

Comments
 (0)