Skip to content

Commit fd078ac

Browse files
committed
gh-148260: Use at least 1 MiB stack size on musl
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.
1 parent bd6bf91 commit fd078ac

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
On Linux when Python is linked to the musl C library, use a thread stack
2+
size of at least 1 MiB instead of musl default which is 128 kiB. Patch by
3+
Victor Stinner.

configure

Lines changed: 52 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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,51 @@ AS_CASE([$ac_sys_system],
24622462
]
24632463
)
24642464

2465+
dnl On Linux, check the thread stack size. musl (ex: Alpine Linux) uses
2466+
dnl a default thread stack size of 128 kB, whereas the glibc uses 8 MiB.
2467+
dnl Python uses at least 1 MiB.
2468+
if test "$ac_sys_system" = "Linux" -a "$cross_compiling" = no; then
2469+
AC_CACHE_CHECK([for thread stack size], [ac_cv_thread_stack_size], [
2470+
cat > conftest.c <<EOF
2471+
#include <pthread.h>
2472+
2473+
int main()
2474+
{
2475+
pthread_attr_t attrs;
2476+
size_t size;
2477+
2478+
int rc = pthread_attr_init(&attrs);
2479+
if (rc != 0) {
2480+
return 2;
2481+
}
2482+
2483+
rc = pthread_attr_getstacksize(&attrs, &size);
2484+
if (rc != 0) {
2485+
return 2;
2486+
}
2487+
2488+
if (size < 1024 * 1024) {
2489+
return 1;
2490+
}
2491+
return 0;
2492+
}
2493+
EOF
2494+
2495+
ac_cv_thread_stack_size="default"
2496+
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
2497+
./conftest &>/dev/null
2498+
if test $? -eq 1; then
2499+
ac_cv_thread_stack_size=1048576
2500+
fi
2501+
fi
2502+
rm -f conftest.c conftest
2503+
])
2504+
2505+
if test "$ac_cv_thread_stack_size" != "default"; then
2506+
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
2507+
fi
2508+
fi
2509+
24652510
AS_CASE([$enable_wasm_dynamic_linking],
24662511
[yes], [ac_cv_func_dlopen=yes],
24672512
[no], [ac_cv_func_dlopen=no],

0 commit comments

Comments
 (0)