[compiler-rt] r201217 - [UBSan] Parse common runtime flags before using a symbolizer

Alexey Samsonov samsonov at google.com
Wed Feb 12 00:21:45 PST 2014


Author: samsonov
Date: Wed Feb 12 02:21:44 2014
New Revision: 201217

URL: http://llvm.org/viewvc/llvm-project?rev=201217&view=rev
Log:
[UBSan] Parse common runtime flags before using a symbolizer

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cc

Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=201217&r1=201216&r2=201217&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Wed Feb 12 02:21:44 2014
@@ -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"
@@ -21,6 +22,22 @@
 
 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
 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) ||





More information about the llvm-commits mailing list