From 62914bad46cf0b010e3277197dc3114fdf0d8b79 Mon Sep 17 00:00:00 2001 From: Mitch Phillips <31459023+hctim@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:27:13 -0800 Subject: [PATCH] [ASan] Fix TLS teardown. TLS teardown is currently broken, as we unpoison the shadow a little bit and to the right of the TLS section, rather than the full TLS section itself. This currently breaks at -O0, and breaks with some upcoming globals code that I have. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D120080 --- compiler-rt/lib/asan/asan_thread.cpp | 4 +--- compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp index 2b06c3c..c15963e 100644 --- a/compiler-rt/lib/asan/asan_thread.cpp +++ b/compiler-rt/lib/asan/asan_thread.cpp @@ -323,9 +323,7 @@ void AsanThread::ClearShadowForThreadStackAndTLS() { if (tls_begin_ != tls_end_) { uptr tls_begin_aligned = RoundDownTo(tls_begin_, ASAN_SHADOW_GRANULARITY); uptr tls_end_aligned = RoundUpTo(tls_end_, ASAN_SHADOW_GRANULARITY); - FastPoisonShadowPartialRightRedzone(tls_begin_aligned, - tls_end_ - tls_begin_aligned, - tls_end_aligned - tls_end_, 0); + FastPoisonShadow(tls_begin_aligned, tls_end_aligned - tls_begin_aligned, 0); } } diff --git a/compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp b/compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp index e223453..8b405ac 100644 --- a/compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp +++ b/compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp @@ -1,6 +1,7 @@ // Test that TLS is unpoisoned on thread death. // REQUIRES: x86-target-arch && !android +// RUN: %clangxx_asan -O0 %s -pthread -o %t && %run %t 2>&1 // RUN: %clangxx_asan -O1 %s -pthread -o %t && %run %t 2>&1 #include -- 2.7.4