Commit Graph

9049 Commits

Author SHA1 Message Date
Kostya Kortchinsky b44364dd15 [scudo] Do not grab a cache for secondary allocation & per related changes
Summary:
Secondary backed allocations do not require a cache. While it's not necessary
an issue when each thread has its cache, it becomes one with a shared pool of
caches (Android), as a Secondary backed allocation or deallocation holds a
cache that could be useful to another thread doing a Primary backed allocation.

We introduce an additional PRNG and its mutex (to avoid contention with the
Fallback one for Primary allocations) that will provide the `Salt` needed for
Secondary backed allocations.

I changed some of the code in a way that feels more readable to me (eg: using
some values directly rather than going  through ternary assigned variables,
using directly `true`/`false` rather than `FromPrimary`). I will let reviewers
decide if it actually is.

An additional change is to mark `CheckForCallocOverflow` as `UNLIKELY`.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 307958
2017-07-13 21:01:19 +00:00
Vedant Kumar 965f23fe84 [ubsan] Teach the pointer overflow check that "p - <unsigned> <= p" (compiler-rt)
Compiler-rt changes associated with: D34121

llvm-svn: 307956
2017-07-13 20:55:41 +00:00
Kuba Mracek f0c652a52e For Darwin's GetTaskInfoMaxAddress, define the real structure with real fields to avoid confusion. NFC.
llvm-svn: 307945
2017-07-13 20:02:45 +00:00
Craig Topper e6b07073ca [compiler-rt][X86] Match the detection of cpu's for __cpu_model to the latest version of gcc
Summary:
We were missing many feature flags that newer gcc supports and we had our own set of feature flags that gcc didnt' support that were overlapping. Clang's implementation assumes gcc's features list so a mismatch here is problematic.

I've also matched the cpu type/subtype lists with gcc and removed all the cpus that gcc doesn't support. I've also removed the fallback autodetection logic that was taken from Host.cpp. It was the main reason we had extra feature flags relative to gcc. I don't think gcc does this in libgcc.

Once this support is in place we can consider implementing __builtin_cpu_is in clang. This could also be needed for function dispatching that Erich Keane is working on.

Reviewers: echristo, asbirlea, RKSimon, erichkeane, zvi

Reviewed By: asbirlea

Subscribers: dberris, llvm-commits

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

llvm-svn: 307878
2017-07-13 02:56:24 +00:00
Xinliang David Li 028c78b593 Fix broken test
llvm-svn: 307869
2017-07-13 00:22:01 +00:00
Vitaly Buka 9fd492e71e [asan] Avoid recompilation of the same code in the test
llvm-svn: 307868
2017-07-12 23:59:22 +00:00
Kuba Mracek c1e903be19 [asan] For iOS/AArch64, if the dynamic shadow doesn't fit, restrict the VM space
On iOS/AArch64, the address space is very limited and has a dynamic maximum address based on the configuration of the device. We're already using a dynamic shadow, and we find a large-enough "gap" in the VM where we place the shadow memory. In some cases and some device configuration, we might not be able to find a large-enough gap: E.g. if the main executable is linked against a large number of libraries that are not part of the system, these libraries can fragment the address space, and this happens before ASan starts initializing.

This patch has a solution, where we have a "backup plan" when we cannot find a large-enough gap: We will restrict the address space (via MmapFixedNoAccess) to a limit, for which the shadow limit will fit.

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

llvm-svn: 307865
2017-07-12 23:29:21 +00:00
Xinliang David Li 07df59b7b6 [PGO] Add a test for 2-deep loop nest
llvm-svn: 307864
2017-07-12 23:28:45 +00:00
Kuba Mracek 7004b7cf0d Add explicit CMake targets for ASan/TSan iOS Simulator testing and update the instructions how to run them.
llvm-svn: 307844
2017-07-12 21:02:48 +00:00
Kuba Mracek 4c4ea1d1ba On Darwin, start building the TSan iOS dylib by default.
llvm-svn: 307839
2017-07-12 20:25:14 +00:00
Petr Hosek 969518b442 [builtins] Better Fuchsia support
Add Fuchsia support to some builtings and avoid building builtins
that are not and will never be used on Fuchsia.

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

llvm-svn: 307832
2017-07-12 19:33:30 +00:00
Kuba Mracek 46f2b8485a On Darwin, start building the TSan dylib for the iOS simulator.
llvm-svn: 307816
2017-07-12 17:30:54 +00:00
Kuba Mracek 476c3e9ba0 Fix the declaration of DARWIN_PREFER_PUBLIC_SDK cmake variable (move before the return).
llvm-svn: 307815
2017-07-12 17:11:53 +00:00
Kostya Kortchinsky 00582563be [scudo] PRNG makeover
Summary:
This follows the addition of `GetRandom` with D34412. We remove our
`/dev/urandom` code and use the new function. Additionally, change the PRNG for
a slightly faster version. One of the issues with the old code is that we have
64 full bits of randomness per "next", using only 8 of those for the Salt and
discarding the rest. So we add a cached u64 in the PRNG that can serve up to
8 u8 before having to call the "next" function again.

During some integration work, I also realized that some very early processes
(like `init`) do not benefit from `/dev/urandom` yet. So if there is no
`getrandom` syscall as well, we have to fallback to some sort of initialization
of the PRNG.

Now a few words on why XoRoShiRo and not something else. I have played a while
with various PRNGs on 32 & 64 bit platforms. Some results are below. LCG 32 & 64
are usually faster but produce respectively 15 & 31 bits of entropy, meaning
that to get a full 64-bit, you would need to call them several times. The simple
XorShift is fast, produces 32 bits but is mediocre with regard to PRNG test
suites, PCG is slower overall, and XoRoShiRo is faster than XorShift128+ and
produces full 64 bits.

%%%
root@tulip-chiphd:/data # ./randtest.arm
[+] starting xs32...
[?] xs32 duration: 22431833053ns
[+] starting lcg32...
[?] lcg32 duration: 14941402090ns
[+] starting pcg32...
[?] pcg32 duration: 44941973771ns
[+] starting xs128p...
[?] xs128p duration: 48889786981ns
[+] starting lcg64...
[?] lcg64 duration: 33831042391ns
[+] starting xos128p...
[?] xos128p duration: 44850878605ns

root@tulip-chiphd:/data # ./randtest.aarch64
[+] starting xs32...
[?] xs32 duration: 22425151678ns
[+] starting lcg32...
[?] lcg32 duration: 14954255257ns
[+] starting pcg32...
[?] pcg32 duration: 37346265726ns
[+] starting xs128p...
[?] xs128p duration: 22523807219ns
[+] starting lcg64...
[?] lcg64 duration: 26141304679ns
[+] starting xos128p...
[?] xos128p duration: 14937033215ns
%%%

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: aemerson, kristof.beyls, llvm-commits

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

llvm-svn: 307798
2017-07-12 15:29:08 +00:00
Dmitry Vyukov 1fa729999b tsan: remove some clock-related stats
The stats are too dependent on implementation
and won't be relevant in future.

llvm-svn: 307786
2017-07-12 12:54:38 +00:00
Dmitry Vyukov 62b9ad718f tsan: refactor SyncClock code
1. Add SyncClock::ResetImpl which removes code
   duplication between ctor and Reset.
2. Move SyncClock::Resize to SyncClock methods,
   currently it's defined between ThreadClock methods.

llvm-svn: 307785
2017-07-12 12:50:36 +00:00
Dmitry Vyukov 5f924089e5 tsan: prepare clock for future changes
Pass ClockCache to ThreadClock::set and introduce ThreadCache::ResetCached.
For now both are unused, but will reduce future diffs.

llvm-svn: 307784
2017-07-12 12:45:20 +00:00
Dmitry Vyukov 293b4fc04e tsan: s/-1/kInvalidTid/
llvm-svn: 307781
2017-07-12 12:36:44 +00:00
Dmitry Vyukov 5abf9bb1ca tsan: give debug names to dense allocators
Improves crash message on dense alloc overflow.
Allows to understand what alloc overflowed.

llvm-svn: 307780
2017-07-12 12:34:12 +00:00
Dmitry Vyukov 7bf9ee041a tsan: don't create sync objects on acquire-load
Don't create sync object if it does not exist yet. For example, an atomic
pointer is initialized to nullptr and then periodically acquire-loaded.

llvm-svn: 307778
2017-07-12 12:28:23 +00:00
Dmitry Vyukov 0a9265c26c tsan: add another test for clock growth
llvm-svn: 307777
2017-07-12 12:25:03 +00:00
Dmitry Vyukov 05d297080e tsan: add test for __tsan_java_find
The test should have been added in 289682
"tsan: allow Java VM iterate over allocated objects"
but I forgot to avn add.

Author: Alexander Smundak (asmundak)
Reviewed in https://reviews.llvm.org/D27720

llvm-svn: 307776
2017-07-12 12:23:31 +00:00
Vitaly Buka 11fe7beda9 [tsan] Update test to r307338
r307338 enabled new optimization reducing number of operation in tested functions.
There is no any performance regression detectable with TsanRtlTest DISABLED_BENCH.Mop* tests.

llvm-svn: 307739
2017-07-12 00:14:05 +00:00
Francis Ricci 9fd8a6381c Use internal_strncpy to copy filename in linux procmaps
Cleaner than using a while loop to copy the string character by character.

Reviewers: alekseyshl, glider

Subscribers: llvm-commits

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

llvm-svn: 307696
2017-07-11 19:40:54 +00:00
Francis Ricci edd53cb652 Inline function to get mac segment address range
Summary:
This function is only called once and is fairly simple. Inline to
keep API simple.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 307695
2017-07-11 19:40:53 +00:00
Francis Ricci f6a4329b7d Refactor MemoryMappingLayout::Next to use a single struct instead of output 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
2017-07-11 18:54:00 +00:00
Evgeniy Stepanov b76e4d12f4 [asan] Fix asan_device_setup --use-su mode on Android 7.x.
mount command does not accept -o remount,rw flag on some versions of Android.
mount -o rw,remount works everywhere.

llvm-svn: 307685
2017-07-11 18:18:50 +00:00
Petar Jovanovic adf4ce3a2c Remove duplicate assignments in stat64/kernel_stat_to_stat functions
Remove duplicate assignments in stat64_to_stat() and kernel_stat_to_stat().

llvm-svn: 307657
2017-07-11 13:03:48 +00:00
George Karpenkov 0b4ebb1d0b Do not crash with missing symbolication when running in DEDUP mode
Printing stacktrace from ASAN crashes with a segfault in DEDUP mode when
symbolication is missing.

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

