summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/tsan/rtl to .cppNico Weber2019-08-011-515/+0
| | | | | | Like r367463, but for tsan/rtl. llvm-svn: 367564
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.10Julian Lettner2019-07-161-5/+0
| | | | | | | Remove now-unused assembly code for determining xor key on Linux/AArch64. This is the final commit of this refactoring. llvm-svn: 366225
* [TSan] Fix asm token error (again)Julian Lettner2019-07-151-1/+1
| | | | llvm-svn: 366150
* [TSan] Fix asm token errorJulian Lettner2019-07-151-1/+1
| | | | llvm-svn: 366131
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.9Julian Lettner2019-07-151-22/+5
| | | | | | | Switch over to computing the xor key in C, instead of assembly for Linux/AArch64. llvm-svn: 366126
* [TSan] Tiny cleanup of UnmangleLongJmpSp for Linux/x86_64Julian Lettner2019-07-131-8/+8
| | | | | | NFC. llvm-svn: 365982
* [TSan] Move DECLARE_REAL macro outside of namespaceJulian Lettner2019-07-111-5/+15
| | | | | | | This should fix the "undefined reference to tsan::interception::real_setjmp" linker errors. llvm-svn: 365806
* [TSan] Fix linker error on Linux/AArch64Julian Lettner2019-07-101-4/+4
| | | | llvm-svn: 365707
* [TSan] Fix compiler error on Linux/AArch64Julian Lettner2019-07-101-1/+1
| | | | llvm-svn: 365693
* [TSan] Attempt to fix linker error on Linux/AArch64Julian Lettner2019-07-101-1/+1
| | | | llvm-svn: 365681
* Reland "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, ↵Julian Lettner2019-07-091-9/+51
| | | | | | | | | | | | | | | | | | 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
* Revert "[TSan] Improve handling of stack pointer mangling in {set,long}jmp, ↵Julian Lettner2019-07-091-45/+5
| | | | | | | | pt.8" This reverts commit 521f77e6351fd921f5a81027c7c72addca378989. llvm-svn: 365534
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.8Julian Lettner2019-07-091-5/+45
| | | | | | | | | | | | 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
* [TSan] Fix linker error for Linux/AArch64Julian Lettner2019-07-091-1/+3
| | | | llvm-svn: 365415
* Revert "[TSan] Attempt to fix linker error for Linux on AArch64"Julian Lettner2019-07-081-1/+1
| | | | | | This reverts commit be4148062b155f3be52e0f6ebcb228f2dc137dcf. llvm-svn: 365367
* [TSan] Improve handling of stack pointer mangling in {set,long}jmp, pt.7Julian Lettner2019-07-021-4/+25
| | | | | | | | | | | 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] 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] Attempt to fix linker error for Linux on AArch64Julian Lettner2019-06-291-1/+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-281-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [TSan] Support fiber API on macOSJulian Lettner2019-04-201-0/+4
| | | | | | | | | | | | | | 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
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [compiler-rt][TSan] Add TSan runtime support for Go on linux-aarch64.Arnaud A. de Grandmaison2018-09-191-0/+8
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds TSan runtime support for Go on linux-aarch64 platforms. This enables people working on golang to implement their platform/language part of the TSan support. Basic testing is done with lib/tsan/go/buildgo.sh. Additional testing will be done as part of the work done in the Go project. It is intended to support other VMA sizes, except 39 which does not have enough bits to support the Go heap requirements. Patch by Fangming Fang <Fangming.Fang@arm.com>. Reviewers: kubamracek, dvyukov, javed.absar Subscribers: mcrosier, dberris, mgorny, kristof.beyls, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D52167 llvm-svn: 342541
* [sanitizer] Replace InternalScopedBuffer with InternalMmapVectorVitaly Buka2018-05-071-1/+1
| | | | llvm-svn: 331618
* [sanitizer] Make InternalScopedBuffer::size() behavior similar to vector.Vitaly Buka2018-05-071-3/+4
| | | | llvm-svn: 331612
* tsan: fix compiler warningsDmitry Vyukov2018-04-191-3/+3
| | | | | | vmaSize is uptr, so we need to print it with %zd. llvm-svn: 330312
* tsan: add support for linux/powerpc64 in buildgo.shDmitry Vyukov2018-04-161-0/+8
| | | | | | | | | | | The current implementation of the Go sanitizer only works on x86_64. Added some modifications to the buildgo.sh script and the Tsan code to make it work on powerpc64/linux. Author: cseo (Carlos Eduardo Seo) Reviewed in: https://reviews.llvm.org/D43025 llvm-svn: 330122
* [PowerPC][tsan] Update tsan to handle changed memory layouts in newer kernelsBill Seurer2017-11-281-2/+2
| | | | | | | | | | | | In more recent Linux kernels with 47 bit VMAs the layout of virtual memory for powerpc64 changed causing the thread sanitizer to not work properly. This patch adds support for 47 bit VMA kernels for powerpc64. (second part) Tested on several 4.x and 3.x kernel releases. llvm-svn: 319180
* Add NetBSD improvements in sanitizersKamil Rytarowski2017-10-251-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Changes: * Add initial msan stub support. * Handle NetBSD specific pthread_setname_np(3). * NetBSD supports __attribute__((tls_model("initial-exec"))), define it in SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE. * Add ReExec() specific bits for NetBSD. * Simplify code and add syscall64 and syscall_ptr for !NetBSD. * Correct bunch of syscall wrappers for NetBSD. * Disable test/tsan/map32bit on NetBSD as not applicable. * Port test/tsan/strerror_r to a POSIX-compliant OSes. * Disable __libc_stack_end on NetBSD. * Disable ReadNullSepFileToArray() on NetBSD. * Define struct_ElfW_Phdr_sz, detected missing symbol by msan. * Change type of __sanitizer_FILE from void to char. This helps to reuse this type as an array. Long term it will be properly implemented along with SANITIZER_HAS_STRUCT_FILE setting to 1. * Add initial NetBSD support in lib/tsan/go/buildgo.sh. * Correct referencing stdout and stderr in tsan_interceptors.cc on NetBSD. * Document NetBSD x86_64 specific virtual memory layout in tsan_platform.h. * Port tests/rtl/tsan_test_util_posix.cc to NetBSD. * Enable NetBSD tests in test/msan/lit.cfg. * Enable NetBSD tests in test/tsan/lit.cfg. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc, dvyukov Reviewed By: dvyukov Subscribers: #sanitizers, llvm-commits, kubamracek Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D39124 llvm-svn: 316591
* Fix sanitizer build against latest glibcKostya Serebryany2017-07-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: libsanitizer doesn't build against latest glibc anymore, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81066 for details. One of the changes is that stack_t changed from typedef struct sigaltstack { ... } stack_t; to typedef struct { ... } stack_t; for conformance reasons. And the other change is that the glibc internal __need_res_state macro is now ignored, so when doing ``` #define __need_res_state #include <resolv.h> ``` the effect is now the same as just ``` #include <resolv.h> ``` and thus one doesn't get just the ``` struct __res_state { ... }; ``` definition, but newly also the ``` extern struct __res_state *__res_state(void) __attribute__ ((__const__)); ``` prototype. So __res_state is no longer a type, but a function. Reviewers: kcc, ygribov Reviewed By: kcc Subscribers: kubamracek Differential Revision: https://reviews.llvm.org/D35246 llvm-svn: 307969
* Refactor MemoryMappingLayout::Next to use a single struct instead of output ↵Francis Ricci2017-07-111-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | | parameters. NFC. Summary: This is the first in a series of patches to refactor sanitizer_procmaps to allow MachO section information to be exposed on darwin. In addition, grouping all segment information in a single struct is cleaner than passing it through a large set of output parameters, and avoids the need for annotations of NULL parameters for unneeded information. The filename string is optional and must be managed and supplied by the calling function. This is to allow the MemoryMappedSegment struct to be stored on the stack without causing overly large stack sizes. Reviewers: alekseyshl, kubamracek, glider Subscribers: emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D35135 llvm-svn: 307688
* [Sanitizers] Consolidate internal errno definitions.Alex Shlyapnikov2017-07-061-1/+0
| | | | | | | Move internal errno definitions to common to be shared by all sanitizers and to be used by allocators. llvm-svn: 307233
* Don't require ThreadState to be contained within tls on all platformsFrancis Ricci2017-05-251-0/+14
| | | | | | | | | | The existing implementation ran CHECKs to assert that the thread state was stored inside the tls. However, the mac implementation of tsan doesn't store the thread state in tls, so these checks fail once darwin tls support is added to the sanitizers. Only run these checks on platforms where the thread state is expected to be contained in the tls. llvm-svn: 303886
* [compiler-rt] move tsan's Android __get_tls() to sanitizer_commonKostya Kortchinsky2017-05-021-19/+5
| | | | | | | | | | | | | | | | | | | | | | Summary: TSan's Android `__get_tls()` and `TLS_SLOT_TSAN` can be used by other sanitizers as well (see D32649), this change moves them to sanitizer_common. I picked sanitizer_linux.h as their new home. In the process, add the 32-bit versions for ARM, i386 & MIPS. Can the address of `__get_tls()[TLS_SLOT_TSAN]` change in between the calls? I am not sure if there is a need to repeat the construct as opposed to using a variable. So I left things as they were. Testing on my side was restricted to a successful cross-compilation. Reviewers: dvyukov, kubamracek Reviewed By: dvyukov Subscribers: aemerson, rengolin, srhines, dberris, arichardson, llvm-commits Differential Revision: https://reviews.llvm.org/D32705 llvm-svn: 301926
* Release memory to OS only when the requested range covers the entire pageEvgeniy Stepanov2016-11-301-1/+1
| | | | | | | | | | | | | | | | | Summary: The current code was sometimes attempting to release huge chunks of memory due to undesired RoundUp/RoundDown interaction when the requested range is fully contained within one memory page. Reviewers: eugenis Subscribers: kubabrecka, llvm-commits Patch by Aleksey Shlyapnikov. Differential Revision: https://reviews.llvm.org/D27228 llvm-svn: 288271
* tsan: always define SANITIZER_GODmitry Vyukov2016-10-281-9/+9
| | | | | | | | | | | | | | | | | | | | | | Currently we either define SANITIZER_GO for Go or don't define it at all for C++. This works fine with preprocessor (ifdef/ifndef/defined), but does not work for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different from majority of SANITIZER_FOO macros which are always defined to either 0 or 1. Always define SANITIZER_GO to either 0 or 1. This allows to use SANITIZER_GO in expressions and in flag default values. Also remove kGoMode and kCppMode, which were meant to be used in expressions, but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent. Also convert some preprocessor checks to C++ if's or ternary expressions. Majority of this change is done mechanically with: sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g" sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g" sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g" llvm-svn: 285443
* [asan] first attempt at releasing free-d memory back to the system using ↵Kostya Serebryany2016-08-261-1/+1
| | | | | | madvise. Requires quite some tuning. llvm-svn: 279887
* tsan: Remove __pointer_chk_guard@GLIBC_PRIVATE requirement for AArch64Adhemerval Zanella2016-08-101-0/+7
| | | | | | | | | | | | | | | | | | | | | Current AArch64 {sig}{set,long}jmp interposing requires accessing glibc private __pointer_chk_guard to get process xor mask to demangled the internal {sig}jmp_buf function pointers. It causes some packing issues, as described in gcc PR#71042 [1], and is is not a godd practice to rely on a private glibc namespace (since ABI is not meant to be stable). This patch fixes it by changing how libtsan obtains the guarded pointer value: at initialization a specific routine issues a setjmp call and using the mangled function pointer and the original value derive the random guarded pointer. Checked on aarch64 39-bit VMA. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71042 llvm-svn: 278292
* tsan: Enable 48-bit VMA support on aarch64Adhemerval Zanella2016-07-291-2/+2
| | | | | | | | | | | | | | | | | | This patch adds 48-bits VMA support for tsan on aarch64. As current mappings for aarch64, 48-bit VMA also supports PIE executable. This limits the mapping mechanism because the PIE address bits (usually 0aaaaXXXXXXXX) makes it harder to create a mask/xor value to include all memory regions. I think it is possible to create a large application VAM range by either dropping PIE support or tune current range. It also changes slight the way addresses are packed in SyncVar structure: previously it assumes x86_64 as the maximum VMA range. Since ID is 14 bits wide, shifting 48 bits should be ok. Tested on x86_64, ppc64le and aarch64 (39 and 48 bits VMA). llvm-svn: 277137
* tsan: rely on AnnotateRWLockCreateStatic to detect linker-initialized mutexesDmitry Vyukov2016-06-031-48/+0
| | | | | | | | | The new annotation was added a while ago, but was not actually used. Use the annotation to detect linker-initialized mutexes instead of the broken IsGlobalVar which has both false positives and false negatives. Remove IsGlobalVar mess. llvm-svn: 271663
* Revert "[sanitizer] [SystemZ] Abort if the kernel might be vulnerable to ↵Marcin Koscielnicki2016-04-151-3/+0
| | | | | | | | CVE-2016-2143." This reverts commit r266297. llvm-svn: 266470
* [sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.Marcin Koscielnicki2016-04-141-0/+3
| | | | | | | | | | | | | | | | | | In short, CVE-2016-2143 will crash the machine if a process uses both >4TB virtual addresses and fork(). ASan, TSan, and MSan will, by necessity, map a sizable chunk of virtual address space, which is much larger than 4TB. Even worse, sanitizers will always use fork() for llvm-symbolizer when a bug is detected. Disable all three by aborting on process initialization if the running kernel version is not known to contain a fix. Unfortunately, there's no reliable way to detect the fix without crashing the kernel. So, we rely on whitelisting - I've included a list of upstream kernel versions that will work. In case someone uses a distribution kernel or applied the fix themselves, an override switch is also included. Differential Revision: http://reviews.llvm.org/D18915 llvm-svn: 266297
* [tsan] Fix freebsd build.Yabin Cui2016-04-051-1/+3
| | | | | | | | | | | | | | Summary: Freebsd doesn't have <sys/personality.h>, so call personality() only in SANITIZER_LINUX. Reviewers: llvm-commits, dvyukov, zatrazz, rengolin, beanz Subscribers: beanz, emaste Differential Revision: http://reviews.llvm.org/D18785 llvm-svn: 265378
* [tsan] Disable randomized address space on aarch64 linux.Yabin Cui2016-04-041-0/+15
| | | | | | | | | | | | | | | | | Summary: After patch https://lkml.org/lkml/2015/12/21/340 is introduced in linux kernel, the random gap between stack and heap is increased from 128M to 36G on 39-bit aarch64. And it is almost impossible to cover this big range. So we need to disable randomized virtual space on aarch64 linux. Reviewers: llvm-commits, zatrazz, dvyukov, rengolin Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines Differential Revision: http://reviews.llvm.org/D18526 llvm-svn: 265366
* Revert "[tsan] Disable randomized address space on linux aarch64."Renato Golin2016-03-231-15/+0
| | | | | | | | This reverts commits r264068 and r264079, and they were breaking the build and weren't reverted in time, nor they exhibited expected behaviour from the reviewers. There is more to discuss than just a test fix. llvm-svn: 264150
* [tsan] Fix check-tsan build by using CHECK_NE.Yabin Cui2016-03-221-1/+1
| | | | | | | | | | Reviewers: llvm-commits, srhines, dvyukov Subscribers: srhines Differential Revision: http://reviews.llvm.org/D18361 llvm-svn: 264079
* [tsan] Disable randomized address space on linux aarch64.Yabin Cui2016-03-221-0/+15
| | | | | | | | | | | | | | | | | Summary: After patch https://lkml.org/lkml/2015/12/21/340 is introduced in linux kernel, the random gap between stack and heap is increased from 128M to 36G on 39-bit aarch64. And it is almost impossible to cover this big range. So I think we need to disable randomized virtual space on aarch64 linux. Reviewers: kcc, llvm-commits, eugenis, zatrazz, dvyukov, rengolin Subscribers: rengolin, aemerson, tberghammer, danalbert, srhines, enh Differential Revision: http://reviews.llvm.org/D18003 llvm-svn: 264068
* [tsan] Fix some tiny errors.Yabin Cui2016-01-151-4/+6
| | | | | | | | | | | | | | Summary: 1. Fix spell error for sigaction. 2. Make line_length <= 80. Reviewers: llvm-commits, eugenis, kcc, dvyukov Subscribers: tberghammer, danalbert, srhines Differential Revision: http://reviews.llvm.org/D16210 llvm-svn: 257872
* [tsan] Store the pointer to ThreadState in TLS slot on Android.Yabin Cui2016-01-151-0/+63
| | | | | | | | | | | | | | | | | | | | Summary: 1. Android doesn't support __thread keyword. So allocate ThreadState dynamically and store its pointer in one TLS slot provided by Android. 2. On Android, intercepted functions can be called before ThreadState is initialized. So add test of thr_->is_inited in some places. 3. On Android, intercepted functions can be called after ThreadState is destroyed. So add a fake dead_thread_state to represent all destroyed ThreadStates. And that is also why we don't store the pointer to ThreadState in shadow memory of pthread_self(). Reviewers: kcc, eugenis, dvyukov Subscribers: kubabrecka, llvm-commits, tberghammer, danalbert, srhines Differential Revision: http://reviews.llvm.org/D15301 llvm-svn: 257866
* [TSAN, PPC64] Fix obvious typo of supported virtual memory sizesBill Schmidt2015-12-141-1/+1
| | | | llvm-svn: 255507
OpenPOWER on IntegriCloud