summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan
Commit message (Collapse)AuthorAgeFilesLines
...
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.7Julian Lettner2019-07-024-29/+36
| | | | | | | | | | | Factor out `ExtractLongJmpSp` helper function and move platform-specific code to tsan_platform_{linux,mac}.cc. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D64050 llvm-svn: 364947
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.3Julian Lettner2019-07-012-36/+8
| | | | | | | | | | Remove unnecessary computation of mangled SP for x86_64 architecture. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D63944 llvm-svn: 364874
* [TSan] Fix initialized and declared ‘extern’ warningJulian Lettner2019-07-011-2/+5
| | | | | | | | | | | | Avoid the following warning which fails a bot (via -Werror). ``` /tmp/gotsan.JfrpVPu7pG/gotsan.cc:10456:25: error: ‘_tsan_pointer_chk_guard’ initialized and declared ‘extern’ [-Werror] extern "C" __tsan::uptr _tsan_pointer_chk_guard = 0; ^~~~~~~~~~~~~~~~~~~~~~~ ``` llvm-svn: 364823
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.2Julian Lettner2019-07-012-8/+4
| | | | | | | | | | | | Switch `LongJmp` over to lookup JmpBuf via plain old (unmangled) SP. This makes the computation of mangled SPs in the TSan assembly files unnecessary, which will be cleaned up in follow-up revisions. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D63942 llvm-svn: 364818
* [TSan] Attempt to fix linker error for Linux on AArch64Julian Lettner2019-06-292-9/+2
| | | | | | Introduced in 5be69ebe121d5b6ea284c3dc6d1cd5098c94f353. llvm-svn: 364700
* [TSan] Fix build build breakage on AndroidJulian Lettner2019-06-281-1/+1
| | | | | | Introduced in 5be69ebe121d5b6ea284c3dc6d1cd5098c94f353. llvm-svn: 364676
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.1Julian Lettner2019-06-284-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | TSan needs to infer which calls to setjmp/longjmp are corresponding pairs. My understanding is, that we can't simply use the jmp_buf address, since this buffer is just a plain data structure storing the environment (registers) with no additional semantics, i.e., it can be copied around and is still expected to work. So we use the stack pointer (SP) instead. The setjmp interceptor stores some metadata, which is then consumed in the corresponding call to longjmp. We use the SP as an "index" (stable identifier) into the metadata table. So far so good. However, when mangling is used, the setjmp interceptor observes the UNmangled SP, but the longjmp interceptor only knows the mangled value for SP. To still correlate corresponding pairs of calls, TSan currently derives the mangled representation in setjmp and uses it as the stable identifer, so that longjmp can do it's lookup. Currently, this works since "mangling" simply means XOR with a secret value. However, in the future we want to use operations that do not allow us to easily go from unmangled -> mangled (pointer authentication). Going from mangled -> unmangled should still be possible (for pointer authentication it means zeroing a few bits). This patch is part 1 of changing set/longjmp interceptors to use the unmangled SP for metadata lookup. Instead of deriving the mangled SP in setjmp, we will derive the unmangled SP in longjmp. Since this change involves difficult-to-test code, it will be done in (at least) 2 parts: This patch only replicates the existing behavior and checks that the newly computed value for SP matches with what we have been doing so far. This should help me to fix issues on architectures I cannot test directly. I tested this patch on x86-64 (Linux/Darwin) and arm64 (Darwin). This patch will also address an orthogonal issue: there is a lot of code duplication in the assembly files, because the `void __tsan_setjmp(uptr sp, uptr mangled_sp)` already demands the mangled SP. This means that the code for computing the mangled SP is duplicated at every call site (in assembly). Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D60981 llvm-svn: 364662
* Stop counting pops in tsan/check_analyze.sh.Evgeniy Stepanov2019-06-171-2/+0
| | | | | | | | | | | | | | | | | Summary: It looks like LLVM has started doing less tail duplication in this code, or something like that, resulting in a significantly smaller number of pop instructions (16 -> 12). Removing the check. Reviewers: vitalybuka, dvyukov Subscribers: kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D63450 llvm-svn: 363615
* Improve error message when '=' is missing in {ASAN,...}_OPTIONS.Vitaly Buka2019-06-154-7/+9
| | | | | | | | | | | | | | | | | | Summary: It's handling isses as described here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89832 Patch by Martin Liška. Reviewers: kcc, vitalybuka Reviewed By: vitalybuka Subscribers: cryptoad, kubamracek Differential Revision: https://reviews.llvm.org/D59876 llvm-svn: 363480
* [compiler-rt][tests] Propagate COMPILER_RT_UNITTEST_LINK_FLAGSHubert Tong2019-05-011-1/+1
| | | | | | | | | | | | | | | | | | | | `COMPILER_RT_UNITTEST_LINK_FLAGS` is dropped in many places, unlike `COMPILER_RT_UNITTEST_CFLAGS`. This patch attempts to remove that inconsistency. Previously reviewed as part of D58951. Reviewers: sfertile, peter.smith, pzheng, phosek, Hahnfeld, nemanjai, jasonliu Reviewed By: sfertile Subscribers: jsji, kubamracek, dberris, mgorny, delcypher, jdoerfert, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60143 llvm-svn: 359733
* [Sanitizer] Reland "Cleanup INTERCEPT_FUNCTION macro"Julian Lettner2019-05-011-7/+6
| | | | | | | | | | | | | | | | | | | | | | On Linux both version of the INTERCEPT_FUNCTION macro now return true when interception was successful. Adapt and cleanup some usages. Also note that `&(func) == &WRAP(func)` is a link-time property, but we do a runtime check. Tested on Linux and macOS. Previous attempt reverted by: 5642c3feb03d020dc06a62e3dc54f3206a97a391 This attempt to bring order to the interceptor macro goes the other direction and aligns the Linux implementation with the way things are done on Windows. Reviewed By: vitalybuka, rnk Differential Revision: https://reviews.llvm.org/D61358 llvm-svn: 359725
* [sanitizer][NFC] Set LargeMmapAllocator type from PrimaryAllocatorVitaly Buka2019-05-011-2/+1
| | | | | | | | | | | | | | They need to have same AddressSpaceView and MapUnmapCallback. Reviewers: eugenis Subscribers: kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61168 llvm-svn: 359719
* [sanitizer][NFC] Get type of AllocatorCache from CombinedAllocatorVitaly Buka2019-05-011-3/+2
| | | | | | | | | | | | | | Reviewers: eugenis, cryptoad, kcc Reviewed By: kcc Subscribers: kcc, kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61155 llvm-svn: 359715
* [sanitizer] Implement reallocarray.Evgeniy Stepanov2019-05-013-0/+25
| | | | | | | | | | | | | | | | Summary: It's a cross of calloc and realloc. Sanitizers implement calloc-like check for size overflow. Reviewers: vitalybuka, kcc Subscribers: kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61108 llvm-svn: 359708
* Revert r359325 "[NFC][Sanitizer] Change "return type" of INTERCEPT_FUNCTION ↵Reid Kleckner2019-04-301-7/+17
| | | | | | | | | | | | | | | to void" Changing INTERCEPT_FUNCTION to return void is not functionally correct. IMO the best way to communicate failure or success of interception is with a return value, not some external address comparison. This change was also creating link errors for _except_handler4_common, which is exported from ucrtbase.dll in 32-bit Windows. Also revert dependent changes r359362 and r359466. llvm-svn: 359611
* [sanitizer] Calculate SizeClassAllocator32::ByteMap type from ↵Vitaly Buka2019-04-271-8/+3
| | | | | | | | | | | | | | Params::kSpaceSize and Params::kRegionSizeLog Reviewers: eugenis Subscribers: kubamracek, cryptoad, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61206 llvm-svn: 359374
* [NFC][Sanitizer] Remove GetRealFunctionAddress and replace usagesJulian Lettner2019-04-271-17/+7
| | | | | | | | Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D61205 llvm-svn: 359362
* [NFC] Remove ::kForTest from AP64, it does not use it.Vitaly Buka2019-04-261-1/+1
| | | | llvm-svn: 359323
* [lsan] Use SANITIZER_WORDSIZE when selecting ByteMapVitaly Buka2019-04-261-2/+2
| | | | | | | Originally this code was added for 64-bit platform and it was never update. Add static_assert to validate type of ByteMap. llvm-svn: 359286
* Revert "[lsan] Use SANITIZER_WORDSIZE when selecting ByteMap"Vitaly Buka2019-04-261-2/+2
| | | | | | | | New static_assert fails on a bot. This reverts commit r359269. llvm-svn: 359276
* [lsan] Use SANITIZER_WORDSIZE when selecting ByteMapVitaly Buka2019-04-261-2/+2
| | | | | | | Originally this code as added for 64-bit platform and was never changed. Add static_assert to make sure that we have correct map on all platforms. llvm-svn: 359269
* [TSan] Support fiber API on macOSJulian Lettner2019-04-206-22/+56
| | | | | | | | | | | | | | Committing on behalf of Yuri Per (yuri). Reviewers: dvyukov, kubamracek, yln Reviewed By: kubamracek Authored By: yuri Differential Revision: https://reviews.llvm.org/D58110 llvm-svn: 358802
* Revert "tsan: Update test expectations."Matt Morehouse2019-04-111-2/+2
| | | | | | This reverts r357831 to go with r358113. llvm-svn: 358202
* tsan: Update test expectations.Peter Collingbourne2019-04-061-2/+2
| | | | llvm-svn: 357831
* [NFC][TSan][libdispatch] Better CMake variable namesJulian Lettner2019-04-042-2/+2
| | | | llvm-svn: 357664
* [TSan][libdispatch] Avoid infinite recursion in dispatch_apply[_f] interceptorsJulian Lettner2019-03-191-9/+29
| | | | | | | | | | | | | | | | | In libdispatch, dispatch_apply is implemented in terms of dispatch_apply_f. Unfortunately, this means that we can't implement the interceptor for dispatch_apply_f by forwarding to the dispatch_apply interceptor. In the interceptor dispatch_apply_f, we can't use WRAP(dispatch_apply). WRAP(dispatch_apply) -> REAL(dispatch_apply_f). Requires duplication of some setup code. Reviewed By: kubamracek Differential Revision: https://reviews.llvm.org/D59526 llvm-svn: 356467
* [TSan][libdispatch] Enable linking and running of tests on LinuxJulian Lettner2019-03-152-4/+2
| | | | | | | | | | | | | | | | | | | | | When COMPILER_RT_INTERCEPT_LIBDISPATCH is ON the TSan runtime library now has a dependency on the blocks runtime and libdispatch. Make sure we set all the required linking options. Also add cmake options for specifying additional library paths to instruct the linker where to search for libdispatch and the blocks runtime. This allows us to build TSan runtime with libdispatch support without installing those libraries into default linker library paths. `CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY` is necessary to avoid aborting the build due to failing the link step in CMake's check_c_compiler test. Reviewed By: dvyukov, kubamracek Differential Revision: https://reviews.llvm.org/D59334 llvm-svn: 356281
* [TSan][libdispatch] Remove dependency on system headersJulian Lettner2019-03-142-15/+75
| | | | | | | | | | | | | | | | | | | | | | | Including <dispatch/dispatch.h> and <Blocks.h> transitively pulls in other system headers. Let's try to avoid that. Blocks.h: compiler-rt already includes a blocks runtime. Just use the header file that comes with it. dispatch.h: Declare the bare minimum required for our implementation, i.e., everything needed to define the interceptors, but not the interceptors themselves. See tsan_dispatch_defs.h. I spotted a few other places in compile-rt, where we declare libdispatch types. Maybe this file can be moved to sanitizer_common if we deem it useful enough. tsan_libdispatch.cc now compiles on Linux/Clang (requires support for -fblocks). Linking still requires some manual configuration. Reviewed By: kubamracek Differential Revision: https://reviews.llvm.org/D59145 llvm-svn: 356201
* [TSan] Initialize libdispatch interceptors if necessaryJulian Lettner2019-03-082-0/+46
| | | | | | | | | | | | On Linux (and other non-Darwin platforms) we need to initialize interceptors. Since tsan_libdispatch.cc is compiled optionally, add a weak default implementation of `InitializeLibdispatchInterceptors`. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D59113 llvm-svn: 355717
* [NFC][TSan] Remove unnecessary #includeJulian Lettner2019-03-071-1/+0
| | | | llvm-svn: 355620
* [TSan][Linux] Fix libdispatch interception macros compilation errorsJulian Lettner2019-03-071-10/+16
| | | | | | | | | | | | | | | | | | | Most libdispatch functions come in two variants: callbacks can be specified via blocks or function pointers. Some of our interceptors for the block variant actually forward to the function variant. However, on Linux, `DECLARE_REAL(name)` has to appear before `REAL(name)`. This patch reorders _f variant interceptors before _b variants where possible and forward declares the _f variant in the remaining cases (cyclic dependency between _f and _b interceptors). Also rename macro to DISPATCH_INTERCEPT_ASYNC_F for better consistency. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D59067 llvm-svn: 355619
* [NFC][TSan][libdispatch] Rename tsan_block_context_t -> block_context_tJulian Lettner2019-03-061-29/+27
| | | | | | | 'tsan_' part of the struct name is redundant since we are already inside the __tsan namespace. llvm-svn: 355539
* [tsan] Support interception of libdispatch on LinuxJulian Lettner2019-03-062-7/+11
| | | | | | | | | | | | | | | | | | | | | | | This is a new attempt for bringing TSan libdispatch support to Linux. The main issue with the last patch (https://reviews.llvm.org/D53171) was that we want to avoid building a separate library. The updated plan is as follows: 1) Hide libdispatch support behind a flag: true on Darwin, false elsewhere. If flag is specified, assume that libdispatch header and -flbocks is available for building. This way we can directly include the libdispatch header and rely on blocks runtime for our implementation. 2) Optionally/weakly intercept libdispatch API functions. This patch accomplishes 1). It compiles (without the flag enabled) on Linux. Follow-up patches will provide 2) and enabling of tests on Linux. Reviewed By: dvyukov Differential Revision: https://reviews.llvm.org/D58935 llvm-svn: 355538
* [NFC][Sanitizer] Make GetStackTrace a private method of BufferedStackTraceJulian Lettner2019-03-011-7/+6
| | | | | | | | | | GetStackTrace is a implementation detail of BufferedStackTrace. Make it a private method. Reviewed By: vitalybuka Differential-Revision: https://reviews.llvm.org/D58753 llvm-svn: 355232
* [NFC][Sanitizer] Add new BufferedStackTrace::Unwind APIJulian Lettner2019-03-012-17/+5
| | | | | | | | | | | | | | | | | | | | | Retrying without replacing call sites in sanitizer_common (which might not have a symbol definition). Add new Unwind API. This is the final envisioned API with the correct abstraction level. It hides/slow fast unwinder selection from the caller and doesn't take any arguments that would leak that abstraction (i.e., arguments like stack_top/stack_bottom). GetStackTrace will become an implementation detail (private method) of the BufferedStackTrace class. Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D58741 > llvm-svn: 355168 llvm-svn: 355172
* Revert "[NFC][Sanitizer] Add new BufferedStackTrace::Unwind API"Julian Lettner2019-03-012-5/+17
| | | | | | This reverts commit 6112f37e758ebf2405955e091a745f5003c1f562. llvm-svn: 355171
* [NFC][Sanitizer] Add new BufferedStackTrace::Unwind APIJulian Lettner2019-03-012-17/+5
| | | | | | | | | | | | | | | | Add new Unwind API. This is the final envisioned API with the correct abstraction level. It hides/slow fast unwinder selection from the caller and doesn't take any arguments that would leak that abstraction (i.e., arguments like stack_top/stack_bottom). GetStackTrace will become an implementation detail (private method) of the BufferedStackTrace class. Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D58741 llvm-svn: 355168
* [NFC][TSan] Don't define GetStackTrace when compiling for GoJulian Lettner2019-02-281-0/+2
| | | | | | rdar://48455255 llvm-svn: 355053
* [NFC][Sanitizer] Pull up GetStackTrace into sanitizer_commonJulian Lettner2019-02-271-0/+12
| | | | | | | | | | | | | | | | | | | | We already independently declare GetStackTrace in all (except TSan) sanitizer runtime headers. Lets move it to sanitizer_stacktrace.h to have one canonical way to fill in a BufferedStackFrame. Also enables us to use it in sanitizer_common itself. This patch defines GetStackTrace for TSan and moves the function from ubsan_diag.cc to ubsan_diag_standalone.cc to avoid duplicate symbols for the UBSan-ASan runtime. Other than that this patch just moves the code out of headers and into the correct namespace. Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D58651 llvm-svn: 355039
* [NFC][Sanitizer] Hard-code fast/slow unwinder at call siteJulian Lettner2019-02-272-7/+10
| | | | | | | | | | | | | Also assert that the caller always gets what it requested. This purely mechanical change simplifies future refactorings and eventual removal of BufferedStackTrace::Unwind. Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D58557 llvm-svn: 355022
* [Sanitizer] Add interceptor for pthread_sigmaskPavel Labath2019-02-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | Summary: pthread_sigmask is just like sigprocmask, except that its behavior in multithreaded programs is explicitly specified. Sanitizers were lacking a common interceptor for pthread_sigmask (although some specific sanitizers defined custom version), which lead to false positives (at least in msan) when using this function. The interceptor implementation, and its test are based on the equivalent code for sigprocmask. Reviewers: eugenis, vitalybuka Subscribers: kubamracek, delcypher, jfb, jdoerfert, llvm-commits, #sanitizers Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D58382 llvm-svn: 354874
* [Sanitizer] Fix uses of stack->Unwind(..., fast)Julian Lettner2019-02-221-1/+2
| | | | | | | | | | | Apply StackTrace::WillUseFastUnwind(fast) in a few more places missed by my previous patch (https://reviews.llvm.org/D58156). Reviewers: vitalybuka Differential Revision: https://reviews.llvm.org/D58550 llvm-svn: 354695
* [sanitizer] Common macro for .note.GNU-stack directives (NFC)Evgeniy Stepanov2019-02-212-9/+2
| | | | llvm-svn: 354632
* [Sanitizer] On Darwin `__sanitizer_print_stack_trace` only prints topmost frameJulian Lettner2019-02-181-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In compiler-rt we have the notion of a `fast` and a `slow` stack unwinder. Darwin currently only supports the fast unwinder. From reading the code, my understanding is that `BufferedStackTrace::Unwind` can be called with `bp=0, stack_top=0, stack_bottom=0, request_fast_unwind=false`. If `request_fast_unwind=true`, then we alos need to supply bp, stack_top, and stack_bottom. However, `BufferedStackTrace::Unwind` uses `StackTrace::WillUseFastUnwind` which will adapt `request_fast_unwind` if the requested unwinder is not supported. On Darwin, the result is that we don't pass actual values for bp, stack_top, and stack_bottom, but end up using the fast unwinder. The tests then fail because we only print the topmost stack frame. This patch adds a check to `WillUseFastUnwind` at the point of usage to avoid the mismatch between `request_fast_unwind` and what `Unwind` actually does. I am also interested in cleaning up the `request_fast_unwind` machinery so this patch just the simplest thing possible so I can enable the tests. Reviewers: vitalybuka, vsk Differential Revision: https://reviews.llvm.org/D58156 llvm-svn: 354282
* [compiler-rt] Build custom libcxx with libcxxabiJonas Hahnfeld2019-02-171-0/+1
| | | | | | | | | | | | | | | This changes add_custom_libcxx to also build libcxxabi and merges the two into a static and hermetic library. There are multiple advantages: 1) The resulting libFuzzer doesn't expose C++ internals and looks like a plain C library. 2) We don't have to manually link in libstdc++ to provide cxxabi. 3) The sanitizer tests cannot interfere with an installed version of libc++.so in LD_LIBRARY_PATH. Differential Revision: https://reviews.llvm.org/D58013 llvm-svn: 354212
* [compiler-rt] Cleanup usage of C++ ABI libraryJonas Hahnfeld2019-02-162-3/+9
| | | | | | | | | | | | | Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking unit tests. This needs to be a full C++ library and cannot be libcxxabi. Recommit r354132 which I reverted in r354153 because it broke a sanitizer bot. This was because of the "fixes" for pthread linking, so I've removed these changes. Differential Revision: https://reviews.llvm.org/D58012 llvm-svn: 354198
* Revert "[compiler-rt] Cleanup usage of C++ ABI library"Jonas Hahnfeld2019-02-152-9/+3
| | | | | | | This reverts r354132 because it breaks sanitizer-x86_64-linux: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/19915 llvm-svn: 354153
* [compiler-rt] Cleanup usage of C++ ABI libraryJonas Hahnfeld2019-02-152-3/+9
| | | | | | | | | Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking unit tests. This needs to be a full C++ library and cannot be libcxxabi. Differential Revision: https://reviews.llvm.org/D58012 llvm-svn: 354132
* Dmitry Vyukov2019-02-136-10/+99
| | | | | | | | | | | | | | | | | | | | | | | tsan: add fiber support This patch adds functions for managing fibers: __tsan_get_current_fiber() __tsan_create_fiber() __tsan_destroy_fiber() __tsan_switch_to_fiber() __tsan_set_fiber_name() See the added tests for use examples. Author: yuri (Yuri Per) Reviewed in: https://reviews.llvm.org/D54889 [The previous commit of this change was reverted, this is a resubmit with a squashed fix for check_analyze.sh and COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED] llvm-svn: 353947
* Revert "tsan: update check_analyze.sh"Diana Picus2019-02-131-1/+7
| | | | | | This reverts commit r353820, to go with the revert of r353817. llvm-svn: 353942
OpenPOWER on IntegriCloud