]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.15] gh-151040: Fix `test_c_stack_unwind` on RISC-V (GH-152370) (#152819)
authorStan Ulbrych <stan@python.org>
Wed, 1 Jul 2026 19:20:27 +0000 (21:20 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Jul 2026 19:20:27 +0000 (19:20 +0000)
(cherry picked from commit 1b0c05f14807a43d070127b3d8eac1af8de27f28)

Co-authored-by: Ivy Xu <fakeshadow1337@gmail.com>
Modules/_testinternalcapi.c

index 92a49d003ca73596be07ef446971b0ce911da658..344d663624b270c403121356f2c7e9c80f7ac1e1 100644 (file)
@@ -98,6 +98,11 @@ 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(__riscv)
+// RISC-V saves the return address at fp[-1], and the previous frame pointer at fp[-2].
+// See: https://riscv-non-isa.github.io/riscv-elf-psabi-doc/#_frame_pointer_convention
+#  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