Commit Graph

6237 Commits

Author SHA1 Message Date
Maxim Ostapenko 6aafa89c34 [lsan] Relax check for allocator_end in ProcessGlobalRegionsCallback.
Differential Revision: https://reviews.llvm.org/D25945

llvm-svn: 285177
2016-10-26 06:56:51 +00:00
Peter Collingbourne 4e271c947c scripts: Document existing problems with the symbolizer build script.
Reviewers: eugenis, vitalybuka

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 285013
2016-10-24 20:15:39 +00:00
Bob Haarman 2bf4a14b3e [compiler-rt] moved __asan_schedule_unregister_globals out of anonymous namespace
Summary: Newer versions of clang complain that __asan_schedule_unregister_globals is unused. Moving it outside the anonymous namespace gets rid of that warning.

Reviewers: rnk, timurrrr

Subscribers: kubabrecka, dberris

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

llvm-svn: 285010
2016-10-24 19:56:18 +00:00
Kostya Serebryany 110e2e52b7 [sanitizers] support strict_string_checks for strncmp
llvm-svn: 284901
2016-10-21 23:52:26 +00:00
Mike Aizatsky 8210959afd adding new symbols to llvm-symbolizer symbol test
llvm-svn: 284773
2016-10-20 20:33:54 +00:00
Vedant Kumar 6ff82bd0ec [profile] Mark lprofCurFilename as COMPILER_RT_WEAK
This makes __llvm_profile_set_filename() work across dylib boundaries on
Darwin.

This functionality was originally meant to work on all platforms, but
was moved to a Linux-only directory with r272404. The root cause of the
test failure on Darwin was that lprofCurFilename was not marked weak.
Each dylib maintained its own copy of the variable due to the two-level
namespace.

Tested with check-profile (on Darwin). I don't expect this to regress
other platforms.

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

llvm-svn: 284440
2016-10-18 00:02:28 +00:00
Vitaly Buka 0f90f9bbda [sanitizers] -Wno-macro-redefined for libc++ build
llvm-svn: 284258
2016-10-14 18:19:02 +00:00
Dean Michael Berris 1b09aae82a [compiler-rt][XRay] Support tail call sleds
Summary:
This change depends on D23986 which adds tail call-specific sleds. For
now we treat them first as normal exits, and in the future leave room
for implementing this as a different kind of log entry.

The reason for deferring the change is so that we can keep the naive
logging implementation more accurate without additional complexity for
reading the log. The accuracy is gained in effectively interpreting call
stacks like:

  A()
    B()
      C()

Which when tail-call merged will end up not having any exit entries for
A() nor B(), but effectively in turn can be reasoned about as:

  A()
  B()
  C()

Although we lose the fact that A() had called B() then had called C()
with the naive approach, a later iteration that adds the explicit tail
call entries would be a change in the log format and thus necessitate a
version change for the header. We can do this later to have a chance at
releasing some tools (in D21987) that are able to handle the naive log
format, then support higher version numbers of the log format too.

Reviewers: echristo, kcc, rSerge, majnemer

Subscribers: mehdi_amini, llvm-commits, dberris

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

llvm-svn: 284178
2016-10-13 23:56:54 +00:00
Kostya Serebryany 8633900e03 Make lsan complain loudly when running under ptrace
Summary:
LeakSanitizer does not work with ptrace but currently it
will print warnings (only under verbosity=1) and then proceed
to print tons of false reports.
This patch makes lsan fail hard under ptrace with a verbose message.

https://github.com/google/sanitizers/issues/728

Reviewers: eugenis, vitalybuka, aizatsky

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 284171
2016-10-13 22:34:13 +00:00
Reid Kleckner 3137c81e56 Make __asan_handle_no_return a no-op during initialization
Some of our existing tests hang on the new Windows bot with this stack:

770, clang_rt.asan_dynamic-i386.dll!__asan::AsanTSDGet+0x3e
771, clang_rt.asan_dynamic-i386.dll!__asan::GetCurrentThread+0x9
772, clang_rt.asan_dynamic-i386.dll!__asan_handle_no_return+0xe
773, clang_rt.asan_dynamic-i386.dll!__asan_wrap__except_handler4_common+0x12
774, ntdll.dll!wcstombs+0xb0 (No unwind info)
775, ntdll.dll!ZwWow64CallFunction64+0x2001 (No unwind info)
776, ntdll.dll!ZwWow64CallFunction64+0x1fd3 (No unwind info)
777, ntdll.dll!KiUserExceptionDispatcher+0xf (No unwind info)
778, clang_rt.asan_dynamic-i386.dll!destroy_fls+0x13
779, ntdll.dll!RtlLockHeap+0xea (No unwind info)
780, ntdll.dll!LdrShutdownProcess+0x7f (No unwind info)
781, ntdll.dll!RtlExitUserProcess+0x81 (No unwind info)
782, kernel32.dll!ExitProcess+0x13 (No unwind info)
783, clang_rt.asan_dynamic-i386.dll!__sanitizer::internal__exit+0xc
784, clang_rt.asan_dynamic-i386.dll!__sanitizer::Die+0x3d
785, clang_rt.asan_dynamic-i386.dll!__asan::AsanInitInternal+0x50b
786, clang_rt.asan_dynamic-i386.dll!__asan::Allocator::Allocate+0x1c
787, clang_rt.asan_dynamic-i386.dll!__asan::Allocator::Calloc+0x43

