summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorVlad Tsyrklevich <vlad@tsyrklevich.net>2018-06-26 18:51:04 +0000
committerVlad Tsyrklevich <vlad@tsyrklevich.net>2018-06-26 18:51:04 +0000
commit45aa866d1317655b2661f9dbebabcd306c501f36 (patch)
tree6d11ac2294cc21b4e72f73cf9dd4a99ffc0a7193 /lib
parent7073422f240f868bd063c30349750b11450e15b9 (diff)
CFI: Print DSO names for failed cross-DSO icalls
Reviewers: pcc Reviewed By: pcc Subscribers: kubamracek, delcypher, llvm-commits, kcc, #sanitizers Differential Revision: https://reviews.llvm.org/D48583 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@335644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/ubsan/ubsan_handlers.cc15
-rw-r--r--lib/ubsan/ubsan_handlers_cxx.cc25
2 files changed, 32 insertions, 8 deletions
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cc
index 2fe83f2bb..59a5a6b72 100644
--- a/lib/ubsan/ubsan_handlers.cc
+++ b/lib/ubsan/ubsan_handlers.cc
@@ -660,6 +660,21 @@ static void handleCFIBadIcall(CFICheckFailData *Data, ValueHandle Function,
if (!FName)
FName = "(unknown)";
Diag(FLoc, DL_Note, ET, "%0 defined here") << FName;
+
+ // If the failure involved different DSOs for the check location and icall
+ // target, report the DSO names.
+ const char *DstModule = FLoc.get()->info.module;
+ if (!DstModule)
+ DstModule = "(unknown)";
+
+ const char *SrcModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Opts.pc);
+ if (!SrcModule)
+ SrcModule = "(unknown)";
+
+ if (internal_strcmp(SrcModule, DstModule))
+ Diag(Loc, DL_Note, ET,
+ "check failed in %0, destination function located in %1")
+ << SrcModule << DstModule;
}
namespace __ubsan {
diff --git a/lib/ubsan/ubsan_handlers_cxx.cc b/lib/ubsan/ubsan_handlers_cxx.cc
index 6b205c2c6..85a3e8dad 100644
--- a/lib/ubsan/ubsan_handlers_cxx.cc
+++ b/lib/ubsan/ubsan_handlers_cxx.cc
@@ -137,16 +137,25 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
<< Data->Type << CheckKindStr << (void *)Vtable;
// If possible, say what type it actually points to.
- if (!DTI.isValid()) {
- const char *module = Symbolizer::GetOrInit()->GetModuleNameForPc(Vtable);
- if (module)
- Diag(Vtable, DL_Note, ET, "invalid vtable in module %0") << module;
- else
- Diag(Vtable, DL_Note, ET, "invalid vtable");
- } else {
+ if (!DTI.isValid())
+ Diag(Vtable, DL_Note, ET, "invalid vtable");
+ else
Diag(Vtable, DL_Note, ET, "vtable is of type %0")
<< TypeName(DTI.getMostDerivedTypeName());
- }
+
+ // If the failure involved different DSOs for the check location and vtable,
+ // report the DSO names.
+ const char *DstModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Vtable);
+ if (!DstModule)
+ DstModule = "(unknown)";
+
+ const char *SrcModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Opts.pc);
+ if (!SrcModule)
+ SrcModule = "(unknown)";
+
+ if (internal_strcmp(SrcModule, DstModule))
+ Diag(Loc, DL_Note, ET, "check failed in %0, vtable located in %1")
+ << SrcModule << DstModule;
}
} // namespace __ubsan