[UBSan] Parse common runtime flags before using a symbolizer
authorAlexey Samsonov <samsonov@google.com>
Wed, 12 Feb 2014 08:21:44 +0000 (08:21 +0000)
committerAlexey Samsonov <samsonov@google.com>
Wed, 12 Feb 2014 08:21:44 +0000 (08:21 +0000)
llvm-svn: 201217

compiler-rt/lib/ubsan/ubsan_diag.cc

index 4e5380b..7a1de21 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "ubsan_diag.h"
 #include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_report_decorator.h"
 #include "sanitizer_common/sanitizer_stacktrace.h"
 
 using namespace __ubsan;
 
+static void InitializeSanitizerCommon() {
+  static StaticSpinMutex init_mu;
+  SpinMutexLock l(&init_mu);
+  static bool initialized;
+  if (initialized)
+   return;
+  if (0 == internal_strcmp(SanitizerToolName, "SanitizerTool")) {
+    // UBSan is run in a standalone mode. Initialize it now.
+    SanitizerToolName = "UndefinedBehaviorSanitizer";
+    CommonFlags *cf = common_flags();
+    SetCommonFlagsDefaults(cf);
+    cf->print_summary = false;
+  }
+  initialized = true;
+}
+
 Location __ubsan::getCallerLocation(uptr CallerLoc) {
   if (!CallerLoc)
     return Location();
@@ -32,6 +49,8 @@ Location __ubsan::getCallerLocation(uptr CallerLoc) {
 Location __ubsan::getFunctionLocation(uptr Loc, const char **FName) {
   if (!Loc)
     return Location();
+  // FIXME: We may need to run initialization earlier.
+  InitializeSanitizerCommon();
 
   AddressInfo Info;
   if (!Symbolizer::GetOrInit()->SymbolizePC(Loc, &Info, 1) ||