[asan] fix a crash in asan stats printing (initialize the allocator in __asan_init)
authorKostya Serebryany <kcc@google.com>
Mon, 28 Jan 2013 08:05:47 +0000 (08:05 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 28 Jan 2013 08:05:47 +0000 (08:05 +0000)
llvm-svn: 173676

compiler-rt/lib/asan/asan_allocator.cc
compiler-rt/lib/asan/asan_allocator.h
compiler-rt/lib/asan/asan_allocator2.cc
compiler-rt/lib/asan/asan_rtl.cc

index 370307a89cc0566d378a5d2fb07a83449f071d90..1fe2bbdbf454dee7ff2a8c046ef62e070656808c 100644 (file)
@@ -688,6 +688,8 @@ void __asan_free_hook(void *ptr) {
 
 namespace __asan {
 
+void InitializeAllocator() { }
+
 void PrintInternalAllocatorStats() {
 }
 
index cca24edad81fbfc7dec2b780c26a64b0285f60e0..2de6b982ac7e67cff800e33e8f77d51124e6cece 100644 (file)
@@ -42,6 +42,8 @@ enum AllocType {
 static const uptr kNumberOfSizeClasses = 255;
 struct AsanChunk;
 
+void InitializeAllocator();
+
 class AsanChunkView {
  public:
   explicit AsanChunkView(AsanChunk *chunk) : chunk_(chunk) {}
index 184627a586a8c5d13dc13610ab03f56b100b7b64..63cb41b4c97ca17fa70c8a9e410c1ae10d9a5966 100644 (file)
@@ -295,18 +295,15 @@ struct QuarantineCallback {
   AllocatorCache *cache_;
 };
 
-static void Init() {
-  static int inited = 0;
-  if (inited) return;
-  __asan_init();
-  inited = true;  // this must happen before any threads are created.
+void InitializeAllocator() {
   allocator.Init();
   quarantine.Init((uptr)flags()->quarantine_size, kMaxThreadLocalQuarantine);
 }
 
 static void *Allocate(uptr size, uptr alignment, StackTrace *stack,
                       AllocType alloc_type) {
-  Init();
+  if (!asan_inited)
+    __asan_init();
   CHECK(stack);
   const uptr min_alignment = SHADOW_GRANULARITY;
   if (alignment < min_alignment)
index d16f1e377358b96863bee85d9787c444ca4424da..2a4adea49f29075eeef880c4b2624eca2dd88084 100644 (file)
@@ -426,6 +426,8 @@ void __asan_init() {
   asanThreadRegistry().GetMain()->ThreadStart();
   force_interface_symbols();  // no-op.
 
+  InitializeAllocator();
+
   if (flags()->verbosity) {
     Report("AddressSanitizer Init done\n");
   }