https://github.com/python/cpython/commit/c005251a2d594de8227dfe8d1f81ca1672fbe48a
commit: c005251a2d594de8227dfe8d1f81ca1672fbe48a
branch: 3.14
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-06-17T09:41:24Z
summary:
[3.14] gh-151546: Fix stack limits on musl (#151548) (#151583) (#151591)
[3.15] gh-151546: Fix stack limits on musl (#151548) (#151583)
gh-151546: Fix stack limits on musl (#151548)
If the thread stack size is set by linker flags, pass the stack size
to Python/ceval.c via the new _Py_LINKER_THREAD_STACK_SIZE variable
to set Py_C_STACK_SIZE macro.
(cherry picked from commit 9a61d1c0c8ebe21277c0a84abf6000049540464f)
(cherry picked from commit a5c5edddbc3ca7192c057f65fb3a8ff4ea360f96)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-17-23-37.gh-issue-151546.LhiaZz.rst
M Python/ceval.c
M configure
M configure.ac
M pyconfig.h.in
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-17-23-37.gh-issue-151546.LhiaZz.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-17-23-37.gh-issue-151546.LhiaZz.rst
new file mode 100644
index 00000000000000..af1c23bd50355f
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-17-23-37.gh-issue-151546.LhiaZz.rst
@@ -0,0 +1,3 @@
+Fix the stack limit check if Python is linked to musl (ex: Alpine Linux).
+Use the stack size set by the linker to compute the stack limits. Patch by
+Victor Stinner.
diff --git a/Python/ceval.c b/Python/ceval.c
index 377b4644eddd2a..b4fded923c10d3 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -366,7 +366,9 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
}
}
-#if defined(__s390x__)
+#if defined(_Py_LINKER_THREAD_STACK_SIZE)
+# define Py_C_STACK_SIZE _Py_LINKER_THREAD_STACK_SIZE
+#elif defined(__s390x__)
# define Py_C_STACK_SIZE 320000
#elif defined(_WIN32)
// Don't define Py_C_STACK_SIZE, ask the O/S
diff --git a/configure b/configure
index 055ecb3b97156e..a03bca2e1f92cb 100755
--- a/configure
+++ b/configure
@@ -9839,6 +9839,10 @@ printf "%s\n" "$ac_cv_thread_stack_size" >&6; }
if test "$ac_cv_thread_stack_size" != "default" -a
"$ac_cv_thread_stack_size" != "unknown"; then
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
+ # Stack size used by Python/ceval.c to set Py_C_STACK_SIZE
+
+printf "%s\n" "#define _Py_LINKER_THREAD_STACK_SIZE $ac_cv_thread_stack_size"
>>confdefs.h
+
fi
fi
diff --git a/configure.ac b/configure.ac
index caf7e88d7f2760..80a3854ce672ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2470,6 +2470,9 @@ EOF
if test "$ac_cv_thread_stack_size" != "default" -a
"$ac_cv_thread_stack_size" != "unknown"; then
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
+ # Stack size used by Python/ceval.c to set Py_C_STACK_SIZE
+ AC_DEFINE_UNQUOTED([_Py_LINKER_THREAD_STACK_SIZE],
[$ac_cv_thread_stack_size],
+ [Thread stack size set by the linker (in bytes).])
fi
fi
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 9502fcebf5d780..3ed77cb7f06454 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -2023,6 +2023,9 @@
/* HACL* library can compile SIMD256 implementations */
#undef _Py_HACL_CAN_COMPILE_VEC256
+/* Thread stack size set by the linker (in bytes). */
+#undef _Py_LINKER_THREAD_STACK_SIZE
+
/* Define to 1 if the machine stack grows down (default); 0 if it grows up. */
#undef _Py_STACK_GROWS_DOWN
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]