summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2017-12-04[libFuzzer] Remove FuzzerCommand.cpp from build sources.Matt Morehouse
FuzzerCommand.cpp was not introduced in r319680. Instead, it was implemented in the header file. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319682 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04[libFuzzer] Encapsulate commands in a class.Matt Morehouse
Summary: To be more portable (especially w.r.t. platforms without system()), commands should be managed programmatically rather than via string manipulation on the command line. This change introduces Fuzzer::Command, with methods to manage arguments and flags, set output options, and execute the command. Patch By: aarongreen Reviewers: kcc, morehouse Reviewed By: kcc, morehouse Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D40103 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319680 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04[sanitizer] 64-bit allocator's PopulateFreeArray partial refactorKostya Kortchinsky
Summary: This is an attempt at making `PopulateFreeArray` less obscure, more consistent, and a tiny bit faster in some circumstances: - use more consistent variable names, that work both for the user & the metadata portions of the code; the purpose of the code is mostly the same for both regions, so it makes sense that the code should be mostly similar as well; - replace the while sum loops with a single `RoundUpTo`; - mask most of the metadata computations behind kMetadataSize, allowing some blocks to be completely optimized out if not use metadata; - `const` the constant variables; - add a `LIKELY` as the branch it applies to will almost always be taken. Reviewers: alekseyshl, flowerhack Reviewed By: alekseyshl Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D40754 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319673 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04Handle NetBSD symbol renaming in sanitizer_common_interceptors.incKamil Rytarowski
Summary: NetBSD renames symbols for historical and compat reasons. Add required symbol renames in sanitizer_common_interceptors.inc: - clock_gettime -> __clock_gettime50 - clock_getres -> __clock_getres50 - clock_settime -> __clock_settime50 - setitimer -> __setitimer50 - getitimer -> __getitimer50 - opendir -> __opendir30 - readdir -> __readdir30 - time -> __time50 - localtime_r -> __localtime_r50 - gmtime_r -> __gmtime_r50 - gmtime -> __gmtime50 - ctime -> __ctime50 - ctime_r -> __ctime_r50 - mktime -> __mktime50 - getpwnam -> __getpwnam50 - getpwuid -> __getpwuid50 - getpwnam_r -> __getpwnam_r50 - getpwuid_r -> __getpwuid_r50 - getpwent -> __getpwent50 - glob -> __glob30 - wait3 -> __wait350 - wait4 -> __wait450 - readdir_r -> __readdir_r30 - setlocale -> __setlocale50 - scandir -> __scandir30 - sigtimedwait -> __sigtimedwait50 - sigemptyset -> __sigemptyset14 - sigfillset -> __sigfillset14 - sigpending -> __sigpending14 - sigprocmask -> __sigprocmask14 - shmctl -> __shmctl50 - times -> __times13 - stat -> __stat50 - getutent -> __getutent50 - getutxent -> __getutxent50 - getutxid -> __getutxid50 - getutxline -> __getutxline50 Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, cryptoad, dvyukov Reviewed By: cryptoad Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40765 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319670 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04[ASan] Enhance libsanitizer support for invalid-pointer-pair.Alex Shlyapnikov
Following patch adds support of all memory origins in CheckForInvalidPointerPair function. For small difference of pointers, it's directly done in shadow memory (the limit was set to 2048B). Then we search for origin of first pointer and verify that the second one has the same origin. If so, we verify that it points either to a same variable (in case of stack memory or a global variable), or to a same heap segment. Committing on behanf of marxin and jakubjelinek. Reviewers: alekseyshl, kcc Subscribers: llvm-commits Differential revision: https://reviews.llvm.org/D40600 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319668 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-04Move __tsan::Vector to __sanitizerKamil Rytarowski
Summary: The low-fat STL-like vector container will be reused in MSan. It is needed to implement an atexit(3) interceptor on NetBSD/amd64 in MSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: dvyukov Subscribers: kubamracek, mgorny, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40726 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319650 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-01[libFuzzer] add a flag -malloc_limit_mbKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319590 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-01[libFuzzer] remove stale flags; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319572 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-01[libFuzzer] add an experimental search heuristic flag -reduce_depthKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319571 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30[msan] Fix return type of mbrtowcVitaly Buka
Summary: Fixes https://github.com/google/oss-fuzz/issues/1009 Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40676 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319484 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30Add powerpc64 to compiler-rt build infrastructure.Sterling Augustine
Now that we have disabled the run-forever tests, and cleaned up the intel 80-bit float based tests, we should be able to enable testing compiler-rt for powerpc64. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319474 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30Move x86-specific sources to x86-specific source lists.Sterling Augustine
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319464 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30Fix the MIPS baremetal buildAlexander Richardson
Summary: Currently sys/cachectl.h is used unconditionally on MIPS although it is only available on Linux and will fail the build when targeting baremetal Reviewers: petarj Reviewed By: petarj Subscribers: sdardis, krytarowski Differential Revision: https://reviews.llvm.org/D40659 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319455 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30Linux needs to include sys/uio.h for readv, preadvStephan Bergmann
...at least when building against glibc-2.26-16.fc27.x86_64 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319412 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[XRay][compiler-rt][Darwin] Use dynamic initialisation as an alternativeDean Michael Berris
Summary: In cases where we can't use the .preinit_array section (as in Darwin for example) we instead use dynamic initialisation. We know that this alternative approach will race with the initializers of other objects at global scope, but this is strictly better than nothing. Reviewers: kubamracek, nglevin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40599 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319366 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[sanitizer] Add 'strip_env' flag to enable/disable removing sanitizer dylib ↵Kuba Mracek
from DYLD_INSERT_LIBRARIES On macOS, we usually don't require launching the target with DYLD_INSERT_LIBRARIES anymore. However, it is still necessary when running a target that is not instrumented (and e.g. dlopen's an instrument library later). In any case, ASan and TSan currently remove themselves from the DYLD_INSERT_LIBRARIES environment variable to avoid passing it onto children. This works well e.g. when instrumenting a shell. A problem arises when the target is a non-instrumented shim (e.g. "xcrun") that either re-execs or launches a child that is supposed to get DYLD_INSERT_LIBRARIES propagated. To support this mode, this patch introduces 'strip_env' flag that can be used to keep DYLD_INSERT_LIBRARIES untouched. Differential Revision: https://reviews.llvm.org/D39991 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319365 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[scudo] Allow for compile-time choice of the SizeClassMapKostya Kortchinsky
Summary: With this change, we allow someone to chose the `SizeClassMap` they want to use at compile time via a define. I feel somewhat unimaginative with the name of the defines, so if someone has a better idea, let me know. I have been alternating between those and `SCUDO_USE_xxx_SIZECLASSMAP` which is clearer but also longer. The issue with those is that it wouldn't be consistent with `SCUDO_TSD_EXCLUSIVE` that should probably become `SCUDO_USE_EXCLUSIVE_TSD` maybe? Anyway, naming is hard, and I am not sure what makes more sense! Reviewers: alekseyshl, flowerhack Reviewed By: alekseyshl Subscribers: llvm-commits, srhines Differential Revision: https://reviews.llvm.org/D40521 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319350 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[compiler-rt] Switch from deprecated TARGET_IPHONE_SIMULATOR to ↵Kuba Mracek
TARGET_OS_SIMULATOR Differential Revision: https://reviews.llvm.org/D39987 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319349 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Fix macOS FindDynamicShadowStart to consider the last gap in the VM mapKuba Mracek
It looks FindDynamicShadowStart has a bug: When iterating over the memory map, we will not consider the very last gap in the address space. Let's fix that. Differential Revision: https://reviews.llvm.org/D39989 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319348 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Don't crash on fclose(NULL)Kuba Mracek
It's explicitly forbidden to call fclose with NULL, but at least on Darwin, this succeeds and doesn't segfault. To maintain binary compatibility, ASan should survice fclose(NULL) as well. Differential Revision: https://reviews.llvm.org/D40053 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319347 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[asan] Allow getpwnam(NULL) for binary compatibilityKuba Mracek
Calling getpwnam(NULL) is probably a bug, but at least on Darwin, such a call succeeds without segfaulting. I have some existing code that relies on that. To maintain binary compatibility, ASan should also survive a call to getpwnam with NULL. Differential Revision: https://reviews.llvm.org/D40052 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319344 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29[sanitizer] Refactor how assembly files are handledKuba Mracek
This renames ASM_TSAN_SYMBOL and ASM_TSAN_SYMBOL_INTERCEPTOR to just ASM_SYMBOL and ASM_SYMBOL_INTERCEPTOR, because they can be useful in more places than just TSan. Also introduce a CMake function to add ASM sources to a target. Differential Revision: https://reviews.llvm.org/D40143 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319339 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-29Defer StartBackgroundThread() and StopBackgroundThread() in TSanKamil Rytarowski
Summary: NetBSD cannot spawn new POSIX thread entities in early libc and libpthread initialization stage. Defer this to the point of intercepting the first pthread_create(3) call. This is the last change that makes Thread Sanitizer functional on NetBSD/amd64 without downstream patches. ******************** Testing Time: 64.91s ******************** Failing Tests (5): ThreadSanitizer-x86_64 :: dtls.c ThreadSanitizer-x86_64 :: ignore_lib5.cc ThreadSanitizer-x86_64 :: ignored-interceptors-mmap.cc ThreadSanitizer-x86_64 :: mutex_lock_destroyed.cc ThreadSanitizer-x86_64 :: vfork.cc Expected Passes : 290 Expected Failures : 1 Unsupported Tests : 83 Unexpected Failures: 5 Sponsored by <The NetBSD Foundation> Reviewers: joerg, eugenis, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40583 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319305 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[XRay][compiler-rt] Fix armhf buildDean Michael Berris
rL319241 was a bit too aggressive removing sources dependencies. This restores the actual required dependency for armhf. Follow-up to D39114. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319255 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[XRay][compiler-rt] Fix runtime buildDean Michael Berris
This isolates the per-architecture files from the common files implementing the XRay facilities. Because of the refactoring done in D39114, we were including the definition of the sources in the archive twice, causing link-time failures. Follow-up to D39114. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319241 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[LSan] Fix one source of stale segments in the process memory mapping.Alex Shlyapnikov
Summary: Load process memory map after updating the same cache to reflect the umap happening in the process of updating. Also clear out the buffer in case of failed read of /proc/self/maps (not the source of stale segments, but can lead to the similar crash). Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D40529 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319237 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[LibFuzzer] Improve comments on `CounterToFeature()` function.Dan Liew
This is based on discussion in https://reviews.llvm.org/D40376 . The comments try to explain the reason for the current implementation and note that it might change in the future, so clients should not rely on this particular implementation. Differential Revision: https://reviews.llvm.org/D40565 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319190 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28Support the setjmp(3) family of functions in TSan/NetBSDKamil Rytarowski
Summary: This change adds support for the setjmp(3)/longjmp(3) family of functions on NetBSD. There are three types of them on NetBSD: - setjmp(3) / longjmp(3) - sigsetjmp(3) / sigsetjmp(3) - _setjmp(3) / _longjmp(3) Due to historical and compat reasons the symbol names are mangled: - setjmp -> __setjmp14 - longjmp -> __longjmp14 - sigsetjmp -> __sigsetjmp14 - siglongjmp -> __siglongjmp14 - _setjmp -> _setjmp - _longjmp -> _longjmp This leads to symbol renaming in the existing codebase. There is no such symbol as __sigsetjmp/__longsetjmp on NetBSD Add a comment that GNU-style executable stack note is not needed on NetBSD. The stack is not executable without it. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40337 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319189 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[PowerPC][tsan] Update tsan to handle changed memory layouts in newer kernelsBill Seurer
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. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319180 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28[XRay][compiler-rt][Darwin] Minimal XRay build support in DarwinDean Michael Berris
This change is the first in a series of changes to get the XRay runtime building on macOS. This first allows us to build the minimal parts of XRay to get us started on supporting macOS development. These include: - CMake changes to allow targeting x86_64 initially. - Allowing for building the initialisation routines without `.preinit_array` support. - Use __sanitizer::SleepForMillis() to work around the lack of clock_nanosleep on macOS. - Deprecate the xray_fdr_log_grace_period_us flag, and introduce the xray_fdr_log_grace_period_ms flag instead, to use milliseconds across platforms. Reviewers: kubamracek Subscribers: llvm-commits, krytarowski, nglevin, mgorny Differential Review: https://reviews.llvm.org/D39114 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319165 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28Correct mangled_sp on NetBSD/amd64 in TSanKamil Rytarowski
The proper index is 6, not 2. Patch extracted from https://reviews.llvm.org/D40337 Reviewed and accepted by <dvyukov>. Sponsored by <The NetBSD Foundation> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319163 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-28Handle symbol renaming of sigaction for NetBSDKamil Rytarowski
Summary: NetBSD uses the __sigaction14 symbol name for historical and compat reasons for the sigaction(2) function name. Rename the interceptors and users of sigaction to sigaction_symname and reuse it in the code base. This change fixes 4 failing tests in TSan/NetBSD: - ThreadSanitizer-x86_64 :: signal_errno.cc - ThreadSanitizer-x86_64 :: signal_malloc.cc - ThreadSanitizer-x86_64 :: signal_sync2.cc - ThreadSanitizer-x86_64 :: signal_thread.cc Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, dvyukov, kcc Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40341 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319160 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27[msan] Avoid shadowing a variable in common interceptors.Evgeniy Stepanov
"offset" declared in a macro may shadow a variable with the same name in the caller which is used in a macro argument. We are quite lucky that it does not actually happen, but rename the variable anyway to be on the safe side. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319115 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27[scudo] Workaround for uninitialized Bionic globalsKostya Kortchinsky
Summary: Bionic doesn't initialize its globals early enough. This causes issues when trying to access them from a preinit_array (b/25751302) or from another constructor called before the libc one (b/68046352). __progname is initialized after the other globals, so we can check its value to know if calling `getauxval` is safe. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, llvm-commits Differential Revision: https://reviews.llvm.org/D40504 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319099 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27[fuchsia] Update Fuchsia with a new mmap implementation.Kostya Kortchinsky
Summary: Now that the sanitizer_common interface for MmapNoAccess / MmapFixed have been refactored to allow a more OO-esque access pattern, update the Fuchsia mmap implementation to take advantage of this. Previously MmapNoAccess / MmapFixed relied on a global allocator_vmar, since the sanitizer_allocator only called MmapNoAccess once. Now, we create a new VMAR per ReservedAddressRange object. This allows the sanitizer allocator to work in tandem with the Scudo secondary allocator. This is part 4 of a 4 part changeset: * part 1 https://reviews.llvm.org/D38593 * part 2 https://reviews.llvm.org/D38592 * part 3 https://reviews.llvm.org/D38593 Reviewers: mcgrathr, cryptoad Reviewed By: cryptoad Subscribers: alekseyshl, mcgrathr, kubamracek, mehdi_amini Differential Revision: https://reviews.llvm.org/D38595 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319083 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-26Prevent Thread Exited/Joined events raceKamil Rytarowski
Summary: Add atomic verification to ensure that Thread is Joined after marking it Finished. It is required for NetBSD in order to prevent Thread Exited/Joined race, that may occur when native system libpthread(3) cannot be reliably traced in a way to guarantee that the mentioned events happen one after another. This change fixes at least TSan and LSan on NetBSD. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40294 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319004 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-26Detect thread termination in LSan/NetBSDKamil Rytarowski
Summary: Stop using the Linux solution with pthread_key_create(3). This approach does not work on NetBSD, because calling the thread destructor is not the latest operation on a POSIX thread entity. Detect _lwp_exit(2) call as it is really the latest operation called from a detaching POSIX thread. The pthread_key_create(3) solution also cannot be used in early libc/libpthread initialization on NetBSD as the system libraries are not bootstrapped enough. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, kcc, dvyukov Reviewed By: dvyukov Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318994 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-25Plug dlerror() leak for swift_demangleKamil Rytarowski
Summary: InitializeSwiftDemangler() attempts to resolve the swift_demangle symbol. If this is not available, we observe dlerror message leak. Caught on NetBSD/amd64 in TSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, kubamracek, vitalybuka, dvyukov, eugenis Reviewed By: dvyukov Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40382 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318980 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-22[scudo] Overhaul hardware CRC32 feature detectionKostya Kortchinsky
Summary: This patch aims at condensing the hardware CRC32 feature detection and making it slightly more effective on Android. The following changes are included: - remove the `CPUFeature` enum, and get rid of one level of nesting of functions: we only used CRC32, so we just implement and use `hasHardwareCRC32`; - allow for a weak `getauxval`: the Android toolchain is compiled at API level 14 for Android ARM, meaning no `getauxval` at compile time, yet we will run on API level 27+ devices. The `/proc/self/auxv` fallback can work but is worthless for a process like `init` where the proc filesystem doesn't exist yet. If a weak `getauxval` doesn't exist, then fallback. - couple of extra corrections. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, aemerson, srhines, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D40322 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318859 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[scudo] Make getNumberOfCPUs Fuchsia compliant v2Kostya Kortchinsky
Summary: This change allows Fuchsia to boot properly using the Scudo allocator. A first version of this commit was reverted by rL317834 because it broke Android builds for toolchains generated with older NDKs. This commit introduces a fall back to solve that issue. Reviewers: cryptoad, krytarowski, rnk, alekseyshl Reviewed By: cryptoad, krytarowski, alekseyshl Subscribers: llvm-commits, srhines, kubamracek, krytarowski Differential Revision: https://reviews.llvm.org/D40121 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318802 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[sanitizer] Define SANITIZER_USE_GETAUXVAL for AndroidKostya Kortchinsky
Summary: Android for API level >= 21 has `getauxval`. Enable `SANITIZER_USE_GETAUXVAL` when those requirements are met. Correct a typo in the header. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D40260 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318775 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21Correct NetBSD support in pthread_once(3)/TSanKamil Rytarowski
Summary: The pthread_once(3)/NetBSD type is built with the following structure: struct __pthread_once_st { pthread_mutex_t pto_mutex; int pto_done; }; Set the pto_done position as shifted by __sanitizer::pthread_mutex_t_sz from the beginning of the pthread_once struct. This corrects deadlocks when the pthread_once(3) function is used. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40262 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318742 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[XRay][compiler-rt] Migrate basic mode logging to the XRay frameworkDean Michael Berris
Summary: Before this patch, XRay's basic (naive mode) logging would be initialised and installed in an adhoc manner. This patch ports the implementation of the basic (naive mode) logging implementation to use the common XRay framework. We also make the following changes to reduce the variance between the usage model of basic mode from FDR (flight data recorder) mode: - Allow programmatic control of the size of the buffers dedicated to per-thread records. This removes some hard-coded constants and turns them into runtime-controllable flags and through an Options structure. - Default the `xray_naive_log` option to false. For now, the only way to start basic mode is to set the environment variable, or set the default at build-time compiler options. Because of this change we've had to update a couple of tests relying on basic mode being always on. - Removed the reliance on a non-trivially destructible per-thread resource manager. We use a similar trick done in D39526 to use pthread_key_create() and pthread_setspecific() to ensure that the per-thread cleanup handling is performed at thread-exit time. We also radically simplify the code structure for basic mode, to move most of the implementation in the `__xray` namespace. Reviewers: pelikan, eizan, kpw Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40164 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318734 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[XRay] Use optimistic logging model for FDR modeDean Michael Berris
Summary: Before this change, the FDR mode implementation relied on at thread-exit handling to return buffers back to the (global) buffer queue. This introduces issues with the initialisation of the thread_local objects which, even through the use of pthread_setspecific(...) may eventually call into an allocation function. Similar to previous changes in this line, we're finding that there is a huge potential for deadlocks when initialising these thread-locals when the memory allocation implementation is also xray-instrumented. In this change, we limit the call to pthread_setspecific(...) to provide a non-null value to associate to the key created with pthread_key_create(...). While this doesn't completely eliminate the potential for the deadlock(s), it does allow us to still clean up at thread exit when we need to. The change is that we don't need to do more work when starting and ending a thread's lifetime. We also have a test to make sure that we actually can safely recycle the buffers in case we end up re-using the buffer(s) available from the queue on multiple thread entry/exits. This change cuts across both LLVM and compiler-rt to allow us to update both the XRay runtime implementation as well as the library support for loading these new versions of the FDR mode logging. Version 2 of the FDR logging implementation makes the following changes: * Introduction of a new 'BufferExtents' metadata record that's outside of the buffer's contents but are written before the actual buffer. This data is associated to the Buffer handed out by the BufferQueue rather than a record that occupies bytes in the actual buffer. * Removal of the "end of buffer" records. This is in-line with the changes we described above, to allow for optimistic logging without explicit record writing at thread exit. The optimistic logging model operates under the following assumptions: * Threads writing to the buffers will potentially race with the thread attempting to flush the log. To avoid this situation from occuring, we make sure that when we've finalized the logging implementation, that threads will see this finalization state on the next write, and either choose to not write records the thread would have written or write the record(s) in two phases -- first write the record(s), then update the extents metadata. * We change the buffer queue implementation so that once it's handed out a buffer to a thread, that we assume that buffer is marked "used" to be able to capture partial writes. None of this will be safe to handle if threads are racing to write the extents records and the reader thread is attempting to flush the log. The optimism comes from the finalization routine being required to complete before we attempt to flush the log. This is a fairly significant semantics change for the FDR implementation. This is why we've decided to update the version number for FDR mode logs. The tools, however, still need to be able to support older versions of the log until we finally deprecate those earlier versions. Reviewers: dblaikie, pelikan, kpw Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D39526 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318733 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-21[sanitizers] Add init function to set alignment of low level allocatorWalter Lee
ASan requires that the min alignment be at least the shadow granularity, so add an init function to do that. Differential Revision: https://reviews.llvm.org/D39473 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318717 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20[tsan] Fix sigaction implementation when it's called only to get handlerVitaly Buka
Reviewers: eugenis Subscribers: kubamracek, llvm-commits, krytarowski Differential Revision: https://reviews.llvm.org/D40272 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318707 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Try to fix syntax for !NetBSD in TSAN_INTERCEPTORsKamil Rytarowski
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318676 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Handle NetBSD specific indirection of libpthread functionsKamil Rytarowski
Summary: Correct handling of libpthread(3) functions in TSan/NetBSD: - pthread_cond_init(3), - pthread_cond_signal(3), - pthread_cond_broadcast(3), - pthread_cond_wait(3), - pthread_cond_destroy(3), - pthread_mutex_init(3), - pthread_mutex_destroy(3), - pthread_mutex_trylock(3), - pthread_rwlock_init(3), - pthread_rwlock_destroy(3), - pthread_rwlock_rdlock(3), - pthread_rwlock_tryrdlock(3), - pthread_rwlock_wrlock(3), - pthread_rwlock_trywrlock(3), - pthread_rwlock_unlock(3), - pthread_once(3). Code out of the libpthread(3) context uses the libc symbols that are prefixed with __libc_, for example: __libc_cond_init. This caused that these functions were invisible to sanitizers on NetBSD. Intercept the libc-specific ones and add them as NetBSD-specific aliases for the common pthread(3) ones. NetBSD needs to intercept both functions, as the regularly named ones are used internally in libpthread(3). Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40243 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318673 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Add DemangleFunctionName for backtracing on NetBSDKamil Rytarowski
Summary: NetBSD uses indirection for old threading functions for historical reasons The mangled names are internal implementation detail and should not be exposed even in backtraces. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, dvyukov Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40251 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318671 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20[asan] Use dynamic shadow on 32-bit Android, try 2.Evgeniy Stepanov
Summary: This change reverts r318575 and changes FindDynamicShadowStart() to keep the memory range it found mapped PROT_NONE to make sure it is not reused. We also skip MemoryRangeIsAvailable() check, because it is (a) unnecessary, and (b) would fail anyway. Reviewers: pcc, vitalybuka, kcc Subscribers: srhines, kubamracek, mgorny, llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D40203 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318666 91177308-0d34-0410-b5e6-96231b3b80d8