Skip to content

Commit a5c5edd

Browse files
authored
[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 9a61d1c)
1 parent ff6e973 commit a5c5edd

5 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix the stack limit check if Python is linked to musl (ex: Alpine Linux).
2+
Use the stack size set by the linker to compute the stack limits. Patch by
3+
Victor Stinner.

Python/ceval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
6363
}
6464
}
6565

66-
#if defined(__s390x__)
66+
#if defined(_Py_LINKER_THREAD_STACK_SIZE)
67+
# define Py_C_STACK_SIZE _Py_LINKER_THREAD_STACK_SIZE
68+
#elif defined(__s390x__)
6769
# define Py_C_STACK_SIZE 320000
6870
#elif defined(_WIN32)
6971
// Don't define Py_C_STACK_SIZE, ask the O/S

configure

Lines changed: 4 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,9 @@ EOF
25072507

25082508
if test "$ac_cv_thread_stack_size" != "default" -a "$ac_cv_thread_stack_size" != "unknown"; then
25092509
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
2510+
# Stack size used by Python/ceval.c to set Py_C_STACK_SIZE
2511+
AC_DEFINE_UNQUOTED([_Py_LINKER_THREAD_STACK_SIZE], [$ac_cv_thread_stack_size],
2512+
[Thread stack size set by the linker (in bytes).])
25102513
fi
25112514
fi
25122515

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,9 @@
20672067
/* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */
20682068
#undef _Py_HAVE_PR_SET_VMA_ANON_NAME
20692069

2070+
/* Thread stack size set by the linker (in bytes). */
2071+
#undef _Py_LINKER_THREAD_STACK_SIZE
2072+
20702073
/* Define to 1 if the machine stack grows down (default); 0 if it grows up. */
20712074
#undef _Py_STACK_GROWS_DOWN
20722075

0 commit comments

Comments
 (0)