[compiler-rt] r202405 - tsan: another attempt to fix the tls_get_addr crash

Dmitry Vyukov dvyukov at google.com
Thu Feb 27 07:07:45 PST 2014


Author: dvyukov
Date: Thu Feb 27 09:07:45 2014
New Revision: 202405

URL: http://llvm.org/viewvc/llvm-project?rev=202405&view=rev
Log:
tsan: another attempt to fix the tls_get_addr crash


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc
    compiler-rt/trunk/test/asan/TestCases/Linux/stress_dtls.c

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc?rev=202405&r1=202404&r2=202405&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_tls_get_addr.cc Thu Feb 27 09:07:45 2014
@@ -75,26 +75,29 @@ void DTLS_on_tls_get_addr(void *arg_void
     return;
   uptr tls_size = 0;
   uptr tls_beg = reinterpret_cast<uptr>(res) - arg->offset;
-  // Don't do anything fancy in this function, in particular don't print.
-  // Some versions of libstdc++ are miscompiled and call this function
-  // with mis-aligned stack:
+  // This function uses the fancy 2147483647 verbosity level,
+  // because printing in this function crashes with some versions of libstdc++
+  // because of the following bug:
   // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066
-  // Printf uses SSE instructions that crash with mis-aligned accesses.
-  // VPrintf(2, "__tls_get_addr: %p {%p,%p} => %p; tls_beg: %p; sp: %p\n", arg,
-  //        arg->dso_id, arg->offset, res, tls_beg, &tls_beg);
+  // The bug leads to mis-aligned stack in this function, and subsequently
+  // SSE instructions in Printf crash.
+  // But there is a test that searches for printfs from this function.
+  // The bug can affect any code, so do as less as possible here.
+  VPrintf(2147483647, "__tls_get_addr: %p {%p,%p} => %p; tls_beg: %p; sp: %p\n",
+      arg, arg->dso_id, arg->offset, res, tls_beg, &tls_beg);
   if (dtls.last_memalign_ptr == tls_beg) {
     tls_size = dtls.last_memalign_size;
-    // VPrintf(2, "__tls_get_addr: glibc <=2.18 suspected; tls={%p,%p}\n",
-    //        tls_beg, tls_size);
+    VPrintf(2147483647, "__tls_get_addr: glibc <=2.18 suspected; tls={%p,%p}\n",
+        tls_beg, tls_size);
   } else if ((tls_beg % 4096) == sizeof(Glibc_2_19_tls_header)) {
     // We may want to check gnu_get_libc_version().
     Glibc_2_19_tls_header *header = (Glibc_2_19_tls_header *)tls_beg - 1;
     tls_size = header->size;
     tls_beg = header->start;
-    //VPrintf(2, "__tls_get_addr: glibc >=2.19 suspected; tls={%p %p}\n",
-    //        tls_beg, tls_size);
+    VPrintf(2147483647, "__tls_get_addr: glibc >=2.19 suspected; tls={%p %p}\n",
+        tls_beg, tls_size);
   } else {
-    //VPrintf(2, "__tls_get_addr: Can't guess glibc version\n");
+    VPrintf(2147483647, "__tls_get_addr: Can't guess glibc version\n");
     // This may happen inside the DTOR of main thread, so just ignore it.
     tls_size = 0;
   }
@@ -103,7 +106,7 @@ void DTLS_on_tls_get_addr(void *arg_void
 }
 
 void DTLS_on_libc_memalign(void *ptr, uptr size) {
-  // VPrintf(2, "DTLS_on_libc_memalign: %p %p\n", ptr, size);
+  VPrintf(2147483647, "DTLS_on_libc_memalign: %p %p\n", ptr, size);
   dtls.last_memalign_ptr = reinterpret_cast<uptr>(ptr);
   dtls.last_memalign_size = size;
 }

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/stress_dtls.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/stress_dtls.c?rev=202405&r1=202404&r2=202405&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/stress_dtls.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/stress_dtls.c Thu Feb 27 09:07:45 2014
@@ -12,7 +12,7 @@
 // RUN: %clangxx_asan %s -o %t
 // RUN: %t 0 3
 // RUN: %t 2 3
-// RUN: ASAN_OPTIONS=verbosity=2 %t 2 2 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=verbosity=2147483647 %t 2 2 2>&1 | FileCheck %s
 // CHECK: __tls_get_addr
 // CHECK: __tls_get_addr
 // CHECK: __tls_get_addr





More information about the llvm-commits mailing list