Skip to content

gh-148260: Use at least 1 MiB stack size on musl#149993

Open
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:musl_stack_size
Open

gh-148260: Use at least 1 MiB stack size on musl#149993
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:musl_stack_size

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented May 18, 2026

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.

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.
@vstinner
Copy link
Copy Markdown
Member Author

On "AMD64 Alpine Linux NoGIL 3.x" buildbot, currently test_threading.test_recursion_limit() does crash with a stack overflow: issue gh-148260.

With this change, Python is built with -Wl,-z,stack-size=1048576 linker flag and so uses a thread stack size of 1 MiB by default, instead of musl default which is 128 kiB.

With this change, test_threading.test_recursion_limit() does pass. I tested Python built in debug mode (gcc -O3) and release mode (gcc -Og), with and without the GIL (--disable-gil). The buildbot worker uses ./configure --with-pydebug --disable-gil.

@vstinner
Copy link
Copy Markdown
Member Author

@corona10 @erlend-aasland @picnixz: I'm looking for autotools experts to review my configure.ac change. I'm not comfortable with changing the build system.

Currently, the ./configure script doesn't run a built C program, it only uses AC_LINK_IFELSE or AC_COMPILE_IFELSE to check if a C program can be built or linked.

It seems like running a program is the only way to check if Python is linked to the musl library. My change is not specific to the musl library, but instead read the default thread stack size to decide if -Wl,-z,stack-size=1048576 linker flag should be used.

My configure.ac is inspired by Python 3.12 ./configure script which runs $CPP $CPPFLAGS conftest.c >conftest.out to read the output of the C preprocessor. But my change is different since it compiles a C program and then runs the C program. The code is skipped if Python is cross-compiled.

Comment thread configure.ac
EOF

ac_cv_thread_stack_size="default"
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to use $CC -pthread to make sure that the pthread API can be used in the C program. We check if -pthread is supported above, near line 3064, which sets CC="$CC -pthread" if the flag is supported. I should maybe omit -pthread and move my code after the -pthread check.

@zware
Copy link
Copy Markdown
Member

zware commented May 18, 2026

!buildbot Alpine

@bedevere-bot
Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @zware for commit fd078ac 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149993%2Fmerge

The command will test the builders whose names match following regular expression: Alpine

The builders matched are:

  • AMD64 Alpine Linux PR
  • AMD64 Alpine Linux NoGIL PR

@vstinner
Copy link
Copy Markdown
Member Author

Cool, the test suite passed on Alpine Linux buildbots:

buildbot/AMD64 Alpine Linux NoGIL PR — Build done.
buildbot/AMD64 Alpine Linux PR — Build done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants