aboutsummaryrefslogtreecommitdiff
path: root/lib/ubsan/ubsan_diag.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ubsan/ubsan_diag.cc')
-rw-r--r--lib/ubsan/ubsan_diag.cc74
1 files changed, 33 insertions, 41 deletions
diff --git a/lib/ubsan/ubsan_diag.cc b/lib/ubsan/ubsan_diag.cc
index 76ce2bd39996..4f2a2a9f3562 100644
--- a/lib/ubsan/ubsan_diag.cc
+++ b/lib/ubsan/ubsan_diag.cc
@@ -14,9 +14,11 @@
#include "ubsan_diag.h"
#include "ubsan_init.h"
#include "ubsan_flags.h"
+#include "sanitizer_common/sanitizer_placement_new.h"
#include "sanitizer_common/sanitizer_report_decorator.h"
#include "sanitizer_common/sanitizer_stacktrace.h"
#include "sanitizer_common/sanitizer_stacktrace_printer.h"
+#include "sanitizer_common/sanitizer_suppressions.h"
#include "sanitizer_common/sanitizer_symbolizer.h"
#include <stdio.h>
@@ -66,39 +68,9 @@ class Decorator : public SanitizerCommonDecorator {
};
}
-Location __ubsan::getCallerLocation(uptr CallerLoc) {
- if (!CallerLoc)
- return Location();
-
- uptr Loc = StackTrace::GetPreviousInstructionPc(CallerLoc);
- return getFunctionLocation(Loc, 0);
-}
-
-Location __ubsan::getFunctionLocation(uptr Loc, const char **FName) {
- if (!Loc)
- return Location();
+SymbolizedStack *__ubsan::getSymbolizedLocation(uptr PC) {
InitIfNecessary();
-
- SymbolizedStack *Frames = Symbolizer::GetOrInit()->SymbolizePC(Loc);
- const AddressInfo &Info = Frames->info;
-
- if (!Info.module) {
- Frames->ClearAll();
- return Location(Loc);
- }
-
- if (FName && Info.function)
- *FName = internal_strdup(Info.function);
-
- if (!Info.file) {
- ModuleLocation MLoc(internal_strdup(Info.module), Info.module_offset);
- Frames->ClearAll();
- return MLoc;
- }
-
- SourceLocation SLoc(internal_strdup(Info.file), Info.line, Info.column);
- Frames->ClearAll();
- return SLoc;
+ return Symbolizer::GetOrInit()->SymbolizePC(PC);
}
Diag &Diag::operator<<(const TypeDescriptor &V) {
@@ -142,15 +114,22 @@ static void renderLocation(Location Loc) {
SLoc.getColumn(), common_flags()->strip_path_prefix);
break;
}
- case Location::LK_Module: {
- ModuleLocation MLoc = Loc.getModuleLocation();
- RenderModuleLocation(&LocBuffer, MLoc.getModuleName(), MLoc.getOffset(),
- common_flags()->strip_path_prefix);
- break;
- }
case Location::LK_Memory:
LocBuffer.append("%p", Loc.getMemoryLocation());
break;
+ case Location::LK_Symbolized: {
+ const AddressInfo &Info = Loc.getSymbolizedStack()->info;
+ if (Info.file) {
+ RenderSourceLocation(&LocBuffer, Info.file, Info.line, Info.column,
+ common_flags()->strip_path_prefix);
+ } else if (Info.module) {
+ RenderModuleLocation(&LocBuffer, Info.module, Info.module_offset,
+ common_flags()->strip_path_prefix);
+ } else {
+ LocBuffer.append("%p", Info.address);
+ }
+ break;
+ }
case Location::LK_Null:
LocBuffer.append("<unknown>");
break;
@@ -356,11 +335,24 @@ ScopedReport::~ScopedReport() {
Die();
}
-bool __ubsan::MatchSuppression(const char *Str, SuppressionType Type) {
- Suppression *s;
+ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
+static SuppressionContext *suppression_ctx = nullptr;
+static const char kVptrCheck[] = "vptr_check";
+static const char *kSuppressionTypes[] = { kVptrCheck };
+
+void __ubsan::InitializeSuppressions() {
+ CHECK_EQ(nullptr, suppression_ctx);
+ suppression_ctx = new (suppression_placeholder) // NOLINT
+ SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
+ suppression_ctx->ParseFromFile(flags()->suppressions);
+}
+
+bool __ubsan::IsVptrCheckSuppressed(const char *TypeName) {
// If .preinit_array is not used, it is possible that the UBSan runtime is not
// initialized.
if (!SANITIZER_CAN_USE_PREINIT_ARRAY)
InitIfNecessary();
- return SuppressionContext::Get()->Match(Str, Type, &s);
+ CHECK(suppression_ctx);
+ Suppression *s;
+ return suppression_ctx->Match(TypeName, kVptrCheck, &s);
}