Skip to content

Commit 5516672

Browse files
[3.14] gh-148260: Use at least 1 MiB stack size on musl (GH-149993) (#151586)
gh-148260: Use at least 1 MiB stack size on musl (GH-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. (cherry picked from commit df6c157) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 60132db commit 5516672

3 files changed

Lines changed: 106 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: 55 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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,54 @@ AS_CASE([$ac_sys_system],
24252425
]
24262426
)
24272427

2428+
dnl On Linux, check the thread stack size. musl (ex: Alpine Linux) uses
2429+
dnl a default thread stack size of 128 kB, whereas the glibc uses 8 MiB.
2430+
dnl Python needs at least 1 MiB.
2431+
if test "$ac_sys_system" = "Linux" -a "$cross_compiling" = no; then
2432+
AC_CACHE_CHECK([for thread stack size], [ac_cv_thread_stack_size], [
2433+
cat > conftest.c <<EOF
2434+
#include <pthread.h>
2435+
2436+
int main()
2437+
{
2438+
pthread_attr_t attrs;
2439+
size_t size;
2440+
2441+
int rc = pthread_attr_init(&attrs);
2442+
if (rc != 0) {
2443+
return 2;
2444+
}
2445+
2446+
rc = pthread_attr_getstacksize(&attrs, &size);
2447+
if (rc != 0) {
2448+
return 2;
2449+
}
2450+
2451+
if (size < 1024 * 1024) {
2452+
return 1;
2453+
}
2454+
return 0;
2455+
}
2456+
EOF
2457+
2458+
ac_cv_thread_stack_size=unknown
2459+
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
2460+
./conftest &>/dev/null
2461+
exitcode=$?
2462+
if test $exitcode -eq 1; then
2463+
ac_cv_thread_stack_size=1048576
2464+
elif test $exitcode -eq 0; then
2465+
ac_cv_thread_stack_size="default"
2466+
fi
2467+
fi
2468+
rm -f conftest.c conftest
2469+
])
2470+
2471+
if test "$ac_cv_thread_stack_size" != "default" -a "$ac_cv_thread_stack_size" != "unknown"; then
2472+
LDFLAGS="$LDFLAGS -Wl,-z,stack-size=$ac_cv_thread_stack_size"
2473+
fi
2474+
fi
2475+
24282476
AS_CASE([$enable_wasm_dynamic_linking],
24292477
[yes], [ac_cv_func_dlopen=yes],
24302478
[no], [ac_cv_func_dlopen=no],

0 commit comments

Comments
 (0)