We hang because AsanDie tries to defend against multi-threaded death by
infinite looping if someone is already exiting. We might want to
reconsider that, but one easy way to avoid getting here is not to let
our noreturn interceptors call back into fragile parts of ASan.

llvm-svn: 284067
2016-10-12 22:33:57 +00:00
Reid Kleckner a8c44c3d0c Follow up to r283955: add _recalloc_base dll thunk
llvm-svn: 284059
2016-10-12 21:59:56 +00:00
Reid Kleckner a335055643 Fix _recalloc redefinition link error in ASan RTL
Fixes PR30329

Patch by Hans-Bernhard Broeker!

llvm-svn: 283955
2016-10-11 23:13:13 +00:00
Qin Zhao 998371f3be [esan] Fix ESan test failure on Debian Sid bot
Summary: Increase early allocation buffer size.

Reviewers: bruening

Subscribers: kubabrecka

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

llvm-svn: 283598
2016-10-07 20:53:35 +00:00
Vedant Kumar 78b2b73ac1 [ubsan] More 0 -> nullptr conversions (NFC)
llvm-svn: 283511
2016-10-06 23:41:57 +00:00
Vedant Kumar 413fce239e [ubsan] 0 -> nullptr (NFC)
llvm-svn: 283506
2016-10-06 22:58:45 +00:00
Sagar Thakur d9a1a53b8d [ESan] [MIPS] Fix workingset-signal-posix.cpp on MIPS
Used uptr for __sanitizer_kernel_sigset_t.sig to avoid byte order issues on big endian systems

Reviewd by bruening.
Differential: D24332 

llvm-svn: 283438
2016-10-06 10:21:42 +00:00
Sagar Thakur 51458256a2 [ESan][MIPS] Adds support for MIPS64
With this patch 12 out of 13 tests are passing.

Reviewed by zhaoqin.
Differential: D23799 

llvm-svn: 283435
2016-10-06 09:58:11 +00:00
Dean Michael Berris 4ef1a69b40 [compiler-rt][XRay][NFC] clang-format XRay sources
llvm-svn: 283421
2016-10-06 07:09:40 +00:00
Anna Zaks bfe61253b8 [asan] Fixup: Switch to using dynamic shadow offset on iOS
Address lint comments.

llvm-svn: 283378
2016-10-05 20:45:34 +00:00
Anna Zaks b17a5db2ee [asan] Reapply: Switch to using dynamic shadow offset on iOS
The VM layout is not stable between iOS version releases, so switch to dynamic shadow offset.

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

llvm-svn: 283375
2016-10-05 20:33:59 +00:00
Anna Zaks 4ca31f8ad9 Revert "[asan] Switch to using dynamic shadow offset on iOS"
This reverts commit b2af965b7924ad793b313996a96633bb72daf629.

Revert as these changes broke a Chromium buildbot.

llvm-svn: 283349
2016-10-05 17:42:24 +00:00
Kostya Serebryany 3aacfafaad [asan] When protect_shadow_gap=0, set up the shadow for the shadow gap. This is needed to support NVIDIA CUDA drivers. Unfortunately, I don't know how to test it properly with CUDA on a public build bot, so adding a test that emulates the CUDA behavior.
llvm-svn: 283270
2016-10-04 23:39:58 +00:00
Anna Zaks 11ee532c3a [asan] Switch to using dynamic shadow offset on iOS
The VM layout is not stable between iOS version releases, so switch to dynamic shadow offset.

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

llvm-svn: 283240
2016-10-04 19:02:53 +00:00
Kostya Serebryany e923a1a486 [sanitizer-coverage] remove stale code, second attempt after failed r282994
llvm-svn: 283185
2016-10-04 04:18:30 +00:00
Vitaly Buka bf1bc21157 Revert "[sanitizer-coverage] remove stale code" at it breaks Windows bot.
This reverts commit r282994.

llvm-svn: 283183
2016-10-04 02:59:03 +00:00
Vitaly Buka b0590268c2 Support configurable path to LLVM src
llvm-svn: 283166
2016-10-04 00:06:23 +00:00
Qin Zhao ab5478a9c6 [esan] Fix ESan test failure on Debian Sid bot
Summary:
Handles early allocation from dlsym by allocating memory from a local
static buffer.

Reviewers: bruening

Subscribers: kubabrecka

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

llvm-svn: 283139
2016-10-03 20:03:10 +00:00
Kostya Serebryany 73957e39a4 [sanitizer-coverage] remove stale code
llvm-svn: 282994
2016-10-01 00:55:13 +00:00
Kostya Kortchinsky ada2761407 [scudo] Fix an edge case in the secondary allocator
Summary:
s/CHECK_LT/CHECK_LE/ in the secondary allocator, as under certain circumstances
Ptr + Size can be equal to MapEnd. This edge case was not found by the current
tests, so those were extended to be able to catch that.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 282913
2016-09-30 19:57:21 +00:00
Etienne Bergeron 9f987d3f89 [compiler-rt] Fix interception of crt atoll on win10 CRT.
Summary:
The check-asan-dynamic tests were broken on win10 because the interception
library was not able to hook on some functions.

