https://github.com/python/cpython/commit/df6c157e51430e8e7458012417c534ad8c33119f
commit: df6c157e51430e8e7458012417c534ad8c33119f
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-05-20T13:21:59+02:00
summary:
gh-148260: Use at least 1 MiB stack size on musl (#149993)
On Linux when Python is linked to the musl C library, use a thread
stack size of at least 1 MiB instead of musl default which is 128
kiB.
files:
A Misc/NEWS.d/next/Build/2026-05-18-16-00-41.gh-issue-148260.UwFiIX.rst
M configure
M configure.ac
diff --git
a/Misc/NEWS.d/next/Build/2026-05-18-16-00-41.gh-issue-148260.UwFiIX.rst
b/Misc/NEWS.d/next/Build/2026-05-18-16-00-41.gh-issue-148260.UwFiIX.rst
new file mode 100644
index 00000000000000..8248c24cbd511a
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-05-18-16-00-41.gh-issue-148260.UwFiIX.rst
@@ -0,0 +1,3 @@
+On Linux when Python is linked to the musl C library, use a thread stack
+size of at least 1 MiB instead of musl default which is 128 kiB. Patch by
+Victor Stinner.
diff --git a/configure b/configure
index 63b41117957cab..a320a397fe10d6 100755
--- a/configure
+++ b/configure
@@ -9861,6 +9861,61 @@ fi
;;
esac
+if test "$ac_sys_system" = "Linux" -a "$cross_compiling" = no; then
+ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for thread stack
size" >&5
+printf %s "checking for thread stack size... " >&6; }
+if test ${ac_cv_thread_stack_size+y}
+then :
+ printf %s "(cached) " >&6
+else case e in #(
+ e)
+ cat > conftest.c <<EOF
+#include <pthread.h>
+
+int main()
+{
+ pthread_attr_t attrs;
+ size_t size;
+
+ int rc = pthread_attr_init(&attrs);
+ if (rc != 0) {
+ return 2;
+ }
+
+ rc = pthread_attr_getstacksize(&attrs, &size);
+ if (rc != 0) {
+ return 2;
+ }
+
+ if (size < 1024 * 1024) {
+ return 1;
+ }
+ return 0;
+}
+EOF
+
+ ac_cv_thread_stack_size=unknown
+ if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
+ ./conftest &>/dev/null
+ exitcode=$?
+ if test $exitcode -eq 1; then
+ ac_cv_thread_stack_size=1048576
+ elif test $exitcode -eq 0; then
+ ac_cv_thread_stack_size="default"
+ fi
+ fi
+ rm -f conftest.c conftest
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result:
$ac_cv_thread_stack_size" >&5
+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"
+ fi
+fi
+
case $enable_wasm_dynamic_linking in #(
yes) :
ac_cv_func_dlopen=yes ;; #(
diff --git a/configure.ac b/configure.ac
index 6df5d1bee31c67..d975d9685caa7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2462,6 +2462,54 @@ AS_CASE([$ac_sys_system],
]
)
+dnl On Linux, check the thread stack size. musl (ex: Alpine Linux) uses
+dnl a default thread stack size of 128 kB, whereas the glibc uses 8 MiB.
+dnl Python needs at least 1 MiB.
+if test "$ac_sys_system" = "Linux" -a "$cross_compiling" = no; then
+ AC_CACHE_CHECK([for thread stack size], [ac_cv_thread_stack_size], [
+ cat > conftest.c <<EOF
+#include <pthread.h>
+
+int main()
+{
+ pthread_attr_t attrs;
+ size_t size;
+
+ int rc = pthread_attr_init(&attrs);
+ if (rc != 0) {
+ return 2;
+ }
+
+ rc = pthread_attr_getstacksize(&attrs, &size);
+ if (rc != 0) {
+ return 2;
+ }
+
+ if (size < 1024 * 1024) {
+ return 1;
+ }
+ return 0;
+}
+EOF
+
+ ac_cv_thread_stack_size=unknown
+ if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
+ ./conftest &>/dev/null
+ exitcode=$?
+ if test $exitcode -eq 1; then
+ ac_cv_thread_stack_size=1048576
+ elif test $exitcode -eq 0; then
+ ac_cv_thread_stack_size="default"
+ fi
+ fi
+ rm -f conftest.c conftest
+ ])
+
+ 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"
+ fi
+fi
+
AS_CASE([$enable_wasm_dynamic_linking],
[yes], [ac_cv_func_dlopen=yes],
[no], [ac_cv_func_dlopen=no],
_______________________________________________
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]