[compiler-rt] r217616 - [UBSan] Parse common flags from UBSAN_OPTIONS runtime variable even if
Alexey Samsonov
vonosmas at gmail.com
Thu Sep 11 11:20:11 PDT 2014
Author: samsonov
Date: Thu Sep 11 13:20:11 2014
New Revision: 217616
URL: http://llvm.org/viewvc/llvm-project?rev=217616&view=rev
Log:
[UBSan] Parse common flags from UBSAN_OPTIONS runtime variable even if
UBSan is combined with ASan.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h
compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
compiler-rt/trunk/lib/ubsan/ubsan_flags.h
compiler-rt/trunk/lib/ubsan/ubsan_init.cc
compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
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=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.cc Thu Sep 11 13:20:11 2014
@@ -20,6 +20,7 @@
namespace __sanitizer {
CommonFlags common_flags_dont_use;
+bool common_flags_defaults_set = false;
struct FlagDescription {
const char *name;
@@ -35,6 +36,11 @@ IntrusiveList<FlagDescription> flag_desc
#endif
void SetCommonFlagsDefaults(CommonFlags *f) {
+ CHECK_EQ(common_flags(), f);
+ if (common_flags_defaults_set)
+ return;
+ common_flags_defaults_set = true;
+
f->symbolize = true;
f->external_symbolizer_path = 0;
f->allow_addr2line = false;
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=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.h Thu Sep 11 13:20:11 2014
@@ -67,7 +67,10 @@ inline CommonFlags *common_flags() {
return &common_flags_dont_use;
}
+// Sets default values for common flags. If called multiple times,
+// sets default values only once.
void SetCommonFlagsDefaults(CommonFlags *f);
+
void ParseCommonFlagsFromString(CommonFlags *f, const char *str);
void PrintFlagDescriptions();
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=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc Thu Sep 11 13:20:11 2014
@@ -28,7 +28,7 @@ static const char *GetRuntimeFlagsFromCo
#endif
}
-void InitializeCommonFlags() {
+static void InitializeCommonFlags() {
CommonFlags *cf = common_flags();
SetCommonFlagsDefaults(cf);
cf->print_summary = false;
@@ -50,6 +50,7 @@ static void ParseFlagsFromString(Flags *
}
void InitializeFlags() {
+ InitializeCommonFlags();
Flags *f = flags();
// Default values.
f->halt_on_error = false;
Modified: compiler-rt/trunk/lib/ubsan/ubsan_flags.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.h?rev=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.h Thu Sep 11 13:20:11 2014
@@ -23,7 +23,6 @@ struct Flags {
extern Flags ubsan_flags;
inline Flags *flags() { return &ubsan_flags; }
-void InitializeCommonFlags();
void InitializeFlags();
} // namespace __ubsan
Modified: compiler-rt/trunk/lib/ubsan/ubsan_init.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cc?rev=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init.cc Thu Sep 11 13:20:11 2014
@@ -32,15 +32,9 @@ void __ubsan::InitIfNecessary() {
if (LIKELY(ubsan_inited))
return;
if (0 == internal_strcmp(SanitizerToolName, "SanitizerTool")) {
- // WARNING: If this condition holds, then either UBSan runs in a standalone
- // mode, or initializer for another sanitizer hasn't run yet. In a latter
- // case, another sanitizer will overwrite "SanitizerToolName" and reparse
- // common flags. It means, that we are not allowed to *use* common flags
- // in this function.
+ // This will be overwritten if another sanitizer will initialize later.
SanitizerToolName = "UndefinedBehaviorSanitizer";
- InitializeCommonFlags();
}
- // Initialize UBSan-specific flags.
InitializeFlags();
SuppressionContext::InitIfNecessary();
ubsan_inited = true;
Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp?rev=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/Function/function.cpp Thu Sep 11 13:20:11 2014
@@ -1,7 +1,7 @@
// RUN: %clangxx -fsanitize=function %s -O3 -g -o %t
// RUN: %run %t 2>&1 | FileCheck %s
// Verify that we can disable symbolization if needed:
-// RUN: UBSAN_OPTIONS=symbolize=0 ASAN_OPTIONS=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
+// RUN: UBSAN_OPTIONS=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
// -fsanitize=function is unsupported on Darwin yet.
// XFAIL: darwin
Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp?rev=217616&r1=217615&r2=217616&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr.cpp Thu Sep 11 13:20:11 2014
@@ -12,16 +12,16 @@
// RUN: UBSAN_OPTIONS=print_stacktrace=1 %run %t m0 2>&1 | FileCheck %s --check-prefix=CHECK-NULL-MEMBER --strict-whitespace
// RUN: (echo "vptr_check:S"; echo "vptr_check:T"; echo "vptr_check:U") > %t.supp
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t mS 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t fS 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t cS 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t mV 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t fV 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t cV 2>&1
-// RUN: ASAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t oU 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t mS 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t fS 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t cS 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t mV 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t fV 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t cV 2>&1
+// RUN: UBSAN_OPTIONS=suppressions=%t.supp:halt_on_error=1 %run %t oU 2>&1
// RUN: echo "vptr_check:S" > %t.loc-supp
-// RUN: ASAN_OPTIONS=suppressions=%t.loc-supp:halt_on_error=1 UBSAN_OPTIONS=suppressions=%t.loc-supp:halt_on_error=1 not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
+// RUN: UBSAN_OPTIONS=suppressions=%t.loc-supp:halt_on_error=1 not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
// FIXME: This test produces linker errors on Darwin.
// XFAIL: darwin
More information about the llvm-commits
mailing list