[Sanitizers] Make sanitizer allocator linker-initialize compliant.
authorAlex Shlyapnikov <alekseys@google.com>
Wed, 13 Jun 2018 21:45:01 +0000 (21:45 +0000)
committerAlex Shlyapnikov <alekseys@google.com>
Wed, 13 Jun 2018 21:45:01 +0000 (21:45 +0000)
Summary:
These four SpinMutex ctors was the only code executed in the ctor for
the static __asan::Allocator instance (same for the other sanitizers
allocators), which is supposed to be fully linker-initialized.

Also, when the global ctor for this allocator instance is executed,
this instance might already be initialized by __asan_init called from
.preinit_array.

Issue: https://github.com/google/sanitizers/issues/194

Reviewers: morehouse, eugenis, cryptoad

Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits

Differential Revision: https://reviews.llvm.org/D48142

llvm-svn: 334660

compiler-rt/lib/sanitizer_common/sanitizer_allocator_secondary.h
compiler-rt/lib/sanitizer_common/sanitizer_allocator_stats.h
compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h

index db52bf5..ab680b5 100644 (file)
@@ -314,6 +314,6 @@ class LargeMmapAllocator {
   struct Stats {
     uptr n_allocs, n_frees, currently_allocated, max_allocated, by_size_log[64];
   } stats;
-  SpinMutex mutex_;
+  StaticSpinMutex mutex_;
 };
 
index 38b088b..76df3ed 100644 (file)
@@ -101,7 +101,7 @@ class AllocatorGlobalStats : public AllocatorStats {
   }
 
  private:
-  mutable SpinMutex mu_;
+  mutable StaticSpinMutex mu_;
 };
 
 
index 886445a..d4aa12f 100644 (file)
@@ -90,6 +90,9 @@ class Quarantine {
     atomic_store_relaxed(&max_size_, size);
     atomic_store_relaxed(&min_size_, size / 10 * 9);  // 90% of max size.
     atomic_store_relaxed(&max_cache_size_, cache_size);
+
+    cache_mutex_.Init();
+    recycle_mutex_.Init();
   }
 
   uptr GetSize() const { return atomic_load_relaxed(&max_size_); }
@@ -142,8 +145,8 @@ class Quarantine {
   atomic_uintptr_t min_size_;
   atomic_uintptr_t max_cache_size_;
   char pad1_[kCacheLineSize];
-  SpinMutex cache_mutex_;
-  SpinMutex recycle_mutex_;
+  StaticSpinMutex cache_mutex_;
+  StaticSpinMutex recycle_mutex_;
   Cache cache_;
   char pad2_[kCacheLineSize];