From 2c02fe03f3146bd6e976fd28ac0973696a7f804e Mon Sep 17 00:00:00 2001 From: yzewei <141103849+yzewei@users.noreply.github.com> Date: Mon, 29 Jun 2026 17:48:05 +0800 Subject: [PATCH] gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds (GH-152241) (cherry picked from commit 8458582736b69b1ac05eef65230c4806f92891cd) Co-authored-by: yzewei <141103849+yzewei@users.noreply.github.com> --- .../Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst | 2 ++ Modules/_testinternalcapi.c | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst diff --git a/Misc/NEWS.d/next/Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst b/Misc/NEWS.d/next/Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst new file mode 100644 index 000000000000000..ce9274a5c108377 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst @@ -0,0 +1,2 @@ +Fix C stack unwinding tests on Linux LoongArch builds by teaching the manual +frame pointer unwinder to recognize the LoongArch frame layout. diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c index 92a49d003ca7359..a96131d1ef4fcc0 100644 --- a/Modules/_testinternalcapi.c +++ b/Modules/_testinternalcapi.c @@ -98,6 +98,12 @@ static const uintptr_t min_frame_pointer_addr = 0x1000; // https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#STACK # define FRAME_POINTER_NEXT_OFFSET 0 # define FRAME_POINTER_RETURN_OFFSET 2 +#elif defined(__loongarch__) +// On LoongArch, the frame pointer is the caller's stack pointer. +// The saved frame pointer is stored at fp[-2], and the return +// address is stored at fp[-1]. +# define FRAME_POINTER_NEXT_OFFSET -2 +# define FRAME_POINTER_RETURN_OFFSET -1 #else # define FRAME_POINTER_NEXT_OFFSET 0 # define FRAME_POINTER_RETURN_OFFSET 1