[PATCH] [ASan] Make BlockingMutex really linker initialized.

Yury Gribov tetra2005 at gmail.com
Mon Jan 26 00:52:42 PST 2015


Hi kcc, samsonov,

This patch adds constexpr to BlockingMutex which instructs compiler to never generate global constructors (and thus fixes -Wglobal-constructors warnings about BlockingMutex globals in sanitizer_common). I could do the same fixes to other LinkerInitialized classes (Allocator, etc.) and enable -Wglobal-constructors for ASan but I wasn't sure whether anyone needs this.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7171

Files:
  lib/sanitizer_common/sanitizer_linux.cc
  lib/sanitizer_common/sanitizer_mac.cc
  lib/sanitizer_common/sanitizer_mutex.h

Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -493,15 +493,10 @@
   MtxSleeping = 2
 };
 
-BlockingMutex::BlockingMutex(LinkerInitialized) {
-  CHECK_EQ(owner_, 0);
-}
-
-BlockingMutex::BlockingMutex() {
-  internal_memset(this, 0, sizeof(*this));
-}
+BlockingMutex::BlockingMutex() {}
 
 void BlockingMutex::Lock() {
+  CHECK_EQ(owner_, 0);
   atomic_uint32_t *m = reinterpret_cast<atomic_uint32_t *>(&opaque_storage_);
   if (atomic_exchange(m, MtxLocked, memory_order_acquire) == MtxUnlocked)
     return;
Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -217,13 +217,7 @@
   return sysconf(_SC_PAGESIZE);
 }
 
-BlockingMutex::BlockingMutex(LinkerInitialized) {
-  // We assume that OS_SPINLOCK_INIT is zero
-}
-
-BlockingMutex::BlockingMutex() {
-  internal_memset(this, 0, sizeof(*this));
-}
+BlockingMutex::BlockingMutex() {}
 
 void BlockingMutex::Lock() {
   CHECK(sizeof(OSSpinLock) <= sizeof(opaque_storage_));
Index: lib/sanitizer_common/sanitizer_mutex.h
===================================================================
--- lib/sanitizer_common/sanitizer_mutex.h
+++ lib/sanitizer_common/sanitizer_mutex.h
@@ -73,14 +73,18 @@
 
 class BlockingMutex {
  public:
+#if SANITIZER_WINDOWS
   explicit BlockingMutex(LinkerInitialized);
+#else
+  explicit constexpr BlockingMutex(LinkerInitialized) {}
+#endif
   BlockingMutex();
   void Lock();
   void Unlock();
   void CheckLocked();
  private:
-  uptr opaque_storage_[10];
-  uptr owner_;  // for debugging
+  uptr opaque_storage_[10] = {};
+  uptr owner_ = 0;  // for debugging
 };
 
 // Reader-writer spin mutex.

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7171.18743.patch
Type: text/x-patch
Size: 1888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150126/67e800bb/attachment.bin>


More information about the llvm-commits mailing list