credits: thanks sebastian marchand to help debugging this on win10.

Reviewers: rnk

Subscribers: chrisha, llvm-commits, dberris

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

llvm-svn: 282904
2016-09-30 19:37:11 +00:00
Etienne Bergeron c07e576968 [compiler-rt] Add support for the dynamic shadow allocation
Summary:
This patch is adding support for dynamic shadow allocation.

This is a merge and re-commit of the following patches.

```
[compiler-rt] Fix Asan build on Android
  https://reviews.llvm.org/D24768
[compiler-rt] Add support for the dynamic shadow allocation
  https://reviews.llvm.org/D23363
```

This patch needed to re-land at the same time:
```
[asan] Support dynamic shadow address instrumentation
  https://reviews.llvm.org/D23354
```

Reviewers: rnk, zaks.anna

Subscribers: tberghammer, danalbert, kubabrecka, dberris, chrisha, llvm-commits

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

llvm-svn: 282882
2016-09-30 17:47:34 +00:00
Vitaly Buka 968bcc421d Remove Google specific code.
llvm-svn: 282808
2016-09-29 23:05:35 +00:00
Vitaly Buka 0ec5a2830d Don't use internal symbolizer if we are in process of reporting Out-of-Memory.
Reviewed by eugenis offline, as reviews.llvm.org is down.

llvm-svn: 282805
2016-09-29 23:00:54 +00:00
Vitaly Buka 19fe95d7d2 Add symbols introduced with -m32 build
llvm-svn: 282695
2016-09-29 07:08:42 +00:00
Vitaly Buka 757a419dd2 Limit script to sanitizers as SCUDO does not pass tests if we add symbolizer
llvm-svn: 282694
2016-09-29 07:08:40 +00:00
Vitaly Buka 29f52fb02c Move verbose clang binaries detection
llvm-svn: 282682
2016-09-29 03:53:20 +00:00
Vitaly Buka e8c12662ac Add build script for symbolizer which can be linked into instrumented process.
Reviewers: eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 282617
2016-09-28 18:46:52 +00:00
Etienne Bergeron 42cdfbcf3e [compiler-rt] Fix interception of multiple defined symbols.
Summary:
The MSVC compiler is generating multiple instance of the exception handler
when compiling on win64 with /MD.

see: https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx

Two tests were failing when running:
```
ninja check-asan-dynamic.
```

The tests were failing because only the first occurence of the function was patched.
The function `__C_specific_handler` is defined in `ntdll` and `vcruntime140`.

After this patch, there is still two remaining tests failing.
```
********************
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 87.81s
********************
Failing Tests (2):
    AddressSanitizer-x86_64-windows-dynamic :: TestCases/Windows/dll_intercept_memchr.cc
    AddressSanitizer-x86_64-windows-dynamic :: TestCases/Windows/dll_intercept_memcpy_indirect.cc

  Expected Passes    : 342
  Passes With Retry  : 2
  Expected Failures  : 16
  Unsupported Tests  : 152
  Unexpected Failures: 2
```

Reviewers: rnk, vitalybuka

Subscribers: vitalybuka, llvm-commits, chrisha, dberris

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

llvm-svn: 282614
2016-09-28 18:04:07 +00:00
Dmitry Vyukov b3587836bc [ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber
This patch extends __sanitizer_finish_switch_fiber method to optionally return previous stack base and size.

This solves the problem of coroutines/fibers library not knowing the original stack context from which the library is used. It's incorrect to assume that such context is always the default stack of current thread (e.g. one such library may be used from a fiber/coroutine created by another library). Bulding a separate stack tracking mechanism would not only duplicate AsanThread, but also require each coroutines/fibers library to integrate with it.

Author: Andrii Grynenko (andriigrynenko)
Reviewed in: https://reviews.llvm.org/D24628

llvm-svn: 282582
2016-09-28 12:28:16 +00:00
Strahinja Petrovic 37d757039d [lsan] [aarch64] Fix calculating TLS area
This patch fixes calculating begin of TLS area on AARCH64.
Differential Revision: https://reviews.llvm.org/D24454

llvm-svn: 282571
2016-09-28 10:15:15 +00:00
Vedant Kumar ff17fcbc58 [sanitizer_common] Delete some copy/move methods in InternalScopedBuffer
Differential Revision: https://reviews.llvm.org/D24811

llvm-svn: 282548
2016-09-27 22:52:34 +00:00
Saleem Abdulrasool 81eb5f6a60 builtins: use thumb-2 if possible on comparesf2
This code can be built with thumb-2 like many of the other builtin routines.
Enable that here as well.

llvm-svn: 282530
2016-09-27 19:12:31 +00:00
Dmitry Vyukov b32c3ecdb1 tsan: relaxed check in CheckShadowMapping
Some platforms use strange addresses in shadow mapping.
E.g. aarch64/42vma:
  static const uptr kHiAppMemEnd   = 0x3ffffffffffull;
instead of 0x40000000000ull (the range is half-open).
This caused bot failures after r282405:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/12242/steps/ninja%20check%201/logs/FAIL%3A%20SanitizerCommon-tsan-aarch64-Linux%3A%3Aclock_gettime.c
Relaxed the new check in CheckShadowMapping to not expect round addresses.

llvm-svn: 282407
2016-09-26 14:23:34 +00:00
Dmitry Vyukov 730aa585c0 tsan: make shadow mapping linear within a single user region
This is a follow up to r282152.
A more extensive testing on real apps revealed a subtle bug in r282152.
The revision made shadow mapping non-linear even within a single
user region. But there are lots of code in runtime that processes
memory ranges and assumes that mapping is linear. For example,
region memory access handling simply increments shadow address
to advance to the next shadow cell group. Similarly, DontNeedShadowFor,
java memory mover, search of heap memory block header, etc
make similar assumptions.
To trigger the bug user range would need to cross 0x008000000000 boundary.
This was observed for a module data section.

Make shadow mapping linear within a single user range again.
Add a startup CHECK for linearity.

llvm-svn: 282405
2016-09-26 13:41:33 +00:00
Dmitry Vyukov a48a998d48 tsan: remove kMidShadowOff mapping parameter
kMidShadowOff is trivially computable from other parameters.
Remove it.

llvm-svn: 282404
2016-09-26 13:27:07 +00:00
Dmitry Vyukov f8f74c7dc1 tsan: simplify meta mapping
Don't xor user address with kAppMemXor in meta mapping.
The only purpose of kAppMemXor is to raise shadow for ~0 user addresses,
so that they don't map to ~0 (which would cause overlap between
user memory and shadow).
For meta mapping we explicitly add kMetaShadowBeg offset,
so we don't need to additionally raise meta shadow.

