[compiler-rt] r334660 - [Sanitizers] Make sanitizer allocator linker-initialize compliant.

Alex Shlyapnikov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 13 14:45:01 PDT 2018


Author: alekseyshl
Date: Wed Jun 13 14:45:01 2018
New Revision: 334660

URL: http://llvm.org/viewvc/llvm-project?rev=334660&view=rev
Log:
[Sanitizers] Make sanitizer allocator linker-initialize compliant.

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

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_secondary.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_stats.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_secondary.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_secondary.h?rev=334660&r1=334659&r2=334660&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_secondary.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_secondary.h Wed Jun 13 14:45:01 2018
@@ -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_;
 };
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_stats.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_stats.h?rev=334660&r1=334659&r2=334660&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_stats.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_stats.h Wed Jun 13 14:45:01 2018
@@ -101,7 +101,7 @@ class AllocatorGlobalStats : public Allo
   }
 
  private:
-  mutable SpinMutex mu_;
+  mutable StaticSpinMutex mu_;
 };
 
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=334660&r1=334659&r2=334660&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h Wed Jun 13 14:45:01 2018
@@ -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];
 




More information about the llvm-commits mailing list