]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds (#152241)
authoryzewei <141103849+yzewei@users.noreply.github.com>
Mon, 29 Jun 2026 09:48:05 +0000 (17:48 +0800)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2026 09:48:05 +0000 (11:48 +0200)
Misc/NEWS.d/next/Build/2026-06-26-16-30-00.gh-issue-152240.loongarch.rst [new file with mode: 0644]
Modules/_testinternalcapi.c

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 (file)
index 0000000..ce9274a
--- /dev/null
@@ -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.
index e3de9006d5a427f31d1e947775e5559108e97e64..6506bd53b0377ad2f098ff5734e54203854c9ee3 100644 (file)
@@ -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