llvm-svn: 282403
2016-09-26 13:24:48 +00:00
Maxim Ostapenko 5b145205b5 [msan] Fix second parameter in MsanReallocate from previous commit.
It's wrong to pass to MsanReallocate a pointer that MSan allocator doesn't own.
Use nullptr instead of ptr to prevent possible (still unlikely) failure.

llvm-svn: 282390
2016-09-26 08:26:23 +00:00
Maxim Ostapenko b3cf42ce56 [asan, msan] Fix reallocation logic when IsInDlsymAllocPool(ptr) is true.
llvm-svn: 282389
2016-09-26 08:11:21 +00:00
Vedant Kumar 1caaa28732 Revert "[profile] Hide lprofCurFilename"
This reverts commit r282294. It breaks a Linux bot:

  http://lab.llvm.org:8011/builders/clang-cmake-aarch64-42vma/builds/12180

It looks like the test checks that __llvm_profile_set_filename() alters the raw
profile filename in both the dylib and the main program. Now that
lprofCurFilename is hidden, this can't work, and we get two profiles (one for
the call to "main" and one for "func").

Back this change out so that we don't affect external users.

llvm-svn: 282304
2016-09-23 21:58:25 +00:00
Vedant Kumar ac9fbf9085 [profile] Hide lprofCurFilename
Differential Revision: https://reviews.llvm.org/D24885

llvm-svn: 282294
2016-09-23 20:53:42 +00:00
Kuba Brecka 7bc254f89c [asan] Stop appending -lm, -pthread and other linker options on Darwin for ASan unit tests
On Darwin, -lm, -pthread and others are implied. -pthread currently produces a warning (compiler option unused).

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

llvm-svn: 282260
2016-09-23 16:43:29 +00:00
Etienne Bergeron e7863a86ad [compiler-rt][lsan] Fix compiler error due to attribute (windows)
Summary:
Window compiler is stricter for attributes location. This patch fixes a compilation error.
```
D:\src\llvm\llvm\projects\compiler-rt\lib\lsan\lsan_thread.cc(39): error C2144: syntax error: 'int' should be preceded by ';'
```

Reviewers: rnk, majnemer

Subscribers: majnemer, llvm-commits, chrisha, dberris

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

llvm-svn: 282254
2016-09-23 15:11:41 +00:00
Maxim Ostapenko f42c138470 [msan] Prevent initialization failure with newer (2.23+) glibc in use.
This patch is pretty the same as http://reviews.llvm.org/D20235 that we used
for ASan. Using the same hack for MSan fixes its initialization with newer
Glibc in use.

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

llvm-svn: 282232
2016-09-23 07:40:55 +00:00
Xinliang David Li 5f78d3894b [Profile] Remove unused variable
llvm-svn: 282198
2016-09-22 21:12:40 +00:00
Xinliang David Li e68df598f5 [Profile] suppress verbose rt message by default
llvm-svn: 282193
2016-09-22 21:00:29 +00:00
Dmitry Vyukov 5f44b04475 tsan: fix bug introduced in 282152
In ShadowToMem we call MemToShadow potentially for incorrect addresses.
So DCHECK(IsAppMem(p)) can fire in debug mode.
Fix this by swapping range and MemToShadow checks.

