commit:     485d5bafcc11703825cb6c3cf7ce2cdd246fb7b1
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed May  7 11:19:38 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed May  7 11:19:38 2025 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=485d5baf

15.1.0: fix libsanitizer build on riscv/musl

Bug: https://gcc.gnu.org/PR119356
Bug: https://bugs.gentoo.org/945920
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../85_all_PR119356-riscv-libsanitizer.patch       | 102 +++++++++++++++++++++
 15.1.0/gentoo/README.history                       |   1 +
 2 files changed, 103 insertions(+)

diff --git a/15.1.0/gentoo/85_all_PR119356-riscv-libsanitizer.patch 
b/15.1.0/gentoo/85_all_PR119356-riscv-libsanitizer.patch
new file mode 100644
index 0000000..d5cc246
--- /dev/null
+++ b/15.1.0/gentoo/85_all_PR119356-riscv-libsanitizer.patch
@@ -0,0 +1,102 @@
+https://bugs.gentoo.org/945920
+https://github.com/llvm/llvm-project/pull/120036
+https://gcc.gnu.org/PR119356
+
+From 534b3ef77c6df932e532c4b63d8c506cda26d4a4 Mon Sep 17 00:00:00 2001
+From: mojyack <[email protected]>
+Date: Mon, 16 Dec 2024 13:42:04 +0900
+Subject: [PATCH] [sanitizer_common] Fix build on ppc64+musl
+
+In powerpc64-unknown-linux-musl, signal.h does not include asm/ptrace.h,
+which causes "member access into incomplete type 'struct pt_regs'" errors.
+Include the header explicitly to fix this.
+
+Also in sanitizer_linux_libcdep.cpp, there is a usage of
+TlsPreTcbSize which is not defined in such a platform.
+Guard the branch with macro.
+
+---
+ libsanitizer/sanitizer_common/sanitizer_linux.cpp   |  4 ++++
+ .../sanitizer_common/sanitizer_linux_libcdep.cpp    | 13 +++++++------
+ .../sanitizer_platform_limits_posix.cpp             |  2 +-
+ .../sanitizer_stoptheworld_linux_libcdep.cpp        |  3 ++-
+ 4 files changed, 14 insertions(+), 8 deletions(-)
+
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux.cpp 
b/libsanitizer/sanitizer_common/sanitizer_linux.cpp
+index 8b1850f85010..6331c26c0a92 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux.cpp
++++ b/libsanitizer/sanitizer_common/sanitizer_linux.cpp
+@@ -86,6 +86,10 @@
+ #    include <sys/sysmacros.h>
+ #  endif
+ 
++#  if SANITIZER_LINUX && defined(__powerpc64__)
++#    include <asm/ptrace.h>
++#  endif
++
+ #  if SANITIZER_FREEBSD
+ #    include <machine/atomic.h>
+ #    include <sys/exec.h>
+diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp 
b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+index ed19e4031a53..9d01a97af5f4 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
++++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
+@@ -619,21 +619,22 @@ static void GetTls(uptr *addr, uptr *size) {
+   *addr = tp - RoundUpTo(*size, align);
+   *size = tp - *addr + ThreadDescriptorSize();
+ #      else
+-  if (SANITIZER_GLIBC)
+-    *size += 1664;
+-  else if (SANITIZER_FREEBSD)
+-    *size += 128;  // RTLD_STATIC_TLS_EXTRA
+-#        if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64
++#        if SANITIZER_GLIBC
++  *size += 1664;
++#        elif SANITIZER_FREEBSD
++  *size += 128;  // RTLD_STATIC_TLS_EXTRA
++#          if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64
+   const uptr pre_tcb_size = TlsPreTcbSize();
+   *addr -= pre_tcb_size;
+   *size += pre_tcb_size;
+-#        else
++#          else
+   // arm and aarch64 reserve two words at TP, so this underestimates the 
range.
+   // However, this is sufficient for the purpose of finding the pointers to
+   // thread-specific data keys.
+   const uptr tcb_size = ThreadDescriptorSize();
+   *addr -= tcb_size;
+   *size += tcb_size;
++#          endif
+ #        endif
+ #      endif
+ #    elif SANITIZER_NETBSD
+diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp 
b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp
+index 7bbc6f2edac2..490e75fe8f65 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp
++++ b/libsanitizer/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(__sparc__) || defined(__powerpc64__)
+ #      include <asm/ptrace.h>
+ #      ifdef __arm__
+ typedef struct user_fpregs elf_fpregset_t;
+diff --git 
a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp 
b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+index 945da99d41f4..58d17d90c343 100644
+--- a/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
++++ b/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+@@ -31,7 +31,8 @@
+ #include <sys/types.h> // for pid_t
+ #include <sys/uio.h> // for iovec
+ #include <elf.h> // for NT_PRSTATUS
+-#if (defined(__aarch64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) && \
++#if (defined(__aarch64__) || defined(__powerpc64__) || \
++     SANITIZER_RISCV64 || SANITIZER_LOONGARCH64) &&    \
+      !SANITIZER_ANDROID
+ // GLIBC 2.20+ sys/user does not include asm/ptrace.h
+ # include <asm/ptrace.h>
+-- 
+2.49.0
+

diff --git a/15.1.0/gentoo/README.history b/15.1.0/gentoo/README.history
index 47c0ad0..06c2ba7 100644
--- a/15.1.0/gentoo/README.history
+++ b/15.1.0/gentoo/README.history
@@ -27,3 +27,4 @@
        + 35_all_checking-gc-use-heuristics.patch
        + 
76_all_PR117854-config-nvptx-fix-bashisms-with-gen-copyright.sh-use.patch
        + 84_all_PR116975-GDCFLAGS.patch
+       + 85_all_PR119356-riscv-libsanitizer.patch

Reply via email to