Skip to content

Commit c005251

Browse files
authored
[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 9a61d1c) (cherry picked from commit a5c5edd)
1 parent 5516672 commit c005251

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
@@ -366,7 +366,9 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
366366
}
367367
}
368368

369-
#if defined(__s390x__)
369+
#if defined(_Py_LINKER_THREAD_STACK_SIZE)
370+
# define Py_C_STACK_SIZE _Py_LINKER_THREAD_STACK_SIZE
371+
#elif defined(__s390x__)
370372
# define Py_C_STACK_SIZE 320000
371373
#elif defined(_WIN32)
372374
// 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
@@ -2470,6 +2470,9 @@ EOF
24702470

24712471
if test "$ac_cv_thread_stack_size" != "default" -a "$ac_cv_thread_stack_size" != "unknown"; then
24722472
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
2473+
# Stack size used by Python/ceval.c to set Py_C_STACK_SIZE
2474+
AC_DEFINE_UNQUOTED([_Py_LINKER_THREAD_STACK_SIZE], [$ac_cv_thread_stack_size],
2475+
[Thread stack size set by the linker (in bytes).])
24732476
fi
24742477
fi
24752478

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,9 @@
20232023
/* HACL* library can compile SIMD256 implementations */
20242024
#undef _Py_HACL_CAN_COMPILE_VEC256
20252025

2026+
/* Thread stack size set by the linker (in bytes). */
2027+
#undef _Py_LINKER_THREAD_STACK_SIZE
2028+
20262029
/* Define to 1 if the machine stack grows down (default); 0 if it grows up. */
20272030
#undef _Py_STACK_GROWS_DOWN
20282031

0 commit comments

Comments
 (0)