Commit Graph

1724 Commits

Author SHA1 Message Date
Dmitry Vyukov d97865e530 tsan: allow the Go runtime to return multiple stack frames for a single PC
This fix allows tsan to report stack traces correctly even in the
presence of mid-stack inlining by the Go compiler.

See https://go-review.googlesource.com/c/go/+/195781 for the Go runtime side of this change.

Author: randall77 (Keith Randall)
Reviewed: https://reviews.llvm.org/D67671
llvm-svn: 372205
2019-09-18 09:18:04 +00:00
Vitaly Buka c0fa632236 Remove NOLINTs from compiler-rt
llvm-svn: 371687
2019-09-11 23:19:48 +00:00
Vitaly Buka 48eb4a27d1 Update compiler-rt cpplint.py
adb3500107

llvm-svn: 371675
2019-09-11 21:33:06 +00:00
Julian Lettner fc910c507e [TSan] Add interceptors for mach_vm_[de]allocate
I verified that the test is red without the interceptors.

rdar://40334350

Reviewed By: kubamracek, vitalybuka

Differential Revision: https://reviews.llvm.org/D66616

llvm-svn: 371439
2019-09-09 18:57:32 +00:00
Julian Lettner 894abb46f8 [TSan] #include header instead of forward declaring interceptees
llvm-svn: 369601
2019-08-21 23:42:06 +00:00
Julian Lettner def061e6f0 [TSan] Rename file with libdispatch interceptors
llvm-svn: 369314
2019-08-20 00:04:19 +00:00
Julian Lettner e644d5e230 [TSan] Rename file to make it clear that it defines interceptors
Rename file `tsan_libdispatch.cpp -> tsan_libdispatch_interceptors.cpp`
to make it clear that it's main purpose is defining interceptors.

llvm-svn: 369289
2019-08-19 18:41:20 +00:00
Julian Lettner 0c2f26d664 Revert "[TSan] Don't guard #include <xpc/xpc.h>"
This reverts commit 8191585b36.

llvm-svn: 369165
2019-08-16 22:58:13 +00:00
Julian Lettner 4a9b747bfb [TSan] Add interceptors for os_unfair_lock
llvm-svn: 369164
2019-08-16 22:41:25 +00:00
Julian Lettner 8191585b36 [TSan] Don't guard #include <xpc/xpc.h>
The xpc_connection_* APIs that we are intercepting are available
starting at macOS 10.7. This is old enough so that we don't need to
guard them.

llvm-svn: 369150
2019-08-16 20:43:09 +00:00
Alexander Richardson 0b168ffdc3 [TSAN] Fix tsan on FreeBSD after D54889
Summary:
It appears that since https://reviews.llvm.org/D54889, BackgroundThread()
crashes immediately because cur_thread()-> will return a null pointer
which is then dereferenced. I'm not sure why I only see this issue on
FreeBSD and not Linux since it should also be unintialized on other platforms.

Reviewers: yuri, dvyukov, dim, emaste

Subscribers: kubamracek, krytarowski, #sanitizers, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D65705

llvm-svn: 368103
2019-08-06 22:30:48 +00:00
David Carlier 906e727972 [Sanitizer] Linux explicitally migrate shadow mapping to Transparent Huge Page
in madvise mode, the shadow pages will be migrated only via madvise explicit calls.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D65775

llvm-svn: 368090
2019-08-06 21:30:03 +00:00
David Carlier 1d92925a5a [Sanitizer] Linux refactor shadow huge page mode handling
Disabling Transparent huge page mode refactored in one function.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D65771

llvm-svn: 367925
2019-08-05 20:54:36 +00:00
Nico Weber bb7ad98a47 Follow-up for r367863 and r367656
llvm-svn: 367888
2019-08-05 16:50:56 +00:00
Nico Weber 4a1a113a99 Remove a few straggler ".cc"s in compiler-rt/lib
llvm-svn: 367589
2019-08-01 17:53:25 +00:00
Nico Weber d11b16e1fe compiler-rt: Rename .cc file in lib/tsan/{benchmarks,dd,go} to .cpp
Like r367463, but for tsan/{benchmarks,dd,go}.

