[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

llvm-svn: 334660
This commit is contained in:
Alex Shlyapnikov 2018-06-13 21:45:01 +00:00
parent a00c372cd3
commit 3fc66075c7
3 changed files with 7 additions and 4 deletions

View 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_;
};

View File

@ -101,7 +101,7 @@ class AllocatorGlobalStats : public AllocatorStats {
}
private:
mutable SpinMutex mu_;
mutable StaticSpinMutex mu_;
};

View 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];