From 6866dba92ac842fc513ba339ba849a953ffb7507 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 15 Oct 2013 13:28:51 +0000 Subject: tsan: move verbosity flag to CommonFlags git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@192701 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/asan/asan_fake_stack.cc | 2 +- lib/asan/asan_flags.h | 2 -- lib/asan/asan_interceptors.cc | 6 +++--- lib/asan/asan_mac.cc | 10 +++++----- lib/asan/asan_poisoning.cc | 9 +++++---- lib/asan/asan_posix.cc | 4 ++-- lib/asan/asan_rtl.cc | 10 ++++------ lib/asan/asan_thread.cc | 8 ++++---- lib/msan/msan.cc | 10 ++++------ lib/msan/msan_flags.h | 1 - lib/msan/msan_interceptors.cc | 2 +- lib/msan/msan_linux.cc | 2 +- lib/msan/msan_report.cc | 2 +- lib/sanitizer_common/sanitizer_flags.h | 2 ++ lib/tsan/rtl/tsan_flags.cc | 13 +++++++------ lib/tsan/rtl/tsan_flags.h | 2 -- 16 files changed, 40 insertions(+), 45 deletions(-) diff --git a/lib/asan/asan_fake_stack.cc b/lib/asan/asan_fake_stack.cc index 4f617cac..d3e55bff 100644 --- a/lib/asan/asan_fake_stack.cc +++ b/lib/asan/asan_fake_stack.cc @@ -45,7 +45,7 @@ FakeStack *FakeStack::Create(uptr stack_size_log) { FakeStack *res = reinterpret_cast( MmapOrDie(RequiredSize(stack_size_log), "FakeStack")); res->stack_size_log_ = stack_size_log; - if (flags()->verbosity) { + if (common_flags()->verbosity) { u8 *p = reinterpret_cast(res); Report("T%d: FakeStack created: %p -- %p stack_size_log: %zd \n", GetCurrentTidOrInvalid(), p, diff --git a/lib/asan/asan_flags.h b/lib/asan/asan_flags.h index 7c2a1e36..93f7346c 100644 --- a/lib/asan/asan_flags.h +++ b/lib/asan/asan_flags.h @@ -32,8 +32,6 @@ struct Flags { // Lower value may reduce memory usage but increase the chance of // false negatives. int quarantine_size; - // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output). - int verbosity; // Size (in bytes) of redzones around heap objects. // Requirement: redzone >= 32, is a power of two. int redzone; diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc index b45266dd..514c1081 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cc @@ -263,7 +263,7 @@ static void MlockIsUnsupported() { static bool printed = false; if (printed) return; printed = true; - if (flags()->verbosity > 0) { + if (common_flags()->verbosity > 0) { Printf("INFO: AddressSanitizer ignores " "mlock/mlockall/munlock/munlockall\n"); } @@ -651,7 +651,7 @@ INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg, #if !SANITIZER_MAC #define ASAN_INTERCEPT_FUNC(name) do { \ - if (!INTERCEPT_FUNCTION(name) && flags()->verbosity > 0) \ + if (!INTERCEPT_FUNCTION(name) && common_flags()->verbosity > 0) \ Report("AddressSanitizer: failed to intercept '" #name "'\n"); \ } while (0) #else @@ -771,7 +771,7 @@ void InitializeAsanInterceptors() { InitializeWindowsInterceptors(); #endif - if (flags()->verbosity > 0) { + if (common_flags()->verbosity > 0) { Report("AddressSanitizer: libc interceptors initialized\n"); } } diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc index 92008376..e27d70ad 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cc @@ -174,7 +174,7 @@ void MaybeReexec() { // Set DYLD_INSERT_LIBRARIES equal to the runtime dylib name. setenv(kDyldInsertLibraries, info.dli_fname, /*overwrite*/0); } - if (flags()->verbosity >= 1) { + if (common_flags()->verbosity >= 1) { Report("exec()-ing the program with\n"); Report("%s=%s\n", kDyldInsertLibraries, new_env); Report("to enable ASan wrappers.\n"); @@ -311,7 +311,7 @@ extern "C" void asan_dispatch_call_block_and_release(void *block) { GET_STACK_TRACE_THREAD; asan_block_context_t *context = (asan_block_context_t*)block; - if (flags()->verbosity >= 2) { + if (common_flags()->verbosity >= 2) { Report("asan_dispatch_call_block_and_release(): " "context: %p, pthread_self: %p\n", block, pthread_self()); @@ -346,7 +346,7 @@ asan_block_context_t *alloc_asan_context(void *ctxt, dispatch_function_t func, dispatch_function_t func) { \ GET_STACK_TRACE_THREAD; \ asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); \ - if (flags()->verbosity >= 2) { \ + if (common_flags()->verbosity >= 2) { \ Report(#dispatch_x_f "(): context: %p, pthread_self: %p\n", \ asan_ctxt, pthread_self()); \ PRINT_CURRENT_STACK(); \ @@ -364,7 +364,7 @@ INTERCEPTOR(void, dispatch_after_f, dispatch_time_t when, dispatch_function_t func) { GET_STACK_TRACE_THREAD; asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); - if (flags()->verbosity >= 2) { + if (common_flags()->verbosity >= 2) { Report("dispatch_after_f: %p\n", asan_ctxt); PRINT_CURRENT_STACK(); } @@ -377,7 +377,7 @@ INTERCEPTOR(void, dispatch_group_async_f, dispatch_group_t group, dispatch_function_t func) { GET_STACK_TRACE_THREAD; asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); - if (flags()->verbosity >= 2) { + if (common_flags()->verbosity >= 2) { Report("dispatch_group_async_f(): context: %p, pthread_self: %p\n", asan_ctxt, pthread_self()); PRINT_CURRENT_STACK(); diff --git a/lib/asan/asan_poisoning.cc b/lib/asan/asan_poisoning.cc index 59309535..0033b61c 100644 --- a/lib/asan/asan_poisoning.cc +++ b/lib/asan/asan_poisoning.cc @@ -14,6 +14,7 @@ #include "asan_poisoning.h" #include "sanitizer_common/sanitizer_libc.h" +#include "sanitizer_common/sanitizer_flags.h" namespace __asan { @@ -68,7 +69,7 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) { if (!flags()->allow_user_poisoning || size == 0) return; uptr beg_addr = (uptr)addr; uptr end_addr = beg_addr + size; - if (flags()->verbosity >= 1) { + if (common_flags()->verbosity >= 1) { Printf("Trying to poison memory region [%p, %p)\n", (void*)beg_addr, (void*)end_addr); } @@ -110,7 +111,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, uptr size) { if (!flags()->allow_user_poisoning || size == 0) return; uptr beg_addr = (uptr)addr; uptr end_addr = beg_addr + size; - if (flags()->verbosity >= 1) { + if (common_flags()->verbosity >= 1) { Printf("Trying to unpoison memory region [%p, %p)\n", (void*)beg_addr, (void*)end_addr); } @@ -244,13 +245,13 @@ static void PoisonAlignedStackMemory(uptr addr, uptr size, bool do_poison) { } void __asan_poison_stack_memory(uptr addr, uptr size) { - if (flags()->verbosity > 0) + if (common_flags()->verbosity > 0) Report("poisoning: %p %zx\n", (void*)addr, size); PoisonAlignedStackMemory(addr, size, true); } void __asan_unpoison_stack_memory(uptr addr, uptr size) { - if (flags()->verbosity > 0) + if (common_flags()->verbosity > 0) Report("unpoisoning: %p %zx\n", (void*)addr, size); PoisonAlignedStackMemory(addr, size, false); } diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc index 1926fccb..bcc6b381 100644 --- a/lib/asan/asan_posix.cc +++ b/lib/asan/asan_posix.cc @@ -44,7 +44,7 @@ static void MaybeInstallSigaction(int signum, sigact.sa_flags = SA_SIGINFO; if (flags()->use_sigaltstack) sigact.sa_flags |= SA_ONSTACK; CHECK_EQ(0, REAL(sigaction)(signum, &sigact, 0)); - if (flags()->verbosity >= 1) { + if (common_flags()->verbosity >= 1) { Report("Installed the sigaction for signal %d\n", signum); } } @@ -71,7 +71,7 @@ void SetAlternateSignalStack() { altstack.ss_flags = 0; altstack.ss_size = kAltStackSize; CHECK_EQ(0, sigaltstack(&altstack, 0)); - if (flags()->verbosity > 0) { + if (common_flags()->verbosity > 0) { Report("Alternative stack for T%d set: [%p,%p)\n", GetCurrentTidOrInvalid(), altstack.ss_sp, (char*)altstack.ss_sp + altstack.ss_size); diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index d93764ce..b34a386b 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -92,7 +92,6 @@ static void ParseFlagsFromString(Flags *f, const char *str) { CHECK((uptr)common_flags()->malloc_context_size <= kStackTraceMax); ParseFlag(str, &f->quarantine_size, "quarantine_size"); - ParseFlag(str, &f->verbosity, "verbosity"); ParseFlag(str, &f->redzone, "redzone"); CHECK_GE(f->redzone, 16); CHECK(IsPowerOfTwo(f->redzone)); @@ -146,7 +145,6 @@ void InitializeFlags(Flags *f, const char *env) { internal_memset(f, 0, sizeof(*f)); f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28; - f->verbosity = 0; f->redzone = 16; f->debug = false; f->report_globals = 1; @@ -186,7 +184,7 @@ void InitializeFlags(Flags *f, const char *env) { // Override from user-specified string. ParseFlagsFromString(f, MaybeCallAsanDefaultOptions()); - if (flags()->verbosity) { + if (common_flags()->verbosity) { Report("Using the defaults from __asan_default_options: %s\n", MaybeCallAsanDefaultOptions()); } @@ -464,7 +462,7 @@ void __asan_init() { __asan_option_detect_stack_use_after_return = flags()->detect_stack_use_after_return; - if (flags()->verbosity && options) { + if (common_flags()->verbosity && options) { Report("Parsed ASAN_OPTIONS: %s\n", options); } @@ -497,7 +495,7 @@ void __asan_init() { } #endif - if (flags()->verbosity) + if (common_flags()->verbosity) PrintAddressSpaceLayout(); if (flags()->disable_core) { @@ -570,7 +568,7 @@ void __asan_init() { } #endif // CAN_SANITIZE_LEAKS - if (flags()->verbosity) { + if (common_flags()->verbosity) { Report("AddressSanitizer Init done\n"); } } diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 7ffac991..5f75f600 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -85,14 +85,14 @@ AsanThread *AsanThread::Create(thread_callback_t start_routine, void AsanThread::TSDDtor(void *tsd) { AsanThreadContext *context = (AsanThreadContext*)tsd; - if (flags()->verbosity >= 1) + if (common_flags()->verbosity >= 1) Report("T%d TSDDtor\n", context->tid); if (context->thread) context->thread->Destroy(); } void AsanThread::Destroy() { - if (flags()->verbosity >= 1) { + if (common_flags()->verbosity >= 1) { Report("T%d exited\n", tid()); } @@ -138,7 +138,7 @@ void AsanThread::Init() { CHECK(AddrIsInMem(stack_bottom_)); CHECK(AddrIsInMem(stack_top_ - 1)); ClearShadowForThreadStackAndTLS(); - if (flags()->verbosity >= 1) { + if (common_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_, @@ -265,7 +265,7 @@ AsanThread *GetCurrentThread() { void SetCurrentThread(AsanThread *t) { CHECK(t->context()); - if (flags()->verbosity >= 2) { + if (common_flags()->verbosity >= 2) { Report("SetCurrentThread: %p for thread %p\n", t->context(), (void*)GetThreadSelf()); } diff --git a/lib/msan/msan.cc b/lib/msan/msan.cc index aebbd052..4b4f7d47 100644 --- a/lib/msan/msan.cc +++ b/lib/msan/msan.cc @@ -129,7 +129,6 @@ static void ParseFlagsFromString(Flags *f, const char *str) { Die(); } ParseFlag(str, &f->report_umrs, "report_umrs"); - ParseFlag(str, &f->verbosity, "verbosity"); ParseFlag(str, &f->wrap_signals, "wrap_signals"); // keep_going is an old name for halt_on_error, @@ -157,7 +156,6 @@ static void InitializeFlags(Flags *f, const char *options) { f->poison_in_free = true; f->exit_code = 77; f->report_umrs = true; - f->verbosity = 0; f->wrap_signals = true; f->halt_on_error = !&__msan_keep_going; @@ -304,7 +302,7 @@ void __msan_init() { InitializeFlags(&msan_flags, msan_options); __sanitizer_set_report_path(common_flags()->log_path); if (StackSizeIsUnlimited()) { - if (flags()->verbosity) + if (common_flags()->verbosity) Printf("Unlimited stack, doing reexec\n"); // A reasonably large stack size. It is bigger than the usual 8Mb, because, // well, the program could have been run with unlimited stack for a reason. @@ -312,12 +310,12 @@ void __msan_init() { ReExec(); } - if (flags()->verbosity) + if (common_flags()->verbosity) Printf("MSAN_OPTIONS: %s\n", msan_options ? msan_options : ""); msan_running_under_dr = IsRunningUnderDr(); __msan_clear_on_return(); - if (__msan_get_track_origins() && flags()->verbosity > 0) + if (__msan_get_track_origins() && common_flags()->verbosity > 0) Printf("msan_track_origins\n"); if (!InitShadow(/* prot1 */ false, /* prot2 */ true, /* map_shadow */ true, __msan_get_track_origins())) { @@ -341,7 +339,7 @@ void __msan_init() { GetThreadStackTopAndBottom(/* at_initialization */true, &__msan_stack_bounds.stack_top, &__msan_stack_bounds.stack_bottom); - if (flags()->verbosity) + if (common_flags()->verbosity) Printf("MemorySanitizer init done\n"); msan_init_is_running = 0; msan_inited = 1; diff --git a/lib/msan/msan_flags.h b/lib/msan/msan_flags.h index 318ea7cf..93fa8a60 100644 --- a/lib/msan/msan_flags.h +++ b/lib/msan/msan_flags.h @@ -19,7 +19,6 @@ namespace __msan { // Flags. struct Flags { int exit_code; - int verbosity; bool poison_heap_with_zeroes; // default: false bool poison_stack_with_zeroes; // default: false bool poison_in_malloc; // default: true diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index 932d58f4..30861543 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -1082,7 +1082,7 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr, void *(*callback)(void*), attr = &myattr; } - AdjustStackSizeLinux(attr, flags()->verbosity); + AdjustStackSizeLinux(attr, common_flags()->verbosity); int res = REAL(pthread_create)(th, attr, callback, param); if (attr == &myattr) diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc index b82ed8ce..ff5fc735 100644 --- a/lib/msan/msan_linux.cc +++ b/lib/msan/msan_linux.cc @@ -45,7 +45,7 @@ static const uptr kOriginsBeg = kBad2Beg; static const uptr kOriginsEnd = kBad2End; bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) { - if (flags()->verbosity) { + if (common_flags()->verbosity) { Printf("__msan_init %p\n", &__msan_init); Printf("Memory : %p %p\n", kMemBeg, kMemEnd); Printf("Bad2 : %p %p\n", kBad2Beg, kBad2End); diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc index 997959ef..7b5a914f 100644 --- a/lib/msan/msan_report.cc +++ b/lib/msan/msan_report.cc @@ -41,7 +41,7 @@ static void PrintStack(const uptr *trace, uptr size) { static void DescribeOrigin(u32 origin) { Decorator d; - if (flags()->verbosity) + if (common_flags()->verbosity) Printf(" raw origin id: %d\n", origin); uptr pc; if (const char *so = GetOriginDescrIfStack(origin, &pc)) { diff --git a/lib/sanitizer_common/sanitizer_flags.h b/lib/sanitizer_common/sanitizer_flags.h index 7740b240..efea6fea 100644 --- a/lib/sanitizer_common/sanitizer_flags.h +++ b/lib/sanitizer_common/sanitizer_flags.h @@ -41,6 +41,8 @@ struct CommonFlags { // The special values are "stdout" and "stderr". // The default is "stderr". const char *log_path; + // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output). + int verbosity; // Enable memory leak detection. bool detect_leaks; // Invoke leak checking in an atexit handler. Has no effect if diff --git a/lib/tsan/rtl/tsan_flags.cc b/lib/tsan/rtl/tsan_flags.cc index 679ea992..1eeb2af5 100644 --- a/lib/tsan/rtl/tsan_flags.cc +++ b/lib/tsan/rtl/tsan_flags.cc @@ -53,7 +53,6 @@ void InitializeFlags(Flags *f, const char *env) { f->exitcode = 66; f->halt_on_error = false; f->atexit_sleep_ms = 1000; - f->verbosity = 0; f->profile_memory = ""; f->flush_memory_ms = 0; f->flush_symbolizer_ms = 5000; @@ -63,6 +62,13 @@ void InitializeFlags(Flags *f, const char *env) { f->history_size = kGoMode ? 1 : 2; // There are a lot of goroutines in Go. f->io_sync = 1; + ParseCommonFlagsFromString("strip_path_prefix="); + ParseCommonFlagsFromString("log_path=stderr"); + ParseCommonFlagsFromString("external_symbolizer_path="); + ParseCommonFlagsFromString("allocator_may_return_null=0"); + ParseCommonFlagsFromString("verbosity=0"); + *static_cast(f) = *common_flags(); + // Let a frontend override. OverrideFlags(f); @@ -83,7 +89,6 @@ void InitializeFlags(Flags *f, const char *env) { ParseFlag(env, &f->exitcode, "exitcode"); ParseFlag(env, &f->halt_on_error, "halt_on_error"); ParseFlag(env, &f->atexit_sleep_ms, "atexit_sleep_ms"); - ParseFlag(env, &f->verbosity, "verbosity"); ParseFlag(env, &f->profile_memory, "profile_memory"); ParseFlag(env, &f->flush_memory_ms, "flush_memory_ms"); ParseFlag(env, &f->flush_symbolizer_ms, "flush_symbolizer_ms"); @@ -111,10 +116,6 @@ void InitializeFlags(Flags *f, const char *env) { } *common_flags() = *f; - ParseCommonFlagsFromString("strip_path_prefix="); - ParseCommonFlagsFromString("log_path=stderr"); - ParseCommonFlagsFromString("external_symbolizer_path="); - ParseCommonFlagsFromString("allocator_may_return_null=0"); ParseCommonFlagsFromString(env); *static_cast(f) = *common_flags(); } diff --git a/lib/tsan/rtl/tsan_flags.h b/lib/tsan/rtl/tsan_flags.h index b240fdce..3916df3c 100644 --- a/lib/tsan/rtl/tsan_flags.h +++ b/lib/tsan/rtl/tsan_flags.h @@ -63,8 +63,6 @@ struct Flags : CommonFlags { // Sleep in main thread before exiting for that many ms // (useful to catch "at exit" races). int atexit_sleep_ms; - // Verbosity level (0 - silent, 1 - a bit of output, 2+ - more output). - int verbosity; // If set, periodically write memory profile to that file. const char *profile_memory; // Flush shadow memory every X ms. -- cgit v1.2.3