aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/gperftools/gperftools/ppc-musl.patch
blob: d06b6af229036fcf81a12e648ca381bb7c3c404e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 328805fd16930deefda400a77e9c2c5d17d04d29 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Sat, 13 Mar 2021 00:42:25 -0800
Subject: [PATCH] Compatibility fixes for musl.

---
 m4/pc_from_ucontext.m4             | 4 +++-
 src/getpc.h                        | 3 +++
 src/stacktrace_powerpc-linux-inl.h | 8 ++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/m4/pc_from_ucontext.m4 b/m4/pc_from_ucontext.m4
index 7f09dd7..5f4ee8c 100644
--- a/m4/pc_from_ucontext.m4
+++ b/m4/pc_from_ucontext.m4
@@ -34,6 +34,7 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
    pc_fields="$pc_fields uc_mcontext.gregs[[R15]]"     # Linux (arm old [untested])
    pc_fields="$pc_fields uc_mcontext.arm_pc"           # Linux (arm arch 5)
    pc_fields="$pc_fields uc_mcontext.gp_regs[[PT_NIP]]"  # Suse SLES 11 (ppc64)
+   pc_fields="$pc_fields uc_mcontext.gregs[[PT_NIP]]"
    pc_fields="$pc_fields uc_mcontext.mc_eip"           # FreeBSD (i386)
    pc_fields="$pc_fields uc_mcontext.mc_srr0"          # FreeBSD (powerpc, powerpc64)
    pc_fields="$pc_fields uc_mcontext.mc_rip"           # FreeBSD (x86_64 [untested])
@@ -77,7 +78,8 @@ AC_DEFUN([AC_PC_FROM_UCONTEXT],
                         pc_field_found=true)
        elif test "x$ac_cv_header_ucontext_h" = xyes; then
          AC_TRY_COMPILE([#define _GNU_SOURCE 1
-                         #include <ucontext.h>],
+                         #include <ucontext.h>
+                         #include <asm/ptrace.h>],
                         [ucontext_t u; return u.$pc_field == 0;],
                         AC_DEFINE_UNQUOTED(PC_FROM_UCONTEXT, $pc_field,
                                            How to access the PC from a struct ucontext)
diff --git a/src/getpc.h b/src/getpc.h
index 9605363..cd8ccfa 100644
--- a/src/getpc.h
+++ b/src/getpc.h
@@ -68,6 +68,9 @@
 typedef ucontext ucontext_t;
 #endif
 
+#if defined(__powerpc__) && !defined(PT_NIP)
+#define PT_NIP 32
+#endif
 
 // Take the example where function Foo() calls function Bar().  For
 // many architectures, Bar() is responsible for setting up and tearing
diff --git a/src/stacktrace_powerpc-linux-inl.h b/src/stacktrace_powerpc-linux-inl.h
index a301a46..efca426 100644
--- a/src/stacktrace_powerpc-linux-inl.h
+++ b/src/stacktrace_powerpc-linux-inl.h
@@ -186,7 +186,7 @@ static int GET_STACK_TRACE_OR_FRAMES {
           ucontext_t uc;
         // We don't care about the rest, since the IP value is at 'uc' field.
         } *sigframe = reinterpret_cast<signal_frame_64*>(current);
-        result[n] = (void*) sigframe->uc.uc_mcontext.gp_regs[PT_NIP];
+        result[n] = (void*) sigframe->uc.uc_mcontext.gp_regs[32];
       }
 #else
       if (sigtramp32_vdso && (sigtramp32_vdso == current->return_addr)) {
@@ -196,7 +196,7 @@ static int GET_STACK_TRACE_OR_FRAMES {
           mcontext_t mctx;
           // We don't care about the rest, since IP value is at 'mctx' field.
         } *sigframe = reinterpret_cast<signal_frame_32*>(current);
-        result[n] = (void*) sigframe->mctx.gregs[PT_NIP];
+        result[n] = (void*) sigframe->mctx.gregs[32];
       } else if (sigtramp32_rt_vdso && (sigtramp32_rt_vdso == current->return_addr)) {
         struct rt_signal_frame_32 {
           char dummy[64 + 16];
@@ -204,7 +204,11 @@ static int GET_STACK_TRACE_OR_FRAMES {
           ucontext_t uc;
           // We don't care about the rest, since IP value is at 'uc' field.A
         } *sigframe = reinterpret_cast<rt_signal_frame_32*>(current);
+#if defined(__GLIBC__)
         result[n] = (void*) sigframe->uc.uc_mcontext.uc_regs->gregs[PT_NIP];
+#else
+        result[n] = (void*) sigframe->uc.uc_mcontext.gregs[32];
+#endif
       }
 #endif