|
| 1 | +From a930a513c42524842931ec9dea7d16728f095043 Mon Sep 17 00:00:00 2001 |
| 2 | + |
| 3 | +Date: Mon, 16 Dec 2024 13:42:04 +0900 |
| 4 | +Subject: [PATCH] Fix build on ppc64+musl |
| 5 | + |
| 6 | +In powerpc64-unknown-linux-musl, signal.h does not include asm/ptrace.h, |
| 7 | +which causes "member access into incomplete type 'struct pt_regs'" errors. |
| 8 | +Include the header explicitly to fix this. |
| 9 | + |
| 10 | +Also in sanitizer_linux_libcdep.cpp, there is a usage of |
| 11 | +TlsPreTcbSize which is not defined in such a platform. |
| 12 | +Guard the branch with macro. |
| 13 | + |
| 14 | +Upstream-Status: Submitted [https://github.com/llvm/llvm-project/pull/120036] |
| 15 | +Signed-off-by: Khem Raj < [email protected]> |
| 16 | +--- |
| 17 | + .../lib/sanitizer_common/sanitizer_linux.cpp | 4 ++++ |
| 18 | + .../sanitizer_common/sanitizer_linux_libcdep.cpp | 13 +++++++------ |
| 19 | + .../sanitizer_platform_limits_posix.cpp | 2 +- |
| 20 | + .../sanitizer_stoptheworld_linux_libcdep.cpp | 3 ++- |
| 21 | + 4 files changed, 14 insertions(+), 8 deletions(-) |
| 22 | + |
| 23 | +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp |
| 24 | +index 7aa48d29d2d5..a4d526b4466c 100644 |
| 25 | +--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp |
| 26 | ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp |
| 27 | +@@ -86,6 +86,10 @@ |
| 28 | + # include <sys/sysmacros.h> |
| 29 | + # endif |
| 30 | + |
| 31 | ++# if SANITIZER_LINUX && defined(__powerpc64__) |
| 32 | ++# include <asm/ptrace.h> |
| 33 | ++# endif |
| 34 | ++ |
| 35 | + # if SANITIZER_FREEBSD |
| 36 | + # include <machine/atomic.h> |
| 37 | + # include <sys/exec.h> |
| 38 | +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp |
| 39 | +index e11eff13cd32..331e1c7d8d15 100644 |
| 40 | +--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp |
| 41 | ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp |
| 42 | +@@ -619,21 +619,22 @@ static void GetTls(uptr *addr, uptr *size) { |
| 43 | + *addr = tp - RoundUpTo(*size, align); |
| 44 | + *size = tp - *addr + ThreadDescriptorSize(); |
| 45 | + # else |
| 46 | +- if (SANITIZER_GLIBC) |
| 47 | +- *size += 1664; |
| 48 | +- else if (SANITIZER_FREEBSD) |
| 49 | +- *size += 128; // RTLD_STATIC_TLS_EXTRA |
| 50 | +-# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64 |
| 51 | ++# if SANITIZER_GLIBC |
| 52 | ++ *size += 1664; |
| 53 | ++# elif SANITIZER_FREEBSD |
| 54 | ++ *size += 128; // RTLD_STATIC_TLS_EXTRA |
| 55 | ++# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64 |
| 56 | + const uptr pre_tcb_size = TlsPreTcbSize(); |
| 57 | + *addr -= pre_tcb_size; |
| 58 | + *size += pre_tcb_size; |
| 59 | +-# else |
| 60 | ++# else |
| 61 | + // arm and aarch64 reserve two words at TP, so this underestimates the range. |
| 62 | + // However, this is sufficient for the purpose of finding the pointers to |
| 63 | + // thread-specific data keys. |
| 64 | + const uptr tcb_size = ThreadDescriptorSize(); |
| 65 | + *addr -= tcb_size; |
| 66 | + *size += tcb_size; |
| 67 | ++# endif |
| 68 | + # endif |
| 69 | + # endif |
| 70 | + # elif SANITIZER_NETBSD |
| 71 | +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp |
| 72 | +index a5311d266b0c..ec5f2edab6a6 100644 |
| 73 | +--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp |
| 74 | ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp |
| 75 | +@@ -96,7 +96,7 @@ |
| 76 | + # include <sys/ptrace.h> |
| 77 | + # if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \ |
| 78 | + defined(__hexagon__) || defined(__loongarch__) || SANITIZER_RISCV64 || \ |
| 79 | +- defined(__sparc__) |
| 80 | ++ defined(__sparc__) || defined(__powerpc64__) |
| 81 | + # include <asm/ptrace.h> |
| 82 | + # ifdef __arm__ |
| 83 | + typedef struct user_fpregs elf_fpregset_t; |
| 84 | +diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 85 | +index 945da99d41f4..58d17d90c343 100644 |
| 86 | +--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 87 | ++++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 88 | +@@ -31,7 +31,8 @@ |
| 89 | + #include <sys/types.h> // for pid_t |
| 90 | + #include <sys/uio.h> // for iovec |
| 91 | + #include <elf.h> // for NT_PRSTATUS |
| 92 | +-#if (defined(__aarch64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \ |
| 93 | ++#if (defined(__aarch64__) || defined(__powerpc64__) || \ |
| 94 | ++ SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \ |
| 95 | + !SANITIZER_ANDROID |
| 96 | + // GLIBC 2.20+ sys/user does not include asm/ptrace.h |
| 97 | + # include <asm/ptrace.h> |
0 commit comments