musllvm/patches/llvm/0005-compiler-rt-ppc-sanitizer-fixes.patch
cowmonk 6110995cfb Initial stub of a Makefile and patches for LLVM
Nothing much, but getting some patches from chimera linux that should
work.
2025-10-25 16:23:17 -07:00

136 lines
5 KiB
Diff

From 682ad99f38c927c37c2c54d12f4084473d67a007 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/29] compiler-rt: ppc sanitizer fixes
---
compiler-rt/cmake/base-config-ix.cmake | 3 +-
.../lib/sanitizer_common/sanitizer_linux.cpp | 4 ++
.../sanitizer_platform_limits_posix.cpp | 2 +-
.../sanitizer_stoptheworld_linux_libcdep.cpp | 2 +-
compiler-rt/lib/xray/xray_powerpc64.inc | 37 ++++++++++++++++++-
5 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index d92bc0e71..caeed40e3 100644
--- 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")
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 7aa48d29d..a782d5221 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -82,6 +82,10 @@
# include <sys/personality.h>
# endif
+# if SANITIZER_LINUX && defined(__powerpc__)
+# include <asm/ptrace.h>
+# endif
+
# if SANITIZER_LINUX && defined(__loongarch__)
# include <sys/sysmacros.h>
# endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index a5311d266..cd86b2383 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -96,7 +96,7 @@
# include <sys/ptrace.h>
# if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \
defined(__hexagon__) || defined(__loongarch__) || SANITIZER_RISCV64 || \
- defined(__sparc__) || defined(__powerpc64__)
+ defined(__sparc__) || defined(__powerpc__)
# include <asm/ptrace.h>
# ifdef __arm__
typedef struct user_fpregs elf_fpregset_t;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
index 945da99d4..81822dbb1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -31,7 +31,7 @@
#include <sys/types.h> // for pid_t
#include <sys/uio.h> // for iovec
#include <elf.h> // for NT_PRSTATUS
-#if (defined(__aarch64__) || defined(__powerpc64__) || \
+#if (defined(__aarch64__) || defined(__powerpc__) || \
SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \
!SANITIZER_ANDROID
// GLIBC 2.20+ sys/user does not include asm/ptrace.h
diff --git a/compiler-rt/lib/xray/xray_powerpc64.inc b/compiler-rt/lib/xray/xray_powerpc64.inc
index 7e872b5b4..9616a09d8 100644
--- 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 {
--
2.49.0