projects/aports·blob master · refs

118 lines · 4.4 KiB

1fixes some sanitizers on ppc64le
2From 95fa3d049e35b141f0c2c3b3b0abb6c1b3702e46 Mon Sep 17 00:00:00 2001
3From: Daniel Kolesa <[email protected]>
4Date: Wed, 6 Apr 2022 00:54:03 +0200
5Subject: [PATCH 07/19] compiler-rt: ppc sanitizer fixes
6
7---
8 .../lib/sanitizer_common/sanitizer_linux.cpp | 4 ++
9 .../sanitizer_platform_limits_posix.cpp | 2 +-
10 .../sanitizer_stoptheworld_linux_libcdep.cpp | 2 +-
11 compiler-rt/lib/xray/xray_powerpc64.inc | 37 ++++++++++++++++++-
12 4 files changed, 42 insertions(+), 3 deletions(-)
13
14diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
15index 24c6acaa9..5d79dea48 100644
16--- a/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
17+++ b/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
18@@ -74,6 +74,10 @@
19 #include <sys/utsname.h>
20 #endif
21
22+#if SANITIZER_LINUX && defined(__powerpc__)
23+#include <asm/ptrace.h>
24+#endif
25+
26 #if SANITIZER_LINUX && !SANITIZER_ANDROID
27 #include <sys/personality.h>
28 #endif
29diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
30index fc01498aa..2fd663d88 100644
31--- a/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
32+++ b/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
33@@ -94,7 +94,7 @@
34 # include <utime.h>
35 # include <sys/ptrace.h>
36 # if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \
37- defined(__hexagon__) || defined(__loongarch__) ||SANITIZER_RISCV64
38+ defined(__hexagon__) || defined(__loongarch__) || defined(__powerpc__) || SANITIZER_RISCV64
39 # include <asm/ptrace.h>
40 # ifdef __arm__
41 typedef struct user_fpregs elf_fpregset_t;
42diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
43index 13b90ce9b..f8702753e 100644
44--- a/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
45+++ b/llvm-project-16.0.6.src/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
46@@ -31,7 +31,7 @@
47 #include <sys/types.h> // for pid_t
48 #include <sys/uio.h> // for iovec
49 #include <elf.h> // for NT_PRSTATUS
50-#if (defined(__aarch64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \
51+#if (defined(__aarch64__) || defined(__powerpc__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \
52 !SANITIZER_ANDROID
53 // GLIBC 2.20+ sys/user does not include asm/ptrace.h
54 # include <asm/ptrace.h>
55diff --git a/compiler-rt/lib/xray/xray_powerpc64.inc b/compiler-rt/lib/xray/xray_powerpc64.inc
56index 7e872b5b4..9616a09d8 100644
57--- a/llvm-project-16.0.6.src/compiler-rt/lib/xray/xray_powerpc64.inc
58+++ b/llvm-project-16.0.6.src/compiler-rt/lib/xray/xray_powerpc64.inc
59@@ -12,7 +12,7 @@
60
61 #include <cstdint>
62 #include <mutex>
63-#ifdef __linux__
64+#ifdef __GLIBC__
65 #include <sys/platform/ppc.h>
66 #elif defined(__FreeBSD__)
67 #include <sys/types.h>
68@@ -27,6 +27,14 @@ uint64_t __ppc_get_timebase_freq (void)
69 sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0);
70 return tb_freq;
71 }
72+#else
73+#include <cctype>
74+#include <cstdio>
75+#include <cstring>
76+#include <cstdlib>
77+
78+#define __ppc_get_timebase __builtin_ppc_get_timebase
79+
80 #endif
81
82 #include "xray_defs.h"
83@@ -41,7 +48,35 @@ ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
84 inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
85 static std::mutex M;
86 std::lock_guard<std::mutex> Guard(M);
87+#ifdef __GLIBC__
88 return __ppc_get_timebase_freq();
89+#else
90+ /* FIXME: a less dirty implementation? */
91+ static uint64_t base;
92+ if (!base) {
93+ FILE *f = fopen("/proc/cpuinfo", "rb");
94+ if (f) {
95+ ssize_t nr;
96+ /* virtually always big enough to hold the line */
97+ char buf[512];
98+ while (fgets(buf, sizeof(buf), f)) {
99+ char *ret = strstr(buf, "timebase");
100+ if (!ret) {
101+ continue;
102+ }
103+ ret += sizeof("timebase") - 1;
104+ ret = strchr(ret, ':');
105+ if (!ret) {
106+ continue;
107+ }
108+ base = strtoul(ret + 1, nullptr, 10);
109+ break;
110+ }
111+ fclose(f);
112+ }
113+ }
114+ return base;
115+#endif
116 }
117
118 inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT {