diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-02-11 19:45:07 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-02-11 19:45:07 +0000 |
commit | 0487d23cf8db4d9104fd0aa0774ababc0a94f9dc (patch) | |
tree | dbb005b811aba0ac4448b2fefaa47bbe0a891c25 /lib/ubsan/ubsan_handlers.cc | |
parent | ec23e9846f12f9681d6a60675dd558a04d3a5b3b (diff) |
[UBSan] Allow UBSan location to store frames returned by symbolizer.
Summary:
__ubsan::getFunctionLocation() used to issue a call to symbolizer, and
convert the result (SymbolizedStack) to one of UBSan structures:
SourceLocation, ModuleLocation or MemoryLocation. This:
(1) is inefficient: we do an extra allocation/deallocation to copy data,
while we can instead can just pass SymbolizedStack around (which
contains all the necessary data).
(2) leaks memory: strings stored in SourceLocation/MemoryLocation are
never deallocated, and Filipe Cabecinhas suggests this causes crashes
of UBSan-ified programs in the wild.
Instead, let Location store a pointer to SymbolizedStack object, and
make sure it's properly deallocated when UBSan handler exits.
ModuleLocation is made obsolete by this change, and is deleted.
Test Plan: check-ubsan test suite
Reviewers: rsmith, filcab
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D7548
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@228869 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ubsan/ubsan_handlers.cc')
-rw-r--r-- | lib/ubsan/ubsan_handlers.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cc index 5b3ef30be..78e7508f7 100644 --- a/lib/ubsan/ubsan_handlers.cc +++ b/lib/ubsan/ubsan_handlers.cc @@ -43,8 +43,11 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer, if (ignoreReport(Loc.getSourceLocation(), Opts)) return; - if (Data->Loc.isInvalid()) - Loc = getCallerLocation(Opts.pc); + SymbolizedStackHolder FallbackLoc; + if (Data->Loc.isInvalid()) { + FallbackLoc.reset(getCallerLocation(Opts.pc)); + Loc = FallbackLoc; + } ScopedReport R(Opts, Loc); @@ -288,7 +291,8 @@ void __ubsan::__ubsan_handle_vla_bound_not_positive_abort(VLABoundData *Data, static void handleFloatCastOverflow(FloatCastOverflowData *Data, ValueHandle From, ReportOptions Opts) { // TODO: Add deduplication once a SourceLocation is generated for this check. - Location Loc = getCallerLocation(Opts.pc); + SymbolizedStackHolder CallerLoc(getCallerLocation(Opts.pc)); + Location Loc = CallerLoc; ScopedReport R(Opts, Loc); Diag(Loc, DL_Error, @@ -343,8 +347,10 @@ static void handleFunctionTypeMismatch(FunctionTypeMismatchData *Data, ScopedReport R(Opts, CallLoc); - const char *FName = "(unknown)"; - Location FLoc = getFunctionLocation(Function, &FName); + SymbolizedStackHolder FLoc(getSymbolizedLocation(Function)); + const char *FName = FLoc.get()->info.function; + if (!FName) + FName = "(unknown)"; Diag(CallLoc, DL_Error, "call to function %0 through pointer to incorrect function type %1") |