summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common
Commit message (Collapse)AuthorAgeFilesLines
...
* [sanitizer] Move exception code to sanitizer_common.Marcos Pividori2017-02-023-1/+55
| | | | | | Differential Revision: https://reviews.llvm.org/D29458 llvm-svn: 293955
* [sanitizer] Add dynamic_runtime_thunk for different sanitizers.Marcos Pividori2017-02-023-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Windows, when the sanitizer is implemented as a shared library (DLL), we need an auxiliary static library dynamic_runtime_thunk that will be linked to the main executable and dlls. In the sanitizer DLL, we are exposing weak functions with WIN_WEAK_EXPORT_DEF(), which exports the default implementation with __dll suffix. For example: for sanitizer coverage, the default implementation of __sanitizer_cov_trace_cmp is exported as: __sanitizer_cov_trace_cmp__dll. In the dynamic_runtime_thunk static library, we include weak aliases to the imported implementation from the dll, using the macro WIN_WEAK_IMPORT_DEF(). By default, all users's programs that include calls to weak functions like __sanitizer_cov_trace_cmp, will be redirected to the implementation in the dll, when linking to dynamic_runtime_thunk. After this diff, we are able to compile code with sanitizer coverage instrumentation on Windows. When the instrumented object files are linked with clang-rt_asan_dynamic_runtime_thunk-arch.lib all the weak symbols will be resolved to the implementation imported from asan dll. All the files sanitizer_dynamic_runtime_thunk.cc are independent, so we do not need to include a specific list of sanitizers. Now, we compile: [asan|ubsan|sanitizer_coverage]_win_dynamic_runtime_thunk.cc and sanitizer_win_dynamic_runtime_thunk.cc to generate asan_dynamic_runtime_thunk.lib, because we include asan, ubsan and sanitizer coverage in the address sanitizer library. Differential Revision: https://reviews.llvm.org/D29158 llvm-svn: 293953
* [sanitizer] Intercept weak functions in dll_thunks.Marcos Pividori2017-02-023-2/+38
| | | | | | | | | | | | | | In this diff, I update current implementation of the interception in dll_thunks to consider the special case of weak functions. First we check if the client has redefined the function in the main executable (for example: __sanitizer_cov_trace_pc_guard). It we can't find it, then we look for the default implementation (__sanitizer_cov_trace_pc_guard__dll). The default implementation is always available because the static runtime is linked to the main executable. Differential Revision: https://reviews.llvm.org/D29155 llvm-svn: 293952
* [sanitizer] Split dll_thunks into different sanitizers.Marcos Pividori2017-02-025-0/+284
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the sanitizer is implemented as a static library and is included in the main executable, we need an auxiliary static library dll_thunk that will be linked to the dlls that have instrumentation, so they can refer to the runtime in the main executable. Basically, it uses interception to get a pointer the function in the main executable and override its function with that pointer. Before this diff, all of the implementation for dll_thunks was included in asan. In this diff I split it into different sanitizers, so we can use other sanitizers regardless of whether we include asan or not. All the sanitizers include a file sanitizer_win_dll_thunk.cc that register functions to be intercepted in the binary section: DLLTH When the dll including dll_thunk is initialized, it will execute __dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc, which will consider all the CB registered in the section DLLTH. So, all the functions registered will be intercepted, and redirected to the implementation in the main executable. All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan, ubsan and sanitizer coverage in the address sanitizer library. Differential Revision: https://reviews.llvm.org/D29154 llvm-svn: 293951
* [compiler-rt] Fix incorrect use of snprintfVitaly Buka2017-02-023-11/+25
| | | | | | | | | | | | | | Summary: snprintf returns buffer size needed for printing. If buffer was small, calling code receives incorrectly symbolized buffer and fail. Reviewers: eugenis Subscribers: kubamracek, dberris, kcc Differential Revision: https://reviews.llvm.org/D29440 llvm-svn: 293930
* Fixup of r293882: Forgot to update sanitizer_thread_registry.test.ccKuba Mracek2017-02-021-6/+6
| | | | llvm-svn: 293884
* [tsan] Properly describe GCD worker threads in reportsKuba Mracek2017-02-022-6/+9
| | | | | | | | When dealing with GCD worker threads, TSan currently prints weird things like "created by thread T-1" and "[failed to restore the stack]" in reports. This patch avoids that and instead prints "Thread T3 (...) is a GCD worker thread". Differential Revision: https://reviews.llvm.org/D29103 llvm-svn: 293882
* [asan] Support handle_sigfpe on DarwinJustin Bogner2017-02-011-0/+2
| | | | llvm-svn: 293746
* [sanitizer] Support SANITIZER_INTERCEPTOR_HOOKS on DarwinJustin Bogner2017-02-012-10/+4
| | | | | | | This basically already worked other than weak symbols needing definitions on darwin. llvm-svn: 293741
* [sancov] Move __sancov_default_options declaration outside the namespace ↵Marcos Pividori2017-02-011-2/+2
| | | | | | | | | | | __sancov After this commint, we can include sancov_flags.h and refer to __sancov_default_options without requiring the namespace prefix. Differential Revision: https://reviews.llvm.org/D29167 llvm-svn: 293731
* [sanitizer] Add list of symbols exported in sanitizers' interface.Marcos Pividori2017-01-314-2/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new auxiliary file to each sanitizer: sanitizer_interface.inc, listing all the functions exported, with the macros: INTERFACE_FUNCTION() and INTERFACE_WEAK_FUNCTION(). So, when we need to define or repeat a procedure for each function in the sanitizer's interface, we can define the macros and include that header. In particular, these files are needed for Windows, in the nexts commits. Also, this files could replace the existing files: weak_symbols.txt for Apple. Instead of reading weak_symbols.txt to get the list of weak symbols, we could read the file sanitizer_interface.inc and consider all the symbols included with the macro INTERFACE_WEAK_FUNCTION(Name). In this commit, I only include these files to the sanitizers that work on Windows. We could do the same for the rest of the sanitizers when needed. I updated tests for: Linux, Darwin and Windows. If a new function is exported but is not present in the interface list, the tests "interface_symbols_[darwin|windows|linux].c" fail. Also, I remove the comments: "/* OPTIONAL */" which are not required any more, because we use the macro: INTERFACE_WEAK_FUNCTION() for weak functions. Differential Revision: https://reviews.llvm.org/D29148 llvm-svn: 293682
* [sanitizer] Define as weak, functions that are declared as weak.Marcos Pividori2017-01-313-3/+6
| | | | | | Differential Revision: https://reviews.llvm.org/D29228 llvm-svn: 293681
* [sancov] Add new sanitizer coverage functions to the internal interface.Marcos Pividori2017-01-311-1/+27
| | | | | | Differential Revision: https://reviews.llvm.org/D28597 llvm-svn: 293672
* [sanitizer] Ensure macro parameters are expanded before stringifying.Marcos Pividori2017-01-311-5/+3
| | | | | | | | Add auxiliary macro to ensure parameters are expanded before stringifying. Differential Revision: https://reviews.llvm.org/D29312 llvm-svn: 293671
* [lsan] Renable LSan for x86 LinuxMaxim Ostapenko2017-01-314-4/+70
| | | | | | | | | The missed clang part was committed at https://reviews.llvm.org/rL293609 thus we can reenable LSan for x86 Linux. Differential Revision: https://reviews.llvm.org/D28609 llvm-svn: 293610
* [compiler-rt] Don't change g_tls_size after initialization.Tim Shen2017-01-311-3/+3
| | | | | | | | | | | | | | | | | | | | Summary: g_tls_size is not supposed to be changed after initialization. It's not atomic, not guarded by a lock, nor thread_local. But it's read by multiple threads. The reason why it's mutated is mips and powerpc64 specific. We can implement the same funcitonality without mutating g_tls_size. I'm not sure how to write a test for this. Please advice. Thanks! Reviewers: eugenis, kcc Subscribers: kubamracek, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D29236 llvm-svn: 293586
* Recommit: Stop intercepting some malloc-related functions on FreeBSD andDimitry Andric2017-01-302-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | macOS Summary: In https://bugs.freebsd.org/215125 I was notified that some configure scripts attempt to test for the Linux-specific `mallinfo` and `mallopt` functions by compiling and linking small programs which references the functions, and observing whether that results in errors. FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so normally these tests would fail, but when sanitizers are enabled, they incorrectly succeed, because the sanitizers define interceptors for these functions. This also applies to some other malloc-related functions, such as `memalign`, `pvalloc` and `cfree`. Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`, `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers. Also delete the non-functional `cfree` wrapper for Windows, to fix the test cases on that platform. Reviewers: emaste, kcc, rnk Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D27654 llvm-svn: 293536
* [windows] Properly use dllimport / dllexport.Marcos Pividori2017-01-291-0/+4
| | | | | | | | | Update the headers, so we can change the dllexports to dllimport when defining SANITIZER_IMPORT_INTERFACE. Differential Revision: https://reviews.llvm.org/D29052 llvm-svn: 293422
* General definition for weak functionsMarcos Pividori2017-01-298-61/+155
| | | | | | | | | | | | | | | | | | In this diff, I define a general macro for defining weak functions with a default implementation: "SANITIZER_INTERFACE_WEAK_DEF()". This way, we simplify the implementation for different platforms. For example, we cannot define weak functions on Windows, but we can use linker pragmas to create an alias to a default implementation. All of these implementation details are hidden in the new macro. Also, as I modify the name for exported weak symbols on Windows, I needed to temporarily disable "dll_host" test for asan, which checks the list of functions included in asan_win_dll_thunk. Differential Revision: https://reviews.llvm.org/D28596 llvm-svn: 293419
* Revert "Stop intercepting some malloc-related functions on FreeBSD and macOS"Evgeniy Stepanov2017-01-272-15/+0
| | | | | | | | This reverts r293337, which breaks tests on Windows: malloc-no-intercept-499eb7.o : error LNK2019: unresolved external symbol _mallinfo referenced in function _main llvm-svn: 293346
* Stop intercepting some malloc-related functions on FreeBSD and macOSDimitry Andric2017-01-272-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: In https://bugs.freebsd.org/215125 I was notified that some configure scripts attempt to test for the Linux-specific `mallinfo` and `mallopt` functions by compiling and linking small programs which references the functions, and observing whether that results in errors. FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so normally these tests would fail, but when sanitizers are enabled, they incorrectly succeed, because the sanitizers define interceptors for these functions. This also applies to some other malloc-related functions, such as `memalign`, `pvalloc` and `cfree`. Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`, `pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers. Reviewers: emaste, kcc Subscribers: hans, joerg, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D27654 llvm-svn: 293337
* [asan] fix __sanitizer_cov_with_check to get the correct caller PC. Before ↵Kostya Serebryany2017-01-251-1/+2
| | | | | | this fix the code relied on the fact that the other function (__sanitizer_cov) is inlined. This was true with clang builds on x86, but not true with gcc builds on x86 and on PPC. This caused bot redness after r292862 llvm-svn: 292998
* Fix pc_array bounds check to use elements instead of bytesReid Kleckner2017-01-241-2/+1
| | | | | | | | | | pc_array_size and kPcArrayMaxSize appear to be measured in elements, not bytes, so we shouldn't multiply idx by sizeof(uptr) in this bounds check. 32-bit Chrome was tripping this assertion because it has 64 million coverage points. I don't think it's worth adding a test that has that many coverage points. llvm-svn: 292955
* Revert "[lsan] Enable LSan for x86 Linux."Evgeniy Stepanov2017-01-234-70/+4
| | | | | | | Breaks tests on i686/Linux due to missing clang driver support: error: unsupported option '-fsanitize=leak' for target 'i386-unknown-linux-gnu' llvm-svn: 292844
* [lsan] Enable LSan for x86 Linux.Maxim Ostapenko2017-01-234-4/+70
| | | | | | | | | | | | | People keep asking LSan to be available on 32 bit targets (e.g. https://github.com/google/sanitizers/issues/403) despite the fact that false negative ratio might be huge (up to 85%). This happens for big real world applications that may contain random binary data (e.g. browser), but for smaller apps situation is not so terrible and LSan still might be useful. This patch adds initial support for x86 Linux (disabled by default), ARM32 is in TODO list. We used this patch (well, ported to GCC) on our 32 bit mobile emulators and it worked pretty fine thus I'm posting it here to initiate further discussion. Differential Revision: https://reviews.llvm.org/D28609 llvm-svn: 292775
* [sanitizer] [asan] Use macros to simplify weak aliases on Windows.Marcos Pividori2017-01-202-5/+62
| | | | | | | | | This patch adds some useful macros for dealing with pragma directives on Windows. Also, I add appropriate documentation for future users. Differential Revision: https://reviews.llvm.org/D28525 llvm-svn: 292650
* Whenever reasonable, merge ASAN quarantine batches to save memory.Alex Shlyapnikov2017-01-195-29/+321
| | | | | | | | | | | | | | | | Summary: There are cases when thread local quarantine drains almost empty quarantine batches into the global quarantine. The current approach leaves them almost empty, which might create a huge memory overhead (each batch is 4K/8K, depends on bitness). Reviewers: eugenis Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D28068 llvm-svn: 292525
* Remove SANITIZER_LINUX ifdefsReid Kleckner2017-01-131-2/+0
| | | | | | | Somehow this causes lots of test failures on Windows. These appear to have been accidentally added back in r291736. llvm-svn: 291947
* ASAN activate/deactive controls thread_local_quarantine_size_kb option.Alex Shlyapnikov2017-01-121-9/+23
| | | | | | | | | | | | | | | Summary: Bypass quarantine altogether when quarantine size is set ot zero. Also, relax atomic load/store of quarantine parameters, the release/acquire semantics is an overkill here. Reviewers: eugenis Subscribers: kubabrecka, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D28586 llvm-svn: 291791
* Revert "[sancov] moving sancov rt to sancov/ directory"Mike Aizatsky2017-01-127-6/+302
| | | | | | | | This reverts commit https://reviews.llvm.org/rL291734 Reason: mac breakage http://lab.llvm.org:8080/green//job/clang-stage1-configure-RA_build/28798/consoleFull#1657087648e9a0fee5-ebcc-4238-a641-c5aa112c323e llvm-svn: 291736
* [sancov] there are windows tests that check linker symbolsMike Aizatsky2017-01-121-2/+0
| | | | llvm-svn: 291735
* [sancov] moving sancov rt to sancov/ directoryMike Aizatsky2017-01-127-300/+8
| | | | | | | | Subscribers: kubabrecka, mgorny Differential Revision: https://reviews.llvm.org/D28541 llvm-svn: 291734
* Follow-up for r291277: Add a return to silence GCC's "control reaches end of ↵Kuba Mracek2017-01-111-0/+1
| | | | | | non-void function" warning. llvm-svn: 291639
* [tsan] Implement a 'ignore_noninstrumented_modules' flag to better suppress ↵Kuba Mracek2017-01-112-11/+67
| | | | | | | | | | | | | | false positive races On Darwin, we currently use 'ignore_interceptors_accesses', which is a heavy-weight solution that simply turns of race detection in all interceptors. This was done to suppress false positives coming from system libraries (non-instrumented code), but it also silences a lot of real races. This patch implements an alternative approach that should allow us to enable interceptors and report races coming from them, but only if they are called directly from instrumented code. The patch matches the caller PC in each interceptors. For non-instrumented code, we call ThreadIgnoreBegin. The assumption here is that the number of instrumented modules is low. Most likely there's only one (the instrumented main executable) and all the other modules are system libraries (non-instrumented). Differential Revision: https://reviews.llvm.org/D28264 llvm-svn: 291631
* [sanitizer] Fix sigaction definition on 32-bit sparcMaxim Ostapenko2017-01-101-2/+5
| | | | | | | | Patch by James Clarke. Differential Revision: https://reviews.llvm.org/D28309 llvm-svn: 291561
* Revert r291509, 291510 and 291511Diana Picus2017-01-101-23/+9
| | | | | | | | | | | | | | | | | | | | | | | Revert "ASAN activate/deactive controls thread_local_quarantine_size_kb option." Revert "Bypass quarantine when quarantine size is set ot zero." Revert "ASAN activate/deactive controls thread_local_quarantine_size_kb option." One of these commits broke some of the ARM / AArch64 buildbots: TEST 'AddressSanitizer-aarch64-linux :: TestCases/Posix/start-deactivated.cc' FAILED Command Output (stderr): -- /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc:85:12: error: expected string not found in input // CHECK: WARNING: AddressSanitizer failed to allocate 0xfff{{.*}} bytes ^ <stdin>:1:1: note: scanning from here start-deactivated.cc.tmp: /home/buildslave/buildslave/clang-cmake-aarch64-42vma/llvm/projects/compiler-rt/test/asan/TestCases/Posix/start-deactivated.cc:40: void test_malloc_shadow(char *, size_t, bool): Assertion `(char *)__asan_region_is_poisoned(p - 1, sz + 1) == (expect_redzones ? p - 1 : nullptr)' failed. ^ <stdin>:2:1: note: possible intended match here Error: Aborted (core dumped) ^ llvm-svn: 291560
* Make cmake link flag naming consistentFrancis Ricci2017-01-101-3/+3
| | | | | | | | | | | | | | | | | | | Summary: The build system was inconsistent in its naming conventions for link flags. This patch changes all uses of LINKFLAGS to LINK_FLAGS, for consistency with cmake's LINK_FLAGS property. This patch should make it easier to search the source code for uses of link flags, as well as providing the benefit of improved style and consistency. Reviewers: compnerd, beanz Subscribers: kubabrecka, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D28506 llvm-svn: 291539
* Bypass quarantine when quarantine size is set ot zero.Alex Shlyapnikov2017-01-091-2/+14
| | | | llvm-svn: 291510
* ASAN activate/deactive controls thread_local_quarantine_size_kb option.Alex Shlyapnikov2017-01-091-8/+10
| | | | llvm-svn: 291509
* [compiler-rt] Include <dlfcn.h> unconditionallyKuba Mracek2017-01-091-3/+0
| | | | | | | | This fixes a build issue with musl-libc. Differential Revision: https://reviews.llvm.org/D21656 llvm-svn: 291454
* Enable weak hooks on darwinFrancis Ricci2017-01-093-1/+10
| | | | | | | | | | | | | | | | Summary: By default, darwin requires a definition for weak interface functions at link time. Adding the '-U' link flag with each weak function allows these weak interface functions to be used without definitions, which mirrors behavior on linux and windows. Reviewers: compnerd, eugenis Subscribers: kubabrecka, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D28203 llvm-svn: 291417
* Revert "Enable weak hooks on darwin"Francis Ricci2017-01-072-7/+1
| | | | | | | | Reverts accidental upload. This reverts commit 421408c0f2cc811bcf9a945be6e95e46f76cb358. llvm-svn: 291316
* Enable weak hooks on darwinFrancis Ricci2017-01-072-1/+7
| | | | | | | | | | | | | | | | Summary: By default, darwin requires a definition for weak interface functions at link time. Adding the '-U' link flag with each weak function allows these weak interface functions to be used without definitions, which mirrors behavior on linux and windows. Reviewers: compnerd, eugenis Subscribers: kubabrecka, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D28203 llvm-svn: 291314
* [sanitizer] Use architecture/slice information when symbolizing fat Mach-O ↵Kuba Mracek2017-01-067-28/+67
| | | | | | | | | | 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 llvm-svn: 291287
* [sanitizer] Add a 'print_module_map' flag which prints modules with UUIDs on ↵Kuba Mracek2017-01-067-11/+88
| | | | | | | | | | Darwin This patch add a new sanitizer flag, print_module_map, which enables printing a module map when the process exits, or after each report (for TSan). The output format is very similar to what Crash Reporter produces on Darwin (e.g. the format of module UUIDs). This enables users to use the existing symbol servers to offline symbolicate and aggregate reports. Differential Revision: https://reviews.llvm.org/D27400 llvm-svn: 291277
* [sanitizer] Track which modules are instrumented in LoadedModule objectsKuba Mracek2017-01-064-17/+42
| | | | | | | | This patch adds tracking which modules are instrumented and which are not. On macOS, instrumented modules link against the ASan/TSan/... dylib, so we can just check if such a load command exists or not. Differential Revision: https://reviews.llvm.org/D28263 llvm-svn: 291268
* [sancov] introducing SANCOV_OPTIONSMike Aizatsky2017-01-065-4/+135
| | | | | | | Reintroducing https://reviews.llvm.org/rL291068 Define options function everywhere but linux. llvm-svn: 291267
* Improved ASAN allocator and quarantine stats.Evgeniy Stepanov2017-01-052-4/+25
| | | | | | | | | | | | | | Summary: Improved ASAN allocator and quarantine stats. Reviewers: eugenis Patch by Alex Shlyapnikov. Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D28333 llvm-svn: 291183
* [compiler-rt] Make macros use __sanitizer::uptr instead of just uptr.Vitaly Buka2017-01-051-9/+10
| | | | | | | | | | | | Summary: This allows to use macros outside of __sanitizer namespace Reviewers: eugenis Subscribers: kubabrecka, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D28375 llvm-svn: 291175
* [asan] Fix comparison in BufferedStackTrace::LocatePcInTraceVitaly Buka2017-01-051-11/+6
| | | | | | | | | | | | | | Summary: Debug builds can have larger distance between stack trace and PC on that stack. If we assume that PC is always correct we can snap it to the nearest trace. Reviewers: eugenis Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D28342 llvm-svn: 291173
OpenPOWER on IntegriCloud