From da1c921a45908cd05aed5bd44245d2b424a8580a Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 14 Apr 2024 14:41:14 +0200 Subject: [PATCH 08/29] compiler-rt: lsan: basic musl fixes on various archs --- .../lib/sanitizer_common/sanitizer_linux_libcdep.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index e11eff13c..96e823ae7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/compiler-rt/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 @@ -467,6 +475,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 *>(data)->push_back( @@ -624,9 +624,11 @@ # elif 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.49.0