Skip to content

Commit 8b0bc4e

Browse files
committed
gh-151546: Fix stack limits on musl
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.
1 parent 0777a58 commit 8b0bc4e

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
@@ -49,7 +49,9 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
4949
#endif
5050
}
5151

52-
#if defined(__s390x__)
52+
#if defined(_Py_LINKER_THREAD_STACK_SIZE)
53+
# define Py_C_STACK_SIZE _Py_LINKER_THREAD_STACK_SIZE
54+
#elif defined(__s390x__)
5355
# define Py_C_STACK_SIZE 320000
5456
#elif defined(_WIN32)
5557
// 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
@@ -2088,6 +2088,9 @@
20882088
/* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */
20892089
#undef _Py_HAVE_PR_SET_VMA_ANON_NAME
20902090

2091+
/* Thread stack size set by the linker (in bytes). */
2092+
#undef _Py_LINKER_THREAD_STACK_SIZE
2093+
20912094
/* Define to 1 if the machine stack grows down (default); 0 if it grows up. */
20922095
#undef _Py_STACK_GROWS_DOWN
20932096

0 commit comments

Comments
 (0)