blob: c5fdcd63d25b5bb83cc178bfbfa6d73dbc9abcfd [file] [log] [blame]
Andrew Geissler9aee5002022-03-30 16:27:02 +00001An all-in-one patch that fixes several issues:
2
31) UnscaledCycleClock not fully implemented for ppc*-musl (disabled on musl)
42) powerpc stacktrace implementation only works on glibc (disabled on musl)
53) powerpc stacktrace implementation has ppc64 assumptions (fixed)
64) examine_stack.cpp makes glibc assumptions on powerpc (fixed)
7
8Sourced from void linux
9
10Signed-off-by: Khem Raj <raj.khem@gmail.com>
Patrick Williams92b42cb2022-09-03 06:53:57 -050011Signed-off-by: Xu Huan <xuhuan.fnst@fujitsu.com>
12---
13 absl/base/internal/unscaledcycleclock.cc | 4 ++--
14 absl/base/internal/unscaledcycleclock.h | 3 ++-
15 absl/debugging/internal/examine_stack.cc | 8 +++++++-
16 absl/debugging/internal/stacktrace_config.h | 2 +-
17 4 files changed, 12 insertions(+), 5 deletions(-)
Andrew Geissler9aee5002022-03-30 16:27:02 +000018
Patrick Williams92b42cb2022-09-03 06:53:57 -050019diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc
20index b1c396c..d62bfd6 100644
Andrew Geissler9aee5002022-03-30 16:27:02 +000021--- a/absl/base/internal/unscaledcycleclock.cc
22+++ b/absl/base/internal/unscaledcycleclock.cc
23@@ -20,7 +20,7 @@
24 #include <intrin.h>
25 #endif
26
27-#if defined(__powerpc__) || defined(__ppc__)
28+#if (defined(__powerpc__) || defined(__ppc__)) && defined(__GLIBC__)
29 #ifdef __GLIBC__
30 #include <sys/platform/ppc.h>
31 #elif defined(__FreeBSD__)
Patrick Williams92b42cb2022-09-03 06:53:57 -050032@@ -58,7 +58,7 @@ double UnscaledCycleClock::Frequency() {
Andrew Geissler9aee5002022-03-30 16:27:02 +000033 return base_internal::NominalCPUFrequency();
34 }
35
36-#elif defined(__powerpc__) || defined(__ppc__)
37+#elif (defined(__powerpc__) || defined(__ppc__)) && defined(__GLIBC__)
38
39 int64_t UnscaledCycleClock::Now() {
40 #ifdef __GLIBC__
Patrick Williams92b42cb2022-09-03 06:53:57 -050041diff --git a/absl/base/internal/unscaledcycleclock.h b/absl/base/internal/unscaledcycleclock.h
42index 2cbeae3..683a5ef 100644
Andrew Geissler9aee5002022-03-30 16:27:02 +000043--- a/absl/base/internal/unscaledcycleclock.h
44+++ b/absl/base/internal/unscaledcycleclock.h
45@@ -46,7 +46,8 @@
46
47 // The following platforms have an implementation of a hardware counter.
48 #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
49- defined(__powerpc__) || defined(__ppc__) || defined(__riscv) || \
50+ ((defined(__powerpc__) || defined(__ppc__)) && defined(__GLIBC__)) || \
51+ defined(__riscv) || \
Patrick Williams92b42cb2022-09-03 06:53:57 -050052 defined(_M_IX86) || (defined(_M_X64) && !defined(_M_ARM64EC))
Andrew Geissler9aee5002022-03-30 16:27:02 +000053 #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1
54 #else
Patrick Williams92b42cb2022-09-03 06:53:57 -050055diff --git a/absl/debugging/internal/examine_stack.cc b/absl/debugging/internal/examine_stack.cc
56index 5bdd341..a784e0d 100644
Andrew Geissler9aee5002022-03-30 16:27:02 +000057--- a/absl/debugging/internal/examine_stack.cc
58+++ b/absl/debugging/internal/examine_stack.cc
Patrick Williams92b42cb2022-09-03 06:53:57 -050059@@ -33,6 +33,10 @@
Andrew Geissler9aee5002022-03-30 16:27:02 +000060 #include <csignal>
61 #include <cstdio>
62
63+#if defined(__powerpc__)
64+#include <asm/ptrace.h>
65+#endif
66+
67 #include "absl/base/attributes.h"
68 #include "absl/base/internal/raw_logging.h"
69 #include "absl/base/macros.h"
Patrick Williams92b42cb2022-09-03 06:53:57 -050070@@ -174,8 +178,10 @@ void* GetProgramCounter(void* const vuc) {
Andrew Geissler9aee5002022-03-30 16:27:02 +000071 return reinterpret_cast<void*>(context->uc_mcontext.pc);
72 #elif defined(__powerpc64__)
73 return reinterpret_cast<void*>(context->uc_mcontext.gp_regs[32]);
74-#elif defined(__powerpc__)
75+#elif defined(__powerpc__) && defined(__GLIBC__)
76 return reinterpret_cast<void*>(context->uc_mcontext.uc_regs->gregs[32]);
77+#elif defined(__powerpc__)
78+ return reinterpret_cast<void*>(((struct pt_regs *)context->uc_regs)->gregs[32]);
79 #elif defined(__riscv)
80 return reinterpret_cast<void*>(context->uc_mcontext.__gregs[REG_PC]);
81 #elif defined(__s390__) && !defined(__s390x__)
Patrick Williams92b42cb2022-09-03 06:53:57 -050082diff --git a/absl/debugging/internal/stacktrace_config.h b/absl/debugging/internal/stacktrace_config.h
83index 3929b1b..23d5e50 100644
Andrew Geissler9aee5002022-03-30 16:27:02 +000084--- a/absl/debugging/internal/stacktrace_config.h
85+++ b/absl/debugging/internal/stacktrace_config.h
Patrick Williams92b42cb2022-09-03 06:53:57 -050086@@ -60,7 +60,7 @@
Andrew Geissler9aee5002022-03-30 16:27:02 +000087 #elif defined(__i386__) || defined(__x86_64__)
88 #define ABSL_STACKTRACE_INL_HEADER \
89 "absl/debugging/internal/stacktrace_x86-inl.inc"
90-#elif defined(__ppc__) || defined(__PPC__)
91+#elif (defined(__ppc__) || defined(__PPC__)) && defined(__GLIBC__)
92 #define ABSL_STACKTRACE_INL_HEADER \
93 "absl/debugging/internal/stacktrace_powerpc-inl.inc"
94 #elif defined(__aarch64__)
Patrick Williams92b42cb2022-09-03 06:53:57 -050095--
962.25.1
97