blob: d06b6af229036fcf81a12e648ca381bb7c3c404e [file] [log] [blame]
Andrew Geissler615f2f12022-07-15 14:00:58 -05001From 328805fd16930deefda400a77e9c2c5d17d04d29 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 13 Mar 2021 00:42:25 -0800
4Subject: [PATCH] Compatibility fixes for musl.
Andrew Geissler32b11992021-03-31 13:37:05 -05005
Andrew Geissler615f2f12022-07-15 14:00:58 -05006---
7 m4/pc_from_ucontext.m4 | 4 +++-
8 src/getpc.h | 3 +++
9 src/stacktrace_powerpc-linux-inl.h | 8 ++++++--
10 3 files changed, 12 insertions(+), 3 deletions(-)
11
12diff --git a/m4/pc_from_ucontext.m4 b/m4/pc_from_ucontext.m4
13index 7f09dd7..5f4ee8c 100644
Andrew Geissler32b11992021-03-31 13:37:05 -050014--- a/m4/pc_from_ucontext.m4
15+++ b/m4/pc_from_ucontext.m4
16@@ -34,6 +34,7 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
Andrew Geissler615f2f12022-07-15 14:00:58 -050017 pc_fields="$pc_fields uc_mcontext.gregs[[R15]]" # Linux (arm old [untested])
Andrew Geissler32b11992021-03-31 13:37:05 -050018 pc_fields="$pc_fields uc_mcontext.arm_pc" # Linux (arm arch 5)
Andrew Geissler32b11992021-03-31 13:37:05 -050019 pc_fields="$pc_fields uc_mcontext.gp_regs[[PT_NIP]]" # Suse SLES 11 (ppc64)
20+ pc_fields="$pc_fields uc_mcontext.gregs[[PT_NIP]]"
21 pc_fields="$pc_fields uc_mcontext.mc_eip" # FreeBSD (i386)
22 pc_fields="$pc_fields uc_mcontext.mc_srr0" # FreeBSD (powerpc, powerpc64)
23 pc_fields="$pc_fields uc_mcontext.mc_rip" # FreeBSD (x86_64 [untested])
24@@ -77,7 +78,8 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
25 pc_field_found=true)
26 elif test "x$ac_cv_header_ucontext_h" = xyes; then
27 AC_TRY_COMPILE([#define _GNU_SOURCE 1
28- #include <ucontext.h>],
29+ #include <ucontext.h>
30+ #include <asm/ptrace.h>],
31 [ucontext_t u; return u.$pc_field == 0;],
32 AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
33 How to access the PC from a struct ucontext)
Andrew Geissler615f2f12022-07-15 14:00:58 -050034diff --git a/src/getpc.h b/src/getpc.h
35index 9605363..cd8ccfa 100644
Andrew Geissler32b11992021-03-31 13:37:05 -050036--- a/src/getpc.h
37+++ b/src/getpc.h
38@@ -68,6 +68,9 @@
39 typedef ucontext ucontext_t;
40 #endif
41
42+#if defined(__powerpc__) && !defined(PT_NIP)
43+#define PT_NIP 32
44+#endif
45
46 // Take the example where function Foo() calls function Bar(). For
47 // many architectures, Bar() is responsible for setting up and tearing
Andrew Geissler615f2f12022-07-15 14:00:58 -050048diff --git a/src/stacktrace_powerpc-linux-inl.h b/src/stacktrace_powerpc-linux-inl.h
49index a301a46..efca426 100644
Andrew Geissler32b11992021-03-31 13:37:05 -050050--- a/src/stacktrace_powerpc-linux-inl.h
51+++ b/src/stacktrace_powerpc-linux-inl.h
52@@ -186,7 +186,7 @@ static int GET_STACK_TRACE_OR_FRAMES {
53 ucontext_t uc;
54 // We don't care about the rest, since the IP value is at 'uc' field.
55 } *sigframe = reinterpret_cast<signal_frame_64*>(current);
56- result[n] = (void*) sigframe->uc.uc_mcontext.gp_regs[PT_NIP];
57+ result[n] = (void*) sigframe->uc.uc_mcontext.gp_regs[32];
58 }
59 #else
60 if (sigtramp32_vdso && (sigtramp32_vdso == current->return_addr)) {
61@@ -196,7 +196,7 @@ static int GET_STACK_TRACE_OR_FRAMES {
62 mcontext_t mctx;
63 // We don't care about the rest, since IP value is at 'mctx' field.
64 } *sigframe = reinterpret_cast<signal_frame_32*>(current);
65- result[n] = (void*) sigframe->mctx.gregs[PT_NIP];
66+ result[n] = (void*) sigframe->mctx.gregs[32];
67 } else if (sigtramp32_rt_vdso && (sigtramp32_rt_vdso == current->return_addr)) {
68 struct rt_signal_frame_32 {
69 char dummy[64 + 16];
70@@ -204,7 +204,11 @@ static int GET_STACK_TRACE_OR_FRAMES {
71 ucontext_t uc;
72 // We don't care about the rest, since IP value is at 'uc' field.A
73 } *sigframe = reinterpret_cast<rt_signal_frame_32*>(current);
74+#if defined(__GLIBC__)
75 result[n] = (void*) sigframe->uc.uc_mcontext.uc_regs->gregs[PT_NIP];
76+#else
77+ result[n] = (void*) sigframe->uc.uc_mcontext.gregs[32];
78+#endif
79 }
80 #endif
81