Skip to content

Commit 1a85b01

Browse files
Block inlining of gigantic functions
1 parent 1a0edb1 commit 1a85b01

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

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:

configure

Lines changed: 48 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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7371,6 +7371,35 @@ 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+
void foo(void *p, void *q) { memmove(p, q, 19); }
7377+
int main(void) {
7378+
// See gh-148284:
7379+
// Clang 22 seems to have interactions with inlining and the stackref buffer
7380+
// which cause 40kB of stack usage on x86-64 in buggy versions of _PyEval_EvalFrameDefault
7381+
// in computed goto interpreter. The normal usage seen is normally 1-2kB.
7382+
#if defined(__clang__) && (__clang_major__ == 22)
7383+
return 1;
7384+
#else
7385+
return 0;
7386+
#endif
7387+
}
7388+
]])],
7389+
[block_huge_inlining_in_ceval=no],
7390+
[block_huge_inlining_in_ceval=yes],
7391+
[block_huge_inlining_in_ceval=undefined])
7392+
AC_MSG_RESULT([$block_huge_inlining_in_ceval])
7393+
7394+
if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" = yes; then
7395+
// This number should be tuned to follow the C stack consumption
7396+
// in _PyEval_EvalFrameDefault on computed goto interpreter.
7397+
CFLAGS_CEVAL="-finline-max-stacksize=512"
7398+
else
7399+
CFLAGS_CEVAL=""
7400+
fi
7401+
AC_SUBST([CFLAGS_CEVAL])
7402+
73747403
if test "$ac_cv_gcc_asm_for_x87" = yes; then
73757404
# Some versions of gcc miscompile inline asm:
73767405
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491

0 commit comments

Comments
 (0)