llvm-svn: 282157
2016-09-22 14:33:43 +00:00
Dmitry Vyukov cc1f318b5a tsan: support pie binaries on newer kernels
4.1+ Linux kernels map pie binaries at 0x55:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d1fd836dcf00d2028c700c7e44d2c23404062c90
Currently tsan does not support app memory at 0x55 (https://github.com/google/sanitizers/issues/503).
Older kernels also map pie binaries at 0x55 when ASLR is disables (most notably under gdb).

This change extends tsan mapping for linux/x86_64 to cover 0x554-0x568 app range and fixes both 4.1+ kernels and gdb.

This required to slightly shrink low and high app ranges and move heap. The mapping become even more non-linear, since now we xor lower bits. Now even a continuous app range maps to split, intermixed shadow ranges. This breaks ShadowToMemImpl as it assumes linear mapping at least within a continuous app range (however it turned out to be already broken at least on arm64/42-bit vma as uncovered by r281970). So also change ShadowToMemImpl to hopefully a more robust implementation that does not assume a linear mapping.

llvm-svn: 282152
2016-09-22 13:42:02 +00:00
Sagar Thakur 2ce2ab3a4d [ESan][MIPS] Fix tests struct-simple.cpp on MIPS
For mips assember '#' is the start of comment. We get assembler error messages if # is used in the struct names. Therefore using '$' which works for all architectures.

Differential: D24335
Reviewed by: zhaoqin

llvm-svn: 282142
2016-09-22 08:36:54 +00:00
Filipe Cabecinhas a8b5f5e9d1 [asan] Reify ErrorGeneric
Summary:
Finish work on PR30351 (last one, after D24551, D24552, and D24554 land)

Also replace the old ReportData structure/variable with the current_error_ static
member of the ScopedInErrorReport class.

This has the following side-effects:
  - Move ASAN_ON_ERROR(); call to the start of the destructor, instead
    of in StartReporting().
      - We only generate the error structure after the
        ScopedInErrorReport constructor finishes, so we can't call
        ASAN_ON_ERROR() during the constructor. I think this makes more
        sense, since we end up never running two of the ASAN_ON_ERROR()
        callback. This also works the same way as error reporting, since
        we end up having a lock around it. Otherwise we could end up
        with the ASAN_ON_ERROR() call for error 1, then the
        ASAN_ON_ERROR() call for error 2, and then lock the mutex for
        reporting error 1.
  - The __asan_get_report_* functions will be able to, in the future,
    provide information about other errors that aren't a "generic
    error". But we might want to rethink that API, since it's too
    restricted. Ideally we teach lldb about the current_error_ member of
    ScopedInErrorReport.

Reviewers: vitalybuka, kcc, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 282107
2016-09-21 20:18:18 +00:00
Filipe Cabecinhas 490f96cba6 [asan] Store full AddressDescription objects in ErrorInvalidPointerPair
Reviewers: kcc, vitalybuka, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 282102
2016-09-21 19:21:01 +00:00
Nico Weber b097c8fa2b revert 282085, 281909, they broke 32-bit dynamic ASan and the sanitizer-windows bot
llvm-svn: 282096
2016-09-21 18:22:43 +00:00
Etienne Bergeron 5e697c679b Fix typo in comment [NFC]
llvm-svn: 282092
2016-09-21 17:16:38 +00:00
Etienne Bergeron d34ee76993 [compiler-rt] Fix Asan build on Android
Summary:
The dynamic shadow code is not detected correctly on Android.
The android shadow seems to start at address zero.

The bug is introduced here:
  https://reviews.llvm.org/D23363

Started here: https://build.chromium.org/p/chromium.fyi/builders/ClangToTAndroidASan/builds/4029
Likely due to an asan runtime change, filed https://llvm.org/bugs/show_bug.cgi?id=30462


From asan_mapping.h:
```
#if SANITIZER_WORDSIZE == 32
#  if SANITIZER_ANDROID
#    define SHADOW_OFFSET (0)   <<---- HERE
#  elif defined(__mips__)
```
Shadow address on android is 0.

From asan_rtl.c:
```
  if (shadow_start == 0) {
    [...]
    shadow_start = FindAvailableMemoryRange(space_size, alignment, granularity);
  }
```
We assumed that 0 is dynamic address.

On windows, the address was determined with:
```
#  elif SANITIZER_WINDOWS64
#   define SHADOW_OFFSET __asan_shadow_memory_dynamic_address
#  else
```
and __asan_shadow_memory_dynamic_address is initially zero.

Reviewers: rnk, eugenis, vitalybuka

Subscribers: kcc, tberghammer, danalbert, kubabrecka, dberris, llvm-commits, chrisha

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

llvm-svn: 282085
2016-09-21 16:32:14 +00:00
Kostya Kortchinsky 1da3ea561a [scudo] Fix a bug in the new Secondary Allocator
Summary:
GetActuallyAllocatedSize() was not accounting for the last page of the mapping
being a guard page, and was returning the wrong number of actually allocated
bytes, which in turn would mess up with the realloc logic. Current tests didn't
find this as the size exercised was only serviced by the Primary.

Correct the issue by subtracting PageSize, and update the realloc test to
exercise paths in both the Primary and the Secondary.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 282030
2016-09-20 22:17:59 +00:00
Kostya Serebryany c7cc93ad07 [asan] Add C++17 aligned new/delete entrypoints. Patch by Jakub Jelinek, see https://reviews.llvm.org/D24771
llvm-svn: 282019
2016-09-20 21:27:10 +00:00
Filipe Cabecinhas 08c1eb9b63 [asan] Fix GlobalAddressDescription::Print()
Summary: Check bug_type for nullptr before calling internal_strcmp

Reviewers: kcc, vitalybuka, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 282012
2016-09-20 20:33:18 +00:00
Dmitry Vyukov 4c8eb4a391 tsan: revert r281970
r281970 extended the check in a useful way,
but caused (true) failures on aarch64.
Revert it for now.

llvm-svn: 281992
2016-09-20 18:05:06 +00:00
Dean Michael Berris d1617cdc49 [XRay] ARM 32-bit no-Thumb support in compiler-rt
This is a port of XRay to ARM 32-bit, without Thumb support yet.
This is one of 3 commits to different repositories of XRay ARM port. The other 2 are:

https://reviews.llvm.org/D23931 (LLVM)
https://reviews.llvm.org/D23932 (Clang test)

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

llvm-svn: 281971
2016-09-20 14:35:57 +00:00
Dmitry Vyukov e2fd4b107c tsan: check more addresses in CheckShadowMapping
There is still a handful of them, so should not slow down
tsan apps. But gives assurance if we change/complicate
shadow mappings.

llvm-svn: 281970
2016-09-20 13:30:01 +00:00
Dmitry Vyukov a386ac6367 tsan: make CHECK more robust
Enable more ignores when we start crashing.
Unwind in CHECK SIGSEGVs if happens early:

FATAL: ThreadSanitizer CHECK failed: ../projects/compiler-rt/lib/tsan/rtl/tsan_platform_posix.cc:105 "((beg)) <= ((end))" (0x8000000000, 0x4000000000)
Program received signal SIGSEGV, Segmentation fault.
__tsan::MetaMap::GetAndLock (this=0x1337c88 <__tsan::ctx_placeholder+8>, thr=thr@entry=0x7ffff7f91800, pc=pc@entry=4639488, addr=addr@entry=140737339086992, write_lock=write_lock@entry=true, 
    create=create@entry=true) at ../projects/compiler-rt/lib/tsan/rtl/tsan_sync.cc:208
208	  u32 idx0 = *meta;
(gdb) bt
#0  __tsan::MetaMap::GetAndLock (this=0x1337c88 <__tsan::ctx_placeholder+8>, thr=thr@entry=0x7ffff7f91800, pc=pc@entry=4639488, addr=addr@entry=140737339086992, write_lock=write_lock@entry=true, 
    create=create@entry=true) at ../projects/compiler-rt/lib/tsan/rtl/tsan_sync.cc:208
