Skip to content

Commit 0a7ad9f

Browse files
committed
gh-152240: Fix test_c_stack_unwind on Linux LoongArch builds
1 parent a00464b commit 0a7ad9f

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix C stack unwinding tests on Linux LoongArch builds. The manual frame
2+
pointer unwinder now recognizes the LoongArch frame layout, and clang builds
3+
now request runtime unwind tables.

Modules/_testinternalcapi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ static const uintptr_t min_frame_pointer_addr = 0x1000;
9898
// https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html#STACK
9999
# define FRAME_POINTER_NEXT_OFFSET 0
100100
# define FRAME_POINTER_RETURN_OFFSET 2
101+
#elif defined(__loongarch__)
102+
// On LoongArch, the frame pointer is the caller's stack pointer.
103+
// The saved frame pointer is stored at fp[-2], and the return
104+
// address is stored at fp[-1].
105+
# define FRAME_POINTER_NEXT_OFFSET -2
106+
# define FRAME_POINTER_RETURN_OFFSET -1
101107
#else
102108
# define FRAME_POINTER_NEXT_OFFSET 0
103109
# define FRAME_POINTER_RETURN_OFFSET 1

configure

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,16 @@ AS_VAR_IF([ac_cv_gcc_compat], [yes], [
26312631
26322632
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
26332633
2634+
AS_IF([test "$MACHDEP" = linux && test "$ac_cv_cc_name" = clang], [
2635+
AS_CASE([$host_cpu], [loongarch*], [
2636+
dnl clang/LoongArch emits only .debug_frame by default, which is not
2637+
dnl available to runtime unwinders such as backtrace().
2638+
AX_CHECK_COMPILE_FLAG([-funwind-tables], [
2639+
CFLAGS_NODIST="$CFLAGS_NODIST -funwind-tables"
2640+
], [], [-Werror])
2641+
])
2642+
])
2643+
26342644
PY_CHECK_CC_WARNING([enable], [extra], [if we can add -Wextra])
26352645
AS_VAR_IF([ac_cv_enable_extra_warning], [yes],
26362646
[CFLAGS_NODIST="$CFLAGS_NODIST -Wextra"])

0 commit comments

Comments
 (0)