[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for clang 22#148326
[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for clang 22#148326Fidget-Spinner wants to merge 4 commits intopython:3.14from
Conversation
…get-Spinner/cpython into block_inlining_of_gigantic_functions
If possible, I would prefer to fix the main branch first, and then backport to 3.14. |
OK, I need to test on |
| else | ||
| CFLAGS_CEVAL="" | ||
| fi | ||
| AC_SUBST([CFLAGS_CEVAL]) |
There was a problem hiding this comment.
Can you document this new variable in https://docs.python.org/dev/using/configure.html#envvar-CFLAGS_ALIASING ?
There was a problem hiding this comment.
Is there a way to make this a private variable? I don't feel good exposing it for now.
| // See gh-148284: | ||
| // Clang 22 seems to have interactions with inlining and the stackref buffer | ||
| // which cause 40kB of stack usage on x86-64 in buggy versions of _PyEval_EvalFrameDefault | ||
| // in computed goto interpreter. The normal usage seen is normally 1-2kB. |
There was a problem hiding this comment.
Reformat to 80 columns and minor cleanup:
| // See gh-148284: | |
| // Clang 22 seems to have interactions with inlining and the stackref buffer | |
| // which cause 40kB of stack usage on x86-64 in buggy versions of _PyEval_EvalFrameDefault | |
| // in computed goto interpreter. The normal usage seen is normally 1-2kB. | |
| // See gh-148284: Clang 22 seems to have interactions with inlining | |
| // and the stackref buffer which cause 40 kB of stack usage on x86-64 | |
| // in buggy versions of _PyEval_EvalFrameDefault() in computed goto | |
| // interpreter. The normal usage seen is normally 1-2 kB. |
| // This number should be tuned to follow the C stack consumption | ||
| // in _PyEval_EvalFrameDefault on computed goto interpreter. |
There was a problem hiding this comment.
I suggest adding "Suppress inlining of functions whose stack size exceeds 512 bytes." to explain the purpose of this option:
| // This number should be tuned to follow the C stack consumption | |
| // in _PyEval_EvalFrameDefault on computed goto interpreter. | |
| // gh-148284: Suppress inlining of functions whose stack size exceeds | |
| // 512 bytes. This number should be tuned to follow the C stack | |
| // consumption in _PyEval_EvalFrameDefault() on computed goto | |
| // interpreter. |
The Clang option is documented at: https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-finline-max-stacksize
|
In the past, when I tried to reduce the stack memory consumption on Python function calls, I used In |
It seems that on clang-22, the inliner is too aggressive on _PyEval_EvalFrameDefault when on computed goto interpreter. Together with some strange interaction with the stackref buffer, the function requires 40kB of stack space (!!!) versus the usual 1-2kB normally used.
This sets the inline limit to functions of max 512B stack space (1/4th of normal) allowed to be inlined in
ceval.c. I checked the dissasembly and the new function uses about 2kB of stack.This will need a forward-port to 3.15 too.
python -m test -v test_callsegfault with clang 22.1.3 build #148284