#1  0x00000000004a965f in __tsan::MetaMap::GetOrCreateAndLock (this=<optimized out>, thr=thr@entry=0x7ffff7f91800, pc=pc@entry=4639488, addr=addr@entry=140737339086992, write_lock=write_lock@entry=true)
    at ../projects/compiler-rt/lib/tsan/rtl/tsan_sync.cc:198
#2  0x00000000004a162a in __tsan::Release (thr=0x7ffff7f91800, pc=pc@entry=4639488, addr=addr@entry=140737339086992) at ../projects/compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cc:395
#3  0x000000000046cc40 in __interceptor_pthread_once (o=0x7ffff71a5890 <once_regsizes>, f=0x7ffff6f9d9c0 <init_dwarf_reg_size_table>) at ../projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:1334
#4  0x00007ffff6f9fe86 in __gthread_once (__func=0x7ffff6f9d9c0 <init_dwarf_reg_size_table>, __once=0x7ffff71a5890 <once_regsizes>) at ./gthr-default.h:699
#5  uw_init_context_1 (context=context@entry=0x7fffffffd6d0, outer_cfa=outer_cfa@entry=0x7fffffffd980, outer_ra=0x437d13 <__sanitizer::BufferedStackTrace::SlowUnwindStack(unsigned long, unsigned int)+67>)
    at ../../../src/libgcc/unwind-dw2.c:1572
#6  0x00007ffff6fa06a8 in _Unwind_Backtrace (trace=0x437c30 <__sanitizer::Unwind_Trace(_Unwind_Context*, void*)>, trace_argument=0x7fffffffd980) at ../../../src/libgcc/unwind.inc:283
#7  0x0000000000437d13 in __sanitizer::BufferedStackTrace::SlowUnwindStack (this=0x7ffff6103208, pc=pc@entry=4863574, max_depth=max_depth@entry=256)
    at ../projects/compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc:125
#8  0x0000000000434f4a in __sanitizer::BufferedStackTrace::Unwind (this=this@entry=0x7ffff6103208, max_depth=max_depth@entry=256, pc=pc@entry=4863574, bp=bp@entry=0, context=context@entry=0x0, 
    stack_top=stack_top@entry=0, stack_bottom=stack_bottom@entry=0, request_fast_unwind=request_fast_unwind@entry=false) at ../projects/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc:76
