[llvm-commits] [compiler-rt] r159933 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_globals.cc asan_interceptors.cc asan_internal.h asan_linux.cc asan_mac.cc asan_malloc_mac.cc asan_poisoning.cc asan_posix.cc asan_rtl.cc asan_stack.cc asan_stack.h asan_thread.cc asan_thread_registry.cc

Alexey Samsonov samsonov at google.com
Mon Jul 9 07:36:05 PDT 2012


Author: samsonov
Date: Mon Jul  9 09:36:04 2012
New Revision: 159933

URL: http://llvm.org/viewvc/llvm-project?rev=159933&view=rev
Log:
[ASan] Use common flags parsing machinery.

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator.cc
    compiler-rt/trunk/lib/asan/asan_globals.cc
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_linux.cc
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
    compiler-rt/trunk/lib/asan/asan_poisoning.cc
    compiler-rt/trunk/lib/asan/asan_posix.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/asan_stack.cc
    compiler-rt/trunk/lib/asan/asan_stack.h
    compiler-rt/trunk/lib/asan/asan_thread.cc
    compiler-rt/trunk/lib/asan/asan_thread_registry.cc

Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Mon Jul  9 09:36:04 2012
@@ -42,7 +42,7 @@
 
 namespace __asan {
 
-#define  REDZONE FLAG_redzone
+#define  REDZONE (flags()->redzone)
 static const uptr kMinAllocSize = REDZONE * 2;
 static const u64 kMaxAvailableRam = 128ULL << 30;  // 128G
 static const uptr kMaxThreadLocalQuarantine = 1 << 20;  // 1M
@@ -134,7 +134,7 @@
   CHECK(IsAligned(size, kPageSize));
   u8 *res = (u8*)MmapOrDie(size, __FUNCTION__);
   PoisonShadow((uptr)res, size, kAsanHeapLeftRedzoneMagic);
-  if (FLAG_debug) {
+  if (flags()->debug) {
     Printf("ASAN_MMAP: [%p, %p)\n", res, res + size);
   }
   return res;
@@ -186,7 +186,7 @@
     return (u32*)((uptr)this + sizeof(ChunkBase));
   }
   u32 *compressed_free_stack() {
-    return (u32*)((uptr)this + Max(REDZONE, (uptr)sizeof(ChunkBase)));
+    return (u32*)((uptr)this + Max((uptr)REDZONE, (uptr)sizeof(ChunkBase)));
   }
 
   // The left redzone after the ChunkBase is given to the alloc stack trace.
@@ -339,12 +339,12 @@
 
   void SwallowThreadLocalMallocStorage(AsanThreadLocalMallocStorage *x,
                                        bool eat_free_lists) {
-    CHECK(FLAG_quarantine_size > 0);
+    CHECK(flags()->quarantine_size > 0);
     ScopedLock lock(&mu_);
     AsanChunkFifoList *q = &x->quarantine_;
     if (q->size() > 0) {
       quarantine_.PushList(q);
-      while (quarantine_.size() > FLAG_quarantine_size) {
+      while (quarantine_.size() > flags()->quarantine_size) {
         QuarantinePop();
       }
     }
@@ -644,7 +644,7 @@
   CHECK(size_to_allocate >= needed_size);
   CHECK(IsAligned(size_to_allocate, REDZONE));
 
-  if (FLAG_v >= 3) {
+  if (flags()->verbosity >= 3) {
     Printf("Allocate align: %zu size: %zu class: %u real: %zu\n",
          alignment, size, size_class, size_to_allocate);
   }
@@ -704,7 +704,7 @@
     PoisonHeapPartialRightRedzone(addr + rounded_size - REDZONE,
                                   size & (REDZONE - 1));
   }
-  if (size <= FLAG_max_malloc_fill_size) {
+  if (size <= flags()->max_malloc_fill_size) {
     REAL(memset)((void*)addr, 0, rounded_size);
   }
   return (u8*)addr;
@@ -714,7 +714,7 @@
   if (!ptr) return;
   CHECK(stack);
 
-  if (FLAG_debug) {
+  if (flags()->debug) {
     CHECK(malloc_info.FindPageGroup((uptr)ptr));
   }
 
@@ -882,7 +882,7 @@
   CHECK(stack);
   if (ptr == 0) return 0;
   uptr usable_size = malloc_info.AllocationSize((uptr)ptr);
-  if (FLAG_check_malloc_usable_size && (usable_size == 0)) {
+  if (flags()->check_malloc_usable_size && (usable_size == 0)) {
     AsanReport("ERROR: AddressSanitizer attempting to call "
                "malloc_usable_size() for pointer which is "
                "not owned: %p\n", ptr);
@@ -1055,7 +1055,7 @@
 using namespace __asan;  // NOLINT
 
 uptr __asan_stack_malloc(uptr size, uptr real_stack) {
-  if (!FLAG_use_fake_stack) return real_stack;
+  if (!flags()->use_fake_stack) return real_stack;
   AsanThread *t = asanThreadRegistry().GetCurrent();
   if (!t) {
     // TSD is gone, use the real stack.
@@ -1067,7 +1067,7 @@
 }
 
 void __asan_stack_free(uptr ptr, uptr size, uptr real_stack) {
-  if (!FLAG_use_fake_stack) return;
+  if (!flags()->use_fake_stack) return;
   if (ptr != real_stack) {
     FakeStack::OnFree(ptr, size, real_stack);
   }

Modified: compiler-rt/trunk/lib/asan/asan_globals.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_globals.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_globals.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_globals.cc Mon Jul  9 09:36:04 2012
@@ -88,12 +88,12 @@
 
 
 bool DescribeAddrIfGlobal(uptr addr) {
-  if (!FLAG_report_globals) return false;
+  if (!flags()->report_globals) return false;
   ScopedLock lock(&mu_for_globals);
   bool res = false;
   for (ListOfGlobals *l = list_of_globals; l; l = l->next) {
     const Global &g = *l->g;
-    if (FLAG_report_globals >= 2)
+    if (flags()->report_globals >= 2)
       AsanPrintf("Search Global: beg=%p size=%zu name=%s\n",
                  (void*)g.beg, g.size, (char*)g.name);
     res |= DescribeAddrIfMyRedZone(g, addr);
@@ -106,7 +106,7 @@
 // so we store the globals in a map.
 static void RegisterGlobal(const Global *g) {
   CHECK(asan_inited);
-  CHECK(FLAG_report_globals);
+  CHECK(flags()->report_globals);
   CHECK(AddrIsInMem(g->beg));
   CHECK(AddrIsAlignedByGranularity(g->beg));
   CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
@@ -116,14 +116,14 @@
   l->g = g;
   l->next = list_of_globals;
   list_of_globals = l;
-  if (FLAG_report_globals >= 2)
+  if (flags()->report_globals >= 2)
     Report("Added Global: beg=%p size=%zu name=%s\n",
            (void*)g->beg, g->size, g->name);
 }
 
 static void UnregisterGlobal(const Global *g) {
   CHECK(asan_inited);
-  CHECK(FLAG_report_globals);
+  CHECK(flags()->report_globals);
   CHECK(AddrIsInMem(g->beg));
   CHECK(AddrIsAlignedByGranularity(g->beg));
   CHECK(AddrIsAlignedByGranularity(g->size_with_redzone));
@@ -141,7 +141,7 @@
 // Register one global with a default redzone.
 void __asan_register_global(uptr addr, uptr size,
                             const char *name) {
-  if (!FLAG_report_globals) return;
+  if (!flags()->report_globals) return;
   ScopedLock lock(&mu_for_globals);
   Global *g = (Global *)allocator_for_globals.Allocate(sizeof(Global));
   g->beg = addr;
@@ -153,7 +153,7 @@
 
 // Register an array of globals.
 void __asan_register_globals(__asan_global *globals, uptr n) {
-  if (!FLAG_report_globals) return;
+  if (!flags()->report_globals) return;
   ScopedLock lock(&mu_for_globals);
   for (uptr i = 0; i < n; i++) {
     RegisterGlobal(&globals[i]);
@@ -163,7 +163,7 @@
 // Unregister an array of globals.
 // We must do it when a shared objects gets dlclosed.
 void __asan_unregister_globals(__asan_global *globals, uptr n) {
-  if (!FLAG_report_globals) return;
+  if (!flags()->report_globals) return;
   ScopedLock lock(&mu_for_globals);
   for (uptr i = 0; i < n; i++) {
     UnregisterGlobal(&globals[i]);

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Mon Jul  9 09:36:04 2012
@@ -321,7 +321,7 @@
     return REAL(memcpy)(to, from, size);
   }
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_intrin) {
+  if (flags()->replace_intrin) {
     if (to != from) {
       // We do not treat memcpy with to==from as a bug.
       // See http://llvm.org/bugs/show_bug.cgi?id=11763.
@@ -338,7 +338,7 @@
     return REAL(memmove)(to, from, size);
   }
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_intrin) {
+  if (flags()->replace_intrin) {
     ASAN_WRITE_RANGE(from, size);
     ASAN_READ_RANGE(to, size);
   }
@@ -351,7 +351,7 @@
     return REAL(memset)(block, c, size);
   }
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_intrin) {
+  if (flags()->replace_intrin) {
     ASAN_WRITE_RANGE(block, size);
   }
   return REAL(memset)(block, c, size);
@@ -360,7 +360,7 @@
 INTERCEPTOR(char*, strchr, const char *str, int c) {
   ENSURE_ASAN_INITED();
   char *result = REAL(strchr)(str, c);
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     uptr bytes_read = (result ? result - str : REAL(strlen)(str)) + 1;
     ASAN_READ_RANGE(str, bytes_read);
   }
@@ -390,7 +390,7 @@
 
 INTERCEPTOR(char*, strcat, char *to, const char *from) {  // NOLINT
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     uptr from_length = REAL(strlen)(from);
     ASAN_READ_RANGE(from, from_length + 1);
     if (from_length > 0) {
@@ -405,7 +405,7 @@
 
 INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_str && size > 0) {
+  if (flags()->replace_str && size > 0) {
     uptr from_length = MaybeRealStrnlen(from, size);
     ASAN_READ_RANGE(from, Min(size, from_length + 1));
     uptr to_length = REAL(strlen)(to);
@@ -442,7 +442,7 @@
     return REAL(strcpy)(to, from);  // NOLINT
   }
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     uptr from_size = REAL(strlen)(from) + 1;
     CHECK_RANGES_OVERLAP("strcpy", to, from_size, from, from_size);
     ASAN_READ_RANGE(from, from_size);
@@ -453,7 +453,7 @@
 
 INTERCEPTOR(char*, strdup, const char *s) {
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     uptr length = REAL(strlen)(s);
     ASAN_READ_RANGE(s, length + 1);
   }
@@ -468,7 +468,7 @@
   }
   ENSURE_ASAN_INITED();
   uptr length = REAL(strlen)(s);
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     ASAN_READ_RANGE(s, length + 1);
   }
   return length;
@@ -508,7 +508,7 @@
 
 INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
   ENSURE_ASAN_INITED();
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
     CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
     ASAN_READ_RANGE(from, from_size);
@@ -521,7 +521,7 @@
 INTERCEPTOR(uptr, strnlen, const char *s, uptr maxlen) {
   ENSURE_ASAN_INITED();
   uptr length = REAL(strnlen)(s, maxlen);
-  if (FLAG_replace_str) {
+  if (flags()->replace_str) {
     ASAN_READ_RANGE(s, Min(length + 1, maxlen));
   }
   return length;
@@ -548,7 +548,7 @@
 INTERCEPTOR(long, strtol, const char *nptr,  // NOLINT
             char **endptr, int base) {
   ENSURE_ASAN_INITED();
-  if (!FLAG_replace_str) {
+  if (!flags()->replace_str) {
     return REAL(strtol)(nptr, endptr, base);
   }
   char *real_endptr;
@@ -565,7 +565,7 @@
 
 INTERCEPTOR(int, atoi, const char *nptr) {
   ENSURE_ASAN_INITED();
-  if (!FLAG_replace_str) {
+  if (!flags()->replace_str) {
     return REAL(atoi)(nptr);
   }
   char *real_endptr;
@@ -581,7 +581,7 @@
 
 INTERCEPTOR(long, atol, const char *nptr) {  // NOLINT
   ENSURE_ASAN_INITED();
-  if (!FLAG_replace_str) {
+  if (!flags()->replace_str) {
     return REAL(atol)(nptr);
   }
   char *real_endptr;
@@ -595,7 +595,7 @@
 INTERCEPTOR(long long, strtoll, const char *nptr,  // NOLINT
             char **endptr, int base) {
   ENSURE_ASAN_INITED();
-  if (!FLAG_replace_str) {
+  if (!flags()->replace_str) {
     return REAL(strtoll)(nptr, endptr, base);
   }
   char *real_endptr;
@@ -615,7 +615,7 @@
 
 INTERCEPTOR(long long, atoll, const char *nptr) {  // NOLINT
   ENSURE_ASAN_INITED();
-  if (!FLAG_replace_str) {
+  if (!flags()->replace_str) {
     return REAL(atoll)(nptr);
   }
   char *real_endptr;
@@ -627,7 +627,7 @@
 #endif  // ASAN_INTERCEPT_ATOLL_AND_STRTOLL
 
 #define ASAN_INTERCEPT_FUNC(name) do { \
-      if (!INTERCEPT_FUNCTION(name) && FLAG_v > 0) \
+      if (!INTERCEPT_FUNCTION(name) && flags()->verbosity > 0) \
         Report("AddressSanitizer: failed to intercept '" #name "'\n"); \
     } while (0)
 
@@ -731,7 +731,7 @@
   InitializeMacInterceptors();
 #endif
 
-  if (FLAG_v > 0) {
+  if (flags()->verbosity > 0) {
     Report("AddressSanitizer: libc interceptors initialized\n");
   }
 }

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon Jul  9 09:36:04 2012
@@ -136,30 +136,34 @@
 # define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
 #endif  // __APPLE__
 
-extern uptr  FLAG_quarantine_size;
-extern s64 FLAG_demangle;
-extern bool    FLAG_symbolize;
-extern s64 FLAG_v;
-extern uptr  FLAG_redzone;
-extern s64 FLAG_debug;
-extern bool    FLAG_poison_shadow;
-extern s64 FLAG_report_globals;
-extern uptr  FLAG_malloc_context_size;
-extern bool    FLAG_replace_str;
-extern bool    FLAG_replace_intrin;
-extern bool    FLAG_replace_cfallocator;
-extern bool    FLAG_mac_ignore_invalid_free;
-extern bool    FLAG_fast_unwind;
-extern bool    FLAG_use_fake_stack;
-extern uptr  FLAG_max_malloc_fill_size;
-extern s64 FLAG_exitcode;
-extern bool    FLAG_allow_user_poisoning;
-extern s64 FLAG_sleep_before_dying;
-extern bool    FLAG_handle_segv;
-extern bool    FLAG_use_sigaltstack;
-extern bool    FLAG_check_malloc_usable_size;
-extern bool    FLAG_unmap_shadow_on_exit;
-extern bool    FLAG_abort_on_error;
+struct Flags {
+  int quarantine_size;
+  bool symbolize;
+  int  verbosity;
+  int redzone;
+  int  debug;
+  bool poison_shadow;
+  int  report_globals;
+  int malloc_context_size;
+  bool replace_str;
+  bool replace_intrin;
+  bool replace_cfallocator;
+  bool mac_ignore_invalid_free;
+  bool use_fake_stack;
+  int max_malloc_fill_size;
+  int  exitcode;
+  bool allow_user_poisoning;
+  int  sleep_before_dying;
+  bool handle_segv;
+  bool use_sigaltstack;
+  bool check_malloc_usable_size;
+  bool unmap_shadow_on_exit;
+  bool abort_on_error;
+  bool atexit;
+  bool disable_core;
+};
+Flags *flags();
+void InitializeFlags(Flags *f, const char *env);
 
 extern int asan_inited;
 // Used to avoid infinite recursion in __asan_init().

Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Mon Jul  9 09:36:04 2012
@@ -69,7 +69,7 @@
 }
 
 bool AsanInterceptsSignal(int signum) {
-  return signum == SIGSEGV && FLAG_handle_segv;
+  return signum == SIGSEGV && flags()->handle_segv;
 }
 
 AsanLock::AsanLock(LinkerInitialized) {

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Mon Jul  9 09:36:04 2012
@@ -89,7 +89,7 @@
 }
 
 bool AsanInterceptsSignal(int signum) {
-  return (signum == SIGSEGV || signum == SIGBUS) && FLAG_handle_segv;
+  return (signum == SIGSEGV || signum == SIGBUS) && flags()->handle_segv;
 }
 
 AsanLock::AsanLock(LinkerInitialized) {
@@ -149,7 +149,7 @@
     if (island_allocator_pos != (void*)kIslandBeg) {
       return KERN_NO_SPACE;
     }
-    if (FLAG_v) {
+    if (flags()->verbosity) {
       Report("Mapped pages %p--%p for branch islands.\n",
              (void*)kIslandBeg, (void*)kIslandEnd);
     }
@@ -158,7 +158,7 @@
   };
   *ptr = island_allocator_pos;
   island_allocator_pos = (char*)island_allocator_pos + kPageSize;
-  if (FLAG_v) {
+  if (flags()->verbosity) {
     Report("Branch island allocated at %p\n", *ptr);
   }
   return err_none;
@@ -241,7 +241,7 @@
 void asan_dispatch_call_block_and_release(void *block) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *context = (asan_block_context_t*)block;
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("asan_dispatch_call_block_and_release(): "
            "context: %p, pthread_self: %p\n",
            block, pthread_self());
@@ -280,7 +280,7 @@
                                     dispatch_function_t func) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("dispatch_async_f(): context: %p, pthread_self: %p\n",
         asan_ctxt, pthread_self());
     PRINT_CURRENT_STACK();
@@ -293,7 +293,7 @@
                                    dispatch_function_t func) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("dispatch_sync_f(): context: %p, pthread_self: %p\n",
         asan_ctxt, pthread_self());
     PRINT_CURRENT_STACK();
@@ -307,7 +307,7 @@
                                     dispatch_function_t func) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("dispatch_after_f: %p\n", asan_ctxt);
     PRINT_CURRENT_STACK();
   }
@@ -319,7 +319,7 @@
                                             dispatch_function_t func) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("dispatch_barrier_async_f(): context: %p, pthread_self: %p\n",
            asan_ctxt, pthread_self());
     PRINT_CURRENT_STACK();
@@ -333,7 +333,7 @@
                                           dispatch_function_t func) {
   GET_STACK_TRACE_HERE(kStackTraceMax);
   asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("dispatch_group_async_f(): context: %p, pthread_self: %p\n",
            asan_ctxt, pthread_self());
     PRINT_CURRENT_STACK();
@@ -350,7 +350,7 @@
 // libdispatch API.
 extern "C"
 void *wrap_workitem_func(void *arg) {
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("wrap_workitem_func: %p, pthread_self: %p\n", arg, pthread_self());
   }
   asan_block_context_t *ctxt = (asan_block_context_t*)arg;
@@ -370,7 +370,7 @@
   asan_ctxt->block = workitem_arg;
   asan_ctxt->func = (dispatch_function_t)workitem_func;
   asan_ctxt->parent_tid = asanThreadRegistry().GetCurrentTidOrInvalid();
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("pthread_workqueue_additem_np: %p\n", asan_ctxt);
     PRINT_CURRENT_STACK();
   }
@@ -415,7 +415,7 @@
   // We don't need to intercept pthread_workqueue_additem_np() to support the
   // libdispatch API, but it helps us to debug the unsupported functions. Let's
   // intercept it only during verbose runs.
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     CHECK(INTERCEPT_FUNCTION(pthread_workqueue_additem_np));
   }
   // Normally CFStringCreateCopy should not copy constant CF strings.
@@ -429,7 +429,7 @@
   // Some of the library functions call free() directly, so we have to
   // intercept it.
   CHECK(INTERCEPT_FUNCTION(free));
-  if (FLAG_replace_cfallocator) {
+  if (flags()->replace_cfallocator) {
     CHECK(INTERCEPT_FUNCTION(__CFInitialize));
   }
 }

Modified: compiler-rt/trunk/lib/asan/asan_malloc_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_mac.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_mac.cc Mon Jul  9 09:36:04 2012
@@ -65,7 +65,7 @@
     malloc_zone_free(zone, ptr);
 #endif
   } else {
-    if (FLAG_replace_cfallocator) {
+    if (flags()->replace_cfallocator) {
       // Make sure we're not hitting the previous page. This may be incorrect
       // if ASan's malloc returns an address ending with 0xFF8, which will be
       // then padded to a page boundary with a CFAllocatorRef.
@@ -95,7 +95,7 @@
 // See http://code.google.com/p/address-sanitizer/issues/detail?id=87
 // and http://opensource.apple.com/source/CF/CF-550.43/CFRuntime.c
 INTERCEPTOR(void, __CFInitialize) {
-  CHECK(FLAG_replace_cfallocator);
+  CHECK(flags()->replace_cfallocator);
   CHECK(asan_inited);
   REAL(__CFInitialize)();
   if (!cf_asan) ReplaceCFAllocator();
@@ -169,7 +169,7 @@
 
 void ALWAYS_INLINE free_common(void *context, void *ptr) {
   if (!ptr) return;
-  if (!FLAG_mac_ignore_invalid_free || asan_mz_size(ptr)) {
+  if (!flags()->mac_ignore_invalid_free || asan_mz_size(ptr)) {
     GET_STACK_TRACE_HERE_FOR_FREE(ptr);
     asan_free(ptr, &stack);
   } else {
@@ -403,7 +403,7 @@
   // Make sure the default allocator was replaced.
   CHECK(malloc_default_zone() == &asan_zone);
 
-  if (FLAG_replace_cfallocator) {
+  if (flags()->replace_cfallocator) {
     // If __CFInitialize() hasn't been called yet, cf_asan will be created and
     // installed as the default allocator after __CFInitialize() finishes (see
     // the interceptor for __CFInitialize() above). Otherwise install cf_asan

Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Mon Jul  9 09:36:04 2012
@@ -75,10 +75,10 @@
 // * if user asks to unpoison region [left, right), the program unpoisons
 // at most [AlignDown(left), right).
 void __asan_poison_memory_region(void const volatile *addr, uptr size) {
-  if (!FLAG_allow_user_poisoning || size == 0) return;
+  if (!flags()->allow_user_poisoning || size == 0) return;
   uptr beg_addr = (uptr)addr;
   uptr end_addr = beg_addr + size;
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     Printf("Trying to poison memory region [%p, %p)\n",
            (void*)beg_addr, (void*)end_addr);
   }
@@ -117,10 +117,10 @@
 }
 
 void __asan_unpoison_memory_region(void const volatile *addr, uptr size) {
-  if (!FLAG_allow_user_poisoning || size == 0) return;
+  if (!flags()->allow_user_poisoning || size == 0) return;
   uptr beg_addr = (uptr)addr;
   uptr end_addr = beg_addr + size;
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     Printf("Trying to unpoison memory region [%p, %p)\n",
            (void*)beg_addr, (void*)end_addr);
   }

Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Mon Jul  9 09:36:04 2012
@@ -40,9 +40,9 @@
   REAL(memset)(&sigact, 0, sizeof(sigact));
   sigact.sa_sigaction = handler;
   sigact.sa_flags = SA_SIGINFO;
-  if (FLAG_use_sigaltstack) sigact.sa_flags |= SA_ONSTACK;
+  if (flags()->use_sigaltstack) sigact.sa_flags |= SA_ONSTACK;
   CHECK(0 == REAL(sigaction)(signum, &sigact, 0));
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     Report("Installed the sigaction for signal %d\n", signum);
   }
 }
@@ -76,7 +76,7 @@
   altstack.ss_flags = 0;
   altstack.ss_size = kAltStackSize;
   CHECK(0 == sigaltstack(&altstack, 0));
-  if (FLAG_v > 0) {
+  if (flags()->verbosity > 0) {
     Report("Alternative stack for T%d set: [%p,%p)\n",
            asanThreadRegistry().GetCurrentTidOrInvalid(),
            altstack.ss_sp, (char*)altstack.ss_sp + altstack.ss_size);
@@ -96,7 +96,7 @@
   // Set the alternate signal stack for the main thread.
   // This will cause SetAlternateSignalStack to be called twice, but the stack
   // will be actually set only once.
-  if (FLAG_use_sigaltstack) SetAlternateSignalStack();
+  if (flags()->use_sigaltstack) SetAlternateSignalStack();
   MaybeInstallSigaction(SIGSEGV, ASAN_OnSIGSEGV);
   MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV);
 }

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon Jul  9 09:36:04 2012
@@ -22,6 +22,7 @@
 #include "asan_thread.h"
 #include "asan_thread_registry.h"
 #include "sanitizer_common/sanitizer_atomic.h"
+#include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_libc.h"
 
 namespace __sanitizer {
@@ -33,17 +34,17 @@
     // Don't die twice - run a busy loop.
     while (1) { }
   }
-  if (FLAG_sleep_before_dying) {
-    Report("Sleeping for %zd second(s)\n", FLAG_sleep_before_dying);
-    SleepForSeconds(FLAG_sleep_before_dying);
+  if (flags()->sleep_before_dying) {
+    Report("Sleeping for %zd second(s)\n", flags()->sleep_before_dying);
+    SleepForSeconds(flags()->sleep_before_dying);
   }
-  if (FLAG_unmap_shadow_on_exit)
+  if (flags()->unmap_shadow_on_exit)
     UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
   if (death_callback)
     death_callback();
-  if (FLAG_abort_on_error)
+  if (flags()->abort_on_error)
     Abort();
-  Exit(FLAG_exitcode);
+  Exit(flags()->exitcode);
 }
 
 void CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2) {
@@ -60,31 +61,97 @@
 // -------------------------- Flags ------------------------- {{{1
 static const uptr kMallocContextSize = 30;
 
-uptr  FLAG_malloc_context_size = kMallocContextSize;
-uptr  FLAG_max_malloc_fill_size = 0;
-s64 FLAG_v = 0;
-uptr  FLAG_redzone = (ASAN_LOW_MEMORY) ? 64 : 128;  // power of two, >= 32
-uptr  FLAG_quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28;
-static s64    FLAG_atexit = 0;
-bool    FLAG_poison_shadow = 1;
-s64 FLAG_report_globals = 1;
-bool    FLAG_handle_segv = ASAN_NEEDS_SEGV;
-bool    FLAG_use_sigaltstack = 0;
-bool    FLAG_symbolize = 0;
-s64 FLAG_demangle = 1;
-s64 FLAG_debug = 0;
-bool    FLAG_replace_cfallocator = 1;  // Used on Mac only.
-bool    FLAG_mac_ignore_invalid_free = 0;  // Used on Mac only.
-bool    FLAG_replace_str = 1;
-bool    FLAG_replace_intrin = 1;
-bool    FLAG_use_fake_stack = 1;
-s64 FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE;
-bool    FLAG_allow_user_poisoning = 1;
-s64 FLAG_sleep_before_dying = 0;
-bool    FLAG_abort_on_error = 0;
-bool    FLAG_unmap_shadow_on_exit = 0;
-bool    FLAG_disable_core = __WORDSIZE == 64;
-bool    FLAG_check_malloc_usable_size = 1;
+static Flags asan_flags;
+
+Flags *flags() {
+  return &asan_flags;
+}
+
+// Can be overriden in frontend.
+void WEAK OverrideFlags(Flags *f) {
+  (void)f;
+}
+
+static void ParseFlagsFromString(Flags *f, const char *str) {
+  ParseFlag(str, &f->quarantine_size, "quarantine_size");
+  ParseFlag(str, &f->symbolize, "symbolize");
+  ParseFlag(str, &f->verbosity, "verbosity");
+  ParseFlag(str, &f->redzone, "redzone");
+  CHECK(f->redzone >= 16);
+  CHECK(IsPowerOfTwo(f->redzone));
+
+  ParseFlag(str, &f->debug, "debug");
+  ParseFlag(str, &f->poison_shadow, "poison_shadow");
+  ParseFlag(str, &f->report_globals, "report_globals");
+  ParseFlag(str, &f->malloc_context_size, "malloc_context_size");
+  CHECK(f->malloc_context_size <= kMallocContextSize);
+
+  ParseFlag(str, &f->replace_str, "replace_str");
+  ParseFlag(str, &f->replace_intrin, "replace_intrin");
+  ParseFlag(str, &f->replace_cfallocator, "replace_cfallocator");
+  ParseFlag(str, &f->mac_ignore_invalid_free, "mac_ignore_invalid_free");
+  ParseFlag(str, &f->use_fake_stack, "use_fake_stack");
+  ParseFlag(str, &f->max_malloc_fill_size, "max_malloc_fill_size");
+  ParseFlag(str, &f->exitcode, "exitcode");
+  ParseFlag(str, &f->allow_user_poisoning, "allow_user_poisoning");
+  ParseFlag(str, &f->sleep_before_dying, "sleep_before_dying");
+  ParseFlag(str, &f->handle_segv, "handle_segv");
+  ParseFlag(str, &f->use_sigaltstack, "use_sigaltstack");
+  // Allow the users to work around the bug in Nvidia drivers prior to 295.*.
+  ParseFlag(str, &f->check_malloc_usable_size, "check_malloc_usable_size");
+  ParseFlag(str, &f->unmap_shadow_on_exit, "unmap_shadow_on_exit");
+  ParseFlag(str, &f->abort_on_error, "abort_on_error");
+  ParseFlag(str, &f->atexit, "atexit");
+  // By default, disable core dumper on 64-bit --
+  // it makes little sense to dump 16T+ core.
+  ParseFlag(str, &f->disable_core, "disable_core");
+}
+
+void InitializeFlags(Flags *f, const char *env) {
+  internal_memset(f, 0, sizeof(*f));
+
+  f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 24 : 1UL << 28;
+  f->symbolize = false;
+  f->verbosity = 0;
+  f->redzone = (ASAN_LOW_MEMORY) ? 64 : 128;  // power of two, >= 32.
+  f->debug = 0;
+  f->poison_shadow = true;
+  f->report_globals = 1;
+  f->malloc_context_size = kMallocContextSize;
+  f->replace_str = true;
+  f->replace_intrin = true;
+  f->replace_cfallocator = true;  // Used on Mac only.
+  f->mac_ignore_invalid_free = false;  // Used on Mac only.
+  f->use_fake_stack = true;
+  f->max_malloc_fill_size = 0;
+  f->exitcode = ASAN_DEFAULT_FAILURE_EXITCODE;
+  f->allow_user_poisoning = true;
+  f->sleep_before_dying = 0;
+  f->handle_segv = ASAN_NEEDS_SEGV;
+  f->use_sigaltstack = false;
+  f->check_malloc_usable_size = true;
+  f->unmap_shadow_on_exit = false;
+  f->abort_on_error = false;
+  f->atexit = false;
+  f->disable_core = (__WORDSIZE == 64);
+
+  // Let a frontend override.
+  OverrideFlags(f);
+
+  // Override from user-specified string.
+#if !defined(_WIN32)
+  if (__asan_default_options) {
+    ParseFlagsFromString(f, __asan_default_options);
+    if (flags()->verbosity) {
+      Report("Using the defaults from __asan_default_options: %s\n",
+             __asan_default_options);
+    }
+  }
+#endif
+
+  // Override from command line.
+  ParseFlagsFromString(f, env);
+}
 
 // -------------------------- Globals --------------------- {{{1
 int asan_inited;
@@ -264,44 +331,6 @@
 }
 
 // -------------------------- Init ------------------- {{{1
-static void IntFlagValue(const char *flags, const char *flag,
-                         s64 *out_val) {
-  if (!flags) return;
-  const char *str = internal_strstr(flags, flag);
-  if (!str) return;
-  *out_val = internal_atoll(str + internal_strlen(flag));
-}
-
-static void BoolFlagValue(const char *flags, const char *flag,
-                          bool *out_val) {
-  if (!flags) return;
-  const char *str = internal_strstr(flags, flag);
-  if (!str) return;
-  const char *suffix = str + internal_strlen(flag);
-  if (!internal_atoll(str + internal_strlen(flag))) {
-    if (suffix[0] == '0') {
-      *out_val = false;
-      return;
-    }
-  } else {
-    *out_val = true;
-    return;
-  }
-  switch (suffix[0]) {
-    case 'y':
-    case 't': {
-      *out_val = true;
-      break;
-    }
-    case 'n':
-    case 'f': {
-      *out_val = false;
-      break;
-    }
-    default: return;
-  }
-}
-
 static void asan_atexit() {
   AsanPrintf("AddressSanitizer exit stats:\n");
   __asan_print_accumulated_stats();
@@ -313,8 +342,8 @@
 using namespace __asan;  // NOLINT
 
 int __asan_set_error_exit_code(int exit_code) {
-  int old = FLAG_exitcode;
-  FLAG_exitcode = exit_code;
+  int old = flags()->exitcode;
+  flags()->exitcode = exit_code;
   return old;
 }
 
@@ -403,7 +432,7 @@
              access_size ? (is_write ? "WRITE" : "READ") : "ACCESS",
              access_size, (void*)addr, curr_tid);
 
-  if (FLAG_debug) {
+  if (flags()->debug) {
     PrintBytes("PC: ", (uptr*)pc);
   }
 
@@ -437,48 +466,6 @@
   Die();
 }
 
-static void ParseAsanOptions(const char *options) {
-  IntFlagValue(options, "malloc_context_size=",
-               (s64*)&FLAG_malloc_context_size);
-  CHECK(FLAG_malloc_context_size <= kMallocContextSize);
-
-  IntFlagValue(options, "max_malloc_fill_size=",
-               (s64*)&FLAG_max_malloc_fill_size);
-
-  IntFlagValue(options, "verbosity=", &FLAG_v);
-
-  IntFlagValue(options, "redzone=", (s64*)&FLAG_redzone);
-  CHECK(FLAG_redzone >= 16);
-  CHECK(IsPowerOfTwo(FLAG_redzone));
-  IntFlagValue(options, "quarantine_size=", (s64*)&FLAG_quarantine_size);
-
-  IntFlagValue(options, "atexit=", &FLAG_atexit);
-  BoolFlagValue(options, "poison_shadow=", &FLAG_poison_shadow);
-  IntFlagValue(options, "report_globals=", &FLAG_report_globals);
-  BoolFlagValue(options, "handle_segv=", &FLAG_handle_segv);
-  BoolFlagValue(options, "use_sigaltstack=", &FLAG_use_sigaltstack);
-  BoolFlagValue(options, "symbolize=", &FLAG_symbolize);
-  IntFlagValue(options, "demangle=", &FLAG_demangle);
-  IntFlagValue(options, "debug=", &FLAG_debug);
-  BoolFlagValue(options, "replace_cfallocator=", &FLAG_replace_cfallocator);
-  BoolFlagValue(options, "mac_ignore_invalid_free=",
-                &FLAG_mac_ignore_invalid_free);
-  BoolFlagValue(options, "replace_str=", &FLAG_replace_str);
-  BoolFlagValue(options, "replace_intrin=", &FLAG_replace_intrin);
-  BoolFlagValue(options, "use_fake_stack=", &FLAG_use_fake_stack);
-  IntFlagValue(options, "exitcode=", &FLAG_exitcode);
-  BoolFlagValue(options, "allow_user_poisoning=", &FLAG_allow_user_poisoning);
-  IntFlagValue(options, "sleep_before_dying=", &FLAG_sleep_before_dying);
-  BoolFlagValue(options, "abort_on_error=", &FLAG_abort_on_error);
-  BoolFlagValue(options, "unmap_shadow_on_exit=", &FLAG_unmap_shadow_on_exit);
-  // By default, disable core dumper on 64-bit --
-  // it makes little sense to dump 16T+ core.
-  BoolFlagValue(options, "disable_core=", &FLAG_disable_core);
-
-  // Allow the users to work around the bug in Nvidia drivers prior to 295.*.
-  BoolFlagValue(options, "check_malloc_usable_size=",
-                &FLAG_check_malloc_usable_size);
-}
 
 void __asan_init() {
   if (asan_inited) return;
@@ -487,24 +474,15 @@
   // Make sure we are not statically linked.
   AsanDoesNotSupportStaticLinkage();
 
-#if !defined(_WIN32)
-  if (__asan_default_options) {
-    ParseAsanOptions(__asan_default_options);
-    if (FLAG_v) {
-      Report("Using the defaults from __asan_default_options: %s\n",
-             __asan_default_options);
-    }
-  }
-#endif
-  // flags
+  // Initialize flags.
   const char *options = GetEnv("ASAN_OPTIONS");
-  ParseAsanOptions(options);
+  InitializeFlags(flags(), options);
 
-  if (FLAG_v && options) {
+  if (flags()->verbosity && options) {
     Report("Parsed ASAN_OPTIONS: %s\n", options);
   }
 
-  if (FLAG_atexit) {
+  if (flags()->atexit) {
     Atexit(asan_atexit);
   }
 
@@ -514,7 +492,7 @@
   ReplaceSystemMalloc();
   ReplaceOperatorsNewAndDelete();
 
-  if (FLAG_v) {
+  if (flags()->verbosity) {
     Printf("|| `[%p, %p]` || HighMem    ||\n",
            (void*)kHighMemBeg, (void*)kHighMemEnd);
     Printf("|| `[%p, %p]` || HighShadow ||\n",
@@ -530,8 +508,8 @@
            (void*)MEM_TO_SHADOW(kLowShadowEnd),
            (void*)MEM_TO_SHADOW(kHighShadowBeg),
            (void*)MEM_TO_SHADOW(kHighShadowEnd));
-    Printf("red_zone=%zu\n", (uptr)FLAG_redzone);
-    Printf("malloc_context_size=%zu\n", (uptr)FLAG_malloc_context_size);
+    Printf("red_zone=%zu\n", (uptr)flags()->redzone);
+    Printf("malloc_context_size=%zu\n", (uptr)flags()->malloc_context_size);
 
     Printf("SHADOW_SCALE: %zx\n", (uptr)SHADOW_SCALE);
     Printf("SHADOW_GRANULARITY: %zx\n", (uptr)SHADOW_GRANULARITY);
@@ -539,7 +517,7 @@
     CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
   }
 
-  if (FLAG_disable_core) {
+  if (flags()->disable_core) {
     DisableCoreDumper();
   }
 
@@ -574,7 +552,7 @@
   asanThreadRegistry().GetMain()->ThreadStart();
   force_interface_symbols();  // no-op.
 
-  if (FLAG_v) {
+  if (flags()->verbosity) {
     Report("AddressSanitizer Init done\n");
   }
 }

Modified: compiler-rt/trunk/lib/asan/asan_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.cc Mon Jul  9 09:36:04 2012
@@ -45,7 +45,7 @@
     uptr pc = addr[i];
     AddressInfo addr_frames[64];
     uptr addr_frames_num = 0;
-    if (FLAG_symbolize) {
+    if (flags()->symbolize) {
       bool last_frame = (i == size - 1) || !addr[i + 1];
       addr_frames_num = SymbolizeCode(pc - !last_frame, addr_frames,
                                       ASAN_ARRAY_SIZE(addr_frames));

Modified: compiler-rt/trunk/lib/asan/asan_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Mon Jul  9 09:36:04 2012
@@ -90,10 +90,10 @@
       AsanStackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
 
 #define GET_STACK_TRACE_HERE_FOR_MALLOC                             \
-  GET_STACK_TRACE_HERE(FLAG_malloc_context_size)
+  GET_STACK_TRACE_HERE(flags()->malloc_context_size)
 
 #define GET_STACK_TRACE_HERE_FOR_FREE(ptr)                          \
-  GET_STACK_TRACE_HERE(FLAG_malloc_context_size)
+  GET_STACK_TRACE_HERE(flags()->malloc_context_size)
 
 #define PRINT_CURRENT_STACK()                    \
   {                                              \

Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Mon Jul  9 09:36:04 2012
@@ -42,7 +42,7 @@
 
 void AsanThreadSummary::TSDDtor(void *tsd) {
   AsanThreadSummary *summary = (AsanThreadSummary*)tsd;
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     Report("T%d TSDDtor\n", summary->tid());
   }
   if (summary->thread()) {
@@ -51,7 +51,7 @@
 }
 
 void AsanThread::Destroy() {
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     Report("T%d exited\n", tid());
   }
 
@@ -71,7 +71,7 @@
   CHECK(AddrIsInMem(stack_bottom_));
   CHECK(AddrIsInMem(stack_top_));
   ClearShadowForThreadStack();
-  if (FLAG_v >= 1) {
+  if (flags()->verbosity >= 1) {
     int local = 0;
     Report("T%d: stack [%p,%p) size 0x%zx; local=%p\n",
            tid(), (void*)stack_bottom_, (void*)stack_top_,
@@ -82,7 +82,7 @@
 
 thread_return_t AsanThread::ThreadStart() {
   Init();
-  if (FLAG_use_sigaltstack) SetAlternateSignalStack();
+  if (flags()->use_sigaltstack) SetAlternateSignalStack();
 
   if (!start_routine_) {
     // start_routine_ == 0 if we're on the main thread or on one of the
@@ -94,7 +94,7 @@
 
   thread_return_t res = start_routine_(arg_);
   malloc_storage().CommitBack();
-  if (FLAG_use_sigaltstack) UnsetAlternateSignalStack();
+  if (flags()->use_sigaltstack) UnsetAlternateSignalStack();
 
   this->Destroy();
 

Modified: compiler-rt/trunk/lib/asan/asan_thread_registry.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread_registry.cc?rev=159933&r1=159932&r2=159933&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread_registry.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread_registry.cc Mon Jul  9 09:36:04 2012
@@ -88,7 +88,7 @@
 
 void AsanThreadRegistry::SetCurrent(AsanThread *t) {
   CHECK(t->summary());
-  if (FLAG_v >= 2) {
+  if (flags()->verbosity >= 2) {
     Report("SetCurrent: %p for thread %p\n",
            t->summary(), (void*)GetThreadSelf());
   }





More information about the llvm-commits mailing list