musllvm

A pure LLVM/Clang cross compiler toolchain targeting musl C
git clone git://git.daat.foo/musllvm.git
Log | Files | Refs | README | LICENSE

0005-compiler-rt-ppc-sanitizer-fixes.patch (5139B)


      1 From 682ad99f38c927c37c2c54d12f4084473d67a007 Mon Sep 17 00:00:00 2001
      2 From: q66 <q66@chimera-linux.org>
      3 Date: Sun, 14 Apr 2024 14:33:38 +0200
      4 Subject: [PATCH 05/29] compiler-rt: ppc sanitizer fixes
      5 
      6 ---
      7  compiler-rt/cmake/base-config-ix.cmake        |  3 +-
      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  5 files changed, 44 insertions(+), 4 deletions(-)
     13 
     14 diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
     15 index d92bc0e71..caeed40e3 100644
     16 --- a/compiler-rt/cmake/base-config-ix.cmake
     17 +++ b/compiler-rt/cmake/base-config-ix.cmake
     18 @@ -233,9 +233,10 @@ macro(test_targets)
     19        test_target_arch(loongarch64 "" "")
     20      elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64le|ppc64le")
     21        test_target_arch(powerpc64le "" "-m64")
     22 +    elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc64")
     23 +      test_target_arch(powerpc64 "" "-m64")
     24      elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
     25        test_target_arch(powerpc "" "-m32")
     26 -      test_target_arch(powerpc64 "" "-m64")
     27      elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
     28        test_target_arch(s390x "" "")
     29      elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
     30 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
     31 index 7aa48d29d..a782d5221 100644
     32 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
     33 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
     34 @@ -82,6 +82,10 @@
     35  #    include <sys/personality.h>
     36  #  endif
     37  
     38 +#  if SANITIZER_LINUX && defined(__powerpc__)
     39 +#    include <asm/ptrace.h>
     40 +#  endif
     41 +
     42  #  if SANITIZER_LINUX && defined(__loongarch__)
     43  #    include <sys/sysmacros.h>
     44  #  endif
     45 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
     46 index a5311d266..cd86b2383 100644
     47 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
     48 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
     49 @@ -96,7 +96,7 @@
     50  # include <sys/ptrace.h>
     51  #    if defined(__mips64) || defined(__aarch64__) || defined(__arm__) ||       \
     52          defined(__hexagon__) || defined(__loongarch__) || SANITIZER_RISCV64 || \
     53 -        defined(__sparc__) || defined(__powerpc64__)
     54 +        defined(__sparc__) || defined(__powerpc__)
     55  #      include <asm/ptrace.h>
     56  #      ifdef __arm__
     57  typedef struct user_fpregs elf_fpregset_t;
     58 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
     59 index 945da99d4..81822dbb1 100644
     60 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
     61 +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
     62 @@ -31,7 +31,7 @@
     63  #include <sys/types.h> // for pid_t
     64  #include <sys/uio.h> // for iovec
     65  #include <elf.h> // for NT_PRSTATUS
     66 -#if (defined(__aarch64__) || defined(__powerpc64__) || \
     67 +#if (defined(__aarch64__) || defined(__powerpc__) || \
     68       SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) &&    \
     69       !SANITIZER_ANDROID
     70  // GLIBC 2.20+ sys/user does not include asm/ptrace.h
     71 diff --git a/compiler-rt/lib/xray/xray_powerpc64.inc b/compiler-rt/lib/xray/xray_powerpc64.inc
     72 index 7e872b5b4..9616a09d8 100644
     73 --- a/compiler-rt/lib/xray/xray_powerpc64.inc
     74 +++ b/compiler-rt/lib/xray/xray_powerpc64.inc
     75 @@ -12,7 +12,7 @@
     76  
     77  #include <cstdint>
     78  #include <mutex>
     79 -#ifdef __linux__
     80 +#ifdef __GLIBC__
     81  #include <sys/platform/ppc.h>
     82  #elif defined(__FreeBSD__)
     83  #include <sys/types.h>
     84 @@ -27,6 +27,13 @@ uint64_t __ppc_get_timebase_freq (void)
     85    sysctlbyname("kern.timecounter.tc.timebase.frequency", &tb_freq, &length, nullptr, 0);
     86    return tb_freq;
     87  }
     88 +#else
     89 +#include <cctype>
     90 +#include <cstring>
     91 +#include <cstdlib>
     92 +
     93 +#define __ppc_get_timebase __builtin_ppc_get_timebase
     94 +
     95  #endif
     96  
     97  #include "xray_defs.h"
     98 @@ -41,7 +48,35 @@ ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT {
     99  inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT {
    100    static std::mutex M;
    101    std::lock_guard<std::mutex> Guard(M);
    102 +#ifdef __GLIBC__
    103    return __ppc_get_timebase_freq();
    104 +#else
    105 +  /* FIXME: a less dirty implementation? */
    106 +  static uint64_t base;
    107 +  if (!base) {
    108 +    FILE *f = fopen("/proc/cpuinfo", "rb");
    109 +    if (f) {
    110 +      ssize_t nr;
    111 +      /* virtually always big enough to hold the line */
    112 +      char buf[512];
    113 +      while (fgets(buf, sizeof(buf), f)) {
    114 +        char *ret = strstr(buf, "timebase");
    115 +        if (!ret) {
    116 +          continue;
    117 +        }
    118 +        ret += sizeof("timebase") - 1;
    119 +        ret = strchr(ret, ':');
    120 +        if (!ret) {
    121 +          continue;
    122 +        }
    123 +        base = strtoul(ret + 1, nullptr, 10);
    124 +        break;
    125 +      }
    126 +      fclose(f);
    127 +    }
    128 +  }
    129 +  return base;
    130 +#endif
    131  }
    132  
    133  inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT {
    134 -- 
    135 2.49.0
    136