summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* [SanitizerCommon] Reduce wasting memory in LowLevelAllocator.Igor Kudrin2019-12-112-1/+12
| | | | | | | | | MmapOrDie allocates memory multiple to page size. LowLevelAllocator should use all that memory for the internal buffer because there are chances that subsequent requests may be small enough to fit in that space. Differential Revision: https://reviews.llvm.org/D71275
* scudo: Tweak how we align UserPtr. NFCI.Peter Collingbourne2019-12-101-5/+6
| | | | | | | | | | | | Instead of testing whether the pointer is aligned, just align it unconditionally and compare it to the original pointer. This moves the computation of UserPtr up to before we start preparing the header, so that the memory tagging code will be able to read the original header containing the bounds of the previous allocation before it gets potentially clobbered by the pointer realignment code. Differential Revision: https://reviews.llvm.org/D71292
* scudo: Move getChunkFromBlock() allocated check into caller. NFCI.Peter Collingbourne2019-12-101-17/+9
| | | | | | | | With tag-on-free we will need to get the chunk of a deallocated block. Change getChunkFromBlock() so that it doesn't check that the chunk is allocated, and move the check into the caller, so that it can be reused for this purpose. Differential Revision: https://reviews.llvm.org/D71291
* [scudo][standalone] Define hasHardwareCRC32 for other archsKostya Kortchinsky2019-12-101-1/+3
| | | | | | | | | | | | | | | | | Summary: The function was only defined for x86 and arm families, which ends up being an issue for PPC in g3. Define the function, simply returning `false` for "other" architectures. Reviewers: hctim, pcc, cferris, eugenis, vitalybuka Subscribers: kristof.beyls, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71223
* Revert "[compiler-rt] Add a critical section when flushing gcov counters"Akira Hatanaka2019-12-091-24/+1
| | | | | | | This reverts commit 88f5bf77f92899b19fdafdffc7b060f930c1cb8b as it broke green dragon bots. http://lab.llvm.org:8080/green/job/clang-stage1-RA/4401/
* [hwasan] Offline symbolization script.Evgenii Stepanov2019-12-093-0/+286
| | | | | | | | | | | | | | | Summary: A script to symbolize hwasan reports after the fact using unstripped binaries. Supports stack-based reports. Requires llvm-symbolizer (addr2line is not an option). Reviewers: pcc, hctim Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71148
* scudo: Add a basic malloc/free benchmark.Peter Collingbourne2019-12-095-0/+126
| | | | Differential Revision: https://reviews.llvm.org/D71104
* [GWP-ASan] 32-bit test pointers, allow multi-init for test.Mitch Phillips2019-12-092-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: GWP-ASan test currently fail on 32-bit platforms, as some of the pointers are larger than `uintptr_t` on 32-bit platforms. Fix up all those instances. Also add an uncompress varint test where the result is an underflow. Furthermore, allow multi-init for testing. Each gtest when running `check-gwp_asan` apparently runs in its own instance, but when integrating these tests into Android, this behaviour isn't the same. We remove the global multi-init check here, to allow for testing to work elsewhere, and we're not really worried about multi-init anyway as it's part of our contract with the allocator. Reviewers: eugenis, vlad.tsyrklevich Reviewed By: eugenis Subscribers: #sanitizers, llvm-commits, pcc Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71121
* [compiler-rt] Add a critical section when flushing gcov countersCalixte Denizet2019-12-091-1/+24
| | | | | | | | | | | | | | | | | Summary: Counters can be flushed in a multi-threaded context for example when the process is forked in different threads (https://github.com/llvm/llvm-project/blob/master/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp#L632-L663). In order to avoid pretty bad things, a critical section is needed around the flush. We had a lot of crashes in this code in Firefox CI when we switched to clang for linux ccov builds and those crashes disappeared with this patch. Reviewers: marco-c, froydnj, dmajor, davidxl Reviewed By: marco-c, dmajor Subscribers: froydnj, dmajor, dberris, jfb, #sanitizers, llvm-commits, sylvestre.ledru Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70910
* scudo: Fix one of the C wrapper tests on Android.Peter Collingbourne2019-12-051-2/+11
| | | | | | | | | The test ScudoWrappersCTest.Realloc expects realloc of memalign to work on Android, but this relies on dealloc_type_mismatch being set to false. Commit 0d3d4d3b0 caused us to start setting it to true in the C wrapper tests, which broke the test. Set it to the correct value on Android. Differential Revision: https://reviews.llvm.org/D71078
* scudo: Fix the build of wrappers_c_test.cpp on Android.Peter Collingbourne2019-12-051-0/+2
| | | | | | | The Android headers don't provide a declaration of valloc or pvalloc, so we need to declare them ourselves. Differential Revision: https://reviews.llvm.org/D71077
* [scudo][standalone] Add chunk ownership functionKostya Kortchinsky2019-12-033-7/+27
| | | | | | | | | | | | | | | | | | | | | | | | Summary: In order to be compliant with tcmalloc's extension ownership determination function, we have to expose a function that will say if a chunk was allocated by us. As to whether or not this has security consequences: someone able to call this function repeatedly could use it to determine secrets (cookie) or craft a valid header. So this should not be exposed directly to untrusted user input. Add related tests. Additionally clang-format caught a few things to change. Reviewers: hctim, pcc, cferris, eugenis, vitalybuka Subscribers: JDevlieghere, jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70908
* Revert "Revert 1689ad27af5 "[builtins] Implement rounding mode support for ↵Yi Kong2019-11-272-0/+46
| | | | | | | | | i386/x86_64"" Don't build specilised fp_mode.c on MSVC since it does not support inline ASM on x86_64. This reverts commit a19f0eec94e195cac676d0d473882b48f4fded90.
* scudo: Limit the number of bytes tested in a realloc test.Peter Collingbourne2019-11-271-1/+1
| | | | | | | | | | | | | | | | | This test was previously effectively doing: P = malloc(X); write X bytes to P; P = realloc(P, X - Y); P = realloc(P, X) and expecting that all X bytes stored to P would still be identical after the final realloc. This happens to be true for the current scudo implementation of realloc, but is not guaranteed to be true by the C standard ("Any bytes in the new object beyond the size of the old object have indeterminate values."). This implementation detail will change with the new memory tagging support, which unconditionally zeros newly allocated granules when memory tagging is enabled. Fix this by limiting the number of bytes that we test to the minimum size that we realloc the allocation to. Differential Revision: https://reviews.llvm.org/D70761
* scudo: Replace a couple of macros with their expansions.Peter Collingbourne2019-11-2716-67/+64
| | | | | | | | | The macros INLINE and COMPILER_CHECK always expand to the same thing (inline and static_assert respectively). Both expansions are standards compliant C++ and are used consistently in the rest of LLVM, so let's improve consistency with the rest of LLVM by replacing them with the expansions. Differential Revision: https://reviews.llvm.org/D70793
* scudo: Call setCurrentTSD(nullptr) when bringing down the TSD registry in tests.Peter Collingbourne2019-11-271-0/+1
| | | | | | | | | Otherwise, we will hit a use-after-free when testing multiple instances of the same allocator on the same thread. This only recently became a problem with D70552 which caused us to run both ScudoCombinedTest.BasicCombined and ScudoCombinedTest.ReleaseToOS on the unit tests' main thread. Differential Revision: https://reviews.llvm.org/D70760
* Make memory dump same as the one in asan.Martin Liska2019-11-271-1/+2
| | | | | | | Shadow memory (and short granules) are not prepended with memory address and arrow at the end of line is removed. Differential Revision: https://reviews.llvm.org/D70707
* [scudo][standalone] Make tests work on FuchsiaKostya Kortchinsky2019-11-2725-90/+157
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This CL makes unit tests compatible with Fuchsia's zxtest. This required a few changes here and there, but also unearthed some incompatibilities that had to be addressed. A header is introduced to allow to account for the zxtest/gtest differences, some `#if SCUDO_FUCHSIA` are used to disable incompatible code (the 32-bit primary, or the exclusive TSD). It also brought to my attention that I was using `__scudo_default_options` in different tests, which ended up in a single binary, and I am not sure how that ever worked. So move this to the main cpp. Additionally fully disable the secondary freelist on Fuchsia as we do not track VMOs for secondary allocations, so no release possible. With some modifications to Scudo's BUILD.gn in Fuchsia: ``` [==========] 79 tests from 23 test cases ran (10280 ms total). [ PASSED ] 79 tests ``` Reviewers: mcgrathr, phosek, hctim, pcc, eugenis, cferris Subscribers: srhines, jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70682
* [profile] Fix file contention causing dropped counts on Windows under ↵Hans Wennborg2019-11-271-2/+7
| | | | | | | | | | | | | | | | | | | | | -fprofile-generate See PR43425: https://bugs.llvm.org/show_bug.cgi?id=43425 When writing profile data on Windows we were opening profile file with exclusive read/write access. In case we are trying to write to the file from multiple processes simultaneously, subsequent calls to CreateFileA would return INVALID_HANDLE_VALUE. To fix this, I changed to open without exclusive access and then take a lock. Patch by Michael Holman! Differential revision: https://reviews.llvm.org/D70330
* Fix sanitizer-common build with glibc 2.31Evgenii Stepanov2019-11-252-19/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: As mentioned in D69104, glibc changed ABI recently with the [[ https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2f959dfe849e0646e27403f2e4091536496ac0f0| 2f959dfe ]] change. D69104 dealt with just 32-bit ARM, but that is just one of the many affected architectures. E.g. x86_64, i?86, riscv64, sparc 32-bit, s390 31-bit are affected too (and various others). This patch instead of adding a long list of further architectures that wouldn't be checked ever next to arm 32-bit changes the structures to match the 2.31 layout and performs the checking on Linux for ipc_perm mode position/size only on non-Linux or on Linux with glibc 2.31 or later. I think this matches what is done for aarch64 already. If needed, we could list architectures that haven't changed ABI (e.g. powerpc), so that they would be checked even with older glibcs. AFAIK sanitizers don't actually use ipc_perm.mode and so all they care about is the size and alignment of the whole structure. Note, s390 31-bit and arm 32-bit big-endian changed ABI even further, there will now be shmctl with old symbol version and shmctl@@GLIBC_2.31 which will be incompatible. I'm afraid this isn't really solvable unless the sanitizer libraries are symbol versioned and use matching symbol versions to glibc symbols for stuff they intercept, plus use dlvsym. This patch doesn't try to address that. Patch by Jakub Jelinek. Reviewers: kcc, eugenis, dvyukov Reviewed By: eugenis Subscribers: jyknight, kristof.beyls, fedor.sergeev, simoncook, PkmX, s.egerton, steven.zhang, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70662
* [PowerPC][compiler-rt][builtins]Add __fixtfti builtin on PowerPCLei Huang2019-11-252-0/+39
| | | | | | | | | | | | Implements __fixtfti builtin for PowerPC. This builtin converts a long double (IBM double-double) to a signed int128. The conversion relies on the unsigned conversion of the absolute value of the long double. Tests included for both positive and negative long doubles. Patch By: Baptiste Saleil Differential Revision: https://reviews.llvm.org/D69730
* [GWP-ASan] Add GWP_ASAN_ prefix to macros.Mitch Phillips2019-11-253-21/+9
| | | | | | | | | | | | | | | | | Summary: When platforms use their own `LIKELY()` definitions, it can be quite troublesome to ensure they don't conflict with the GWP-ASan internal definitions. Just force the GWP_ASAN_ prefix to help this issue. Reviewers: eugenis Reviewed By: eugenis Subscribers: #sanitizers, llvm-commits, cferris, pcc Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70683
* [scudo][standalone] Fix for releaseToOS prior to initKostya Kortchinsky2019-11-252-1/+19
| | | | | | | | | | | | | | | | | | | | Summary: cferris@ found an issue where calling `releaseToOS` prior to any other heap operation would lead to a crash, due to the allocator not being properly initialized (it was discovered via `mallopt`). The fix is to call `initThreadMaybe` prior to calling `releaseToOS` for the Primary. Add a test that crashes prior to fix. Reviewers: hctim, cferris, pcc, eugenis Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70552
* Reland "[CMake] Support installation of InstrProfData.inc"Petr Hosek2019-11-228-767/+15
| | | | | | | | | | | This header fragment is useful on its own for any consumer that wants to use custom instruction profile runtime with the LLVM instrumentation. The concrete use case is in Fuchsia's kernel where we want to use instruction profile instrumentation, but we cannot use the compiler-rt runtime because it's not designed for use in the kernel environment. This change allows installing this header as part of compiler-rt. Differential Revision: https://reviews.llvm.org/D64532
* Revert "[CMake] Support installation of InstrProfData.inc"Petr Hosek2019-11-227-12/+766
| | | | | This reverts commit f11bc1776fd2815b60e0b1ed97be00b517348162 since it's failing to build on some bots.
* [CMake] Support installation of InstrProfData.incPetr Hosek2019-11-227-766/+12
| | | | | | | | | | | This header fragment is useful on its own for any consumer that wants to use custom instruction profile runtime with the LLVM instrumentation. The concrete use case is in Fuchsia's kernel where we want to use instruction profile instrumentation, but we cannot use the compiler-rt runtime because it's not designed for use in the kernel environment. This change allows installing this header as part of compiler-rt. Differential Revision: https://reviews.llvm.org/D64532
* Don't forward __pthread_mutex_* interceptors to pthread_mutex_* versionVitaly Buka2019-11-221-2/+18
| | | | | | | | | | | | | | | Summary: Allows to use rr with asan Fixes PR41095 Reviewers: eugenis Subscribers: jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70581
* [libFuzzer] don't use /dev/null for DiscardOuput in Fuchsia.Marco Vanotti2019-11-218-18/+42
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This commit moves the `DiscardOutput` function in FuzzerIO to FuzzerUtil, so fuchsia can have its own specialized version. In fuchsia, accessing `/dev/null` is not supported, and there's nothing similar to a file that discards everything that is written to it. The way of doing something similar in fuchsia is by using `fdio_null_create` and binding that to a file descriptor with `fdio_bind_to_fd`. This change should fix one of the issues with the `-close_fd_mask` flag in libfuzzer, in which closing stdout was not working due to `fopen("/dev/null", "w")` returning `NULL`. Reviewers: kcc, aarongreen Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69593
* [libFuzzer] Fix unwinding for FuchsiaMarco Vanotti2019-11-211-16/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This commit fixes part of the issues with stack unwinding in fuchsia for arm64 and x86_64. It consists of multiple fixes: (1) The cfa_offset calculation was wrong, instead of pointing to the previous stack pointer, it was pointing to the current one. It worked in most of the cases because the crashing functions already had a prologue and had their cfa information relative to another register. The fix consists on adding a constant that can be used to calculate the crashing function's stack pointer, and base all the cfi information relative to that offset. (2) (arm64) Due to errors with the syntax for the dwarf information, most of the `OP_NUM` macros were not working. The problem was that they were referred to as `r##NUM` (like `r14`), when it should have been `x##num` (like `x14`), or even without the x. (3) (arm64) The link register was being considered a part of the main registers (`r30`), when in the real struct it has its own field. Given that the link register is in the same spot in the struct as r[30] would be, and that C++ doesn't care about anything, the calculation was still correct. (4) (x86_64) The stack doesn't need to be aligned to 16 bytes when we jump to the trampoline function, but it needs to be before performing call instructions. Encoding that logic in cfi information was tricky, so we decided to make the cfa information relative to `rbp` and align `rsp`. Note that this could have been done using another register directly, but it seems cleaner to make a new fake stack frame. There are some other minor changes like adding a `brk 1` instruction in arm64 to make sure that we never return to the crash trampoline (similar to what we do in x86_64). Sadly this commit does not fix unwinding for all use cases for arm64. Crashing functions that do not add information related to the return column in their cfi information will fail to unwind due to a bug in libunwinder. Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen Subscribers: aprantl, kristof.beyls, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69579
* [libFuzzer] Fix fd check in DupAndCloseStderr.Marco Vanotti2019-11-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This commit fixes the check in the return value from the `DuplicateFile` function, which returns a new file descriptor. `DuplicateFile` can return 0 if that file descriptor is available (for example, if stdin has already been closed). In particular, this could cause a bug with the `-close_fd_mask` flag in some platforms: just call the fuzzer with stdin closed and the `-close_fd_mask=2` flag, and stderr will not be muted. Example fuzzer: ``` extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) { fprintf(stderr, "STDERR\n"); fprintf(stdout, "STDOUT\n"); return 0; } ``` Invocation (muting both stderr and stdout): ``` ./test -close_fd_mask=3 -runs=1 0<&- INFO: Seed: 1155116940 INFO: Loaded 1 modules (1 inline 8-bit counters): 1 [0x48b020, 0x48b021), INFO: Loaded 1 PC tables (1 PCs): 1 [0x478dc8,0x478dd8), INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes STDERR INFO: A corpus is not provided, starting from an empty corpus STDERR Done 2 runs in 0 second(s) ``` Reviewers: mcgrathr, jakehehrlich, phosek, kcc, aarongreen Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D68775
* [scudo][standalone] Minor optimization & improvementsKostya Kortchinsky2019-11-213-11/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: A few small improvements and optimizations: - when refilling the free list, push back the last batch and return the front one: this allows to keep the allocations towards the front of the region; - instead of using 48 entries in the shuffle array, use a multiple of `MaxNumCached`; - make the maximum number of batches to create on refil a constant; ultimately it should be configurable, but that's for later; - `initCache` doesn't need to zero out the cache, it's already done. - it turns out that when using `||` or `&&`, the compiler is adamant on adding a short circuit for every part of the expression. Which ends up making somewhat annoying asm with lots of test and conditional jump. I am changing that to bitwise `|` or `&` in two place so that the generated code looks better. Added comments since it might feel weird to people. This yields to some small performance gains overall, nothing drastic though. Reviewers: hctim, morehouse, cferris, eugenis Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70452
* [compiler-rt] Don't check XCR0 when detecting avx512 on Darwin.Florian Hahn2019-11-211-0/+8
| | | | | | | | | | | | | | | | | | | Darwin lazily saves the AVX512 context on first use [1]: instead of checking that it already does to figure out if the OS supports AVX512, trust that the kernel will do the right thing and always assume the context save support is available. [1] https://github.com/apple/darwin-xnu/blob/xnu-4903.221.2/osfmk/i386/fpu.c#L174 Reviewers: ab, RKSimon, craig.topper Reviewed By: craig.topper Subscribers: dberris, JDevlieghere, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70454
* scudo: Only use the Android reserved TLS slot when building libc's copy of ↵Peter Collingbourne2019-11-203-4/+10
| | | | | | | | | | | | | | the allocator. When we're not building libc's allocator, just use a regular TLS variable. This lets the unit tests pass on Android devices whose libc uses Scudo. Otherwise libc's copy of Scudo and the unit tests' copy will both try to use the same TLS slot, in likely incompatible ways. This requires using ELF TLS, so start passing -fno-emulated-tls when building the library and the unit tests on Android. Differential Revision: https://reviews.llvm.org/D70472
* scudo: Switch from std::random_shuffle to std::shuffle in a test.Peter Collingbourne2019-11-191-1/+2
| | | | | | This lets the test build with C++17. Differential Revision: https://reviews.llvm.org/D70471
* [profile] Address unused function warnings on Windows after D69586Vedant Kumar2019-11-191-0/+2
| | | | | This '#ifdef's out two functions which are unused on Windows, to prevent -Wunused-function warnings.
* [profile] Unbreak Fuchsia/Windows after D68351Vedant Kumar2019-11-191-3/+3
| | | | | | Continuous mode is not yet supported on Fuchsia/Windows, however an error should not be reported unless the user attempted to actually enable continuous mode.
* [Symbolizers] On Darwin compute function offset when possible.Dan Liew2019-11-191-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The sanitizer symbolizers support printing the function offset (difference between pc and function start) of a stackframe using the `%q` format specifier. Unfortunately this didn't actually work because neither the atos or dladdr symbolizer set the `AddressInfo::function_offset` field. This patch teaches both symbolizers to try to compute the function offset. In the case of the atos symbolizer, atos might not report the function offset (e.g. it reports a source location instead) so in this case it fallsback to using `dladdr()` to compute the function offset. Two test cases are included. rdar://problem/56695185 Reviewers: kubamracek, yln Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69549
* Revert 1689ad27af5 "[builtins] Implement rounding mode support for i386/x86_64"Hans Wennborg2019-11-192-40/+0
| | | | | | | | It broke the build with MSVC: fp_mode.c(20): error C2065: '__asm__': undeclared identifier > Differential Revision: https://reviews.llvm.org/D69870
* [profile] Support online merging with continuous sync modeVedant Kumar2019-11-183-44/+95
| | | | | | | | | | | | | | | Make it possible to use online profile merging ("%m" mode) with continuous sync ("%c" mode). To implement this, the merged profile is locked in the runtime initialization step and either a) filled out for the first time or b) checked for compatibility. Then, the profile can simply be mmap()'d with MAP_SHARED set. With the mmap() in place, counter updates from every process which uses an image are mapped onto the same set of physical pages assigned by the filesystem cache. After the mmap() is set up, the profile is unlocked. Differential Revision: https://reviews.llvm.org/D69586
* [X86] Add AMD Matisse (znver2) model number to getHostCPUName and ↵Craig Topper2019-11-181-2/+2
| | | | | | | | | | compiler-rt's getAMDProcessorTypeAndSubtype. This is the CPUID model used on Ryzen 3000 series (Zen 2/Matisse) CPUs. Patch by Alex James Differential Revision: https://reviews.llvm.org/D70279
* [builtins] Implement rounding mode support for i386/x86_64Yi Kong2019-11-182-0/+40
| | | | Differential Revision: https://reviews.llvm.org/D69870
* [scudo][standalone] Enabled SCUDO_DEBUG for tests + fixesKostya Kortchinsky2019-11-156-10/+13
| | | | | | | | | | | | | | | | | | | Summary: `SCUDO_DEBUG` was not enabled for unit tests, meaning the `DCHECK`s were never tripped. While turning this on, I discovered that a few of those not-exercised checks were actually wrong. This CL addresses those incorrect checks. Not that to work in tests `CHECK_IMPL` has to explicitely use the `scudo` namespace. Also changes a C cast to a C++ cast. Reviewers: hctim, pcc, cferris, eugenis, vitalybuka Subscribers: mgorny, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70276
* [SanitizerCommon] Print the current value of options when printing out help.Dan Liew2019-11-144-3/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously it wasn't obvious what the default value of various sanitizer options were. A very close approximation of the "default values" for the options are the current value of the options at the time of printing the help output. In the case that no other options are provided then the current values are the default values (apart from `help`). ``` ASAN_OPTIONS=help=1 ./program ``` This patch causes the current option values to be printed when the `help` output is enabled. The original intention for this patch was to append `(Default: <value>)` to an option's help text. However because this is technically wrong (and misleading) I've opted to append `(Current Value: <value>)` instead. When trying to implement a way of displaying the default value of the options I tried another solution where the default value used in `*.inc` files were used to create compile time strings that where used when printing the help output. This solution was not satisfactory for several reasons: * Stringifying the default values with the preprocessor did not work very well in several cases. Some options contain boolean operators which no amount of macro expansion can get rid of. * It was much more invasive than this patch. Every sanitizer had to be changed. * The settings of `__<sanitizer>_default_options()` are ignored. For those reasons I opted for the solution in this patch. rdar://problem/42567204 Reviewers: kubamracek, yln, kcc, dvyukov, vitalybuka, cryptoad, eugenis, samsonov Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D69546
* [profile] Factor out logic for mmap'ing merged profile, NFCVedant Kumar2019-11-131-22/+51
| | | | | | | | | | | Split out the logic to get the size of a merged profile and to do a compatibility check. This can be shared with both the continuous+merging mode implementation, as well as the runtime-allocated counters implementation planned for Fuchsia. Lifted out of D69586. Differential Revision: https://reviews.llvm.org/D70135
* Add a shim for setenv on PS4 since it does not exist.Douglas Yung2019-11-121-1/+3
| | | | | | | | A few years back a similar change was made for getenv since neither function is supported on the PS4 platform. Recently, commit d889d1e added a call to setenv in compiler-rt which was causing linking errors because the symbol was not found. This fixes that issue by putting in a shim similar to how we previously dealt with the lack of getenv. Differential Revision: https://reviews.llvm.org/D70033
* Fix include guard and properly order __deregister_frame_info.Sterling Augustine2019-11-122-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch fixes two problems with the crtbegin.c as written: 1. In do_init, register_frame_info is not guarded by a #define, but in do_fini, deregister_frame_info is guarded by #ifndef CRT_HAS_INITFINI_ARRAY. Thus when CRT_HAS_INITFINI_ARRAY is not defined, frames are registered but then never deregistered. The frame registry mechanism builds a linked-list from the .so's static variable do_init.object, and when the .so is unloaded, this memory becomes invalid and should be deregistered. Further, libgcc's crtbegin treats the frame registry as independent from the initfini array mechanism. This patch fixes this by adding a new #define, "EH_USE_FRAME_INFO_REGISTRY", which is set by the cmake option COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY Currently, do_init calls register_frame_info, and then calls the binary's constructors. This allows constructors to safely use libunwind. However, do_fini calls deregister_frame_info and then calls the binary's destructors. This prevents destructors from safely using libunwind. This patch also switches that ordering, so that destructors can safely use libunwind. As it happens, this is a fairly common scenario for thread sanitizer.
* [scudo][standalone] Match function name change to bionic name change.Christopher Ferris2019-11-111-9/+1
| | | | | | | | | | | | | | Summary: Bionic was modified to have all function names consistent. Modify the code and get rid of the special case for bionic since it's no longer needed. Reviewers: cryptoad Reviewed By: cryptoad Subscribers: srhines, llvm-commits, #sanitizers Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70031
* [PowerPC][compiler-rt][builtins]Fix __fixunstfti builtin on PowerPCLei Huang2019-11-081-2/+12
| | | | | | | | | | | __fixunstfti converts a long double (IBM double-double) to an unsigned 128 bit integer. This patch enables it to handle a previously unhandled case in which a negative low double may impact the result of the conversion. Collaborated with @masoud.ataei and @renenkel. Patch By: Baptiste Saleil Differential Revision: https://reviews.llvm.org/D69193
* [GWP-ASan] Respect compiler-rt's -fno-ltoMitch Phillips2019-11-071-1/+2
| | | | | | | https://bugs.llvm.org/show_bug.cgi?id=43722 GWP-ASan didn't include SANITIZER_COMMON_CFLAGS, and thus would produce LLVM bitcode files, when compiler-rt is generally built without LTO.
* Remove unused variables, as suggested by @mcgov.Alexandre Ganea2019-11-041-3/+0
| | | | Fixes warning: unused variable 'XXX' [-Wunused-const-variable]
OpenPOWER on IntegriCloud