Repository navigation
Excessive stack usage for clang-cl debug builds on Windows #157789
Description
Activity
- addedbuildThe build process and cross-buildThe build process and cross-build
on Sep 19, 2026 I'm neutral either way on this, but any reason we shouldn't adjust the limits instead of the compiler options?
Historically, the debug stack size becoming excessive has been a sign that we're doing silly stuff with local variables. Since ceval has been hand-micro-optimised to the extreme, there's not much we can do about it, but sudden jumps are worth treating as a warning sign that something has changed.
- Thank you for the update.…On Mon, Sep 21, 2026 at 8:34 PM Steve Dower ***@***.***> wrote: *zooba* left a comment (python/cpython#157789) <#157789 (comment)> I'm neutral either way on this, but any reason we shouldn't adjust the limits instead of the compiler options? Historically, the debug stack size becoming excessive has been a sign that we're doing silly stuff with local variables. Since ceval has been hand-micro-optimised to the extreme, there's not much we can do about it, but sudden jumps are worth treating as a warning sign that *something* has changed. — Reply to this email directly, view it on GitHub <#157789?email_source=notifications&email_token=CI4YCMHWWUETGRDS4WR5F2T5QF7EZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWGYZTGNBTGQ42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-5766334349>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CI4YCMFNCEE4T67VK5WPCCD5QF7EZAVCNFSNUABEKJSXA33TNF2G64TZHM4DCNJZHA4TMMJ3JFZXG5LFHM2TKMBZGY4DKMZUG2QXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CI4YCMEN3MIMJEFMDBRDCWT5QF7EZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWGYZTGNBTGQ42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CI4YCMEDYCIHLAOIATLXIDL5QF7EZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKNZWGYZTGNBTGQ42M4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
Yupp, adjusting
_PyOS_STACK_MARGIN_BYTESby increasing 1
cpython/Include/internal/pycore_pythonrun.h
Lines 48 to 52 in a3e389d
#if (defined(Py_DEBUG) \ || defined(_Py_ADDRESS_SANITIZER) \ || defined(_Py_THREAD_SANITIZER)) \ || defined(_Py_UNDEFINED_BEHAVIOR_SANITIZER) # define _PyOS_LOG2_STACK_MARGIN 12
to 13 would be fine as well. @markshannon wdyt?Footnotes
-
only in case of clang-cl? and maybe only on 3.14? ↩
-
The reason I've chosen the
-Ogapproach is that AFAICT this is almost always used in CI and the buildbots in case of debug builds due toLines 2384 to 2386 in a321390
PYDEBUG_CFLAGS="-O0" AS_VAR_IF([ac_cv_cc_supports_og], [yes], [PYDEBUG_CFLAGS="-Og"]) where
ac_cv_cc_supports_og(supporting-Og) is true for gcc and clang.AFAICT this is almost always used in CI and the buildbots in case of debug builds ...
Ah, compatibility with the Makefile is a good reason.
Though it's probably also worth making sure that option flows through
sysconfigas well (if that variable does, it usually doesn't exist on Windows and so may not be there for clang-cl either, in which case you can ignore it).Building current main on WSL using
configure --with-pydebugyields
-OginCFLAGS$ ./python -c 'import sysconfig;print(sysconfig.get_config_vars()["CFLAGS"])' -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -g -Og -Walland a lot more vars that contain -Og;
LIBEXPAT_CFLAGS LIBHACL_CFLAGS MODULE__BLAKE2_CFLAGS MODULE__HMAC_CFLAGS MODULE__MD5_CFLAGS MODULE__SHA1_CFLAGS MODULE__SHA2_CFLAGS MODULE__SHA3_CFLAGS OPT PY_BUILTIN_MODULE_CFLAGS PY_CFLAGS PY_CORE_CFLAGS PY_STDMODULE_CFLAGSBut for Windows none of them exist:
pprint.pprint(sysconfig.get_config_vars()) {'ABIFLAGS': '_d', 'BINDIR': 'E:\\cpython_clang\\PCbuild\\amd64', 'BINLIBDEST': 'E:\\cpython_clang\\Lib', 'EXE': '.exe', 'EXT_SUFFIX': '_d.cp316-win_amd64.pyd', 'INCLUDEPY': 'E:\\cpython_clang\\Include', 'LDLIBRARY': 'python316_d.dll', 'LIBDEST': 'E:\\cpython_clang\\Lib', 'LIBDIR': 'E:\\cpython_clang\\libs', 'LIBRARY': 'python316_d.dll', 'Py_DEBUG': 1, 'Py_GIL_DISABLED': 0, 'SOABI': 'cp316-win_amd64', 'TZPATH': '', 'VERSION': '316', 'VPATH': '..\\..', 'abi_thread': '', 'abiflags': '', 'base': 'E:\\cpython_clang', 'exec_prefix': 'E:\\cpython_clang', 'implementation': 'Python', 'implementation_lower': 'python', 'installed_base': 'E:\\cpython_clang', 'installed_platbase': 'E:\\cpython_clang', 'platbase': 'E:\\cpython_clang', 'platlibdir': 'DLLs', 'prefix': 'E:\\cpython_clang', 'projectbase': 'E:\\cpython_clang', 'py_version': '3.16.0a0', 'py_version_nodot': '316', 'py_version_nodot_plat': '316', 'py_version_short': '3.16', 'srcdir': 'E:\\cpython_clang', 'userbase': 'C:\\Users\\suc\\AppData\\Roaming\\Python'}The closest might be
'Py_DEBUG': 1. Is there any other place insysconfigto look for compiler flags in case of Windows?The closest might be
'Py_DEBUG': 1.Yeah, not really close enough.
Is there any other place in
sysconfigto look for compiler flags in case of Windows?No, and generally speaking anything that might get built on Windows is going to be ABI compatible without specific compiler settings, so they aren't necessary (the debug/non-debug CRT issue isn't really ABI-related, but in any case all the choices are viable so we couldn't really provide them anyway).
I think you're justified in just setting the argument without updating anything else.
Reacted by Chris Eibl
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
test.test_call.TestRecursion.test_margin_is_sufficientfails on the AMD64 Windows Server 2025 Clang 3.14 buildbot.The table lists
safe_marginbefore it is multiplied, because 3.14 and main use different extra percentscpython/Lib/test/test_call.py
Lines 1105 to 1107 in 5b34363
and
_testinternalcapi.get_stack_margin(), which is actually just_PyOS_STACK_MARGIN_BYTES.Using -Og drastically improves stack usage.
Linked PRs
-Ogin case of clang-cl debug builds #157791-Ogin case of clang-cl debug builds (GH-157791) #158921-Ogin case of clang-cl debug builds (GH-157791) #158922