[compiler-rt] r225088 - Revert "Revert r224736: "[Sanitizer] Make CommonFlags immutable after initialization.""
Alexey Samsonov
vonosmas at gmail.com
Fri Jan 2 13:28:37 PST 2015
Author: samsonov
Date: Fri Jan 2 15:28:37 2015
New Revision: 225088
URL: http://llvm.org/viewvc/llvm-project?rev=225088&view=rev
Log:
Revert "Revert r224736: "[Sanitizer] Make CommonFlags immutable after initialization.""
Fix test failures by introducing CommonFlags::CopyFrom() to make sure
compiler doesn't insert memcpy() calls into runtime code.
Original commit message:
Protect CommonFlags singleton by adding const qualifier to
common_flags() accessor. The only ways to modify the flags are
SetCommonFlagsDefaults(), ParseCommonFlagsFromString() and
OverrideCommonFlags() functions, which are only supposed to be
called during initialization.
Modified:
compiler-rt/trunk/lib/asan/asan_flags.cc
compiler-rt/trunk/lib/lsan/lsan_common.cc
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc
compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
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=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_flags.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_flags.cc Fri Jan 2 15:28:37 2015
@@ -172,13 +172,16 @@ void ParseFlagsFromString(Flags *f, cons
}
void InitializeFlags(Flags *f) {
- CommonFlags *cf = common_flags();
SetCommonFlagsDefaults();
- cf->detect_leaks = CAN_SANITIZE_LEAKS;
- cf->external_symbolizer_path = GetEnv("ASAN_SYMBOLIZER_PATH");
- cf->malloc_context_size = kDefaultMallocContextSize;
- cf->intercept_tls_get_addr = true;
- cf->coverage = false;
+ {
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.detect_leaks = CAN_SANITIZE_LEAKS;
+ cf.external_symbolizer_path = GetEnv("ASAN_SYMBOLIZER_PATH");
+ cf.malloc_context_size = kDefaultMallocContextSize;
+ cf.intercept_tls_get_addr = true;
+ OverrideCommonFlags(cf);
+ }
internal_memset(f, 0, sizeof(*f));
f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28;
@@ -258,17 +261,17 @@ void InitializeFlags(Flags *f) {
}
// Flag validation:
- if (!CAN_SANITIZE_LEAKS && cf->detect_leaks) {
+ if (!CAN_SANITIZE_LEAKS && common_flags()->detect_leaks) {
Report("%s: detect_leaks is not supported on this platform.\n",
SanitizerToolName);
- cf->detect_leaks = false;
+ Die();
}
// Make "strict_init_order" imply "check_initialization_order".
// TODO(samsonov): Use a single runtime flag for an init-order checker.
if (f->strict_init_order) {
f->check_initialization_order = true;
}
- CHECK_LE((uptr)cf->malloc_context_size, kStackTraceMax);
+ CHECK_LE((uptr)common_flags()->malloc_context_size, kStackTraceMax);
CHECK_LE(f->min_uar_stack_size_log, f->max_uar_stack_size_log);
CHECK_GE(f->redzone, 16);
CHECK_GE(f->max_redzone, f->redzone);
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=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Fri Jan 2 15:28:37 2015
@@ -74,12 +74,14 @@ static void InitializeFlags(bool standal
// Set defaults for common flags (only in standalone mode) and parse
// them from LSAN_OPTIONS.
- CommonFlags *cf = common_flags();
if (standalone) {
SetCommonFlagsDefaults();
- cf->external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
- cf->malloc_context_size = 30;
- cf->detect_leaks = true;
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.external_symbolizer_path = GetEnv("LSAN_SYMBOLIZER_PATH");
+ cf.malloc_context_size = 30;
+ cf.detect_leaks = true;
+ OverrideCommonFlags(cf);
}
ParseCommonFlagsFromString(options);
}
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Fri Jan 2 15:28:37 2015
@@ -144,14 +144,18 @@ static void ParseFlagsFromString(Flags *
}
static void InitializeFlags(Flags *f, const char *options) {
- CommonFlags *cf = common_flags();
SetCommonFlagsDefaults();
- cf->external_symbolizer_path = GetEnv("MSAN_SYMBOLIZER_PATH");
- cf->malloc_context_size = 20;
- cf->handle_ioctl = true;
- // FIXME: test and enable.
- cf->check_printf = false;
- cf->intercept_tls_get_addr = true;
+ {
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.external_symbolizer_path = GetEnv("MSAN_SYMBOLIZER_PATH");
+ cf.malloc_context_size = 20;
+ cf.handle_ioctl = true;
+ // FIXME: test and enable.
+ cf.check_printf = false;
+ cf.intercept_tls_get_addr = true;
+ OverrideCommonFlags(cf);
+ }
internal_memset(f, 0, sizeof(*f));
f->poison_heap_with_zeroes = false;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc?rev=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Fri Jan 2 15:28:37 2015
@@ -187,6 +187,10 @@ void CommonFlags::ParseFromString(const
malloc_context_size = 1;
}
+void CommonFlags::CopyFrom(const CommonFlags &other) {
+ internal_memcpy(this, &other, sizeof(*this));
+}
+
static bool GetFlagValue(const char *env, const char *name,
const char **value, int *value_length) {
if (env == 0)
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h?rev=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Fri Jan 2 15:28:37 2015
@@ -69,11 +69,13 @@ struct CommonFlags {
void SetDefaults();
void ParseFromString(const char *str);
+
+ void CopyFrom(const CommonFlags &other);
};
// Functions to get/set global CommonFlags shared by all sanitizer runtimes:
extern CommonFlags common_flags_dont_use;
-inline CommonFlags *common_flags() {
+inline const CommonFlags *common_flags() {
return &common_flags_dont_use;
}
@@ -84,6 +86,16 @@ inline void SetCommonFlagsDefaults() {
inline void ParseCommonFlagsFromString(const char *str) {
common_flags_dont_use.ParseFromString(str);
}
+
+// This function can only be used to setup tool-specific overrides for
+// CommonFlags defaults. Generally, it should only be used right after
+// SetCommonFlagsDefaults(), but before ParseCommonFlagsFromString(), and
+// only during the flags initialization (i.e. before they are used for
+// the first time).
+inline void OverrideCommonFlags(const CommonFlags &cf) {
+ common_flags_dont_use.CopyFrom(cf);
+}
+
void PrintFlagDescriptions();
} // namespace __sanitizer
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=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc Fri Jan 2 15:28:37 2015
@@ -70,10 +70,14 @@ void InitializeFlags(Flags *f, const cha
// Default values.
f->second_deadlock_stack = false;
- CommonFlags *cf = common_flags();
SetCommonFlagsDefaults();
- // Override some common flags defaults.
- cf->allow_addr2line = true;
+ {
+ // Override some common flags defaults.
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.allow_addr2line = true;
+ OverrideCommonFlags(cf);
+ }
// Override from command line.
ParseFlag(env, &f->second_deadlock_stack, "second_deadlock_stack", "");
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=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_flags.cc Fri Jan 2 15:28:37 2015
@@ -93,13 +93,17 @@ void InitializeFlags(Flags *f, const cha
// DDFlags
f->second_deadlock_stack = false;
- CommonFlags *cf = common_flags();
SetCommonFlagsDefaults();
- // Override some common flags defaults.
- cf->allow_addr2line = true;
- cf->detect_deadlocks = true;
- cf->print_suppressions = false;
- cf->stack_trace_format = " #%n %f %S %M";
+ {
+ // Override some common flags defaults.
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.allow_addr2line = true;
+ cf.detect_deadlocks = true;
+ cf.print_suppressions = false;
+ cf.stack_trace_format = " #%n %f %S %M";
+ OverrideCommonFlags(cf);
+ }
// Let a frontend override.
ParseFlags(f, __tsan_default_options());
@@ -115,7 +119,8 @@ void InitializeFlags(Flags *f, const cha
f->report_signal_unsafe = false;
}
- if (cf->help) PrintFlagDescriptions();
+ if (common_flags()->help)
+ PrintFlagDescriptions();
if (f->history_size < 0 || f->history_size > 7) {
Printf("ThreadSanitizer: incorrect value for history_size"
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=225088&r1=225087&r2=225088&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc Fri Jan 2 15:28:37 2015
@@ -22,9 +22,11 @@ static const char *MaybeCallUbsanDefault
}
void InitializeCommonFlags() {
- CommonFlags *cf = common_flags();
SetCommonFlagsDefaults();
- cf->print_summary = false;
+ CommonFlags cf;
+ cf.CopyFrom(*common_flags());
+ cf.print_summary = false;
+ OverrideCommonFlags(cf);
// Override from user-specified string.
ParseCommonFlagsFromString(MaybeCallUbsanDefaultOptions());
// Override from environment variable.
More information about the llvm-commits
mailing list