Commit Graph

8605 Commits

Author SHA1 Message Date
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
Simon Dardis 456218438a mips] XFAIL wcsncpy.cc test.
The stack unwinder fails to unwind the stack past the interceptor stack
frame, resulting in a test failure. XFAIL this for now.

llvm-svn: 302783
2017-05-11 09:56:01 +00:00
Pierre Gousseau 0550581070 [asan] Recommit of r301904: Add strndup/__strndup interceptors
Fix undeclared __interceptor_malloc in esan_interceptors.cc
Fix undeclared strnlen on OSX

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

llvm-svn: 302781
2017-05-11 08:53:24 +00:00
Francis Ricci 4cd7a15cea Revert "Add dyld to sanitizer procmaps on darwin"
This breaks several tests because we don't always have
access to __cxa_guard functions

This reverts commit 45eb470c3e9e8f6993a204e247c33d4092237efe.

llvm-svn: 302693
2017-05-10 16:33:46 +00:00
Francis Ricci 48eab42101 Revert "Disable static caching of dyld header on Go sanitizers"
This is a problem on more than just the go sanitizers, so it's
not a good enough fix for the issue.

llvm-svn: 302692
2017-05-10 16:33:43 +00:00
Tim Shen bb6fdd66fc [XRay] Fix XRay PPC return value bug.
Summary:
This bug is caused by the incorrect handling of return-value registers.

According to OpenPOWER 64-Bit ELF V2 ABI 2.2.5, up to 2 general-purpose
registers are going to be used for return values, and up to 8 floating
point registers or vector registers are going to be used for return
values.

Reviewers: dberris, echristo

Subscribers: nemanjai, llvm-commits

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

llvm-svn: 302691
2017-05-10 16:28:21 +00:00
Tim Shen 40c012654e [XRay] Fix the test func-id-utils.cc on PPC.
Summary:
The test fails on PPC, because the address of a function may vary
depending on whether the "taker" shares the same ToC (roughly, in the
same "module") as the function.

Therefore the addresses of the functions taken in func-id-utils.cc may be
different from the addresses taken in xray runtime.

Change the test to be permissive on address comparison.

Reviewers: dberris, echristo

Subscribers: llvm-commits

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

llvm-svn: 302686
2017-05-10 16:07:03 +00:00
Francis Ricci 15dc8c93bc Disable static caching of dyld header on Go sanitizers
This causes buildbot failures due to undefined __cxa_guard_acquire

llvm-svn: 302681
2017-05-10 15:40:29 +00:00
Catherine Moore 61efa174d7 [cmake] Disable building enable_execute_stack.c for baremetal targets.
Disable building enable_execute_stack.c for targets that do not have
support for mprotect().

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

llvm-svn: 302680
2017-05-10 15:34:25 +00:00
Francis Ricci 1cdcbcdb92 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: 302673
2017-05-10 14:38:04 +00:00
Adhemerval Zanella 6b989288ab [msan] Fix getmntent{_r} for empty /etc/fstab
Some configuration (for instance default docker ubuntu images) uses
a default empty and invalid /etc/fstab configuration file.  It makes
any call to getmntent return NULL and it leads to failures on
Msan-aarch64{-with-call}-Test/MemorySanitizer.getmntent{_r}.

This patch fixes it by creating a temporary file with some valid
entries (although not valid for the system) to use along with
setmntent/getmntent.

llvm-svn: 302639
2017-05-10 12:18:25 +00:00
Simon Dardis be1d6315e1 [mips] XFAIL getpwnam_r_invalid_user.cc test
XFAIL this test while we investigate the root cause.

llvm-svn: 302635
2017-05-10 10:58:11 +00:00
Ivan A. Kosarev e73af512a6 [Safestack] Fix the canary test to catch the libc's message regarding stack smashing
By default glibc writes its diagnostics directly to tty so the `2>&1 |`
redirection in the test doesn't catch the *** stack smashing detected ***
message, which in turn breaks printing the lit's progress bar. By defining
the LIBC_FATAL_STDERR_ environment variable we force glibc to direct
diagnostic messages to stderr.

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

llvm-svn: 302628
2017-05-10 08:06:42 +00:00
Simon Dardis f570c76c5c [mips] XFAIL dfsan's custom.cc test on mips64.
Test was already marked as failing for mips64el. Now that it's being
tested on mips64, it has to be XFAILed there as well.

