summaryrefslogtreecommitdiff
path: root/lib/ubsan/ubsan_diag.cc
AgeCommit message (Collapse)Author
2017-11-09[sanitizers] Rename GetStackTraceWithPcBpAndContextVitaly Buka
Name does not need to enumerate arguments. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317774 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-23[ubsan] Replace CommonSanitizerReportMutex with ScopedErrorReportLockVitaly Buka
Reviewers: eugenis, alekseyshl Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D38194 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@314053 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-15[ubsan] Extract GetStackTraceWithPcBpAndContext similar to asan versionVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@313350 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-11[compiler-rt] Cleanup decoratorsVitaly Buka
Summary: Removed redundant End*() methods which defined same way. Removed redundant Warning() methods. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, dberris Differential Revision: https://reviews.llvm.org/D37549 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312950 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-01[ubsan] Fall back to the fast unwinder when print_stacktrace=1Vedant Kumar
This makes it possible to get stacktrace info when print_stacktrace=1 on Darwin (where the slow unwinder is not currently supported [1]). This should not regress any other platforms. [1] The thread about r300295 has a relatively recent discusion about this. We should be able to enable the existing slow unwind functionality for Darwin, but this needs more testing. Differential Revision: https://reviews.llvm.org/D32517 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301839 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-14[ubsan] Use the correct tool name in diagnosticsVedant Kumar
When using ASan and UBSan together, the common sanitizer tool name is set to "AddressSanitizer". That means that when a UBSan diagnostic is printed out, it looks like this: SUMMARY: AddressSanitizer: ... This can confuse users. Fix it so that we always use the correct tool name when printing out UBSan diagnostics. Differential Revision: https://reviews.llvm.org/D32066 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300358 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06[sanitizer] Use architecture/slice information when symbolizing fat Mach-O ↵Kuba Mracek
files on Darwin This patch starts passing architecture information about a module to llvm-symbolizer and into text reports. This fixes the longstanding x86_64/x86_64h mismatch issue on Darwin. Differential Revision: https://reviews.llvm.org/D27390 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@291287 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-11[UBSan] Improve bufferization of UBSan error reports.Alexey Samsonov
Summary: Use InternalScopedString more extensively. This reduces the number of write() syscalls, and reduces the chance that UBSan output will be mixed with program output. Reviewers: vitalybuka Subscribers: kcc, llvm-commits Differential Revision: http://reviews.llvm.org/D18068 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@263176 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18[UBSan] Implement runtime suppressions (PR25066).Alexey Samsonov
Summary: Add the ability to suppress UBSan reports for files/functions/modules at runtime. The user can now pass UBSAN_OPTIONS=suppressions=supp.txt with the contents of the form: signed-integer-overflow:file-with-known-overflow.cpp alignment:function_doing_unaligned_access vptr:shared_object_with_vptr_failures.so Suppression categories match the arguments passed to -fsanitize= flag (although, see below). There is no overhead if suppressions are not provided. Otherwise there is extra overhead for symbolization. Limitations: 1) sometimes suppressions need debug info / symbol table to function properly (although sometimes frontend generates enough info to do the match). 2) it's only possible to suppress recoverable UB kinds - if you've built the code with -fno-sanitize-recover=undefined, suppressions will not work. 3) categories are fine-grained check kinds, not groups like "undefined" or "integer", so you can't write "undefined:file_with_ub.cc". Reviewers: rsmith, kcc Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15363 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@256018 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-09[UBSan] Clarify the way we disable de-duplication of reports from ↵Alexey Samsonov
unrecoverable handlers. Let unrecoverable handlers be responsbile for killing the program with Die(), and let functions which print the error report know if it's going to happen. Re-write the comments to describe the situation. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@255081 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-08[UBSan] Remove "-fsanitize=" prefix from ubsan_checks.inc. NFC.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@255075 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-24[UBSan] Add the ability to print more precise error kind in summary line.Alexey Samsonov
Reviewers: rsmith, pcc Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D12215 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@245897 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-08CFI: Get check-cfi passing on Windows.Peter Collingbourne
Specifically: - Start using %expect_crash. - Provide an implementation of __ubsan::getDynamicTypeInfoFromVtable for the Microsoft C++ ABI. This is all that is needed for CFI diagnostics; UBSan's -fsanitize=vptr also requires an implementation of __ubsan::checkDynamicType. - Build the sanitizer runtimes against the release version of the C runtime, even in debug builds. - Accommodate demangling differences in tests. Differential Revision: http://reviews.llvm.org/D11029 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@241745 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02Re-apply r241217 with build fixes:Peter Collingbourne
- Disable building of the interceptor library on 64-bit Windows. - Mangle names in /alternatename directive for 32-bit Windows. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@241224 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02Revert r241217, it breaks the build on Windows.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@241219 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-02ubsan: Port runtime library to (32- and 64-bit) Windows.Peter Collingbourne
Differential Revision: http://reviews.llvm.org/D10856 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@241217 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-04[sanitizer_common] Added VS-style output for source locationsFilipe Cabecinhas
Summary: With this patch, we have a flag to toggle displaying source locations in the regular style: file:line:column or Visual Studio style: file(line,column) This way, they get picked up on the Visual Studio output window and one can double-click them to get to that file location. Reviewers: samsonov, rnk Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10113 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@239000 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-23[UBSan] Make sure proper error summary is printed for ↵Alexey Samsonov
-fsanitize=float-cast-overflow. float-cast-overflow handler doesn't have source location provided by the compiler, but we still have *some* source location if we have a symbolizer. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@235567 91177308-0d34-0410-b5e6-96231b3b80d8
2015-04-01[UBSan] Embed UBSan into ASan runtime (compiler-rt part).Alexey Samsonov
Summary: Change the way we use ASan and UBSan together. Instead of keeping two separate runtimes (libclang_rt.asan and libclang_rt.ubsan), embed UBSan into ASan and get rid of libclang_rt.ubsan. If UBSan is not supported on a platform, all UBSan sources are just compiled into dummy empty object files. UBSan initialization code (e.g. flag parsing) is directly called from ASan initialization, so we are able to enforce correct initialization order. This mirrors the approach we already use for ASan+LSan. This change doesn't modify the way we use standalone UBSan. Test Plan: regression test suite Reviewers: kubabrecka, zaks.anna, rsmith, kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8646 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@233861 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-26[UBSan] Explicitly list all supported OS/arch pairs supported by UBSan.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@233295 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-27[Sanitizer] Print column number in SUMMARY line if it's available.Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230721 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-20[Sanitizer] Refactor SuppressionContext class.Alexey Samsonov
SuppressionContext is no longer a singleton, shared by all sanitizers, but a regular class. Each of ASan, LSan, UBSan and TSan now have their own SuppressionContext, which only parses suppressions specific to that sanitizer. "suppressions" flag is moved away from common flags into tool-specific flags, so the user now may pass ASAN_OPTIONS=suppressions=asan_supp.txt LSAN_OPIONS=suppressions=lsan_supp.txt in a single invocation. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@230026 91177308-0d34-0410-b5e6-96231b3b80d8
2015-02-11[UBSan] Allow UBSan location to store frames returned by symbolizer.Alexey Samsonov
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
2015-02-10[UBSan] Reduce the number of getCallerLocation() calls.Alexey Samsonov
getCallerLocation() is expensive as it issues a call to symbolizer. (In fact, this function has a memory leak at the moment, but this will be fixed in the nearest future). We should only call it if we're actually going to print an error report, in particular, once for every reported source location. __ubsan_handle_type_mismatch: call getCallerLocation() only if provided source location is invalid, and only if the report is not deduplicated. __ubsan_handle_float_cast_overflow: call getSourceLocation with correct CallerPC (the one in user code, not in UBSan handler). Source location for this check is not currently emitted by frontend. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@228732 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-02Simplify Symbolizer::SymbolizePC() interface.Alexey Samsonov
Return a linked list of AddressInfo objects, instead of using an array of these objects as an output parameter. This simplifies the code in callers of this function (especially TSan). Fix a few memory leaks from internal allocator, when the returned AddressInfo objects were not properly cleared. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223145 91177308-0d34-0410-b5e6-96231b3b80d8
2014-11-05[Sanitizer] Introduce generic stack frame rendering machineryAlexey Samsonov
Summary: This commit introduces function __sanitizer::RenderFrame() that allows to render the contents of AddressInfo (essentially, symbolized stack frame) using the custom format string. This function can be used to implement stack frame formatting for both ThreadSanitizer and generic StackTrace::Print(), used in another places. This paves the way towards allowing user to control the format of stack frames, obtaining them in any format he desires, and/or enforcing the consistent output from all sanitizers. Test Plan: compiler-rt test suite Reviewers: kcc Reviewed By: kcc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6140 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@221409 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-26[Sanitizer] Make StackTrace a lightweight reference to array of PCs, andAlexey Samsonov
introduce a BufferedStackTrace class, which owns this array. Summary: This change splits __sanitizer::StackTrace class into a lightweight __sanitizer::StackTrace, which doesn't own array of PCs, and BufferedStackTrace, which owns it. This would allow us to simplify the interface of StackDepot, and eventually merge __sanitizer::StackTrace with __tsan::StackTrace. Test Plan: regression test suite. Reviewers: kcc, dvyukov Reviewed By: dvyukov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D5985 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@220635 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-22UBSan: print 'undefined-behavior' instead of 'runtime-error' in report summaryAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@218264 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-19[UBSan] Optionally report summary in UBSan error reports.Alexey Samsonov
By default summary is not printed if UBSan is run in a standalone mode, but is printed if it's combined with another sanitizer (like ASan). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@218135 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-17PR20721: Don't let UBSan print inaccessible memoryAlexey Samsonov
Summary: UBSan needs to check if memory snippet it's going to print resides in addressable memory. Similar check might be helpful in ASan with dump_instruction_bytes option (see http://reviews.llvm.org/D5167). Instead of scanning /proc/self/maps manually, delegate this check to the OS kernel: try to write this memory in a syscall and assume that memory is inaccessible if the syscall failed (e.g. with EFAULT). Fixes PR20721. Test Plan: compiler-rt test suite Reviewers: eugenis, glider Reviewed By: glider Subscribers: emaste, ygribov, llvm-commits, glider, rsmith Differential Revision: http://reviews.llvm.org/D5253 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217971 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-12[UBSan] Don't overflow when calculating memory range that should be dumpedAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217703 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-10[Sanitizer] Get rid of Symbolizer::Get() and Symbolizer::GetOrNull().Alexey Samsonov
We may as well just use Symbolizer::GetOrInit() in all the cases. Don't call Symbolizer::Get() early in tools initialization: these days it doesn't do any important setup work, and we may as well create the symbolizer the first time it's actually needed. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217558 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-10[UBSan] Add halt_on_error runtime flagAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217535 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-08Revert accidental changeAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217391 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-08Implement nonnull-attribute sanitizerAlexey Samsonov
Summary: This patch implements a new UBSan check, which verifies that function arguments declared to be nonnull with __attribute__((nonnull)) are actually nonnull in runtime. To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs (where applicable) and if function declaration has nonnull attribute specified for a certain formal parameter, we compare the corresponding RValue to null as soon as it's calculated. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, rnk Differential Revision: http://reviews.llvm.org/D5082 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217389 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-22[UBSan] Add support for printing backtraces to all UBSan handlersAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@216289 91177308-0d34-0410-b5e6-96231b3b80d8
2014-08-05[UBSan] Allow to suppress reports from vptr checker for specified types.Alexey Samsonov
Based on http://reviews.llvm.org/D4702 by Byoungyoung Lee! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214833 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-30[UBSan] Introduce ScopedReport object.Alexey Samsonov
This object is used to encapsulate all actions that need to be done before/after printing UBSan diagnostics. Currently these actions are: * locking a mutex to ensure that UBSan diagnostics from several threads won't mix with each other and with other sanitizers' reports * killing a program once the report is printed (if necessary). Use this object in all UBSan handlers. Unify the way we implement fatal and non-fatal handlers by making all the handlers simple one-liners that redirect __ubsan_handle_foo(_abort)? to handleFooImpl(). git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214279 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-26[UBSan] Initialize symbolizer inside __ubsan::Init().Alexey Samsonov
We used to initialize symbolizer lazily, but this doesn't work in various sandboxed environments. Instead, let's be consistent with the rest of sanitizers. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214006 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-25[UBSan] Call UBSan initialization as early as possible.Alexey Samsonov
Specifically, use .preinit_array initialization on Linux and dynamic global initializer on another platforms. Historically UBSan didn't have any initialization code and its runtime was stateless. This is no longer the case - UBSan relies on some non-trivial functionality from sanitizer_common (e.g. online symbolization) and is now configurable by runtime flags. Additionally, we've dropped support for enabling UBSan only for a few shared objects, so UBSan is now always linked into the main executable, so now we can use similar initialization as all the rest sanitizers. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213983 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-23[UBSan] Add the ability to dump call stacks to -fsanitize=vptrAlexey Samsonov
This change introduces the first UBSan-specific runtime flag: print_stacktrace (off by default). It can be set in UBSAN_OPTIONS to unwind and print call stacks in addition to diagnostic messages. For now these stacks are printed only in vptr checker. This change is based on http://reviews.llvm.org/D4410 by Byoungyoung Lee! git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213783 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-23[UBSan] Introduce UBSAN_OPTIONS environment variable.Alexey Samsonov
If UBSan is run in a standalone mode (w/o any other sanitizer), it still uses functions from sanitizer_common, some of which depend on the value of runtime flags. Allow to override the default values of these flags with UBSAN_OPTIONS variable. In particular, UBSAN_OPTIONS=symbolize=0 can be used to turn off online symbolization. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@213782 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-13[Sanitizer] Merge AnsiColorDecorator and SanitizerCommonDecorator, use the ↵Alexey Samsonov
latter in UBSan git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210959 91177308-0d34-0410-b5e6-96231b3b80d8
2014-06-13[UBSan] Respect runtime flag for colorizing reportsAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@210950 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-12[UBSan] Parse common runtime flags before using a symbolizerAlexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@201217 91177308-0d34-0410-b5e6-96231b3b80d8
2013-12-18[Sanitizers] Rename Symbolizer::SymbolizeCode to Symbolizer::SymbolizePCTimur Iskhodzhanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@197569 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-14[UBSan] Update UBSan location rendering to match r194686Alexey Samsonov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194687 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-25Overhaul the symbolizer interface.Peter Collingbourne
This moves away from creating the symbolizer object and initializing the external symbolizer as separate steps. Those steps now always take place together. Sanitizers with a legacy requirement to specify their own symbolizer path should use InitSymbolizer to initialize the symbolizer with the desired path, and GetSymbolizer to access the symbolizer. Sanitizers with no such requirement (e.g. UBSan) can use GetOrInitSymbolizer with no need for initialization. The symbolizer interface has been made thread-safe (as far as I can tell) by protecting its member functions with mutexes. Finally, the symbolizer interface no longer relies on weak externals, the introduction of which was probably a mistake on my part. Differential Revision: http://llvm-reviews.chandlerc.com/D1985 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193448 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-20Runtime support for the indirect function call checker.Peter Collingbourne
Differential Revision: http://llvm-reviews.chandlerc.com/D1339 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193060 91177308-0d34-0410-b5e6-96231b3b80d8
2013-10-04Refactor the usage of strip_path_prefix option and make it more consistent ↵Alexey Samsonov
across sanitizers git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@191943 91177308-0d34-0410-b5e6-96231b3b80d8