[compiler-rt] 7ddd354 - [RISCV][ASAN] Fix TLS offsets
Luís Marques via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 05:42:04 PDT 2020
Author: Luís Marques
Date: 2020-10-19T13:41:50+01:00
New Revision: 7ddd354d47cc2f41a072e116b879c6bdf32a1578
URL: https://github.com/llvm/llvm-project/commit/7ddd354d47cc2f41a072e116b879c6bdf32a1578
DIFF: https://github.com/llvm/llvm-project/commit/7ddd354d47cc2f41a072e116b879c6bdf32a1578.diff
LOG: [RISCV][ASAN] Fix TLS offsets
Fix a RISC-V ASan test failure: `TestCases/Linux/static_tls.cpp`.
Differential Revision: https://reviews.llvm.org/D89244
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index e17f23efbd0b..10627549704a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -375,12 +375,9 @@ uptr ThreadSelf() {
descr_addr = reinterpret_cast<uptr>(__builtin_thread_pointer()) -
ThreadDescriptorSize();
#elif SANITIZER_RISCV64
- uptr tcb_end;
- asm volatile("mv %0, tp;\n" : "=r"(tcb_end));
// https://github.com/riscv/riscv-elf-psabi-doc/issues/53
- const uptr kTlsTcbOffset = 0x800;
- descr_addr =
- reinterpret_cast<uptr>(tcb_end - kTlsTcbOffset - TlsPreTcbSize());
+ uptr thread_pointer = reinterpret_cast<uptr>(__builtin_thread_pointer());
+ descr_addr = thread_pointer - TlsPreTcbSize();
#elif defined(__s390__)
descr_addr = reinterpret_cast<uptr>(__builtin_thread_pointer());
#elif defined(__powerpc64__)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
index 9ca898a306a8..10748f96420a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_tls_get_addr.cpp
@@ -80,8 +80,13 @@ void DTLS_Destroy() {
#if defined(__powerpc64__) || defined(__mips__)
// This is glibc's TLS_DTV_OFFSET:
// "Dynamic thread vector pointers point 0x8000 past the start of each
-// TLS block."
+// TLS block." (sysdeps/<arch>/dl-tls.h)
static const uptr kDtvOffset = 0x8000;
+#elif defined(__riscv)
+// This is glibc's TLS_DTV_OFFSET:
+// "Dynamic thread vector pointers point 0x800 past the start of each
+// TLS block." (sysdeps/riscv/dl-tls.h)
+static const uptr kDtvOffset = 0x800;
#else
static const uptr kDtvOffset = 0;
#endif
More information about the llvm-commits
mailing list