[PATCH] D29236: [compiler-rt] Don't change g_tls_size after initialization.

Tim Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 27 15:46:31 PST 2017


timshen created this revision.
Herald added subscribers: dberris, kubamracek.

g_tls_size is not supposed to be changed after initialization. It's not
atomic, not guarded by a lock, nor thread_local. But it's read by
multiple threads.

The reason why it's mutated is mips and powerpc64 specific. We can
implement the same funcitonality without mutating g_tls_size.

I'm not sure how to write a test for this. Please advice. Thanks!


https://reviews.llvm.org/D29236

Files:
  compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc


Index: compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -270,9 +270,7 @@
 # endif
   const uptr kTlsAlign = 16;
   const uptr kTlsPreTcbSize =
-    (ThreadDescriptorSize() + kTcbHead + kTlsAlign - 1) & ~(kTlsAlign - 1);
-  InitTlsSize();
-  g_tls_size = (g_tls_size + kTlsPreTcbSize + kTlsAlign -1) & ~(kTlsAlign - 1);
+      RoundUpTo(ThreadDescriptorSize() + kTcbHead, kTlsAlign);
   return kTlsPreTcbSize;
 }
 #endif
@@ -379,6 +377,8 @@
   uptr addr, size;
   GetTls(&addr, &size);
   return size;
+#elif defined(__mips__) || defined(__powerpc64__)
+  return RoundUpTo(g_tls_size + TlsPreTcbSize(), 16);
 #else
   return g_tls_size;
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29236.86141.patch
Type: text/x-patch
Size: 854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170127/3cc9cc7b/attachment.bin>


More information about the llvm-commits mailing list