[compiler-rt] r226566 - [asan] Allow changing verbosity in activation flags.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Tue Jan 20 05:21:21 PST 2015
Author: eugenis
Date: Tue Jan 20 07:21:20 2015
New Revision: 226566
URL: http://llvm.org/viewvc/llvm-project?rev=226566&view=rev
Log:
[asan] Allow changing verbosity in activation flags.
This change removes some debug output in asan_flags.cc that
was reading the verbosity level before all the flags were parsed.
Modified:
compiler-rt/trunk/lib/asan/asan_activation.cc
compiler-rt/trunk/lib/asan/asan_activation_flags.inc
compiler-rt/trunk/lib/asan/asan_fake_stack.cc
compiler-rt/trunk/lib/asan/asan_flags.cc
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/asan/asan_poisoning.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/lsan/lsan_common.cc
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan_report.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc
compiler-rt/trunk/test/asan/TestCases/default_options.cc
Modified: compiler-rt/trunk/lib/asan/asan_activation.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_activation.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_activation.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_activation.cc Tue Jan 20 07:21:20 2015
@@ -53,6 +53,7 @@ static struct AsanDeactivatedFlags {
f.poison_heap = poison_heap;
cf.coverage = coverage;
cf.coverage_dir = coverage_dir;
+ cf.verbosity = Verbosity();
cf.help = false; // this is activation-specific help
// Check if activation flags need to be overriden.
@@ -65,7 +66,9 @@ static struct AsanDeactivatedFlags {
GetExtraActivationFlags(buf, sizeof(buf));
parser.ParseString(buf);
- if (common_flags()->verbosity) ReportUnrecognizedFlags();
+ SetVerbosity(cf.verbosity);
+
+ if (Verbosity()) ReportUnrecognizedFlags();
if (cf.help) parser.PrintFlagDescriptions();
@@ -130,7 +133,7 @@ void AsanActivate() {
ReInitializeAllocator(asan_deactivated_flags.allocator_options);
asan_is_deactivated = false;
- if (common_flags()->verbosity) {
+ if (Verbosity()) {
Report("Activated with flags:\n");
asan_deactivated_flags.Print();
}
Modified: compiler-rt/trunk/lib/asan/asan_activation_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_activation_flags.inc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_activation_flags.inc (original)
+++ compiler-rt/trunk/lib/asan/asan_activation_flags.inc Tue Jan 20 07:21:20 2015
@@ -31,4 +31,5 @@ COMMON_ACTIVATION_FLAG(bool, allocator_m
COMMON_ACTIVATION_FLAG(int, malloc_context_size)
COMMON_ACTIVATION_FLAG(bool, coverage)
COMMON_ACTIVATION_FLAG(const char *, coverage_dir)
+COMMON_ACTIVATION_FLAG(int, verbosity)
COMMON_ACTIVATION_FLAG(bool, help)
Modified: compiler-rt/trunk/lib/asan/asan_fake_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_fake_stack.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_fake_stack.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_fake_stack.cc Tue Jan 20 07:21:20 2015
@@ -60,7 +60,7 @@ FakeStack *FakeStack::Create(uptr stack_
void FakeStack::Destroy(int tid) {
PoisonAll(0);
- if (common_flags()->verbosity >= 2) {
+ if (Verbosity() >= 2) {
InternalScopedString str(kNumberOfSizeClasses * 50);
for (uptr class_id = 0; class_id < kNumberOfSizeClasses; class_id++)
str.append("%zd: %zd/%zd; ", class_id, hint_position_[class_id],
Modified: compiler-rt/trunk/lib/asan/asan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_flags.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.cc Tue Jan 20 07:21:20 2015
@@ -79,14 +79,10 @@ void InitializeFlags(Flags *f) {
// Override from user-specified string.
const char *default_options = MaybeCallAsanDefaultOptions();
parser.ParseString(default_options);
- VReport(1, "Using the defaults from __asan_default_options: %s\n",
- MaybeCallAsanDefaultOptions());
// Override from command line.
- if (const char *env = GetEnv("ASAN_OPTIONS")) {
- parser.ParseString(env);
- VReport(1, "Parsed ASAN_OPTIONS: %s\n", env);
- }
+ const char *env = GetEnv("ASAN_OPTIONS");
+ if (env) parser.ParseString(env);
// Let activation flags override current settings. On Android they come
// from a system property. On other platforms this is no-op.
@@ -94,11 +90,12 @@ void InitializeFlags(Flags *f) {
char buf[100];
GetExtraActivationFlags(buf, sizeof(buf));
parser.ParseString(buf);
- if (buf[0] != '\0')
- VReport(1, "Parsed activation flags: %s\n", buf);
}
- if (common_flags()->verbosity) ReportUnrecognizedFlags();
+ SetVerbosity(common_flags()->verbosity);
+
+ // TODO(eugenis): dump all flags at verbosity>=2?
+ if (Verbosity()) ReportUnrecognizedFlags();
if (common_flags()->help) parser.PrintFlagDescriptions();
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=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Tue Jan 20 07:21:20 2015
@@ -313,7 +313,7 @@ asan_block_context_t *alloc_asan_context
dispatch_function_t func) { \
GET_STACK_TRACE_THREAD; \
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack); \
- if (common_flags()->verbosity >= 2) { \
+ if (Verbosity() >= 2) { \
Report(#dispatch_x_f "(): context: %p, pthread_self: %p\n", \
asan_ctxt, pthread_self()); \
PRINT_CURRENT_STACK(); \
@@ -331,7 +331,7 @@ INTERCEPTOR(void, dispatch_after_f, disp
dispatch_function_t func) {
GET_STACK_TRACE_THREAD;
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
- if (common_flags()->verbosity >= 2) {
+ if (Verbosity() >= 2) {
Report("dispatch_after_f: %p\n", asan_ctxt);
PRINT_CURRENT_STACK();
}
@@ -344,7 +344,7 @@ INTERCEPTOR(void, dispatch_group_async_f
dispatch_function_t func) {
GET_STACK_TRACE_THREAD;
asan_block_context_t *asan_ctxt = alloc_asan_context(ctxt, func, &stack);
- if (common_flags()->verbosity >= 2) {
+ if (Verbosity() >= 2) {
Report("dispatch_group_async_f(): context: %p, pthread_self: %p\n",
asan_ctxt, pthread_self());
PRINT_CURRENT_STACK();
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=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Tue Jan 20 07:21:20 2015
@@ -74,10 +74,10 @@ void FlushUnneededASanShadowMemory(uptr
void AsanPoisonOrUnpoisonIntraObjectRedzone(uptr ptr, uptr size, bool poison) {
uptr end = ptr + size;
- if (common_flags()->verbosity) {
+ if (Verbosity()) {
Printf("__asan_%spoison_intra_object_redzone [%p,%p) %zd\n",
poison ? "" : "un", ptr, end, size);
- if (common_flags()->verbosity >= 2)
+ if (Verbosity() >= 2)
PRINT_CURRENT_STACK();
}
CHECK(size);
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=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue Jan 20 07:21:20 2015
@@ -353,8 +353,7 @@ static void AsanInitInternal() {
}
#endif
- if (common_flags()->verbosity)
- PrintAddressSpaceLayout();
+ if (Verbosity()) PrintAddressSpaceLayout();
DisableCoreDumperIfNecessary();
Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Tue Jan 20 07:21:20 2015
@@ -75,7 +75,9 @@ static void InitializeFlags(bool standal
const char *options = GetEnv("LSAN_OPTIONS");
parser.ParseString(options);
- if (common_flags()->verbosity) ReportUnrecognizedFlags();
+ SetVerbosity(common_flags()->verbosity);
+
+ if (Verbosity()) ReportUnrecognizedFlags();
if (!help_before && common_flags()->help)
parser.PrintFlagDescriptions();
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Tue Jan 20 07:21:20 2015
@@ -157,7 +157,9 @@ static void InitializeFlags(Flags *f, co
parser.ParseString(options);
- if (common_flags()->verbosity) ReportUnrecognizedFlags();
+ SetVerbosity(common_flags()->verbosity);
+
+ if (Verbosity()) ReportUnrecognizedFlags();
if (common_flags()->help) parser.PrintFlagDescriptions();
Modified: compiler-rt/trunk/lib/msan/msan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_report.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_report.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_report.cc Tue Jan 20 07:21:20 2015
@@ -255,7 +255,7 @@ void ReportUMRInsideAddressRange(const c
Printf("%sUninitialized bytes in %s%s%s at offset %zu inside [%p, %zu)%s\n",
d.Warning(), d.Name(), what, d.Warning(), offset, start, size,
d.End());
- if (__sanitizer::common_flags()->verbosity > 0)
+ if (__sanitizer::Verbosity())
DescribeMemoryRange(start, size);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Tue Jan 20 07:21:20 2015
@@ -21,6 +21,8 @@ namespace __sanitizer {
const char *SanitizerToolName = "SanitizerTool";
+atomic_uint32_t current_verbosity;
+
uptr GetPageSizeCached() {
static uptr PageSize;
if (!PageSize)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Tue Jan 20 07:21:20 2015
@@ -41,6 +41,14 @@ const uptr kMaxThreadStackSize = 1 << 30
extern const char *SanitizerToolName; // Can be changed by the tool.
+extern atomic_uint32_t current_verbosity;
+INLINE void SetVerbosity(int verbosity) {
+ atomic_store(¤t_verbosity, verbosity, memory_order_relaxed);
+}
+INLINE int Verbosity() {
+ return atomic_load(¤t_verbosity, memory_order_relaxed);
+}
+
uptr GetPageSize();
uptr GetPageSizeCached();
uptr GetMmapGranularity();
@@ -136,11 +144,11 @@ void Report(const char *format, ...);
void SetPrintfAndReportCallback(void (*callback)(const char *));
#define VReport(level, ...) \
do { \
- if ((uptr)common_flags()->verbosity >= (level)) Report(__VA_ARGS__); \
+ if ((uptr)Verbosity() >= (level)) Report(__VA_ARGS__); \
} while (0)
#define VPrintf(level, ...) \
do { \
- if ((uptr)common_flags()->verbosity >= (level)) Printf(__VA_ARGS__); \
+ if ((uptr)Verbosity() >= (level)) Printf(__VA_ARGS__); \
} while (0)
// Can be used to prevent mixing error reports from different sanitizers.
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_libcdep.cc Tue Jan 20 07:21:20 2015
@@ -75,7 +75,7 @@ void BackgroundThread(void *arg) {
while (true) {
SleepForMillis(100);
uptr current_rss_mb = GetRSS() >> 20;
- if (common_flags()->verbosity) {
+ if (Verbosity()) {
// If RSS has grown 10% since last time, print some information.
if (prev_reported_rss * 11 / 10 < current_rss_mb) {
Printf("%s: RSS: %zdMb\n", SanitizerToolName, current_rss_mb);
Modified: compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc Tue Jan 20 07:21:20 2015
@@ -85,6 +85,7 @@ void InitializeFlags(Flags *f, const cha
RegisterFlag(&parser, "second_deadlock_stack", "", &f->second_deadlock_stack);
RegisterCommonFlags(&parser);
parser.ParseString(env);
+ SetVerbosity(common_flags()->verbosity);
}
void Initialize() {
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Tue Jan 20 07:21:20 2015
@@ -80,7 +80,9 @@ void InitializeFlags(Flags *f, const cha
f->report_signal_unsafe = false;
}
- if (common_flags()->verbosity) ReportUnrecognizedFlags();
+ SetVerbosity(common_flags()->verbosity);
+
+ if (Verbosity()) ReportUnrecognizedFlags();
if (common_flags()->help) parser.PrintFlagDescriptions();
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue Jan 20 07:21:20 2015
@@ -365,8 +365,7 @@ int Finalize(ThreadState *thr) {
ctx->report_mtx.Unlock();
#ifndef SANITIZER_GO
- if (common_flags()->verbosity)
- AllocatorPrintStats();
+ if (Verbosity()) AllocatorPrintStats();
#endif
ThreadFinalize(thr);
Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc Tue Jan 20 07:21:20 2015
@@ -66,6 +66,7 @@ void InitializeFlags(bool standalone) {
parser.ParseString(MaybeCallUbsanDefaultOptions());
// Override from environment variable.
parser.ParseString(GetEnv("UBSAN_OPTIONS"));
+ SetVerbosity(common_flags()->verbosity);
}
} // namespace __ubsan
Modified: compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/start-deactivated.cc Tue Jan 20 07:21:20 2015
@@ -11,6 +11,12 @@
// RUN: ASAN_ACTIVATION_OPTIONS=help=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HELP
// RUN: ASAN_OPTIONS=start_deactivated=1,verbosity=1 \
// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
+// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED-V0
+
+// Check that verbosity=1 in activation flags affects reporting of unrecognized activation flags.
+// RUN: ASAN_OPTIONS=start_deactivated=1 \
+// RUN: ASAN_ACTIVATION_OPTIONS=help=1,handle_segv=0,verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-UNSUPPORTED
// XFAIL: arm-linux-gnueabi
// XFAIL: armv7l-unknown-linux-gnueabihf
@@ -87,6 +93,9 @@ extern "C" void do_another_bad_thing() {
// CHECK-HELP: max_redzone
// CHECK-HELP-NOT: handle_segv
-// unsupported activation flags produce a warning
+// unsupported activation flags produce a warning ...
// CHECK-UNSUPPORTED: WARNING: found 1 unrecognized
// CHECK-UNSUPPORTED: handle_segv
+
+// ... but not at verbosity=0
+// CHECK-UNSUPPORTED-V0-NOT: WARNING: found {{.*}} unrecognized
Modified: compiler-rt/trunk/test/asan/TestCases/default_options.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/default_options.cc?rev=226566&r1=226565&r2=226566&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/default_options.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/default_options.cc Tue Jan 20 07:21:20 2015
@@ -4,12 +4,12 @@
// __asan_default_options() are not supported on Windows.
// XFAIL: win32
-const char *kAsanDefaultOptions="verbosity=1 strip_path_prefix=bar";
+const char *kAsanDefaultOptions="verbosity=1 help=1";
extern "C"
__attribute__((no_sanitize_address))
const char *__asan_default_options() {
- // CHECK: Using the defaults from __asan_default_options: {{.*}} strip_path_prefix=bar
+ // CHECK: Available flags for AddressSanitizer:
return kAsanDefaultOptions;
}
More information about the llvm-commits
mailing list