The files benchmarks aren't referenced in the build anywhere and where added
in 2012 with the comment "no Makefiles yet".

llvm-svn: 367567
2019-08-01 14:30:49 +00:00
Nico Weber 5de29a4b0e compiler-rt: Rename .cc file in lib/tsan/tests/{rtl,unit} to .cpp
Like r367463, but for tsan/tests/{rtl,unit}.

llvm-svn: 367566
2019-08-01 14:26:37 +00:00
Nico Weber 5a3bb1a4d6 compiler-rt: Rename .cc file in lib/tsan/rtl to .cpp
Like r367463, but for tsan/rtl.

llvm-svn: 367564
2019-08-01 14:22:42 +00:00
Nico Weber f724b460bd Attempt to heal tsan bot after r367463
llvm-svn: 367469
2019-07-31 19:31:36 +00:00
Nico Weber 65492d959b compiler-rt: Rename .cc file in lib/sanitizer_common to .cpp
See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done

and manually updated (many) references to renamed files found by that.

llvm-svn: 367463
2019-07-31 18:51:27 +00:00
Julian Lettner d069a19210 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.6
Cleanup ARM64 assembly after removing unnecessary computation of mangled
stack pointer in previous commit.

llvm-svn: 366258
2019-07-16 20:41:04 +00:00
Julian Lettner e6e33cf9f5 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.10
Remove now-unused assembly code for determining xor key on
Linux/AArch64. This is the final commit of this refactoring.

llvm-svn: 366225
2019-07-16 16:22:04 +00:00
Julian Lettner c48162db99 [TSan] Fix asm token error (again)
llvm-svn: 366150
2019-07-15 23:05:14 +00:00
Julian Lettner 228f80d92d [TSan] Fix asm token error
llvm-svn: 366131
2019-07-15 21:22:57 +00:00
Julian Lettner 39d888c1e4 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.9
Switch over to computing the xor key in C, instead of assembly for
Linux/AArch64.

llvm-svn: 366126
2019-07-15 20:22:27 +00:00
Julian Lettner 4f519b6919 [TSan] Tiny cleanup of UnmangleLongJmpSp for Linux/x86_64
NFC.

llvm-svn: 365982
2019-07-13 00:55:06 +00:00
Julian Lettner 9d41429ff7 [TSan] Move DECLARE_REAL macro outside of namespace
This should fix the "undefined reference to
tsan::interception::real_setjmp" linker errors.

llvm-svn: 365806
2019-07-11 18:26:33 +00:00
Kamil Rytarowski 983d7ddd0b Add NetBSD LSan support
Summary:
Combine few relatively small changes into one:

 - implement internal_ptrace() and internal_clone() for NetBSD
 - add support for stoptheworld based on the ptrace(2) API
 - define COMPILER_RT_HAS_LSAN for NetBSD
 - enable tests for NetBSD/amd64

Inspired by the original implementation by Christos Zoulas in netbsd/src for GCC.

The implementation is in theory CPU independent through well defined macros
across all NetBSD ports, however only the x86_64 version was tested.

Reviewers: mgorny, dvyukov, vitalybuka, joerg, jfb

Reviewed By: vitalybuka

Subscribers: dexonsmith, jfb, srhines, kubamracek, llvm-commits, christos

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64057