llvm-svn: 302570
2017-05-09 19:17:16 +00:00
Simon Dardis 35392b8e37 [mips] Remove XFAIL from sanitizer_coverage_no_prune.cc
Test is XPASSing, so remove the XFAIL marker.

llvm-svn: 302567
2017-05-09 18:29:44 +00:00
Ulrich Weigand 41ffc70484 [SystemZ] Remove XFAIL on sanitizer_coverage_no_prune.cc
This test case works fine on SystemZ as well.

llvm-svn: 302563
2017-05-09 18:17:26 +00:00
Ulrich Weigand 9d190c22b5 [SystemZ] Fix failures after D32542
This commit made ubsan use the fast unwinder.  On SystemZ this requires
test cases to be compiled with -mbackchain.  That was already done for
asan, but not ubsan.  Add the flag for ubsan as well.

llvm-svn: 302562
2017-05-09 18:07:50 +00:00
Simon Dardis ad11bf54bf [compiler-rt][mips] Fix a test for mips.
GCC 4.9.2 likes the specialize one of the memcpys in msan_interceptors.cc,
leading to test failure.

llvm-svn: 302561
2017-05-09 17:58:33 +00:00
Reid Kleckner e2328ebae2 Allow compiler-rt to find lld and libc++ parallel to LLVM, as in the monorepo
llvm-svn: 302541
2017-05-09 15:54:57 +00:00
Kostya Kortchinsky b0e96eb28e [scudo] CRC32 optimizations
Summary:
This change optimizes several aspects of the checksum used for chunk headers.

First, there is no point in checking the weak symbol `computeHardwareCRC32`
everytime, it will either be there or not when we start, so check it once
during initialization and set the checksum type accordingly.

Then, the loading of `HashAlgorithm` for SSE versions (and ARM equivalent) was
not optimized out, while not necessary. So I reshuffled that part of the code,
which duplicates a tiny bit of code, but ends up in a much cleaner assembly
(and faster as we avoid an extraneous load and some calls).

The following code is the checksum at the end of `scudoMalloc` for x86_64 with
full SSE 4.2, before:
```
mov     rax, 0FFFFFFFFFFFFFFh
shl     r10, 38h
mov     edi, dword ptr cs:_ZN7__scudoL6CookieE ; __scudo::Cookie
and     r14, rax
lea     rsi, [r13-10h]
movzx   eax, cs:_ZN7__scudoL13HashAlgorithmE ; __scudo::HashAlgorithm
or      r14, r10
mov     rbx, r14
xor     bx, bx
call    _ZN7__scudo20computeHardwareCRC32Ejm ; __scudo::computeHardwareCRC32(uint,ulong)
mov     rsi, rbx
mov     edi, eax
call    _ZN7__scudo20computeHardwareCRC32Ejm ; __scudo::computeHardwareCRC32(uint,ulong)
mov     r14w, ax
mov     rax, r13
mov     [r13-10h], r14
```
After:
```
mov     rax, cs:_ZN7__scudoL6CookieE ; __scudo::Cookie
lea     rcx, [rbx-10h]
mov     rdx, 0FFFFFFFFFFFFFFh
and     r14, rdx
shl     r9, 38h
or      r14, r9
crc32   eax, rcx
mov     rdx, r14
xor     dx, dx
mov     eax, eax
crc32   eax, rdx
mov     r14w, ax
mov     rax, rbx
mov     [rbx-10h], r14
```

Reviewers: dvyukov, alekseyshl, kcc

Reviewed By: alekseyshl

Subscribers: aemerson, rengolin, llvm-commits

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

llvm-svn: 302538
2017-05-09 15:12:38 +00:00
Francis Ricci 0f3d30960e Avoid unnecessary calls to vm_region_recurse
Summary: This should significantly improve darwin lsan performance in cases where root regions are not used.

Reviewers: alekseyshl, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 302530
2017-05-09 14:10:30 +00:00
Bill Seurer 360f4783cf [powerpc] Remove XFAIL for sanitizer_coverage_no_prune.cc on powerpc64
This test case works fine on powerpc64 (both BE and LE).

