gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds by yzewei · Pull Request #152241 · python/cpython · GitHub
Skip to content

gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds#152241

Open
yzewei wants to merge 1 commit into
python:mainfrom
Loongson-Cloud-Community:loongarch-clang-unwind
Open

gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds#152241
yzewei wants to merge 1 commit into
python:mainfrom
Loongson-Cloud-Community:loongarch-clang-unwind

Conversation

@yzewei

@yzewei yzewei commented Jun 26, 2026

Copy link
Copy Markdown

Fix test_c_stack_unwind on Linux LoongArch builds.

This change teaches _testinternalcapi's manual frame-pointer unwinder about
the LoongArch frame layout. On LoongArch, the frame pointer is the caller's
stack pointer; the previous frame pointer is at fp[-2], and the return
address is at fp[-1].

It also adds -funwind-tables for Linux LoongArch clang builds. clang/LoongArch
emits .debug_frame but not runtime .eh_frame unwind tables by default, so
glibc backtrace() cannot unwind through CPython frames unless unwind tables
are requested.

Validated on Linux LoongArch64:

GCC build:

../cpython/configure --with-pydebug CC=gcc
make -j8
PYTHON_JIT=0 ./python -m test -v test_c_stack_unwind

clang build with clang 20.1.8:

../cpython/configure --with-pydebug CC=clang
make -j8
PYTHON_JIT=0 ./python -m test -v test_c_stack_unwind

Also verified that -funwind-tables makes CPython C objects contain
.eh_frame, and the GNU backtrace test passes.

@python-cla-bot

python-cla-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

@yzewei

yzewei commented Jun 26, 2026

Copy link
Copy Markdown
Author

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change LGTM, even if I don't know LoongArch architecture.

The -funwind-tables compiler flag is only needed by GnuBacktraceUnwindTests of test_c_stack_unwind? If yes, is it really worth it to add .eh_frame unwind tables just for a test?

@diegorusso @pablogsal: What do you think about the -funwind-tables flag?

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.

2 participants