[compiler-rt] 62914ba - [ASan] Fix TLS teardown.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 13:34:50 PST 2022


Author: Mitch Phillips
Date: 2022-02-17T13:34:36-08:00
New Revision: 62914bad46cf0b010e3277197dc3114fdf0d8b79

URL: https://github.com/llvm/llvm-project/commit/62914bad46cf0b010e3277197dc3114fdf0d8b79
DIFF: https://github.com/llvm/llvm-project/commit/62914bad46cf0b010e3277197dc3114fdf0d8b79.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_thread.cpp
    compiler-rt/test/asan/TestCases/Linux/unpoison_tls.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 2b06c3c4e7c04..c15963e141832 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 e22345342f3f5..8b405ac5f8651 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 <assert.h>


        


More information about the llvm-commits mailing list