llvm-svn: 302430
2017-05-08 15:17:43 +00:00
Dean Michael Berris 90a8fc8cb8 [XRay][compiler-rt] XFAIL on ppc
Follow-up on D32846.

llvm-svn: 302392
2017-05-08 00:38:13 +00:00
Martell Malone c348a8c747 [builtins] Fixup emulated TLS for mingw.
Enabled emulated TLS on WOA for mingw
Fix <windows.h> include for mingw

Reviewed By: chapuni, mstorsjo

Subscribers: compnerd, llvm-commits

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

llvm-svn: 302340
2017-05-06 15:13:17 +00:00
Kostya Serebryany ddf8111331 [sanitizer-coverage] implement -fsanitize-coverage=no-prune,... instead of a hidden -mllvm flag. compiler-rt part (test only).
llvm-svn: 302321
2017-05-05 23:28:47 +00:00
Kostya Kortchinsky ee0695766c [scudo] Add Android support
Summary:
This change adds Android support to the allocator (but doesn't yet enable it in
the cmake config), and should be the last fragment of the rewritten change
D31947.

Android has more memory constraints than other platforms, so the idea of a
unique context per thread would not have worked. The alternative chosen is to
allocate a set of contexts based on the number of cores on the machine, and
share those contexts within the threads. Contexts can be dynamically reassigned
to threads to prevent contention, based on a scheme suggested by @dvyuokv in
the initial review.

Additionally, given that Android doesn't support ELF TLS (only emutls for now),
we use the TSan TLS slot to make things faster: Scudo is mutually exclusive
with other sanitizers so this shouldn't cause any problem.

An additional change made here, is replacing `thread_local` by `THREADLOCAL`
and using the initial-exec thread model in the non-Android version to prevent
extraneous weak definition and checks on the relevant variables.

Reviewers: kcc, dvyukov, alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, mgorny, llvm-commits

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

llvm-svn: 302300
2017-05-05 21:38:22 +00:00
Peter Collingbourne 44781f1b0c CFI: Add a blacklist entry for std::_Sp_counted_ptr_inplace::_Sp_counted_ptr_inplace().
This ctor is used by std::make_shared and needs to cast to uninitialized T*
in order to call std::allocator_traits<T>::construct.

llvm-svn: 302272
2017-05-05 18:46:14 +00:00
Alexander Potapenko 27b09270c4 [ubsan]: temporarily disable print_stack_trace.cc test
Some problems with ARM stack unwinding led to inaccurate stack traces being
printed, which caused this test to fail on
http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh

llvm-svn: 302239
2017-05-05 14:51:16 +00:00
Bill Seurer e608f6a632 [powerpc] Mark coverage-sample.cc as XFAIL on powerpc64le
When run this test case causes a segementation fault on powerpc64le.
The xfail should be removed when the problem is fixed.

llvm-svn: 302237
2017-05-05 14:20:11 +00:00
Alexander Potapenko 416c14d409 [ubsan] Implement __sanitizer_print_stack_trace for standalone UBSan runtime.
Patch by Max Moroz, reviewed at https://reviews.llvm.org/D32542

llvm-svn: 302218
2017-05-05 09:02:28 +00:00
Dean Michael Berris 6016158215 [XRay][compiler-rt] Remove dependency on FileCheck from function id utilities tests
Follow-up on D32846 to simplify testing and not rely on FileCheck to
test boundary conditions, and instead do all the testing in code
instead.

llvm-svn: 302212
2017-05-05 01:55:13 +00:00
Vedant Kumar 6a877cfec4 [ubsan] Fix error summary message for ObjC BOOL invalid loads
llvm-svn: 302211
2017-05-05 01:35:42 +00:00
Dean Michael Berris d45003ca19 [XRay][compiler-rt] Add function id utilities for XRay
Summary:
This change allows us to provide users and implementers of XRay handlers
a means of converting XRay function id's to addresses. This, in
combination with the facilities provided in D32695, allows users to find
out:

  - How many function id's there are defined in the current binary.
  - Get the address of the function associated with this function id.
  - Patch only specific functions according to their requirements.

While we don't directly provide symbolization support in XRay, having
the function's address lets users determine this information easily
either during runtime, or offline with tools like 'addr2line'.

Reviewers: dblaikie, echristo, pelikan

Subscribers: kpw, llvm-commits

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

