]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-151546: Fix stack limits on musl (#151548) (#151583)
authorVictor Stinner <vstinner@python.org>
Wed, 17 Jun 2026 09:13:40 +0000 (11:13 +0200)
committerGitHub <noreply@github.com>
Wed, 17 Jun 2026 09:13:40 +0000 (11:13 +0200)
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)

Misc/NEWS.d/next/Core_and_Builtins/2026-06-16-17-23-37.gh-issue-151546.LhiaZz.rst [new file with mode: 0644]
Python/ceval.c
configure
configure.ac
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 (file)
index 0000000..af1c23b
--- /dev/null
@@ -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.
index 5661200e74d0a55bce71bb4b5c2a2e29f8e313b8..3feb6ad0050d14c1899d82588287f570549e6b90 100644 (file)
@@ -63,7 +63,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
index 3a1c40e49d580b6c4b83e342b74e00b3fb6a5f2a..e60a71cff469bca459e9670caae54ba9b3d20978 100755 (executable)
--- a/configure
+++ b/configure
@@ -9918,6 +9918,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
 
index 62d761130ac07f736f1fe3020ac7ffa47c1fd324..c64850930324394accf58c008b827d5e91e5fc8c 100644 (file)
@@ -2507,6 +2507,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
 
index 7ef83fcd0b9e0bfc868b7dcda2d50b097655d34a..f26c67644d5e5d784050459de7124fd4d7960efe 100644 (file)
 /* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */
 #undef _Py_HAVE_PR_SET_VMA_ANON_NAME
 
+/* 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