aboutsummaryrefslogtreecommitdiff
path: root/libsanitizer/ubsan/ubsan_diag.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libsanitizer/ubsan/ubsan_diag.cc')
-rw-r--r--libsanitizer/ubsan/ubsan_diag.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/libsanitizer/ubsan/ubsan_diag.cc b/libsanitizer/ubsan/ubsan_diag.cc
index 786ffa7254f..1dfe7255f68 100644
--- a/libsanitizer/ubsan/ubsan_diag.cc
+++ b/libsanitizer/ubsan/ubsan_diag.cc
@@ -11,6 +11,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"
@@ -19,6 +20,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();
@@ -30,9 +47,11 @@ 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()->SymbolizeCode(Loc, &Info, 1) ||
+ if (!Symbolizer::GetOrInit()->SymbolizePC(Loc, &Info, 1) ||
!Info.module || !*Info.module)
return Location(Loc);