llvm-svn: 302210
2017-05-05 01:27:11 +00:00
Peter Wu dbc4f7413c [ASAN] Add interceptor for __longjmp_chk
Summary:
glibc on Linux calls __longjmp_chk instead of longjmp (or _longjmp) when
_FORTIFY_SOURCE is defined. Ensure that an ASAN-instrumented program
intercepts this function when a system library calls it, otherwise the
stack might remain poisoned and result in CHECK failures and false
positives.

Fixes https://github.com/google/sanitizers/issues/721

Reviewed By: eugenis

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

llvm-svn: 302152
2017-05-04 14:03:57 +00:00
Simon Dardis 19a4d97127 [compiler-rt][mips] Add support for quad precision builtins for mips64
Match the builtins that GCC provides for IEEE754 quad precision
on MIPS64. Also, enable building them with clang as PR20098 is resolved.

Disable tests for xf and xc modes as MIPS doesn't support that mode in
hardware or software.

Reviewers: slthakur

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

llvm-svn: 302147
2017-05-04 13:34:17 +00:00
Dean Michael Berris 768c5cc9c5 [XRay][compiler-rt][NFC] Update comments to doxygen format; group functions better.
llvm-svn: 302121
2017-05-04 06:27:51 +00:00
Dean Michael Berris 5cc4632b5b [XRay][compiler-rt] Support patching/unpatching specific functions
Summary:
This change allows us to patch/unpatch specific functions using the
function ID. This is useful in cases where implementations might want to
do coverage-style, or more fine-grained control of which functions to
patch or un-patch at runtime.

Depends on D32693.

Reviewers: dblaikie, echristo, kpw

Subscribers: llvm-commits

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

llvm-svn: 302112
2017-05-04 04:59:20 +00:00
Kostya Serebryany 8c34243a13 [asan] print the 'unexpected format specifier in printf interceptor' warning just once (came up in https://github.com/google/oss-fuzz/pull/562). Not touching a similar scanf warning -- for some reason it does not fire for me.
llvm-svn: 302064
2017-05-03 18:38:34 +00:00
Kuba Mracek a7cad4fcb7 [tsan] Detect races on modifying accesses in Swift code
This patch allows the Swift compiler to emit calls to `__tsan_external_write` before starting any modifying access, which will cause TSan to detect races on arrays, dictionaries and other classes defined in non-instrumented modules. Races on collections from the Swift standard library and user-defined structs and a frequent cause of subtle bugs and it's important that TSan detects those on top of existing LLVM IR instrumentation, which already detects races in direct memory accesses.

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

llvm-svn: 302050
2017-05-03 16:51:01 +00:00
Reid Kleckner eceba0d2e3 Revert my bad winasan coverage test fix and apply one that actually works
trace-pc doesn't work, but trace-pc-guard does. *shrug*

llvm-svn: 302045
2017-05-03 16:11:01 +00:00
Reid Kleckner d7e681ca10 Speculative fix for WinASan after r301994
llvm-svn: 302043
2017-05-03 15:59:07 +00:00
Maxim Ostapenko 726701b0ed [sanitizer] Intercept mcheck and mprobe on Linux
This patch addresses https://github.com/google/sanitizers/issues/804.
Users can use mcheck and mprobe functions to verify heap state so we should intercept them to avoid breakage of valid code.

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

llvm-svn: 302001
2017-05-03 07:09:10 +00:00
Kuba Mracek 9537912961 [asan] Mark some more testcases as unsupported on iOS.
llvm-svn: 301976
2017-05-02 21:22:29 +00:00
Kuba Mracek 24d7542715 [asan] Mark atos-symbolizer-dyld-root-path.cc testcase as unsupported on iOS.
llvm-svn: 301967
2017-05-02 20:09:33 +00:00
Kuba Mracek 1a8e0b0b0e [asan] Mark a bunch of tests as unsupported on iOS
This patch marks a few ASan tests as unsupported on iOS. These are mostly tests that use files or paths that are invalid/inaccessible on iOS or the simulator. We currently don't have a good way of propagating/copying secondary files that individual tests need. The same problem exists on Android, so I'm just marking the tests as UNSUPPORTED now.

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

llvm-svn: 301966
2017-05-02 19:37:28 +00:00