#9  0x00000000004a36b3 in PrintCurrentStackSlow (pc=4863574) at ../projects/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:696
#10 __tsan::TsanCheckFailed (file=<optimized out>, line=<optimized out>, cond=<optimized out>, v1=<optimized out>, v2=<optimized out>) at ../projects/compiler-rt/lib/tsan/rtl/tsan_rtl_report.cc:44
#11 0x000000000042dfd6 in __sanitizer::CheckFailed (file=file@entry=0x4b9fd0 "../projects/compiler-rt/lib/tsan/rtl/tsan_platform_posix.cc", line=line@entry=105, 
    cond=cond@entry=0x4ba049 "((beg)) <= ((end))", v1=v1@entry=549755813888, v2=v2@entry=274877906944) at ../projects/compiler-rt/lib/sanitizer_common/sanitizer_termination.cc:79
#12 0x00000000004aa36c in ProtectRange (end=274877906944, beg=549755813888) at ../projects/compiler-rt/lib/tsan/rtl/tsan_platform_posix.cc:105
#13 __tsan::CheckAndProtect () at ../projects/compiler-rt/lib/tsan/rtl/tsan_platform_posix.cc:133
#14 0x00000000004a9e95 in __tsan::InitializePlatform () at ../projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc:280
#15 0x0000000000497e73 in __tsan::Initialize (thr=0x7ffff7f91800) at ../projects/compiler-rt/lib/tsan/rtl/tsan_rtl.cc:343
#16 0x00007ffff7dea25a in _dl_init (main_map=0x7ffff7ffe1c8, argc=1, argv=0x7fffffffdb88, env=0x7fffffffdb98) at dl-init.c:111
#17 0x00007ffff7ddb30a in _dl_start_user () at rtld.c:871

llvm-svn: 281969
2016-09-20 13:28:20 +00:00
Kostya Kortchinsky 3beafffcca [scudo] Modify Scudo to use its own Secondary Allocator
Summary:
The Sanitizer Secondary Allocator was not entirely ideal was Scudo for several
reasons: decent amount of unneeded code, redundant checks already performed by
the front end, unneeded data structures, difficulty to properly protect the
secondary chunks header.

Given that the second allocator is pretty straight forward, Scudo will use its
own, trimming all the unneeded code off of the Sanitizer one. A significant
difference in terms of security is that now each secondary chunk is preceded
and followed by a guard page, thus mitigating overflows into and from the
chunk.

A test was added as well to illustrate the overflow & underflow situations
into the guard pages.

Reviewers: kcc

Subscribers: llvm-commits

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

llvm-svn: 281938
2016-09-19 21:11:55 +00:00
Etienne Bergeron 130a190bf0 [compiler-rt] Add support for the dynamic shadow allocation
Summary:
This patch is adding the needed code to compiler-rt to support
dynamic shadow.

This is to support this patch:
  https://reviews.llvm.org/D23354

It's adding support for using a shadow placed at a dynamic address determined
at runtime.

The dynamic shadow is required to work on windows 64-bits.

Reviewers: rnk, kcc, vitalybuka

Subscribers: kubabrecka, dberris, llvm-commits, chrisha

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

llvm-svn: 281909
2016-09-19 15:59:01 +00:00
Kostya Serebryany f0ca160ea2 [sanitizer] rename __sanitizer_symbolize_data to __sanitizer_symbolize_global (to avoid conflict with another definition)
llvm-svn: 281902
2016-09-19 14:18:16 +00:00
Kostya Serebryany 88b93166dc [sanitizer] add __sanitizer_symbolize_data (can only print the names of the globals for now)
llvm-svn: 281886
2016-09-19 05:10:32 +00:00
Reid Kleckner 6a5c2cd2b1 Remove undefined weak hooks from dll thunk export list to really fix windows build
llvm-svn: 281747
2016-09-16 17:05:40 +00:00
Francis Ricci 363bcc59a5 [compiler-rt] Don't force ASAN_HAS_EXCEPTIONS to be true for all builds
Summary:
This value is already defaulted to true in asan_internal.h.
Allow the value to be overriden in cases where exceptions are unavailable.

Reviewers: kcc, samsonov, compnerd

Subscribers: kubabrecka, dberris, beanz, mgorny, llvm-commits

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

llvm-svn: 281746
2016-09-16 16:59:31 +00:00
Kostya Serebryany 4dd6b50f6e [asan] fix window build
llvm-svn: 281679
2016-09-15 23:17:02 +00:00
Kostya Serebryany 3e9ce5f447 [asan] provide dummy implementations for __sanitizer_cov_trace_pc_*
llvm-svn: 281677
2016-09-15 23:02:20 +00:00
Evgeniy Stepanov 8652d6ac05 [asan] Reenable 64-bit allocator on android/aarch64.
This is a re-commit of r281371, with updated tests.

llvm-svn: 281674
2016-09-15 22:34:53 +00:00
Anna Zaks de3fb6f0b4 [sanitizer] Fixup 2: Do not introduce __sanitizer namespace globally
This got committed by mistake. Should fix some bots.

llvm-svn: 281668
2016-09-15 22:18:36 +00:00
Anna Zaks 8cea92b972 [sanitizer] Fixup: Do not introduce __sanitizer namespace globally
Use the namespace in asan_win_dll_thunk.cc to fix the Windows bot.

