summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2017-11-20[sanitizer] New attempt at using runtime checks for Android loggingKostya Kortchinsky
Summary: This is a second attempt after D40100 induced racey crashes with ASan (due to `__android_log_write` and the `strncpy` interceptor on API >= 21). This new version checks the runtime API level to be <= `ANDROID_KITKAT` for the use of `__android_log_write`, otherwise we use `syslog`, which should conform with the previous behavior. Unfortunately despite numerous efforts I couldn't reproduce the original crashes in my environments so I couldn't test that the fix was actually preventing crashes. Reviewers: eugenis Reviewed By: eugenis Subscribers: llvm-commits, srhines, kubamracek Differential Revision: https://reviews.llvm.org/D40149 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318659 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Correct return types of NetBSD specific functionsKamil Rytarowski
The __libc_mutex_lock, __libc_mutex_unlock and __libc_thr_setcancelstate functions return int, not void. This does not seem to introduce a functional change, however it looks better with fixed the function prototype. Sponsored by <The NetBSD Foundation> git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-20Handle NetBSD specific indirection of libpthread functionsKamil Rytarowski
Summary: Correct handling of three libpthread(3) functions on NetBSD: - pthread_mutex_lock(3), - pthread_mutex_unlock(3), - pthread_setcancelstate(3). Code out of the libpthread(3) context uses the libc symbols: - __libc_mutex_lock, - __libc_mutex_unlock, - __libc_thr_setcancelstate. The threading library (libpthread(3)) defines strong aliases: - __strong_alias(__libc_mutex_lock,pthread_mutex_lock) - __strong_alias(__libc_mutex_unlock,pthread_mutex_unlock) - __strong_alias(__libc_thr_setcancelstate,pthread_setcancelstate) 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: llvm-commits, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40241 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318646 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-19[X86] Add cpu detection for cannonlake.Craig Topper
This uses the same encoding for cannonlake in the proposed gcc patches here. https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00551.html git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318610 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-18Revert "[asan] Use dynamic shadow on 32-bit Android" and 3 more.Evgeniy Stepanov
Revert the following commits: r318369 [asan] Fallback to non-ifunc dynamic shadow on android<22. r318235 [asan] Prevent rematerialization of &__asan_shadow. r317948 [sanitizer] Remove unnecessary attribute hidden. r317943 [asan] Use dynamic shadow on 32-bit Android. MemoryRangeIsAvailable() reads /proc/$PID/maps into an mmap-ed buffer that may overlap with the address range that we plan to use for the dynamic shadow mapping. This is causing random startup crashes. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318575 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-17[asan] Fix asan_device_setup on KitKat.Evgeniy Stepanov
"ln" from toybox does not understand -f (force) flag. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318573 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-17[fuzzer] Initialize PcDescr buffer before calling __sanitizer_symbolize_pcVitaly Buka
__sanitizer_symbolize_pc is not instrumented so msan assumes that PcDescr was not initialized. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318488 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[asan] Properly mark or disable tests that only work with shadow scale of 3Walter Lee
Differential Revision: https://reviews.llvm.org/D39774 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318471 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[asan] Avoid assert failure for non-default shadow scaleWalter Lee
Rather than assertion failing, we can fall back to the non-optimized version which works for any shadow scale. Differential Revision: https://reviews.llvm.org/D39474 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318460 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[sanitizer] Revert rL318410Kostya Kortchinsky
Summary: The patch seems to have turned some Android tests flaky. The reason is unclear. This reverts D40100 in case we can't figure out what is happening. Reviewers: eugenis Reviewed By: eugenis Subscribers: srhines, kubamracek Differential Revision: https://reviews.llvm.org/D40138 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318438 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16Implement GetTls() for NetBSDKamil Rytarowski
Summary: Reuse the existing code for FreeBSD that is compatible with NetBSD. Add NetBSD support in tests: tls_race.cc and tls_race2.cc. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, vitalybuka, kcc, eugenis Reviewed By: dvyukov Subscribers: srhines, emaste, kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40105 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318431 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[asan] Ensure that the minimum redzone is at least SHADOW_GRANULARITYWalter Lee
This is required by the Asan run-time. Differential Revision: https://reviews.llvm.org/D39472 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318422 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[asan] Fix small X86_64 ShadowOffset for non-default shadow scaleWalter Lee
The requirement is that shadow memory must be aligned to page boundaries (4k in this case). Use a closed form equation that always satisfies this requirement. Differential Revision: https://reviews.llvm.org/D39471 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318421 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[sanitizer] Use runtime checks instead of API level for Android loggingKostya Kortchinsky
Summary: Recent Bionic have a slew of `async_safe_*` logging functions that are basically the liblog ones but included within the libc. They have the advantage of not allocating memory. `async_safe_write_log` does no formatting and is likely the best candidate for logging. Use a weak definition to try and use it. Also, avoid API level checks (as the toolchain is compiled at a rather low API level) for `__android_log_write` in favor of a weak definition as well. Keep the fallback to `syslog` if nothing else was found. I tried to overhaul the code block to only have a single #if SANITIZER_ANDROID but I am not particularly attached to the form. LMKWYT. Reviewers: eugenis Reviewed By: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D40100 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318410 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-16[asan] Fallback to non-ifunc dynamic shadow on android<22.Evgeniy Stepanov
Summary: Android < 22 does not support ifunc. Reviewers: pcc Subscribers: srhines, kubamracek, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D40116 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318369 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15[LSan] Export __lsan_initAlex Shlyapnikov
Summary: lsan_preinit.cc is meant to be linked into executable and calls lsan_init from .preinit_array section. But if liblsan is a shared library, then this doesn't work, because the symbol is not exported. This patch fixes that. The counterparts like asan_init or __tsan_init already do have SANITIZER_INTERFACE_ATTRIBUTE. Committing on behalf of jakubjelinek. Reviewers: alekseyshl, kcc Subscribers: llvm-commits Differential revision: https://reviews.llvm.org/D39889 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318349 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15Fix some typos in a comment.Francis Ricci
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318336 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15libfuzzer: Fix file listing on some filesystemsKostya Serebryany
Summary: For some filesystems, readdir will not populate dirent::d_type with valuable information. This causes libfuzzer to proceed with an empty corpus, instead of the file it contains. This has been tested on a server using XFS. It should fix https://bugs.llvm.org//show_bug.cgi?id=25991 Reviewers: kcc Reviewed By: kcc Differential Revision: https://reviews.llvm.org/D40028 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318303 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15[libFuzzer] respect max_len during mergeKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318302 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15[scudo] Soft and hard RSS limit checksKostya Kortchinsky
Summary: This implements an opportunistic check for the RSS limit. For ASan, this was implemented thanks to a background thread checking the current RSS vs the set limit every 100ms. This was deemed problematic for Scudo due to potential Android concerns (Zygote as pointed out by Aleksey) as well as the general inconvenience of having a permanent background thread. If a limit (soft or hard) is specified, we will attempt to update the RSS limit status (exceeded or not) every 100ms. This is done in an opportunistic way: if we can update it, we do it, if not we return the current status, mostly because we don't need it to be fully consistent (it's done every 100ms anyway). If the limit is exceeded `allocate` will act as if OOM for a soft limit, or just die for a hard limit. We use the `common_flags()`'s `hard_rss_limit_mb` & `soft_rss_limit_mb` for configuration of the limits. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40038 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318301 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-15[XRay][compiler-rt][x86_64] Align the stack before and after calling handlersDean Michael Berris
Summary: This change fixes the XRay trampolines aside from the __xray_CustomEvent trampoline to align the stack to 16-byte boundaries before calling the handler. Before this change we've not been explicitly aligning the stack to 16-byte boundaries, which makes it dangerous when calling handlers that leave the stack in a state that isn't strictly 16-byte aligned after calling the handlers. We add a test that makes sure we can handle these cases appropriately after the changes, and prevents us from regressing the state moving forward. Fixes http://llvm.org/PR35294. Reviewers: pelikan, pcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40004 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318261 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-14[profile] Update InstrProfData.inc to sync with llvmVedant Kumar
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318230 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-14[scudo] Simplify initialization and flagsKostya Kortchinsky
Summary: This is mostly some cleanup and shouldn't affect functionalities. Reviewing some code for a future addition, I realized that the complexity of the initialization path was unnecessary, and so was maintaining a structure for the allocator options throughout the initialization. So we get rid of that structure, of an extraneous level of nesting for the `init` function, and correct a couple of related code inaccuracies in the flags cpp. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39974 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318157 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-14[builtins] Include GENERIC_SOURCES in arm_SOURCES for MinGWMartin Storsjo
It is included in the built sources for all other arches supported for MinGW currently, except for arm. Differential Revision: https://reviews.llvm.org/D39938 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318139 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13Update TSan/ARM64 max VM to 0xfc0000000 to reflect a kernel change.Kuba Mracek
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318103 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[lsan] Remove semicolon after do {} while (0)Tom de Vries
Remove semicolon after "do {} while (0)" in LOG_POINTERS and LOG_THREADS. Reviewed by: kcc git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318085 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[asan] Remove semicolon after do {} while (0)Tom de Vries
Remove semicolon after "do {} while (0)" in in CHECK_SMALL_REGION git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318084 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[tsan] Fix signal chainingVitaly Buka
Summary: Return saved values only if installed sigaction is our wrapper. Reviewers: eugenis, dvyukov Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D39935 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318082 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[sanitizer] Update scudo to use new APIKostya Kortchinsky
Summary: The ScudoAllocator uses a SecondaryHeader to keep track of the size and base address of each mmap'd chunk. This aligns well with what the ReservedAddressRange is trying to do. This changeset converts the scudo allocator from using the MmapNoAccess/MmapFixed APIs to the ReservedAddressRange::Init and ::Map APIs. In doing so, it replaces the SecondayHeader struct with the ReservedAddressRange object. This is part 3 of a 4 part changeset; part 1 https://reviews.llvm.org/D39072 and part 2 https://reviews.llvm.org/D38592 Reviewers: alekseyshl, mcgrathr, cryptoad, phosek Reviewed By: cryptoad Subscribers: llvm-commits, cryptoad, kubamracek Differential Revision: https://reviews.llvm.org/D38593 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318080 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[tsan] Deadly signal handler for tsanVitaly Buka
Summary: https://github.com/google/sanitizers/issues/637 Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D39929 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318078 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[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. Tested on several 4.x and 3.x kernel releases. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318044 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-13[asan] Add CMake hook to override shadow scale in compiler_rtWalter Lee
Allow user to override shadow scale in compiler_rt by passing -DCOMPILER_RT_ASAN_SHADOW_SCALE=n to CMake. Propagate the override shadow scale value via a compiler define to compiler-rt and asan tests. Tests will use the define to partially disable unsupported tests. Set "-mllvm -asan-mapping-scale=<n>" for compiler_rt tests. Differential Revision: https://reviews.llvm.org/D39469 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@318038 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-11Correct NetBSD build issueKamil Rytarowski
Cast SIG_IGN to (uptr). SIG_IGN is defined on NetBSD as a function pointer and cannot be assigned to an integer as it is. sys/signal.h:#define SIG_IGN ((void (*)(int)) 1) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317978 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-11[msan] Fix signal chainingVitaly Buka
Return internally stored handlers only if handlers is set to wrapper git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317970 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-11[ubsan-minimal] Get rid of the libc++ dependency.Evgeniy Stepanov
Summary: Use -nodefaultlibs. Replace std:atomic with sanitizer atomics. Reviewers: vitalybuka, kongyi, EricWF Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D39934 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317969 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Remove unnecessary attribute hidden.Evgeniy Stepanov
This should fix windows build of compiler-rt broken in r317943. The attribute is unnecessary because since GetMaxVirtualAddress was split in two, we no longer use common_flags() in the ifunc resolver context. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317948 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Move out more types to sanitizer_commonVitaly Buka
https://github.com/google/sanitizers/issues/637 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317946 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[asan] Use dynamic shadow on 32-bit Android.Evgeniy Stepanov
Summary: The following kernel change has moved ET_DYN base to 0x4000000 on arm32: https://marc.info/?l=linux-kernel&m=149825162606848&w=2 Switch to dynamic shadow base to avoid such conflicts in the future. Reserve shadow memory in an ifunc resolver, but don't use it in the instrumentation until PR35221 is fixed. This will eventually let use save one load per function. Reviewers: kcc Subscribers: aemerson, srhines, kubamracek, kristof.beyls, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D39393 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317943 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10sanitizer_common: Try looking up symbols with RTLD_DEFAULT if RTLD_NEXT does ↵Peter Collingbourne
not work. If the lookup using RTLD_NEXT failed, the sanitizer runtime library is later in the library search order than the DSO that we are trying to intercept, which means that we cannot intercept this function. We still want the address of the real definition, though, so look it up using RTLD_DEFAULT. Differential Revision: https://reviews.llvm.org/D39779 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317930 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[compiler-rt] Fix const and volatile qualifier warningsKuba Mracek
Building with a new clang produces a bunch of warnings about dropped 'const' and 'volatile' qualifiers on pointers. Let's fix them. Differential Revision: https://reviews.llvm.org/D39861 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317929 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Move code of sigaction_impl and signal_implVitaly Buka
They need to be after sanitizer_signal_interceptors.inc to use READ function Part of https://github.com/google/sanitizers/issues/637 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317914 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Extract sigaction_impl and signal_implVitaly Buka
Preparation for switching to sanitizer_signal_interceptors.inc Part of https://github.com/google/sanitizers/issues/637 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317913 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[scudo] Bump the Android API level requirement to 21 for getauxvalKostya Kortchinsky
Summary: `getauxval` was introduced in 18 & 21 depending on the architecture. Bump the requirement to 21. It also turns out that the NDK is finicky: NDK r13b doesn't include sys/auxv.h when creating a standalone toolchain at API level 19 for ARM. So 18 didn't work well with older NDKs. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: aemerson, srhines, llvm-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D39905 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317907 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[msan] Remove INTERCEPT_FUNCTION for sigaction and signalVitaly Buka
Already done in InitializeSignalInterceptors() git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317906 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10Revert "[XRay][darwin] Initial XRay in Darwin Support"Dean Michael Berris
This reverts r317875. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317877 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[XRay][darwin] Initial XRay in Darwin SupportDean Michael Berris
Summary: This change implements the changes required in both clang and compiler-rt to allow building XRay-instrumented binaries in Darwin. For now we limit this to x86_64. We also start building the XRay runtime library in compiler-rt for osx. A caveat to this is that we don't have the tests set up and running yet, which we'll do in a set of follow-on changes. This patch uses the monorepo layout for the coordinated change across multiple projects. Reviewers: kubamracek Subscribers: mgorny, cfe-commits, llvm-commits Differential Revision: https://reviews.llvm.org/D39114 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317875 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[esan] Fix compilation of signal handlersVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317874 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Use __sanitizer_siginfo from sanitizer_commonVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317872 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Remove unused <signal.h> which conflicts with asan declarationsVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317871 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[sanitizer] Forward declaration of __sanitizer_sigaction without signal ↵Vitaly Buka
interceptors git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317870 91177308-0d34-0410-b5e6-96231b3b80d8