llvm-svn: 307577
2017-07-10 20:06:06 +00:00
Kuba Mracek 7fa20ac847 Add an #if SANITIZER_MAC and a comment to lsan_common's suppression for "_os_trace".
llvm-svn: 307567
2017-07-10 18:55:33 +00:00
Craig Topper 76ac813790 [X86] Sync a few more things from llvm's Host.cpp to cpu_model.
This syncs the cpuid functions and adds breaks to the appropriate spots in the CPU decoding switches. Also a few formatting tweaks.

llvm-svn: 307561
2017-07-10 17:47:23 +00:00
Craig Topper 61d8450277 [X86] Resync cpu_model.c with llvm's Host.cpp in preparation for making it compatible with newer gcc.
llvm-svn: 307558
2017-07-10 17:30:20 +00:00
Kuba Mracek 21ad3fd3c5 Fix-up for r307537: We need to #include stdint.h to get int32_t.
llvm-svn: 307557
2017-07-10 17:11:52 +00:00
Kuba Mracek dbfd7f35ff Fix a build failure due to r307541 (tsan_rtl_aarch64.S:54: Error: unknown pseudo-op: `.').
llvm-svn: 307549
2017-07-10 15:58:22 +00:00
Kuba Mracek 6496d92dd2 [lsan] Add _os_trace into LSan's suppression list
Differential Revision: https://reviews.llvm.org/D35173

llvm-svn: 307548
2017-07-10 15:55:25 +00:00
Kuba Mracek 9ae34c2d3f Fix-up for r307540.
llvm-svn: 307547
2017-07-10 15:52:30 +00:00
Kuba Mracek 7cd7c1a7b5 [tsan] Add comments for the bool argument of ThreadIgnoreBegin/ThreadIgnoreSyncBegin, NFC.
Differential Revision: https://reviews.llvm.org/D35134

llvm-svn: 307545
2017-07-10 15:37:13 +00:00
Kuba Mracek f20cb690b5 [tsan] Add a mapping for Darwin/AArch64
This patch defines the TSan memory map and offsets for Darwin on AArch64.

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

llvm-svn: 307544
2017-07-10 15:35:04 +00:00
Kuba Mracek 8bd2cca391 [tsan] Port setjmp/longjmp assembly to Darwin/AArch64
This patch ports the assembly file implementing TSan's setjmp support to AArch64 on Darwin.

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

llvm-svn: 307541
2017-07-10 15:28:16 +00:00
Kuba Mracek 8b225456c2 [tsan] Add a max VM address check for Darwin/AArch64
Differential Revision: https://reviews.llvm.org/D35154

llvm-svn: 307540
2017-07-10 15:24:48 +00:00
Kuba Mracek 989513be94 Reverting an accidentally landed change.
llvm-svn: 307539
2017-07-10 15:20:50 +00:00
Kuba Mracek 872cb7086c Fixup whitespace.
llvm-svn: 307538
2017-07-10 15:19:14 +00:00
Kuba Mracek 91f3fa5f31 [tsan] Add support for running TSan tests on iOS simulator and devices
Differential Revision: https://reviews.llvm.org/D35157

llvm-svn: 307537
2017-07-10 15:00:55 +00:00
Kuba Mracek 5c2e3e2b75 Make sure SANITIZER_MIN_OSX_VERSION is defined before using it.
llvm-svn: 307448
2017-07-07 22:40:13 +00:00
Kuba Mracek afbde43a8f Update buildgo.sh to pass -isysroot on Darwin.
llvm-svn: 307443
2017-07-07 21:17:29 +00:00
Kuba Mracek 0fa9d68740 Fix-up for r307307: vm_info.max_address is the first non-addressable pointer, so we need to subtract one.
llvm-svn: 307408
2017-07-07 15:32:44 +00:00
Evgeniy Stepanov 7d3eeaaa96 Revert r307342, r307343.
Revert "Copy arguments passed by value into explicit allocas for ASan."
Revert "[asan] Add end-to-end tests for overflows of byval arguments."

Build failure on lldb-x86_64-ubuntu-14.04-buildserver.
Test failure on clang-cmake-aarch64-42vma and sanitizer-x86_64-linux-android.

llvm-svn: 307345
2017-07-07 01:31:23 +00:00
Kuba Mracek 7a493393b3 [cmake] Cache results of find_darwin_sdk_dir
This improves find_darwin_sdk_dir to cache the results of executing xcodebuild to find the SDK. Should significantly reduce the CMake re-configure time.

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

llvm-svn: 307344
2017-07-07 01:06:20 +00:00
Evgeniy Stepanov 03542db81c [asan] Add end-to-end tests for overflows of byval arguments.
Included is one test for passing structs by value and one test for passing C++
objects by value.

Patch by Matt Morehouse.

Differential revision: https://reviews.llvm.org/D34827

llvm-svn: 307343
2017-07-07 00:48:38 +00:00
Kuba Mracek 935243486c [cmake] Add an option to prefer public SDK in find_darwin_sdk_dir
Adds a CMake option DARWIN_PREFER_PUBLIC_SDK, off by default. When on, this prefers to use the public SDK, even when an internal one is present. With this, it's easy to emulate a build that the public buildbots are doing.

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

llvm-svn: 307330
2017-07-06 23:09:16 +00:00
Reid Kleckner da565bc97c [asan] Fix -Winvalid-paste error with clang-cl
We don't need to paste tokens here. String literal concatenation works
just fine here with MSVC and Clang.

llvm-svn: 307321
2017-07-06 21:51:32 +00:00
Kuba Mracek 560440975a Fix whitespace lint issue (introduced in r307307).
llvm-svn: 307309
2017-07-06 20:38:33 +00:00
Kuba Mracek e9b5857db3 [sanitizer] Use TASK_VM_INFO to get the maximum VM address on iOS/AArch64
We currently hardcode the maximum VM address on iOS/AArch64, which is not really correct and this value changes between device configurations. Let's use TASK_VM_INFO to retrieve the maximum VM address dynamically.

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

llvm-svn: 307307
2017-07-06 20:30:09 +00:00
Kuba Mracek c7f895351e More fixup for r307281: Move the #includes to sanitizer_linux.cc
llvm-svn: 307284
2017-07-06 17:45:01 +00:00
Kuba Mracek 47e994c4f1 Fixup for r307281: Also move GetKernelAreaSize into sanitizer_linux.cc
llvm-svn: 307282
2017-07-06 17:17:50 +00:00
Kuba Mracek 72665d6c15 [sanitizer] Split GetMaxVirtualAddress into separate Linux version and Mac version [NFC]
The logic in GetMaxVirtualAddress is already pretty complex, and I want to get rid of the hardcoded value for iOS/AArch64, which would need adding more Darwin-specific code, so let's split the implementation into sanitizer_linux.cc and sanitizer_mac.cc files. NFC.

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

llvm-svn: 307281
2017-07-06 17:13:40 +00:00
Alex Shlyapnikov 35adb43950 [Sanitizers] Consolidate internal errno definitions.
Move internal errno definitions to common to be shared by all sanitizers
and to be used by allocators.

llvm-svn: 307233
2017-07-06 00:50:57 +00:00
Kuba Mracek 7149ca04ad [tsan] Use pthread_sigmask instead of sigprocmask to block signals in a thread on Darwin
On Darwin, sigprocmask changes the signal mask for the entire process. This has some unwanted consequences, because e.g. internal_start_thread wants to disable signals only in the current thread (to make the new thread inherit the signal mask), which is currently broken on Darwin. This patch switches to pthread_sigmask.

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

llvm-svn: 307212
2017-07-05 22:17:44 +00:00
Jonas Hahnfeld 5b14061848 [asan] Remove check for stack size
This has been introduced in r304598 and fails for increased stack sizes.

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

llvm-svn: 307127
2017-07-05 06:54:43 +00:00
Hiroshi Inoue 7e6d29535d fix trivial typos in comments; NFC
llvm-svn: 307124
2017-07-05 05:43:31 +00:00
Hiroshi Inoue 03656aa3dc fix trivial typos in comments; NFC
llvm-svn: 307005
2017-07-03 06:44:05 +00:00
Hiroshi Inoue 85c529c988 fix trivial typo; NFC
llvm-svn: 306955
2017-07-01 08:58:47 +00:00
Vitaly Buka 080118351b [asan] This Android lit workaround should not be needed as bug is fixed
llvm-svn: 306942
2017-07-01 04:23:47 +00:00
Vitaly Buka d29d3da349 [asan] Fix test on Android i686/fugu
printf from .preinit_array may crash.

llvm-svn: 306940
2017-07-01 03:54:19 +00:00
Vitaly Buka c1c17833ff [asan] Disable test which fails on Android x86
Other Android CPUs probably pass just by luck as ulimit was not executed.

llvm-svn: 306914
2017-06-30 23:47:03 +00:00
Alex Shlyapnikov d3213c792e [LSan] Make LSan allocator allocator_may_return_null compliant
Summary:
An attempt to reland D34786 (which caused bot failres on Mac), now with
properly intercepted operators new() and delete().

LSan allocator used to always return nullptr on too big allocation requests
(the definition of "too big" depends on platform and bitness), now it
follows policy configured by allocator_may_return_null flag

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 306845
2017-06-30 17:21:34 +00:00
Kuba Mracek c41ba09433 [objc] Don't require null-check and don't emit memset when result is ignored for struct-returning method calls [compiler-rt part]
This fixes an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. When the result of a struct-returning call is ignored, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes a use-after-scope false positive with AddressSanitizer.

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

llvm-svn: 306838
2017-06-30 16:29:43 +00:00
Kostya Kortchinsky b138ab810f [sanitizer] Small tweaks and fixes to allocator related functions
Summary:
In `sanitizer_allocator_primary32.h`:
- rounding up in `MapWithCallback` is not needed as `MmapOrDie` does it. Note
  that the 64-bit counterpart doesn't round up, this keeps the behavior
  consistent;
- since `IsAligned` exists, use it in `AllocateRegion`;
- in `PopulateFreeList`:
  - checking `b->Count` to be greater than 0 when `b->Count() == max_count` is
    redundant when done more than once. Just check that `max_count` is greater
    than 0 out of the loop; the compiler (at least on ARM) didn't optimize it;
  - mark the batch creation failure as `UNLIKELY`;

In `sanitizer_allocator_primary64.h`:
- in `MapWithCallback`, mark the failure condition as `UNLIKELY`;

In `sanitizer_posix.h`:
- mark a bunch of Mmap related failure conditions as `UNLIKELY`;
- in `MmapAlignedOrDieOnFatalError`, we have `IsAligned`, so use it; rearrange
  the conditions as one test was redudant;
- in `MmapFixedImpl`, 30 chars was not large enough to hold the message and a
  full 64-bit address (or at least a 48-bit usermode address), increase to 40.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: aemerson, kubamracek, kristof.beyls, llvm-commits

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

llvm-svn: 306834
2017-06-30 16:05:40 +00:00
Hiroshi Inoue 32f2183483 fix trivial typos, NFC
llvm-svn: 306807
2017-06-30 08:28:50 +00:00
Alex Shlyapnikov 346988bf02 Merge
llvm-svn: 306748
2017-06-29 21:54:38 +00:00
Alex Shlyapnikov cb823f6a19 [Sanitizers] Rename CallocShouldReturnNullDueToOverflow to CheckForCallocOverflow
Summary:
Due to changes in semantics, CheckForCallocOverflow makes much more sense
now.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 306747
2017-06-29 21:54:37 +00:00
Alex Shlyapnikov 93c1a8c7c7 Merge
llvm-svn: 306746
2017-06-29 21:54:36 +00:00
Vedant Kumar ff3227e77d [profile] Move __llvm_profile_filename into a separate object
Users can specify the path a raw profile is written to by passing
-fprofile-instr-generate=<path>, but this functionality broke on Darwin
after __llvm_profile_filename was made weak [1], resulting in profiles
being written to "default.profraw" even when <path> is specified.

The situation is that instrumented programs provide a weak definition of
__llvm_profile_filename, which conflicts with a weak redefinition
provided by the profiling runtime.

The linker appears to pick the 'winning' definition arbitrarily: on
Darwin, it usually prefers the larger definition, which is probably why
the instrprof-override-filename.c test has been passing.

The fix is to move the runtime's definition into a separate object file
within the archive. This means that the linker won't "see" the runtime's
definition unless the user program has not provided one. I couldn't
think of a great way to test this other than to mimic the Darwin
failure: use -fprofile-instr-generate=<some-small-path>.

Testing: check-{clang,profile}, modified instrprof-override-filename.c.

[1] [Profile] deprecate __llvm_profile_override_default_filename
https://reviews.llvm.org/D22613
https://reviews.llvm.org/D22614

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

llvm-svn: 306710
2017-06-29 17:42:24 +00:00
Reid Kleckner 4f98ab369d Export the nothrow overload of operator new
This missing export was causing allocator_returns_null.cc to fail on
Windows with a dynamic ASan runtime.

llvm-svn: 306707
2017-06-29 17:39:53 +00:00
Reid Kleckner 4acf36beb6 Fix WinASan after moving wcslen interceptor to sanitizer_common
Do this by removing SANITIZER_INTERCEPT_WCSLEN and intercept wcslen
everywhere. Before this change, we were already intercepting wcslen on
Windows, but the interceptor was in asan, not sanitizer_common. After
this change, we stopped intercepting wcslen on Windows, which broke
asan_dll_thunk.c, which attempts to thunk to __asan_wcslen in the ASan
runtime.

llvm-svn: 306706
2017-06-29 17:15:53 +00:00
Kostya Kortchinsky 0ce4999002 [scudo] Change aligned alloc functions to be more compliant & perf changes
Summary:
We were not following the `man` documented behaviors for invalid arguments to
`memalign` and associated functions. Using `CHECK` for those was a bit extreme,
so we relax the behavior to return null pointers as expected when this happens.
Adapt the associated test.

I am using this change also to change a few more minor performance improvements:
- mark as `UNLIKELY` a bunch of unlikely conditions;
- the current `CHECK` in `__sanitizer::RoundUpTo` is redundant for us in *all*
  calls. So I am introducing our own version without said `CHECK`.
- change our combined allocator `GetActuallyAllocatedSize`. We already know if
  the pointer is from the Primary or Secondary, so the `PointerIsMine` check is
  redundant as well, and costly for the 32-bit Primary. So we get the size by
  directly using the available Primary functions.

Finally, change a `int` to `uptr` to avoid a warning/error when compiling on
Android.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 306698
2017-06-29 16:45:20 +00:00
Michael Zolotukhin 1576571112 Revert "[LSan] Make LSan allocator allocator_may_return_null compliant"
This reverts commit r306624.

The committed test failed on various bots (e.g. on green dragon).

llvm-svn: 306644
2017-06-29 04:39:17 +00:00
Vitaly Buka 1631129834 Revert "[asan] Control location of symbolizer on device using ANDROID_SYMBOLIZER_PATH"
Not needed, I am going to put symbolizer into tests dir.

This reverts commit r306627.

llvm-svn: 306630
2017-06-29 02:48:06 +00:00
Vitaly Buka 72c24da063 [asan] Control location of symbolizer on device using ANDROID_SYMBOLIZER_PATH
llvm-svn: 306627
2017-06-29 01:04:32 +00:00
Alex Shlyapnikov 17277f13f0 [LSan] Make LSan allocator allocator_may_return_null compliant
Summary:
LSan allocator used to always return nullptr on too big allocation requests
(the definition of "too big" depends on platform and bitness), now it
follows policy configured by allocator_may_return_null flag.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 306624
2017-06-29 01:02:40 +00:00
Vitaly Buka 2af2fd5f76 [asan] Fix try to fix test on Android
%T is dir on host system, device does not have it

llvm-svn: 306621
2017-06-29 00:19:29 +00:00
Vitaly Buka 0c981cf69b [asan] Disable tests which do no work on Android
llvm-svn: 306620
2017-06-29 00:19:28 +00:00
Vitaly Buka 3681a55137 [asan] This test now passes
llvm-svn: 306619
2017-06-29 00:19:27 +00:00
Alex Shlyapnikov 4b450685d3 [Sanitizers] Operator new() interceptors always die on allocation error
Summary:
Operator new interceptors behavior is now controlled by their nothrow
property as well as by allocator_may_return_null flag value:

- allocator_may_return_null=* + new()        - die on allocation error
- allocator_may_return_null=0 + new(nothrow) - die on allocation error
- allocator_may_return_null=1 + new(nothrow) - return null

Ideally new() should throw std::bad_alloc exception, but that is not
trivial to achieve, hence TODO.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306604
2017-06-28 21:58:57 +00:00
Xinliang David Li f50cc3ed8a [PGO] Reduce IO in profile dumping with merging
Differential Revision: http://reviews.llvm.org/D34709

llvm-svn: 306561
2017-06-28 16:46:06 +00:00
Kuba Mracek ce65982ea1 Revert r306504: Re-enable wait.cc, wait4.cc, waitid.cc tests on Darwin.
llvm-svn: 306551
2017-06-28 15:13:09 +00:00
Dean Michael Berris 66e08e7781 [XRay][compiler-rt][NFC] Move test case into correct directory.
Followup to D34669.

llvm-svn: 306506
2017-06-28 05:21:15 +00:00
Dean Michael Berris c3881436cf [XRay][compiler-rt] Only run test in x86_64 linux.
Followup to D34669.

llvm-svn: 306505
2017-06-28 05:19:59 +00:00
Kuba Mracek 70e8e9d8f6 Re-enable wait.cc, wait4.cc, waitid.cc tests on Darwin. They used to be flaky, something to do with LeakSanitizer now being enabled on Darwin. Let's re-enable them and see if they are still flaky or not.
llvm-svn: 306504
2017-06-28 05:03:28 +00:00
Dean Michael Berris 261d97332d [XRay][compiler-rt][NFC] Add example always/never instrument files.
Summary:
This change introduces two files that show exaples of the
always/never instrument files that can be provided to clang. We don't
add these as defaults yet in clang, which we can do later on (in a
separate change).

We also add a test that makes sure that these apply in the compiler-rt
project tests, and that changes in clang don't break the expectations in
compiler-rt.

Reviewers: pelikan, kpw

Subscribers: llvm-commits

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

llvm-svn: 306502
2017-06-28 04:44:36 +00:00
Evgeniy Stepanov 9e4519db1e [asan] Fix windows build.
llvm-svn: 306493
2017-06-28 00:37:29 +00:00
Evgeniy Stepanov 6f75e2dd48 [msan] Intercept wcscat, wcsncat.
Also move wcslen, wscnlen to common interceptors.

Reviewers: vitalybuka

Reviewed By: vitalybuka

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306482
2017-06-27 22:52:38 +00:00
Xinliang David Li 1f0d0b2a4c [Profile] Remove redundant call
llvm-svn: 306480
2017-06-27 22:42:24 +00:00
Francis Ricci fa0e536521 Don't build tsan/dd when COMPILER_RT_HAS_TSAN is false
llvm-svn: 306463
2017-06-27 21:10:46 +00:00
Francis Ricci 23aae3b554 Don't double-include cfi tests on linux
llvm-svn: 306455
2017-06-27 19:52:35 +00:00
Francis Ricci d379d1c2ee Loop directly over sanitizers to build in cmake
Summary: Cleaner than computing the intersection for each possible sanitizer

Reviewers: compnerd, beanz

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306453
2017-06-27 19:32:39 +00:00
Francis Ricci 57a3f4584d Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used
Summary: This allows check-all to be used when only a subset of the sanitizers are built.

Reviewers: beanz, compnerd, rnk, pcc

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306450
2017-06-27 19:18:01 +00:00
Xinliang David Li 967669f6c1 [PGO] Refactor file/buffer writer callback interfaces /NFC
Introduces a 'owner' struct to include the overridable write
method and the write context in C.

This allows easy introdution of new member API to help reduce
profile merge time in the follow up patch.

llvm-svn: 306432
2017-06-27 17:28:01 +00:00
Francis Ricci 07fa7942fd Revert "Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used"
This breaks cfi testing in cases when the cfi runtime isn't built.

This reverts commit 1c6a7b07545f0c9ce68e8b226f5397694ce48af7.

llvm-svn: 306431
2017-06-27 17:24:26 +00:00
Francis Ricci 80296ee7f3 Only test sanitizers that are built when COMPILER_RT_SANITIZERS_TO_BUILD is used
Summary: This allows check-all to be used when only a subset of the sanitizers are built.

Reviewers: beanz, compnerd

Subscribers: llvm-commits, mgorny

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

llvm-svn: 306415
2017-06-27 15:22:56 +00:00
Francis Ricci 2189fe1870 [tsan] Add missing include directory for test unittests
Summary: Required to fix standalone builds in some configurations

Reviewers: kubamracek, zaks.anna

Subscribers: mgorny, llvm-commits

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

llvm-svn: 306411
2017-06-27 14:56:59 +00:00
Alex Shlyapnikov 01676883cd [Sanitizers] 64 bit allocator respects allocator_may_return_null flag
Summary:
Make SizeClassAllocator64 return nullptr when it encounters OOM, which
allows the entire sanitizer's allocator to follow
allocator_may_return_null=1 policy
(LargeMmapAllocator: D34243, SizeClassAllocator64: D34433).

Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 306342
2017-06-26 22:54:10 +00:00
Kuba Mracek 495371d6df [asan] Flag 'asan_gen_prefixes.cc' as unsupported on iOS. The ARM and ARM64 assemblers can use different label prefixes than the expected.
llvm-svn: 306335
2017-06-26 21:37:40 +00:00
Derek Bruening 92e4443c32 [esan] Disable flaky tests for PR33590
Disables 3 esan workingset tests until their underlying failures are
determined and resolved.

llvm-svn: 306259
2017-06-26 01:02:54 +00:00
Xinliang David Li 95ce779185 [PGO] Implementate profile counter regiser promotion (test case)
Differential Revision: http://reviews.llvm.org/D34085

llvm-svn: 306232
2017-06-25 00:27:09 +00:00
Vitaly Buka b768d5b863 [asan] Regression test for PR33372
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 306195
2017-06-24 01:40:41 +00:00
Evgeniy Stepanov 90e5c30836 [asan] Add support for Android debug message.
Add ASan report to the "debug message" field in Android tombstones.

llvm-svn: 306184
2017-06-23 23:38:20 +00:00
Vedant Kumar d1c3780cf6 [ubsan] Improve diagnostics for return value checks (compiler-rt)
Differential Revision: https://reviews.llvm.org/D34298

llvm-svn: 306164
2017-06-23 21:32:48 +00:00
Alex Shlyapnikov f3cc7cc3d8 [Sanitizers] 32 bit allocator respects allocator_may_return_null flag
Summary:
Make SizeClassAllocator32 return nullptr when it encounters OOM, which
allows the entire sanitizer's allocator to follow allocator_may_return_null=1
policy, even for small allocations (LargeMmapAllocator is already fixed
by D34243).

Will add a test for OOM in primary allocator later, when
SizeClassAllocator64 can gracefully handle OOM too.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305972
2017-06-22 00:02:37 +00:00
Justin Bogner dd862f9106 [sanitizer-coverage] Stop marking this test as unsupported on Darwin
The bug that was causing this to fail was fixed in r305429.

llvm-svn: 305942
2017-06-21 19:04:59 +00:00
Kostya Kortchinsky 2b053b1c28 [sanitizer] Add a function to gather random bytes
Summary:
AFAICT compiler-rt doesn't have a function that would return 'good' random
bytes to seed a PRNG. Currently, the `SizeClassAllocator64` uses addresses
returned by `mmap` to seed its PRNG, which is not ideal, and  
`SizeClassAllocator32` doesn't benefit from the entropy offered by its 64-bit
counterpart address space, so right now it has nothing. This function aims at
solving this, allowing to implement good 32-bit chunk randomization. Scudo also
has a function that does this for Cookie purposes, which would go away in a
later CL once this lands.

This function will try the `getrandom` syscall if available, and fallback to
`/dev/urandom` if not.

Unfortunately, I do not have a way to implement and test a Mac and Windows
version, so those are unimplemented as of now. Note that `kRandomShuffleChunks`
is only used on Linux for now.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: zturner, rnk, llvm-commits, kubamracek

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

llvm-svn: 305922
2017-06-21 15:56:03 +00:00
Simon Dardis f62399945c [mips][compiler-rt] Fix build breakage.
Change some reinterpret_casts to c-style casts due to template instantiation
restrictions and build breakage due to missing paranthesises.

llvm-svn: 305899
2017-06-21 11:29:15 +00:00
Vitaly Buka ff7b8ea2a0 Revert "[compiler-rt] Don't reset non-default user handler if allow_user_segv_handler is true."
Summary:
On Android we still need to reset preinstalled handlers and allow use handlers later.

This reverts commit r304039.

Reviewers: eugenis

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 305871
2017-06-21 01:10:23 +00:00
Evgeniy Stepanov 827cd74618 [asan] Fix android compiler wrapper lost in r301617.
llvm-svn: 305870
2017-06-21 00:56:31 +00:00
Alex Shlyapnikov ccab11b0e8 [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocator
Summary:
Move cached allocator_may_return_null flag to sanitizer_allocator.cc and
provide API to consolidate and unify the behavior of all specific allocators.

Make all sanitizers using CombinedAllocator to follow
AllocatorReturnNullOrDieOnOOM() rules to behave the same way when OOM
happens.

When OOM happens, turn allocator_out_of_memory flag on regardless of
allocator_may_return_null flag value (it used to not to be set when
allocator_may_return_null == true).

release_to_os_interval_ms and rss_limit_exceeded will likely be moved to
sanitizer_allocator.cc too (later).

Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 305858
2017-06-20 21:23:02 +00:00
Alex Shlyapnikov a26d10802b [ASan] Disable allocator_oom_test.cc on s390
Summary:
ASan shadow memory on s390 is larger than other configurations, let's
disable this test for now (will revisit it later).

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305822
2017-06-20 19:16:41 +00:00
Evgeniy Stepanov a2049b5210 [asan] Fix android setup script to overwrite the symlink.
This fixes asan_device_setup failing to update an existing asan
installation.

llvm-svn: 305746
2017-06-19 21:42:44 +00:00
Francis Ricci 42175cb0d7 Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Re-commit of r305695 with use_stacks=0 to get around a racy lingering pointer.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 305732
2017-06-19 19:21:31 +00:00
Francis Ricci 214b354f2e Revert "Add lsan interceptors for libdispatch functions on darwin"
This reverts r305695

llvm-svn: 305712
2017-06-19 17:08:55 +00:00
Francis Ricci 4f1e047a6d Add lsan interceptors for libdispatch functions on darwin
Summary:
This is required for standalone LSan to work with libdispatch worker threads,
and is a slimmed down version of the functionality provided for ASan
in asan_mac.cc.

Reviewers: alekseyshl, kubamracek, glider, kcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 305695
2017-06-19 14:09:10 +00:00
Sagar Thakur 6478d14a0d [scudo] Enabling MIPS support for Scudo
Adding MIPS 32-bit and 64-bit support for Scudo.

Reviewed by cryptoad, sdardis.
Differential: D31803

llvm-svn: 305682
2017-06-19 11:28:59 +00:00
Dean Michael Berris 8d6f9c24d3 [XRay][compiler-rt][NFC] Add a test for both arg1 and arg0 handling in the same binary
This test makes sure we can handle both arg0 and arg1 handling in the
same binary, and making sure that the XRay runtime calls the correct
trampoline when handlers for both of these cases are installed.

llvm-svn: 305660
2017-06-19 03:52:25 +00:00
Dean Michael Berris 043d3f8682 [XRay][compiler-rt][NFC] Add a name for argument to __xray_set_handler_arg1(...)
Just makes the interface consistent with the other functions in
include/xray/xray_interface.h.

llvm-svn: 305658
2017-06-19 01:30:04 +00:00
Pirama Arumuga Nainar 31b825d834 Call cmake_minimum_required at the top of CMakeLists.txt
Summary:
Since r298413, the NEW behavior of the CMake policy CMP0056 is followed.
However, it is only effective after the call to cmake_minimum_required.
This causes CMAKE_EXE_LINKER_FLAGS etc. to be unused when CMake tries to
check compilers for languages specified in the 'project' declaration.

Set cmake_minimum_required(VERSION) at the top of the file and ahead of
the project declaration.

Reviewers: beanz

Subscribers: mgorny, srhines, llvm-commits

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

llvm-svn: 305593
2017-06-16 21:14:45 +00:00
Alex Shlyapnikov 5a308f24c3 [Sanitizer] Remove CombinedAllocator::Allocate's 'cleared' parameter
Summary:
CombinedAllocator::Allocate cleared parameter is not used anywhere and
seem to be obsolete.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305590
2017-06-16 21:00:03 +00:00
Reid Kleckner f1b9f3a23f [WinASan] Fix hotpatching new Win 10 build 1703 x64 strnlen prologue
The first instruction of the new ucrtbase!strnlen implementation loads a
global, presumably to dispatch between SSE and non-SSE optimized strnlen
implementations.

Fixes PR32895 and probably
https://github.com/google/sanitizers/issues/818

llvm-svn: 305581
2017-06-16 20:44:00 +00:00
Alex Shlyapnikov d340605a37 [Sanitizers] Fix allocator OOM test on Windows.
Summary:
Point of failure is different after D34243, hence the change of the
message.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305580
2017-06-16 20:36:39 +00:00
Alex Shlyapnikov 9092fe6f4b [Sanitizers] Secondary allocator respects allocator_may_return_null=1.
Summary:
Context: https://github.com/google/sanitizers/issues/740.

Making secondary allocator to respect allocator_may_return_null=1 flag
and return nullptr when "out of memory" happens.

More changes in primary allocator and operator new will follow.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305569
2017-06-16 18:48:08 +00:00
Dean Michael Berris 10bbc4f99e Add test for logging the implicit "this" argument for C++ member functions.
Summary:
This allows us to do more interesting things with the data available to
C++ methods, to log the `this` pointer.

Depends on D34050.

Reviewers: pelikan

Subscribers: llvm-commits

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

llvm-svn: 305545
2017-06-16 03:24:07 +00:00
Evgeniy Stepanov 2aed0fb07e [cfi] Enable icall tests with thinlto.
llvm-svn: 305534
2017-06-16 00:18:35 +00:00
Vedant Kumar f7e804157e [ubsan] Fix a faulty memory accessibility check
The dynamic type check needs to inspect vtables, but could crash if it
encounters a vtable pointer to inaccessible memory. In the first attempt
to fix the issue (r304437), we performed a memory accessibility check on
the wrong range of memory. This should *really* fix the problem.

Patch by Max Moroz!

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

llvm-svn: 305489
2017-06-15 18:23:16 +00:00
Vitaly Buka 4a2cc96f1f [asan] Fix typo in doc string.
llvm-svn: 305436
2017-06-15 00:31:59 +00:00
Vitaly Buka 7901b47094 [asan] Return allow_user_segv_handler=0 to fix compatibility issues.
Summary:
After r303941 it was not possible to setup ASAN_OPTIONS to have the same
behavior for pre r303941 and post r303941 builds.
Pre r303941 Asan does not accept handle_sigbus=2.
Post r303941 Asan does not accept allow_user_segv_handler.

This fix ignores allow_user_segv_handler=1, but for allow_user_segv_handler=0
it will upgrade flags like handle_sigbus=1 to handle_sigbus=2. So user can set
ASAN_OPTIONS=allow_user_segv_handler=0 and have same behavior on old and new
clang builds (except range from r303941 to this revision).

In future users which need to prevent third party handlers should switch to
handle_sigbus=2 and remove allow_user_segv_handler as soon as suport of older
builds is not needed.

Related bugs:
  https://github.com/google/oss-fuzz/issues/675
  https://bugs.chromium.org/p/chromium/issues/detail?id=731130

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305433
2017-06-15 00:19:13 +00:00
Kostya Kortchinsky 77f30c9c31 [sanitizer] Reverting D34152
Summary:
This broke thread_local_quarantine_pthread_join.cc on some architectures, due
to the overhead of the stashed regions. Reverting while figuring out the best
way to deal with it.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305404
2017-06-14 17:32:26 +00:00
Kostya Kortchinsky eca926ab3a [sanitizer] MmapAlignedOrDie changes to reduce fragmentation
Summary:
The reasoning behind this change is explained in D33454, which unfortunately
broke the Windows version (due to the platform not supporting partial unmapping
of a memory region).

This new approach changes `MmapAlignedOrDie` to allow for the specification of
a `padding_chunk`. If non-null, and the initial allocation is aligned, this
padding chunk will hold the address of the extra memory (of `alignment` bytes).
This allows `AllocateRegion` to get 2 regions if the memory is aligned
properly, and thus help reduce fragmentation (and saves on unmapping
operations). As with the initial D33454, we use a stash in the 32-bit Primary
to hold those extra regions and return them on the fast-path.

The Windows version of `MmapAlignedOrDie` will always return a 0
`padding_chunk` if one was requested.

Reviewers: alekseyshl, dvyukov, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 305391
2017-06-14 15:32:17 +00:00
Alex Shlyapnikov 8531fa3028 [ASan] Move rss_limit_is_exceeded_ flag to ASan.
Summary:
Move the OOM decision based on RSS limits out of generic allocator to
ASan allocator, where it makes more sense at the moment.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 305342
2017-06-13 23:57:24 +00:00
Evgeniy Stepanov cde90a66b5 [sanitize] Remove stack size limits from secondary threads.
If pthread_attr_getstack tell us the stack is 2G, why would we doubt that?

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

llvm-svn: 305330
2017-06-13 22:29:15 +00:00
Dmitry Vyukov dc2a38cdf2 tsan: fix reading of mutex flags
SyncVar::IsFlagSet returns true if any flag is set.
This is wrong. Check the actual requested flag.

llvm-svn: 305281
2017-06-13 09:37:51 +00:00
Dmitry Vyukov f5b3b84826 tsan: fix pedantic warnings
ISO C++ does not allow ?: with omitted middle operand

llvm-svn: 305273
2017-06-13 07:09:56 +00:00
Vedant Kumar 8c31c2a546 [ubsan] Detect invalid unsigned pointer index expression (compiler-rt)
Compiler-rt part of: https://reviews.llvm.org/D33910

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

llvm-svn: 305217
2017-06-12 18:42:51 +00:00
Vedant Kumar c7672d66ba Mark a sancov test as unsupported on x86_64h-darwin
Failing bot: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/6891

llvm-svn: 305133
2017-06-10 00:12:11 +00:00
Xinliang David Li 384f704834 Minor clean up of profile rt tests
llvm-svn: 305113
2017-06-09 21:14:19 +00:00
Maxim Ostapenko d8c47ca836 [asan] Fix ASan internal failure in AllocateFromLocalPool
This patch addresses PR 33206. There might be a situation when dynamic ASan runtime initializes later
than shared library which has malloc in static constructor (rtld doesn't provide an order of shared libs initialization).
In this case ASan hasn't yet initialized interceptors, but already intercepts malloc.
If malloc is too big to be handled by static local pool, ASan will die with error: 
Sanitizer CHECK failed: lib/asan/asan_malloc_linux.cc:40 ((allocated_for_dlsym)) < ((kDlsymAllocPoolSize)) (1036, 1024)

Patch by Denis Khalikov.

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

llvm-svn: 305058
2017-06-09 07:47:38 +00:00
Kostya Serebryany 2c2fb8896b [sanitizer-coverage] one more flavor of coverage: -fsanitize-coverage=inline-8bit-counters. Experimental so far, not documenting yet. Reapplying revisions 304630, 304631, 304632, 304673, see PR33308
llvm-svn: 305026
2017-06-08 22:58:19 +00:00
Vedant Kumar cecb1121bb Mark the tsan strerror_r test as unsupported on Darwin
llvm-svn: 304944
2017-06-07 21:10:35 +00:00
Vedant Kumar 3e95c498aa Revert "Fix tsan test for Darwin. NFCI."
This reverts commit r304941. Vitaly Buka writes:
"Actually it depends on return value.
Test is for char* version of function. It will probably fail for int
version."

llvm-svn: 304943
2017-06-07 21:10:33 +00:00
Vedant Kumar a302ae096e Fix tsan test for Darwin. NFCI.
On Darwin, strerror_r returns an int, not a char*. I don't think this
test really depends on what strerror_r returns, so I've used something
else in place of the result of the call to strerror_r.

llvm-svn: 304941
2017-06-07 20:43:15 +00:00
Evgeniy Stepanov 7922ac23f1 [sanitizer] Fix symbolizer build after r304864.
r304864 moved code into a new BinaryFormat library. Update the
symbolizer build script.

llvm-svn: 304930
2017-06-07 17:24:58 +00:00
Vitaly Buka d9bc851fb3 [tsan]: Fix GNU version of strerror_r interceptor
GNU version of strerror_r returns a result pointer that doesn't match the input
buffer. The result pointer is in fact a pointer to some internal storage.
TSAN was recording a write to this location, which was incorrect.

Fixed https://github.com/google/sanitizers/issues/696

llvm-svn: 304858
2017-06-07 01:53:38 +00:00
Alex Shlyapnikov effb794346 [ASan] A speculative attempt to fix a flaky test on ppc64be.
Summary:
As mentioned in test/msan/fork.cc, if test output is redirected to a file
(as opposed to being piped directly to FileCheck), we may lose some "done"s due to
a kernel bug: https://lkml.org/lkml/2014/2/17/324, so let's pipe the
output of the test.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 304744
2017-06-05 22:23:15 +00:00
Evgeniy Stepanov 790838110f Revert r304285, r304297.
r304285 - [sanitizer] Avoid possible deadlock in child process after fork
r304297 - [sanitizer] Trying to fix MAC buildbots after r304285

These changes create deadlock when Tcl calls pthread_create from a
pthread_atfork child handler. More info in the original review at
https://reviews.llvm.org/D33325

llvm-svn: 304735
2017-06-05 21:20:55 +00:00
Alex Shlyapnikov abe8af9fac [asan] Use asan exitcode=0 option to always succeed a test run.
Summary:
halt_on_error-torture.cc intermittently fails on ppc64be, let's try to
collect more info on failures.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304731
2017-06-05 20:36:57 +00:00
Tim Northover ada043541d CMake: don't try to use lld if we're not building it.
Monorepo version!

llvm-svn: 304716
2017-06-05 15:10:04 +00:00
Renato Golin 77a12b3972 Revert "[sanitizer-coverage] test for -fsanitize-coverage=inline-8bit-counters"
Revert "Mark sancov test as unsupported on Darwin"
Revert "[LSan] Detect dynamic loader by its base address."

This reverts commit r304633.
This reverts commit r304673.
This reverts commit r304632.

Those commit have broken LOTS of ARM/AArch64 bots for two days.

llvm-svn: 304699
2017-06-05 07:36:02 +00:00
Vedant Kumar 921e4ddbad Mark the atos-symbolizer test as unsupported on i386-darwin
atos is apparently not able to resolve symbol addresses properly on
i386-darwin reliably any more. This is causing bot flakiness:
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/6841

There have not been any SDK changes on the bot as of late.

/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/llvm/projects/compiler-rt/test/asan/TestCases/Darwin/atos-symbolizer.cc:20:12: error: expected string not found in input
 // CHECK: #1 0x{{.*}} in main {{.*}}atos-symbolizer.cc:[[@LINE-4]]
           ^
<stdin>:35:27: note: scanning from here
 #0 0x112f56 in wrap_free (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/lib/clang/5.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:i386+0x56f56)
                          ^
<stdin>:35:27: note: with expression "@LINE-4" equal to "16"
 #0 0x112f56 in wrap_free (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/lib/clang/5.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:i386+0x56f56)
                          ^
<stdin>:36:168: note: possible intended match here
 #1 0xb6f20 in main (/Users/buildslave/jenkins/sharedspace/clang-stage1-cmake-RA_workspace/clang-build/tools/clang/runtime/compiler-rt-bins/test/asan/I386DarwinConfig/TestCases/Darwin/Output/atos-symbolizer.cc.tmp:i386+0x1f20)

llvm-svn: 304674
2017-06-04 02:18:45 +00:00
Vedant Kumar d3322c1ed7 Mark sancov test as unsupported on Darwin
This test has been failing on all Darwin bots since it was introduced:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/32111

fatal error: error in backend: Global variable '__sancov_gen_' has an invalid section specifier '__DATA,__sancov_counters': mach-o section specifier requires a section whose length is between 1 and 16 characters.
Target: x86_64-apple-darwin15.6.0

llvm-svn: 304673
2017-06-04 01:56:44 +00:00
Dimitry Andric 6c00c9950c Adjust sanitizers for FreeBSD 64-bit inode update
Summary:
Very recently, FreeBSD 12 has been updated to use 64-bit inode numbers:
<https://svnweb.freebsd.org/changeset/base/318737>.  This entails many
user-visible changes, but for the sanitizers the modifications are
limited in scope:
* The `stat` and `lstat` syscalls were removed, and should be replaced
  with calls to `fstatat`.
* The `getdents` syscall was removed, and should be replaced with calls
  to `getdirentries`.
* The layout of `struct dirent` was changed to accomodate 64-bit inode
  numbers, and a new `d_off` field was added.
* The system header <sys/_types.h> now contains a macro `__INO64` to
  determine whether the system uses 64-bit inode numbers.

I tested these changes on both FreeBSD 12.0-CURRENT (after r318959,
which adds the `__INO64` macro), and FreeBSD 11.0-STABLE (which still
uses 32-bit inode numbers).

Reviewers: emaste, kcc, vitalybuka, kubamracek

Reviewed By: vitalybuka

Subscribers: llvm-commits

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

llvm-svn: 304658
2017-06-03 11:11:36 +00:00
Alex Shlyapnikov 2090504453 [LSan] Detect dynamic loader by its base address.
Summary:
Whenever possible (Linux + glibc 2.16+), detect dynamic loader module by
its base address, not by the module name matching. The current name
matching approach fails on some configurations.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304633
2017-06-03 01:43:44 +00:00
Kostya Serebryany edc20a10c1 [sanitizer-coverage] test for -fsanitize-coverage=inline-8bit-counters
llvm-svn: 304632
2017-06-03 01:36:53 +00:00
Kostya Serebryany ad272b0861 [asan] fix one more case where stack-use-after-return is not async-signal-safe (during thread startup). beef-up the test to give it a chance to catch regressions. Also relax the lint to make C++11 more usable.
llvm-svn: 304598
2017-06-02 21:32:04 +00:00
Kostya Serebryany 124c2ae4fa [sanitizer-coverage] nuke more stale code
llvm-svn: 304508
2017-06-02 01:17:04 +00:00
Kostya Serebryany 1800814b41 [sanitizer-coverage] nuke more stale code
llvm-svn: 304504
2017-06-02 00:52:35 +00:00
Kostya Serebryany c1a56baa3e [sanitizer-coverage] nuke more stale code
llvm-svn: 304503
2017-06-02 00:17:54 +00:00
Kostya Serebryany 70c64869b5 [sanitizer-coverage] nuke more stale code
llvm-svn: 304500
2017-06-01 23:56:49 +00:00
Vedant Kumar 41dfc4f1fa [ubsan] Runtime support for pointer overflow checking
Patch by John Regehr and Will Dietz!

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

llvm-svn: 304461
2017-06-01 19:40:59 +00:00
Vedant Kumar 8f5073446f Tighten up test to address bot failure. NFC.
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/32035

llvm-svn: 304440
2017-06-01 17:56:12 +00:00
Vedant Kumar 9af30e3541 Bug 33221 [UBSAN] segfault with -fsanitize=undefined
There is can be a situation when vptr is not initializing
by constructor of the object, and has a junk data which should
be properly checked, because c++ standard says:

"if default constructor is not specified
16 (7.3) no initialization is performed."

Patch by Denis Khalikov!

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

llvm-svn: 304437
2017-06-01 16:44:11 +00:00
Pierre Gousseau 183d1368f3 [asan] Add strndup/__strndup interceptors.
Recommit of r302781 with Vitaly Buka's fix for non zero terminated strings.

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

llvm-svn: 304399
2017-06-01 09:37:22 +00:00
Kostya Serebryany 9c50876120 [sanitizer-coverage] remove stale code (old coverage); compiler-rt part
llvm-svn: 304318
2017-05-31 18:26:32 +00:00
Maxim Ostapenko b1f0a346d6 [sanitizer] Trying to fix MAC buildbots after r304285
It seems that on MAC allocator already locks on fork thus adding another ForceLock
in fork interceptor will cause a deadlock.

llvm-svn: 304297
2017-05-31 11:40:57 +00:00
Maxim Ostapenko 62a0f55930 [sanitizer] Avoid possible deadlock in child process after fork
This patch addresses https://github.com/google/sanitizers/issues/774. When we
fork a multi-threaded process it's possible to deadlock if some thread acquired
StackDepot or allocator internal lock just before fork. In this case the lock
will never be released in child process causing deadlock on following memory alloc/dealloc
routine. While calling alloc/dealloc routines after multi-threaded fork is not allowed,
most of modern allocators (Glibc, tcmalloc, jemalloc) are actually fork safe. Let's do the same
for sanitizers except TSan that has complex locking rules.

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

llvm-svn: 304285
2017-05-31 07:28:09 +00:00
Alex Shlyapnikov 0145dee366 [sanitizer] Add "isapla" to symbolizer's global symbols whitelist.
Summary: D33637 introduced isalpha, whitelist need to reflect that.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304234
2017-05-30 19:52:34 +00:00
Alex Shlyapnikov f8f8f49a24 [asan] Enable back halt_on_error-torture.cc disabled on PowerPC.
Summary:
D33521 addressed a memory ordering issue in BlockingMutex, which seems
to be the cause of a flakiness of a few ASan tests on PowerPC.

Reviewers: eugenis

Subscribers: kubamracek, nemanjai, llvm-commits

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

llvm-svn: 304045
2017-05-26 23:14:06 +00:00
Vitaly Buka e8b09195fa [compiler-rt] Don't reset non-default user handler if allow_user_segv_handler is true.
Reviewers: eugenis, kcc

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 304039
2017-05-26 21:51:26 +00:00
Renato Golin 5ade1f1c86 [LSAN-ARM] Marking new test unsupported on ARMHF due to bot failures
The test was meant for Darwin anyway, so I'm not even sure it's supposed
to run on Linux. If it was, then we need time to investigate, but since
the test is new, there's no point in reverting the whole patch because
of it.

llvm-svn: 304010
2017-05-26 17:31:33 +00:00
Kostya Kortchinsky db18e4d993 [scudo] Check the return values of the pthread_* functions
Summary:
Currently we are not enforcing the success of `pthread_once`, and
`pthread_setspecific`. Errors could lead to harder to debug issues later in
the thread's life. This adds checks for a 0 return value for both.
If `pthread_setspecific` fails in the teardown path, opt for an immediate
teardown as opposed to a fatal failure.

Reviewers: alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 303998
2017-05-26 15:39:22 +00:00
Alex Shlyapnikov 23ff882e45 [asan] Enable back some ASan tests disabled on PowerPC.
Summary:
D33521 addressed a memory ordering issue in BlockingMutex, which seems
to be the cause of a flakiness of a few ASan tests on PowerPC.

Reviewers: eugenis

Subscribers: kubamracek, nemanjai, llvm-commits

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

llvm-svn: 303995
2017-05-26 14:49:42 +00:00
Vitaly Buka a05da1fca9 [compiler-rt] Replace allow_user_segv_handler=0 with kHandleSignalExclusive
Summary:
allow_user_segv_handler had confusing name did not allow to control behavior for
signals separately.

Reviewers: eugenis, alekseyshl, kcc

Subscribers: llvm-commits, dberris, kubamracek

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

llvm-svn: 303941
2017-05-25 23:42:33 +00:00
Kostya Serebryany f3509b6d9b [asan] relax sanbox_read_proc_self_maps_test to pass even if unshare() fails.
llvm-svn: 303911
2017-05-25 20:50:36 +00:00
Francis Ricci 3bfbd70840 Fix typo in tls patch
llvm-svn: 303906
2017-05-25 19:55:44 +00:00
Vitaly Buka 40d54d408b [compiler-rt] Make print_module_map description consistent with the rest.
Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303892
2017-05-25 18:07:48 +00:00
Francis Ricci 86e070f7e9 Implement tls scanning for darwin LSan
Summary:
This required for any users who call exit() after creating
thread-specific data, as tls destructors are only called when
pthread_exit() or pthread_cancel() are used. This should also
match tls behavior on linux.

Getting the base address of the tls section is straightforward,
as it's stored as a section offset in %gs. The size is a bit trickier
to work out, as there doesn't appear to be any official documentation
or source code referring to it. The size used in this patch was determined
by taking the difference between the base address and the address of the
subsequent memory region returned by vm_region_recurse_64, which was
1024 * sizeof(uptr) on all threads except the main thread, where it was
larger. Since the section must be the same size on all of the threads,
1024 * sizeof(uptr) seemed to be a reasonable size to use, barring
a more programtic way to get the size.

1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX
is 512 on darwin, so pthread keys will fit inside the region while
leaving space for other tls data. A larger size would overflow the
memory region returned by vm_region_recurse_64, and a smaller size
wouldn't leave room for all the pthread keys. In addition, the
stress test added here passes, which means that we are scanning at
least the full set of possible pthread keys, and probably
the full tls section.

Reviewers: alekseyshl, kubamracek

Subscribers: krytarowski, llvm-commits

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

llvm-svn: 303887
2017-05-25 17:41:13 +00:00
Francis Ricci 75ca300f2b Don't require ThreadState to be contained within tls on all platforms
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
2017-05-25 17:41:10 +00:00
Adam Nemet 14205b4a76 Disable two more flaky ASan wait* tests temporarily on Darwin
llvm-svn: 303885
2017-05-25 17:24:54 +00:00
Kostya Kortchinsky 5d0ecbc8d9 [sanitizer] Revert rL303879 as it breaks Windows
Summary:
Apparently Windows's `UnmapOrDie` doesn't support partial unmapping. Which
makes the new region allocation technique not Windows compliant.

Reviewers: alekseyshl, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303883
2017-05-25 16:54:44 +00:00
Kostya Kortchinsky 0dd40cf28d [sanitizer] Change the 32-bit Primary AllocateRegion to reduce fragmentation
Summary:
Currently, AllocateRegion has a tendency to fragment memory: it allocates
`2*kRegionSize`, and if the memory is aligned, will unmap `kRegionSize` bytes,
thus creating a hole, which can't itself be reused for another region. This
is exacerbated by the fact that if 2 regions get allocated one after another
without any `mmap` in between, the second will be aligned due to mappings 
generally being contiguous.

An idea, suggested by @alekseyshl, to prevent such a behavior is to have a
stash of regions: if the `2*kRegionSize` allocation is properly aligned, split
it in two, and stash the second part to be returned next time a region is
requested.

At this point, I thought about a couple of ways to implement this:
 - either an `IntrusiveList` of regions candidates, storing `next` at the
   begining of the region;
 - a small array of regions candidates existing in the Primary.

While the second option is more constrained in terms of size, it offers several
advantages:
 - security wise, a pointer in a region candidate could be overflowed into, and
   abused when popping an element;
 - we do not dirty the first page of the region by storing something in it;
 - unless several threads request regions simultaneously from different size
   classes, the stash rarely goes above 1 entry.

I am not certain about the Windows impact of this change, as `sanitizer_win.cc`
has its own version of MmapAlignedOrDie, maybe someone could chime in on this.

MmapAlignedOrDie is effectively unused after this change and could be removed
at a later point. I didn't notice any sizeable performance gain, even though we
are saving a few `mmap`/`munmap` syscalls.

Reviewers: alekseyshl, kcc, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303879
2017-05-25 16:19:57 +00:00
Alex Shlyapnikov 3ea9499e75 [sanitizer] Pair atomic acquire with release in BlockingMutex::Unlock
Summary:
Dmitry, seeking your expertise. I believe, the proper way to implement
Lock/Unlock here would be to use acquire/release semantics. Am I missing
something?

Reviewers: dvyukov

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303869
2017-05-25 15:07:07 +00:00
Dimitry Andric 8779ea7aed Add generic __bswap[ds]i2 implementations
Summary:
In FreeBSD we needed to add generic implementations for `__bswapdi2` and
`__bswapsi2`, since gcc 6.x for mips is emitting calls to these.  See:

https://reviews.freebsd.org/D10838 and https://reviews.freebsd.org/rS318601

The actual mips code generated for these generic C versions is pretty
OK, as can be seen in the (FreeBSD) review.

I checked over gcc sources, and it seems that it can emit these calls on
more architectures, so maybe it's best to simply always add them to the
compiler-rt builtins library.

Reviewers: howard.hinnant, compnerd, petarj, emaste

Reviewed By: compnerd, emaste

Subscribers: mgorny, llvm-commits, arichardson

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

llvm-svn: 303866
2017-05-25 14:52:14 +00:00
Catherine Moore b9f969d9e0 [cmake] Disable building emutls.c for baremetal targets.
Differential Revision: https://reviews.llvm.org/D33199

llvm-svn: 303865
2017-05-25 14:45:54 +00:00
Bill Seurer ec372bd8ed [powerpc] deactivate flakey test halt_on_error-torture.cc on powerpc64 be
This test case occassionally fails when run on powerpc64 be.

asan/TestCases/Posix/halt_on_error-torture.cc

The failure causes false problem reports to be sent to developers whose
code had nothing to do with the failures.  Reactivate it when the real
problem is fixed.

This could also be related to the same problems as with the tests
ThreadedOneSizeMallocStressTest, ThreadedMallocStressTest, ManyThreadsTest,
and several others that do not run reliably on powerpc.

llvm-svn: 303864
2017-05-25 14:41:58 +00:00
Bill Seurer 37c9be9393 [PowerPC] Fix test case sem_init_glibc.cc for powerpc64be
This test case fails on powerpc64be with older glibcs because of the glibc
version test.

llvm-svn: 303863
2017-05-25 14:32:22 +00:00
Vitaly Buka 4974f108ac [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303842
2017-05-25 06:29:30 +00:00
Jonathan Roelofs 3c8f953f61 Allow builds to set COMPILER_RT_OS_DIR differently from CMAKE_SYSTEM_NAME
llvm-svn: 303817
2017-05-24 22:41:49 +00:00
Hans Wennborg 0eec1f0b96 Fix negate-overflow.cpp test on Windows after r303440
lit would interpret the exit code as failuire.

llvm-svn: 303809
2017-05-24 21:52:40 +00:00
Vitaly Buka 62882c93c8 Revert "[compiler-rt] Change default of allow_user_segv_handler to true"
Breaks sanitizer-x86_64-linux-fuzzer bot.

This reverts commit r303729.

llvm-svn: 303795
2017-05-24 19:09:24 +00:00
Jonathan Roelofs dc62b80c82 Allow armv{7,7s,7k,7m,7em} builds
llvm-svn: 303765
2017-05-24 15:53:24 +00:00
Ulrich Weigand 66f2260837 [sanitizer] [SystemZ] Update CVE-2016-2143 check for Ubuntu 16.04
The Ubuntu 16.04 kernel contains a backport of the CVE check
starting with version 4.4.0-13.  Update FixedCVE_2016_2143.

llvm-svn: 303757
2017-05-24 15:06:33 +00:00
Vitaly Buka 354439a5a1 [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303729
2017-05-24 07:21:39 +00:00
Vitaly Buka 9808ff5d6a [asan] Remove allow_user_segv_handler on Windows.
Summary:
This flags is not covered by tests on Windows and looks like it's implemented
incorrectly. Switching its default breaks some tests.

Taking into account that related handle_segv flag is not supported on Windows
it's safer to remove it until we commit to support it.

Reviewers: eugenis, zturner, rnk

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 303728
2017-05-24 07:17:27 +00:00
Adam Nemet 4f4748557e Disable flaky ASan tests temporarily on darwin
llvm-svn: 303662
2017-05-23 17:50:48 +00:00
Dean Michael Berris 36778a54fe [XRay][compiler-rt] Add __xray_remove_customevent_handler(...)
This change adds __xray_remove_customevent_handler(...) to be consistent
with other APIs that add/remove handlers.

llvm-svn: 303526
2017-05-22 03:23:54 +00:00
Vitaly Buka 4eff87c36d Revert "[compiler-rt] Change default of allow_user_segv_handler to true"
Failed libFuzzer tests on Windows.

This reverts commit r303476.

llvm-svn: 303481
2017-05-20 02:09:25 +00:00
Vitaly Buka 99534e8040 [compiler-rt] Change default of allow_user_segv_handler to true
Reviewers: eugenis

Subscribers: srhines, kubamracek, llvm-commits

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

llvm-svn: 303476
2017-05-20 01:04:59 +00:00
Vitaly Buka 8018780d39 [compiler-rt] Switch handle_<signal> flags from bool to enum.
Summary: We are going to make it tri-state and remove allow_user_segv_handler.

Reviewers: eugenis, alekseys, kcc

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 303464
2017-05-19 22:37:16 +00:00
Vitaly Buka 5934882576 [compiler-rt] Add negative test for boolean flags.
Reviewers: eugenis, alekseyshl

Subscribers: kubamracek, dberris, llvm-commits

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

llvm-svn: 303462
2017-05-19 22:37:13 +00:00
Francis Ricci dd592ff467 Use write instead of read permissions to check for global sections on mac
Summary:
The LINKEDIT section is very large and is read-only. Scanning this
section caused LSan on darwin to be very slow. When only writable sections
are scanned for global pointers, performance improved by a factor of about 25x.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 303422
2017-05-19 13:34:02 +00:00
Vitaly Buka 1cfc81f1de [compiler-rt] Replace ifs with switch statement in IsHandledDeadlySignal
Reviewers: eugenis

Subscribers: kubamracek, llvm-commits, dberris

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

llvm-svn: 303392
2017-05-18 23:13:22 +00:00
Kostya Kortchinsky 432b8dd8ad [scudo] lower quarantine default sizes
Summary:
After discussing the current defaults with a couple of parties, the consensus
is that they are too high. 1Mb of quarantine has about a 4Mb impact on PSS, so
memory usage goes up quickly.
This is obviously configurable, but the default value should be more
"approachable", so both the global size and the thread local size are 1/4 of
what they used to be.

Reviewers: alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 303380
2017-05-18 20:47:35 +00:00
Simon Dardis 657899bad1 [compiler-rt][cmake] Build unit tests conditionally with _FILE_OFFSET_BITS=64 and _LARGEFILE_SOURCE
The sanitizer library unit tests for libc can get a different definition
of 'struct stat' to what the sanitizer library is built with for certain
targets.

For MIPS the size element of 'struct stat' is after a macro guarded
explicit padding element.

This patch resolves any possible inconsistency by adding the same
_FILE_OFFSET_BITS=64 and _LARGE_SOURCE with the same
conditions as the sanitizer library to the build flags for the unit tests.

This resolves a recurring build failure on the MIPS buildbots due to
'struct stat' defintion differences.

Reviewers: slthakur

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

llvm-svn: 303350
2017-05-18 13:19:35 +00:00
Daniel Jasper f97310fb7a Revert r302781 and subsequent attempts to disable part of it.
The Msan unit tests are still broken and by this point, I think we
should start over.

llvm-svn: 303339
2017-05-18 09:31:37 +00:00
Diana Picus 44514860f4 Fixup r303324 - temporary disable stndup interceptor, due to r302781 being buggy
r303324 missed one of the tests added by r302781. This commit applies
the same fix as r303324 to the missed test (strndup.cc).

llvm-svn: 303338
2017-05-18 09:12:27 +00:00
Kostya Serebryany 9aa8ef8504 temporary disable stndup interceptor, due to r302781 being buggy
llvm-svn: 303324
2017-05-18 03:00:07 +00:00
Tim Shen af3ffcc1f8 [XRay] Fix __xray_function_address on PPC reguarding local entry points.
Reviewers: echristo, dberris

Subscribers: llvm-commits

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

llvm-svn: 303302
2017-05-17 21:20:00 +00:00
Leo Li f084f6d7d1 [Ubsan]Remove unused link libraries.
Summary: Remove unused link libraries metioned in D33216.

Reviewers: llvm-commits, vsk

Reviewed By: vsk

Subscribers: vsk, kubamracek, mgorny, filcab

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

llvm-svn: 303286
2017-05-17 19:37:27 +00:00
Leo Li 3f55f7e02d Generate ubsan shared libraries.
Summary: Those libraries are required by aosp (https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/Android.mk). Currenly the shared libraries are generated by aosp Makefile system. We are looking forward to using cmake to generate them.

Reviewers: llvm-commits, vsk

Reviewed By: vsk

Subscribers: filcab, vsk, srhines, kubamracek, mgorny, krytarowski

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

llvm-svn: 303276
2017-05-17 17:17:41 +00:00
Hans Wennborg 4035ec59bf Include setjmp.h unconditionally in asan_test_utils.h
It's used in asan_test.cc also on Windows, and my build was failing
with:

C:/src/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc:549:28: error: unknown type name 'jmp_buf'
NOINLINE void LongJmpFunc1(jmp_buf buf) {
                           ^
C:/src/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc:569:10: error: unknown type name 'jmp_buf'
  static jmp_buf buf;
         ^

I couldn't find what changed to make this not work anymore, but this should fix
it.

llvm-svn: 303273
2017-05-17 16:44:08 +00:00
Francis Ricci 3b57da0c73 Revert "Implement tls scanning for darwin LSan"
This reverts r303262, due to TSan buildbot breakages.

llvm-svn: 303266
2017-05-17 15:25:41 +00:00
Francis Ricci eab89eb850 Implement tls scanning for darwin LSan
Summary:
This required for any users who call exit() after creating
thread-specific data, as tls destructors are only called when
pthread_exit() or pthread_cancel() are used. This should also
match tls behavior on linux.

Getting the base address of the tls section is straightforward,
as it's stored as a section offset in %gs. The size is a bit trickier
to work out, as there doesn't appear to be any official documentation
or source code referring to it. The size used in this patch was determined
by taking the difference between the base address and the address of the
subsequent memory region returned by vm_region_recurse_64, which was
1024 * sizeof(uptr) on all threads except the main thread, where it was
larger. Since the section must be the same size on all of the threads,
1024 * sizeof(uptr) seemed to be a reasonable size to use, barring
a more programtic way to get the size.

1024 seems like a reasonable number, given that PTHREAD_KEYS_MAX
is 512 on darwin, so pthread keys will fit inside the region while
leaving space for other tls data. A larger size would overflow the
memory region returned by vm_region_recurse_64, and a smaller size
wouldn't leave room for all the pthread keys. In addition, the
stress test added here passes, which means that we are scanning at
least the full set of possible pthread keys, and probably
the full tls section.

Reviewers: alekseyshl, kubamracek

Subscribers: krytarowski, llvm-commits

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

llvm-svn: 303262
2017-05-17 14:35:17 +00:00
Saleem Abdulrasool 4a45838d10 builtins: fix guard __AEABI__ -> __ARM_EABI__
llvm-svn: 303207
2017-05-16 20:25:07 +00:00
Saleem Abdulrasool 92a239b225 builtins: one more case of a missing header
llvm-svn: 303195
2017-05-16 18:19:44 +00:00
Saleem Abdulrasool 369f74c16b builtins: add missing includes
This inclusion is needed to fix the ARM build.  The int_lib.h include is
slightly ugly, but allows us to use the `AEABI_RTABI` macro to decorate
the CC for the functions.

llvm-svn: 303190
2017-05-16 17:06:48 +00:00
Saleem Abdulrasool 36ac5ddff7 builtins: expand out the AEABI function stubs
These actually may change calling conventions.  We cannot simply provide
function aliases as the aliased function may have a different calling
convention.  Provide a forwarding function instead to permit the
compiler to synthesize the calling convention adjustment thunk.

Remove the `ARM_EABI_FNALIAS` macro as that is not safe to use.

Resolves PR33030!

llvm-svn: 303188
2017-05-16 16:41:37 +00:00
Saleem Abdulrasool 44c45717b9 builtins: use reserved spelling (NFC)
llvm-svn: 303138
2017-05-16 04:17:12 +00:00
Vitaly Buka a0a6d59da8 [tsan] Update tsan test for r303084
Tail duplication changed number of pop instruction, but TSAN performance was not
affected.

llvm-svn: 303136
2017-05-16 02:06:15 +00:00
Kostya Serebryany 130fca1882 [asan] make asan under sandboxes more robust
llvm-svn: 303132
2017-05-15 23:37:54 +00:00
Manoj Gupta 2361a394b6 Fix executable stack directive on Linux.
Summary: Use __linux__  to check for Linux and bring back the check for __GNU__.

Reviewers: echristo, krytarowski, compnerd, rengolin

Reviewed By: krytarowski

Subscribers: phosek, llvm-commits, srhines

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

llvm-svn: 303131
2017-05-15 23:13:54 +00:00
Alex Shlyapnikov cbb1fdf350 [lsan] Report the missing linker only when the linker is actually missing.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 303129
2017-05-15 23:11:01 +00:00
Manoj Gupta cf0675bb74 [builtins] Fix a check from __GNU__ to __GNUC__ for disabling executable stack.
Summary:
Neither GCC nor Clang define __GNU__. Instead use __GNUC__ for the check.

Reviewers: echristo, rengolin, compnerd

Subscribers: srhines, krytarowski, llvm-commits

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

llvm-svn: 303112
2017-05-15 20:41:17 +00:00
Saleem Abdulrasool 12588d76db builtins: fix filtering aliased targets
Some build targets (e.g. i686) have aliased names (e.g. i386).  We would
get multiple definitions previously and have the linker arbitrarily
select a definition on those aliased targets.  Make this more
deterministic by checking those aliases.

llvm-svn: 303103
2017-05-15 19:09:13 +00:00
Reid Kleckner 886d2e6ef0 [ubsan] Don't enable debug info in all tests
Add a lit substitution (I chose %gmlt) so that only stack trace tests
get debug info.

We need a lit substition so that this expands to -gline-tables-only
-gcodeview on Windows. I think in the future we should reconsider the
need for -gcodeview from the GCC driver, but for now, this is necessary.

llvm-svn: 303083
2017-05-15 17:25:10 +00:00
Kostya Kortchinsky dc646a0889 [sanitizer] Change SizeClassAllocator32 to accept just one template
Summary:
With rL279771, SizeClassAllocator64 was changed to accept only one template
instead of 5, for the following reasons: "First, this will make the mangled
names shorter. Second, this will make adding more parameters simpler". This
patch mirrors that work for SizeClassAllocator32.

This is in preparation for introducing the randomization of chunks in the
32-bit SizeClassAllocator in a later patch.

Reviewers: kcc, alekseyshl, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 303071
2017-05-15 14:47:19 +00:00
Eugene Zelenko 12aa9554a6 [XRay] Fix build with libc++ (NFC).
llvm-svn: 302962
2017-05-12 22:26:42 +00:00
Reid Kleckner 999f74ad59 [ubsan] Enable debug info in test binaries
This fixes tests that use debug info to check ubsan stack traces.  One
was XFAILd on Windows and the other was actively failing for weeks.

llvm-svn: 302924
2017-05-12 17:06:16 +00:00
Francis Ricci fb3d1ea063 Disable two failing darwin lsan tests
These tests don't fail consistently in all cases, but they
fail most of the time on the buildbots. Mark as UNSUPPORTED for now to
avoid buildbots failing due to XPASS.

llvm-svn: 302920
2017-05-12 16:52:19 +00:00
Reid Kleckner 07c0dd7654 [asan/win] Re-enable Win64 asan tests on Win8+
Our theory is that reserving large amounts of shadow memory isn't
reliable on Win7 and earlier NT kernels. This affects the
clang-x64-ninja-win7 buildbot, which uses Windows 7.

llvm-svn: 302917
2017-05-12 16:30:56 +00:00
Francis Ricci b680e9742a Disable two failing darwin lsan tests
These are causing buildbot failures, disable for now.

llvm-svn: 302912
2017-05-12 16:01:15 +00:00
Francis Ricci fdcab2cbf2 Enable lsan test suite on Darwin x86_64 builds
Reviewers: kubamracek, alekseyshl

Subscribers: mgorny, llvm-commits

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

llvm-svn: 302904
2017-05-12 15:10:05 +00:00
Francis Ricci 61ed9345c9 Add dyld to sanitizer procmaps on darwin
Summary:
Sanitizer procmaps uses dyld apis to iterate over the list of images
in the process. This is much more performan than manually recursing
over all of the memory regions in the process, however, dyld does
not report itself in the list of images. In order to prevent reporting
leaks from dyld globals and to symbolize dyld functions in stack traces,
this patch special-cases dyld and ensures that it is added to the
list of modules.

This is accomplished by recursing through the memory map of the process
until a dyld Mach header is found. While this recursion is expensive,
it is run before the full set of images has been loaded in the process,
so only a few calls are required. The result is cached so that it never
needs to be searched for when the full process memory map exists, as this
would be incredibly slow, on the order of minutes for leak sanitizer with
only 25 or so libraries loaded.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 302899
2017-05-12 14:10:53 +00:00
Francis Ricci 5d4ad5c7d2 Account for stack redzone when computing sp on darwin
thread_get_register_pointer_values handles the redzone computation
automatically, but is marked as an unavailable API function. This
patch replicates its logic accounting for the stack redzone on
x86_64.

Should fix flakiness in the use_stack_threaded test for lsan on darwin.

llvm-svn: 302898
2017-05-12 14:10:51 +00:00
Alexander Potapenko f06fbd4794 [msan] Remove a failing test from MemorySanitizer.ICmpRelational
This is a follow-up to r302787, which broke MemorySanitizer.ICmpRelational.

MSan is now reporting a false positive on the following test case:
  TestForNotPoisoned((poisoned(-1, 0x80000000U) >= poisoned(-1, 0U)))
, which is sort of anticipated, because we're approximating the comparison
with an OR of the arguments' shadow values.

llvm-svn: 302887
2017-05-12 09:39:32 +00:00
Dean Michael Berris 1cc7504774 [XRay][compiler-rt] Only run custom event logging in x86_64-linux
We only have an implementation in x86_64 that works for the
patching/unpatching and runtime support (trampolines).

Follow-up to D30630.

llvm-svn: 302873
2017-05-12 05:13:11 +00:00
Dean Michael Berris 71086a87b1 [XRay][compiler-rt] Remove unused variable after refactoring
Follow-up to D30630.

llvm-svn: 302861
2017-05-12 01:43:20 +00:00
Dean Michael Berris 724de21662 [XRay][compiler-rt] Fix misspeling of XRaySledEntry
Follow-up to D30630.

llvm-svn: 302860
2017-05-12 01:33:55 +00:00
Dean Michael Berris 29e16deb17 [XRay][compiler-rt] Runtime changes to support custom event logging
Summary:
This change implements support for the custom event logging sleds and
intrinsics at runtime. For now it only supports handling the sleds in
x86_64, with the implementations for other architectures stubbed out to
do nothing.

NOTE: Work in progress, uploaded for exposition/exploration purposes.

Depends on D27503, D30018, and D33032.

Reviewers: echristo, javed.absar, timshen

Subscribers: mehdi_amini, nemanjai, llvm-commits

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

llvm-svn: 302857
2017-05-12 01:07:41 +00:00
Kostya Kortchinsky 01a66fc928 [scudo] Use our own combined allocator
Summary:
The reasoning behind this change is twofold:
- the current combined allocator (sanitizer_allocator_combined.h) implements
  features that are not relevant for Scudo, making some code redundant, and
  some restrictions not pertinent (alignments for example). This forced us to
  do some weird things between the frontend and our secondary to make things
  work;
- we have enough information to be able to know if a chunk will be serviced by
  the Primary or Secondary, allowing us to avoid extraneous calls to functions
  such as `PointerIsMine` or `CanAllocate`.

As a result, the new scudo-specific combined allocator is very straightforward,
and allows us to remove some now unnecessary code both in the frontend and the
secondary. Unused functions have been left in as unimplemented for now.

It turns out to also be a sizeable performance gain (3% faster in some Android
memory_replay benchmarks, doing some more on other platforms).

Reviewers: alekseyshl, kcc, dvyukov

Reviewed By: alekseyshl

Subscribers: llvm-commits

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

llvm-svn: 302830
2017-05-11 21:40:45 +00:00
Pierre Gousseau 9ce59db426 [asan] Test 'strndup_oob_test.cc' added in r302781 fails on the clang-cmake-thumbv7-a15-full-sh bot.
Marking as unsupported on armv7l-unknown-linux-gnueabihf, same as strdup_oob_test.cc

llvm-svn: 302807
2017-05-11 16:26:50 +00:00
Benjamin Kramer 71ed2e6457 Renumber test line number expectations after r302783.
Also remove a confused stable-runtimes requirement.

llvm-svn: 302801
2017-05-11 14:04:23 +00:00
Pierre Gousseau 24090e59ea [asan] Test 'strndup_oob_test.cc' added in r302781 fails on clang-s390x-linux.
Marking it as unsupported for now to hopefully make the bot green.

llvm-svn: 302789
2017-05-11 11:22:04 +00:00
Alexander Potapenko 65de57150e [msan] add a regression test for PR32842
Make sure MSan doesn't miss a bug comparing two integers with defined low bits.

llvm-svn: 302788
2017-05-11 11:12:26 +00:00
Renato Golin 29006dc724 [MSAN] test failed randomly on ARM when XFAILED for MIPS
llvm-svn: 302786
2017-05-11 11:05:52 +00:00