llvm-svn: 365735
2019-07-11 06:22:35 +00:00
Julian Lettner 6a155f52bc [TSan] Fix linker error on Linux/AArch64
llvm-svn: 365707
2019-07-10 22:50:07 +00:00
Julian Lettner 098e0a79fa [TSan] Fix compiler error on Linux/AArch64
llvm-svn: 365693
2019-07-10 19:46:08 +00:00
Julian Lettner 1a2c880924 [TSan] Attempt to fix linker error on Linux/AArch64
llvm-svn: 365681
2019-07-10 18:37:57 +00:00
Julian Lettner ba9eb48318 Reland "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.8"
Fix compilation errors related to `SANITIZER_GO` `#ifdef`s.

Refine longjmp key management.  For Linux, re-implement key retrieval in
C (instead of assembly).  Removal of `InitializeGuardPtr` and a final
round of cleanups will be done in the next commit.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D64092

> llvm-svn: 365513

llvm-svn: 365560
2019-07-09 21:27:37 +00:00
Julian Lettner c11c43b64f [TSan] Refine longjmp key management on Darwin
NFC.

llvm-svn: 365554
2019-07-09 20:47:37 +00:00
Julian Lettner 95176d72c7 Revert "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.8"
This reverts commit 521f77e635.

llvm-svn: 365534
2019-07-09 18:42:01 +00:00
Julian Lettner 521f77e635 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.8
Refine longjmp key management.  For Linux, re-implement key retrieval in
C (instead of assembly).  Removal of `InitializeGuardPtr` and a final
round of cleanups will be done in the next commit.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D64092

llvm-svn: 365513
2019-07-09 16:49:43 +00:00
Julian Lettner c6fe02b60b [TSan] Fix linker error for Linux/AArch64
llvm-svn: 365415
2019-07-09 00:48:38 +00:00
Julian Lettner fa0d1d8e45 Revert "[TSan] Attempt to fix linker error for Linux on AArch64"
This reverts commit be4148062b.

llvm-svn: 365367
2019-07-08 18:37:36 +00:00
Julian Lettner 2f533bdd2a Revert "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.4"
This reverts commit 6bb13da7c1.

llvm-svn: 365244
2019-07-05 21:03:46 +00:00
Julian Lettner 515fdfd512 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.5
Remove unnecessary computation of mangled SP for ARM64 architecture.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D64022

llvm-svn: 365230
2019-07-05 18:00:16 +00:00
Julian Lettner 6bb13da7c1 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.4
For x86_64, since we don't clobber %rsi (2nd argument) anymore, we don't
have to save/restore it.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D63946

llvm-svn: 365229
2019-07-05 18:00:12 +00:00
Julian Lettner 36face4c1d [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.7
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
2019-07-02 17:32:04 +00:00
Julian Lettner d66c606a34 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.3
Remove unnecessary computation of mangled SP for x86_64 architecture.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D63944

llvm-svn: 364874
2019-07-01 23:23:18 +00:00
Julian Lettner b7fb723ea3 [TSan] Fix initialized and declared ‘extern’ warning
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
2019-07-01 18:06:31 +00:00
Julian Lettner e934586680 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.2
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
2019-07-01 17:39:39 +00:00
Julian Lettner be4148062b [TSan] Attempt to fix linker error for Linux on AArch64
Introduced in 5be69ebe12.

llvm-svn: 364700
2019-06-29 00:40:45 +00:00
Julian Lettner 1c6337ca5a [TSan] Fix build build breakage on Android
Introduced in 5be69ebe12.

llvm-svn: 364676
2019-06-28 19:49:14 +00:00
Julian Lettner 5be69ebe12 [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.1
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
2019-06-28 17:27:30 +00:00
Evgeniy Stepanov 17bd226b6a Stop counting pops in tsan/check_analyze.sh.
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
2019-06-17 20:47:16 +00:00
Vitaly Buka 0b1ea8cb28 Improve error message when '=' is missing in {ASAN,...}_OPTIONS.
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
2019-06-15 01:37:14 +00:00
Hubert Tong 50721b27c4 [compiler-rt][tests] Propagate COMPILER_RT_UNITTEST_LINK_FLAGS
`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
2019-05-01 22:25:16 +00:00