aports/community/clang-rtlib/1801-compiler-rt-lsan-dtp-offset.patch
Celeste 0f1a6d44b3 community/clang-rtlib: new aport
my attempt at unblocking the Chromium security upgrade,
while waiting for !82919 to make it buildable with Clang 20
2025-04-19 11:45:01 +00:00

70 lines
2.4 KiB
Diff

more ppc64le sanitizer fixes
From 01de315ff348fec5b7c17a6ae94ce517d23a2f0c Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Sat, 5 Nov 2022 23:39:29 +0100
Subject: [PATCH] rudimentary lsan musl fixes on some archs (ppc64le)
---
.../sanitizer_common/sanitizer_linux_libcdep.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index d74851c43..f13fc84be 100644
--- a/compiler-rt-18.1.8.src/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt-18.1.8.src/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -28,6 +28,14 @@
# include "sanitizer_procmaps.h"
# include "sanitizer_solaris.h"
+#if defined(__powerpc__)
+#define DTP_OFFSET 0x8000
+#elif SANITIZER_RISCV64
+#define DTP_OFFSET 0x800
+#else
+#define DTP_OFFSET 0
+#endif
+
# if SANITIZER_NETBSD
# define _RTLD_SOURCE // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
# endif
@@ -294,6 +302,7 @@ static uptr ThreadDescriptorSizeFallback() {
return val;
}
+#if SANITIZER_GLIBC
uptr ThreadDescriptorSize() {
uptr val = atomic_load_relaxed(&thread_descriptor_size);
if (val)
@@ -308,6 +317,9 @@ uptr ThreadDescriptorSize() {
atomic_store_relaxed(&thread_descriptor_size, val);
return val;
}
+#else
+uptr ThreadDescriptorSize() { return 0; }
+#endif
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64 || \
SANITIZER_LOONGARCH64
@@ -399,6 +411,7 @@ static int CollectStaticTlsBlocks(struct dl_phdr_info *info, size_t size,
begin = (uptr)__tls_get_addr(mod_and_off);
# endif
}
+ begin -= DTP_OFFSET;
for (unsigned i = 0; i != info->dlpi_phnum; ++i)
if (info->dlpi_phdr[i].p_type == PT_TLS) {
static_cast<InternalMmapVector<TlsBlock> *>(data)->push_back(
@@ -556,9 +569,11 @@ static void GetTls(uptr *addr, uptr *size) {
else if (SANITIZER_FREEBSD)
*size += 128; // RTLD_STATIC_TLS_EXTRA
# if defined(__mips__) || defined(__powerpc64__) || SANITIZER_RISCV64
+#if SANITIZER_GLIBC
const uptr pre_tcb_size = TlsPreTcbSize();
*addr -= pre_tcb_size;
*size += pre_tcb_size;
+#endif
# 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
--
2.38.1