Skip to content

Commit e007631

Browse files
gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 (GH-148334)
Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 70b86e7 commit e007631

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
@@ -1574,6 +1574,12 @@ Compiler flags
15741574

15751575
.. versionadded:: 3.7
15761576

1577+
.. envvar:: CFLAGS_CEVAL
1578+
1579+
Flags used to compile ``Python/ceval.c``.
1580+
1581+
.. versionadded:: 3.14.5
1582+
15771583
.. envvar:: CCSHARED
15781584

15791585
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
@@ -130,6 +130,8 @@ CONFIGURE_EXE_LDFLAGS=@EXE_LDFLAGS@
130130
PY_CORE_EXE_LDFLAGS:= $(if $(CONFIGURE_EXE_LDFLAGS), $(CONFIGURE_EXE_LDFLAGS) $(PY_LDFLAGS_NODIST), $(PY_CORE_LDFLAGS))
131131
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
132132
CFLAGS_ALIASING=@CFLAGS_ALIASING@
133+
# Compilation flags only for ceval.c.
134+
CFLAGS_CEVAL=@CFLAGS_CEVAL@
133135

134136

135137
# Machine-dependent subdirectories
@@ -3203,6 +3205,9 @@ regen-jit:
32033205
Python/dtoa.o: Python/dtoa.c
32043206
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<
32053207

3208+
Python/ceval.o: Python/ceval.c
3209+
$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_CEVAL) -o $@ $<
3210+
32063211
# Run reindent on the library
32073212
.PHONY: reindent
32083213
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
@@ -7371,6 +7371,34 @@ if test "$have_glibc_memmove_bug" = yes; then
73717371
for memmove and bcopy.])
73727372
fi
73737373

7374+
AC_MSG_CHECKING([if we need to manually block large inlining in ceval.c])
7375+
AC_RUN_IFELSE([AC_LANG_SOURCE([[
7376+
int main(void) {
7377+
// See gh-148284: Clang 22 seems to have interactions with inlining
7378+
// and the stackref buffer which cause 40 kB of stack usage on x86-64
7379+
// in buggy versions of _PyEval_EvalFrameDefault() in computed goto
7380+
// interpreter. The normal usage seen is normally 1-2 kB.
7381+
#if defined(__clang__) && (__clang_major__ == 22)
7382+
return 1;
7383+
#else
7384+
return 0;
7385+
#endif
7386+
}
7387+
]])],
7388+
[block_huge_inlining_in_ceval=no],
7389+
[block_huge_inlining_in_ceval=yes],
7390+
[block_huge_inlining_in_ceval=undefined])
7391+
AC_MSG_RESULT([$block_huge_inlining_in_ceval])
7392+
7393+
if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" = yes; then
7394+
# gh-148284: Suppress inlining of functions whose stack size exceeds
7395+
# 512 bytes. This number should be tuned to follow the C stack
7396+
# consumption in _PyEval_EvalFrameDefault() on computed goto
7397+
# interpreter.
7398+
CFLAGS_CEVAL="$CFLAGS_CEVAL -finline-max-stacksize=512"
7399+
fi
7400+
AC_SUBST([CFLAGS_CEVAL])
7401+
73747402
if test "$ac_cv_gcc_asm_for_x87" = yes; then
73757403
# Some versions of gcc miscompile inline asm:
73767404
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491

0 commit comments

Comments
 (0)