llvm-svn: 281659
2016-09-15 21:15:06 +00:00
Anna Zaks 8835e9076c [compiler-rt] Remove the system includes from __sanitizer namespace
llvm-svn: 281658
2016-09-15 21:02:22 +00:00
Anna Zaks 691644f3ca [compiler-rt] Do not introduce __sanitizer namespace globally
The definitions in sanitizer_common may conflict with definitions from system headers because:

The runtime includes the system headers after the project headers (as per LLVM coding guidelines).
lib/sanitizer_common/sanitizer_internal_defs.h pollutes the namespace of everything defined after it, which is all/most of the sanitizer .h and .cc files and the included system headers with: using namespace __sanitizer; // NOLINT
This patch solves the problem by introducing the namespace only within the sanitizer namespaces as proposed by Dmitry.

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

llvm-svn: 281657
2016-09-15 21:02:18 +00:00
Anna Zaks 592bc45533 [sanitizers] DLAddr Symbolizer should fail if demangle fails
This can case crashes in high verbosity mode when demangling fails.
Not including a test case since this is hard to reproduce.

llvm-svn: 281656
2016-09-15 21:02:09 +00:00
Reid Kleckner 110ecbd336 [sanitizer] Test the allocator with the ASan win64 memory constants
These got out of sync and the tests were failing for me locally.  We
assume a 47 bit address space in ASan, so we should do the same in the
tests.

llvm-svn: 281622
2016-09-15 16:00:46 +00:00
Reid Kleckner 389c7f9142 Really fix the Windows sanitizer build
Don't list __sanitizer_print_memory profile as an INTERFACE_FUNCTION. It
is not exported by ASan; it is exported by user code.

Move the weak definition from asan_win.cc to sanitizer_win.cc to fix the
ubsan tests.

llvm-svn: 281619
2016-09-15 15:39:52 +00:00
Filipe Cabecinhas 1b3742eb8f [asan] Reify ErrorInvalidPointerPair
Summary: Continue work on PR30351

Reviewers: vitalybuka, kcc, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 281593
2016-09-15 08:10:56 +00:00
Filipe Cabecinhas 719db0c0c5 [asan] Reify ErrorODRViolation
Summary: Continue work on PR30351

Reviewers: vitalybuka, kcc, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 281592
2016-09-15 08:10:52 +00:00
Filipe Cabecinhas b50a5b31ce [asan] Reify ErrorBadParamsToAnnotateContiguousContainer
Summary: Continue work on PR30351

Reviewers: vitalybuka, kcc, eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 281591
2016-09-15 08:10:48 +00:00
Ahmed Bougacha 546d2a3820 [sanitizer] Fix darwin Go tsan build by unifying r281567 and r281553.
Avoid redefining the weak stub when building gotsan.cc

llvm-svn: 281576
2016-09-15 04:28:20 +00:00
Kostya Serebryany 5fd668fcfb [sanitizer] one more attempt to fix things with __sanitizer_print_memory_profile
llvm-svn: 281574
2016-09-15 02:11:07 +00:00
Ahmed Bougacha 5a19a2732c Define the weak symbol added by r281546 on mac.
'weak' doesn't behave like it does on linux.

llvm-svn: 281567
2016-09-15 01:04:32 +00:00
Reid Kleckner ba0126896c Fix the Windows build after r281546
llvm-svn: 281558
2016-09-14 23:07:05 +00:00
Kostya Serebryany 446b5d8811 [tsan] fix tsan build by adding a dummy __sanitizer_print_memory_profile
llvm-svn: 281553
2016-09-14 22:35:56 +00:00
Kostya Serebryany 8d22e6c27b [asan] fix windows
llvm-svn: 281548
2016-09-14 22:13:20 +00:00
Kostya Serebryany 7b296aa567 [asan] add heap_profile=1 to asan to periodically print the heap profile. So far this is a very basic heap-profile functionality
llvm-svn: 281546
2016-09-14 22:00:58 +00:00
Evgeniy Stepanov 8bb104b587 [asan] Disable 64-bit allocator on android/aarch64.
Makes the device strangely unstable, and fails one sanitizer_common test.

llvm-svn: 281533
2016-09-14 20:25:51 +00:00
Etienne Bergeron 780507c183 [compiler-rt] Set asan win 64-bits to use dynamic address for memory allocator
Summary:
ASAN on Windows 64-bits should use a dynamic address instead of a fixed one.
The asan-allocator code to support dynamic address is already landed.
This patch is turning on the feature.

Reviewers: rnk

Subscribers: kubabrecka, dberris, llvm-commits, chrisha

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

llvm-svn: 281522
2016-09-14 19:23:21 +00:00
Jonas Hahnfeld 6ba29e2130 [interception] Avoid duplicate declaration of isdigit in test
Differential Revision: https://reviews.llvm.org/D24504

llvm-svn: 281486
2016-09-14 15:02:32 +00:00
Filipe Cabecinhas 36229e96bc [asan] Reify ErrorStringFunctionSizeOverflow
Summary: Continuing implementation mentioned in this thread: http://lists.llvm.org/pipermail/llvm-dev/2016-July/101933.html

Reviewers: kcc, eugenis, vitalybuka

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 281444
2016-09-14 07:37:20 +00:00