Skip to content

Commit 012b8a9

Browse files
Block inlining of gigantic functions
1 parent b87590f commit 012b8a9

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
@@ -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:

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
@@ -7244,6 +7244,35 @@ 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+
void foo(void *p, void *q) { memmove(p, q, 19); }
7250+
int main(void) {
7251+
// See gh-148284:
7252+
// Clang 22 seems to have interactions with inlining and the stackref buffer
7253+
// which cause 40kB of stack usage on x86-64 in buggy versions of _PyEval_EvalFrameDefault
7254+
// in computed goto interpreter. The normal usage seen is normally 1-2kB.
7255+
#if defined(__clang__) && (__clang_major__ == 22)
7256+
return 1;
7257+
#else
7258+
return 0;
7259+
#endif
7260+
}
7261+
]])],
7262+
[block_huge_inlining_in_ceval=no],
7263+
[block_huge_inlining_in_ceval=yes],
7264+
[block_huge_inlining_in_ceval=undefined])
7265+
AC_MSG_RESULT([$block_huge_inlining_in_ceval])
7266+
7267+
if test "$block_huge_inlining_in_ceval" = yes && test "$ac_cv_computed_gotos" = yes; then
7268+
// This number should be tuned to follow the C stack consumption
7269+
// in _PyEval_EvalFrameDefault on computed goto interpreter.
7270+
CFLAGS_CEVAL="-finline-max-stacksize=512"
7271+
else
7272+
CFLAGS_CEVAL=""
7273+
fi
7274+
AC_SUBST([CFLAGS_CEVAL])
7275+
72477276
if test "$ac_cv_gcc_asm_for_x87" = yes; then
72487277
# Some versions of gcc miscompile inline asm:
72497278
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491

0 commit comments

Comments
 (0)