aports/testing/llvm-next/0015-PPC-sanitizer-fixes.patch
2025-04-18 04:00:49 +00:00

85 lines
2.6 KiB
Diff

From dce4bbc5d698f6dd4f80016824a9179a5d731f9f Mon Sep 17 00:00:00 2001
From: q66 <q66@chimera-linux.org>
Date: Sun, 14 Apr 2024 14:33:38 +0200
Subject: [PATCH 05/30] compiler-rt: ppc sanitizer fixes
---
compiler-rt/cmake/base-config-ix.cmake | 3 +-
compiler-rt/lib/xray/xray_powerpc64.inc | 37 +++++++++++++++++++++++-
2 files changed, 38 insertions(+), 2 deletions(-)
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -233,9 +233,10 @@ macro(test_targets)
test_target_arch(loongarch64 "" "")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le|ppc64le")
test_target_arch(powerpc64le "" "-m64")
+ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64")
+ test_target_arch(powerpc64 "" "-m64")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
test_target_arch(powerpc "" "-m32")
- test_target_arch(powerpc64 "" "-m64")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
test_target_arch(s390x "" "")
elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
--- a/compiler-rt/lib/xray/xray_powerpc64.inc
+++ b/compiler-rt/lib/xray/xray_powerpc64.inc
@@ -12,7 +12,7 @@
#include <cstdint>
#include <mutex>
-#ifdef __linux__
+#ifdef __GLIBC__
#include <sys/platform/ppc.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
@@ -27,6 +27,13 @@ uint64_t __ppc_get_timebase_freq (void)
sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0);
return tb_freq;
}
+#else
+#include <cctype>
+#include <cstring>
+#include <cstdlib>
+
+#define __ppc_get_timebase __builtin_ppc_get_timebase
+
#endif
#include "xray_defs.h"
@@ -41,7 +48,35 @@ ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
static std::mutex M;
std::lock_guard<std::mutex> Guard(M);
+#ifdef __GLIBC__
return __ppc_get_timebase_freq();
+#else
+ /* FIXME: a less dirty implementation? */
+ static uint64_t base;
+ if (!base) {
+ FILE *f = fopen("/proc/cpuinfo", "rb");
+ if (f) {
+ ssize_t nr;
+ /* virtually always big enough to hold the line */
+ char buf[512];
+ while (fgets(buf, sizeof(buf), f)) {
+ char *ret = strstr(buf, "timebase");
+ if (!ret) {
+ continue;
+ }
+ ret += sizeof("timebase") - 1;
+ ret = strchr(ret, ':');
+ if (!ret) {
+ continue;
+ }
+ base = strtoul(ret + 1, nullptr, 10);
+ break;
+ }
+ fclose(f);
+ }
+ }
+ return base;
+#endif
}
inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT {