Commit Graph

7432 Commits

Author SHA1 Message Date
Dmitry Vyukov bbed03ee9b tsan: fix windows build
Currently fails as:

gotsan.cc: In function 'void* __sanitizer::__libc_memalign(__sanitizer::uptr, __sanitizer::uptr)':
gotsan.cc:6194:50: error: 'posix_memalign' was not declared in this scope
   uptr error = posix_memalign(&p, alignment, size);

Windows does not provide posix_memalign.

llvm-svn: 276107
2016-07-20 11:43:52 +00:00
Dmitry Vyukov dcad913ab6 tsan: fix leak of shadow stacks
llvm-svn: 276103
2016-07-20 10:29:08 +00:00
Xinliang David Li b061cdb0e3 Minor cleanup -- clear name structure before parsing
llvm-svn: 276089
2016-07-20 05:10:56 +00:00
Xinliang David Li eaf238d494 [Profile] implement interface to get profile path prefix
Differential Revision:  http://reviews.llvm.org/D22546

llvm-svn: 276083
2016-07-20 04:26:09 +00:00
Xinliang David Li 5d2ea9dcf8 [Profile] Test cleanup -- use new lit var for IR PGO tests /NFC
llvm-svn: 276036
2016-07-19 22:12:00 +00:00
Xinliang David Li f26e1d9fb5 [Profile] Introduce lit test vars for IR based instrumentation
llvm-svn: 276034
2016-07-19 21:55:55 +00:00
Kostya Serebryany 1abc356e3e [asan] trying to fix the android bot
llvm-svn: 276031
2016-07-19 21:35:01 +00:00
Xinliang David Li b6d43b7994 [Profile] introduce reusable internal interfaces to find dir separator \NFC
llvm-svn: 276027
2016-07-19 20:48:00 +00:00
Xinliang David Li d4c5e27a27 [Profile] move utility interfaces to the right header /NFC
llvm-svn: 276021
2016-07-19 20:31:46 +00:00
Xinliang David Li d9689aff32 [Profile] use portable macro /NFC
llvm-svn: 276019
2016-07-19 20:20:20 +00:00
Vitaly Buka 9f9c089fe2 Add detect_stack_use_after_scope runtime flag
Summary: This flag could be used to disable check in runtime.

Subscribers: kubabrecka

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

llvm-svn: 276004
2016-07-19 18:11:08 +00:00
Etienne Bergeron cb35161ba3 fix compiler warnings [NFC]
llvm-svn: 275984
2016-07-19 15:30:22 +00:00
Etienne Bergeron 83cc0622ec [compiler-rt] Fix Asan imports/exports unittest
Summary:
Avoid mismatch between imports/exports for 32-bit and 64-bits version.

The test is running grep over macros to detect which functions are
intercepted. Unfortunately, exception handlers differ in 32-bit and
64-bit.

This patch is removing the exception handlers from the test.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275982
2016-07-19 15:27:23 +00:00
Derek Bruening 0fc992442c [esan|wset] Fix flaky sampling tests
Adds a new esan public interface routine __esan_get_sample_count() and uses
it to ensure that tests of sampling receive the minimum number of samples.

llvm-svn: 275948
2016-07-19 05:06:48 +00:00
Derek Bruening 9419737fa8 [esan] Fix sideline thread flaky assert
Fixes an esan sideline thread CHECK that failed to account for the sideline
thread reaching its code before the internal_clone() return value was
assigned in the parent.

llvm-svn: 275946
2016-07-19 05:03:38 +00:00
Vedant Kumar 55ecc100b0 [interception] Remove extra whitespace to appease linters (NFC)
Attempt to fix:

  http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/7774

llvm-svn: 275901
2016-07-18 20:07:27 +00:00
Etienne Bergeron a81a44ffd4 [compiler-rt] Fix incorrect handling of indirect load.
Summary:
Indirect load are relative offset from RIP.

The current trampoline implementation is incorrectly
copying these instructions which make some unittests
crashing.

This patch is not fixing the unittests but it's fixing
the crashes. The functions are no longer hooked.

Patches will come soon to fix these unittests.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275892
2016-07-18 19:50:55 +00:00
Etienne Bergeron d61042b549 [compiler-rt] Allow trampoline allocation further and 1 gig.
Summary:
The trampoline allocation limits the memory scanning to 1 gig.
There is an unittest that is allocating a large object which make
it impossible to the trampoline allocator to find a free spot.

see shadow_mapping_failures:
```
char bigchunk[1 << 30];
```

This patch is not fixing the unittest but it's fixing it's infinite
loop behavior.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275887
2016-07-18 19:33:05 +00:00
Etienne Bergeron d215a8f37e revert https://reviews.llvm.org/D22393
It is breaking build 32-bit build bots.

llvm-svn: 275816
2016-07-18 17:15:22 +00:00
Xinliang David Li fe9ecc9d9a Code refactoring: extract path prefix handling code
.. into reusable interfaces. No functional change is expected.

llvm-svn: 275807
2016-07-18 16:16:12 +00:00
Adhemerval Zanella ab1b926bb9 [asan] Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for asan on aarch64. The current
47-bit mask is not suffice since on aarch64 kernel with 48-bit vma
(default on ubuntu 16.04) the process may use full VMA range as:

[...]
ffffa39a7000-ffffa39a8000 r--p 00000000 00:00 0 [vvar]
ffffa39a8000-ffffa39a9000 r-xp 00000000 00:00 0 [vdso]
ffffa39a9000-ffffa39aa000 r--p 0001c000 08:02 13631554 /lib/aarch64-linux-gnu/ld-2.23.so
ffffa39aa000-ffffa39ac000 rw-p 0001d000 08:02 13631554 /lib/aarch64-linux-gnu/ld-2.23.so
ffffc2227000-ffffc2248000 rw-p 00000000 00:00 0 [stack]

llvm-svn: 275792
2016-07-18 14:47:18 +00:00
Mohit K. Bhakkad d7ae23b563 [Compiler-rt][MIPS] Fix simple test failure when using gcc
Reviewers: dsanders

Subscribers: slthakur, jaydeep, llvm-commits, Sanitizers

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

llvm-svn: 275780
2016-07-18 09:23:23 +00:00
Alina Sbirlea 9b47673e3f [compiler-rt] Change all asm directives to __asm__ in cpu_model.
Summary:
Aiming to resolve failure in sanitizer bot by changning all asm directives to __asm__.
Also, consistency.

Reviewers: llvm-commits, echristo, vitalybuka

Subscribers: mehdi_amini

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

llvm-svn: 275740
2016-07-17 23:45:55 +00:00
Kostya Serebryany 4953a01461 [asan] trying to fix the windows build
llvm-svn: 275644
2016-07-15 23:13:03 +00:00
George Burgess IV 70a65c28a7 Fix a typeo.
(obligatory s/typeo/typo)

llvm-svn: 275632
2016-07-15 22:24:24 +00:00
Kostya Serebryany ad0724692e [sanitizers] add interceptor for memmem; add weak hooks for strncasecmp, strcasecmp, strstr, strcasestr, memmem
llvm-svn: 275621
2016-07-15 21:28:58 +00:00
Xinliang David Li aeff1518e0 [Profile] instroduce portability macro for dir separator(s
llvm-svn: 275597
2016-07-15 18:48:14 +00:00
Etienne Bergeron 9da82d6aca [compiler-rt] Fix 64-bits exception handlers in ASAN 64-bits runtime
Summary:
This is adding the appropriate suport for exception handling for
64-bits ASAN on windows.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 275585
2016-07-15 17:28:10 +00:00
Etienne Bergeron a566fe341f [compiler-rt] Fix incorrect handling of indirect load.
Summary:
Indirect load are relative offset from RIP.

The current trampoline implementation is incorrectly
copying these instructions which make some unittests
crashing.

This patch is not fixing the unittests but it's fixing
the crashes. The functions are no longer hooked.

Patches will come soon to fix these unittests.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275584
2016-07-15 17:26:33 +00:00
Etienne Bergeron 3d89db445d TestCase null_deref was failing in Win64:
c:\lipo\work\asan\b_llvm>c:\lipo\work\asan\b_llvm\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output\null_deref.cc.tmp
=================================================================
==5488==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000028 (pc 0x7ff701f91067 bp 0x000c8cf8fbf0 sp 0x000c8cf8fbb0 T0)
==5488==The signal is caused by a READ memory access.
==5488==Hint: address points to the zero page.
    #0 0x7ff701f91066 in NullDeref(int *) C:\lipo\work\asan\llvm\projects\compiler-rt\test\asan\TestCases\null_deref.cc:15:10
    #1 0x8a0388830a67  (<unknown module>)
The reason was symbols was not initilized. In fact, it was first inited
with a call to stack.Print(), which calls
WinSymbolizerTool::SymbolizePC, then InitializeDbgHelpIfNeeded().

Since the StackWalk was performed before the stack.Print(), stack frames
where not gathered correctly.

There should be a better place to initialize symbols. For now, this
patch makes the test happy.

Patch by Wei Wang
Differential Revision: https://reviews.llvm.org/D22410

llvm-svn: 275580
2016-07-15 17:16:37 +00:00
Maxim Ostapenko 26b0bc0bd6 [asan] Reduce flakiness of halt_on_error-torture.cc testcase.
It seems in some situations we have clashes on very first error so test only prints "nested bug in the same thread, aborting" rather than "use-after-poison", so remove corresponding " RUN: FileCheck %s < 10.txt" line.
Also, the two last " RUN: FileCheck --check-prefix=CHECK-COLLISION %s < 1.txt || FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt" look wrong, they should check 10.txt. Fix these lines too.

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

llvm-svn: 275539
2016-07-15 07:57:43 +00:00
Etienne Bergeron c52ae0e8d1 [asan] Avoid hooking memchr() on Windows64
There is not enough padding in front of memchr(), and, the first 6 bytes
contains a branch instruction. Basically the current interception will
not work on memchr().

It was disabled before, but was missing the part to disable it for
INTERCEPT_LIBRARY_FUNCTION.

Patch by Wei Wang

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

llvm-svn: 275494
2016-07-14 22:29:22 +00:00
Etienne Bergeron 31795c7576 address comments in: https://reviews.llvm.org/D22363
llvm-svn: 275492
2016-07-14 22:18:21 +00:00
Etienne Bergeron 47ea8f536d [compiler-rt] Fix missing argument in asan unittest
Summary:
Both test have the same command-line.
The second test is missing the /GS-.

Keep in mind that /GS is on by default.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275491
2016-07-14 22:16:31 +00:00
Etienne Bergeron 8fc1dca8f7 [compiler-rt] Add more assembly patterns for interception
Summary:
These patterns are encounter when using instrumented DLL.

Without this patch, asan lit test are crashing when trying to hook
on RaiseException function.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275489
2016-07-14 22:14:33 +00:00
Etienne Bergeron 7903382468 [compiler-rt] Add internal wcslen to avoid crashing on windows 64-bits
Summary:
The function wcslen is incorrectly hooked on windows 64-bits.

The interception library is not able to hook without breaking the code.
The function is too small and the interception must be done with
trampoline-hooking which turned out to be incorrect on a small
loop (first few instructions have a backedge).

Reviewers: rnk

Subscribers: wang0109, chrisha, llvm-commits, kubabrecka

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

llvm-svn: 275488
2016-07-14 22:13:41 +00:00
Etienne Bergeron 85be3afda4 [compiler-rt] Fix missing frame with stackwalking on windows 64-bits
Summary: Fix missing frame with stackwalking on windows 64-bits

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275486
2016-07-14 22:04:28 +00:00
Alina Sbirlea 36f57fbc66 Add runtime support for __cpu_model (__builtin_cpu_supports)
Summary:
    This aims to add support for __cpu_model and address Bug 25510. It uses
    the code from lib/Support/Host.cpp for cpu detection, and creates
    __cpu_model with that info.

    Tested on OSX and built on Linux as well (though libgcc is the default).
    The use of "asm" required -std=gnu99, hence the cmake change. Corrections
    on better addressing this are welcome.

    Previously reverted, up for review again to iron out outstanding issues.

Reviewers: llvm-commits, joerg, echristo, mehdi_amini

Subscribers: mehdi_amini

Differential Revision: http://reviews.llvm.org/D22181

llvm-svn: 275484
2016-07-14 22:02:35 +00:00
Vitaly Buka 0ba360bd68 Replace -mllvm -asan-use-after-scope=1 with -fsanitize-address-use-after-scope
Summary:
When test was added we had no -fsanitize-address-use-after-scope in clang
so we had to use -mllvm -asan-use-after-scope=1.

Reviewers: eugenis

Subscribers: kubabrecka

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

llvm-svn: 275475
2016-07-14 21:18:06 +00:00
Benjamin Kramer 56a46bc680 Upgrade all the .arcconfigs to https.
llvm-svn: 275409
2016-07-14 13:15:37 +00:00
Renato Golin 2931b21286 [RT-ARM] Syntax unified for aeabi_mem* functions
Use unified syntax for builtins/arm/aeabi_mem*.S.

This makes these files consistent with the others.

This fixes a problem on the linker, which can fail with the message
"relocation truncated to fit: R_ARM_THM_JUMP11 against symbol"

Patch by Kor Nielsen.

llvm-svn: 275264
2016-07-13 14:01:15 +00:00
Reid Kleckner cd03f6f4f6 [sanitizers] Allocate 12MB for stack instead of 134MB
The thread registry test was failing to allocate 25 threads with stack
size 134MB, which is pretty reasonable.

Also print the error code in our pthread wrappers in case this happens
again.

llvm-svn: 275209
2016-07-12 20:10:28 +00:00
Etienne Bergeron e318b83745 [asan] Fix interception unittest on Windows64.
mov edi,edi is _not_ NOP in 64-bit, use 66,90h instead.
This bug was causing interception unittest to crash on 
Windows64 (windows 8 and windows 10).

Credits to etienneb for finding the root cause.

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D22274

llvm-svn: 275207
2016-07-12 19:39:07 +00:00
Kuba Brecka 9880bfda07 Disable the "gcd-io-race.mm" test to investigate bot hangs due to the test being deadlocked.
llvm-svn: 275182
2016-07-12 15:41:14 +00:00
Etienne Bergeron c4d57d9c5f [compiler-rt] Disable a test failing on windows.
Summary:
The unittest is not working on windows. The "regexp.h" is not available and
gtest-port won't support regexp with operator '|'.

The test wasn't failing on 32-bits because of this check:
```
  if (SANITIZER_WORDSIZE != 64 || ASAN_AVOID_EXPENSIVE_TESTS) return;
```

```
[ RUN      ] AddressSanitizer.HugeMallocTest
C:/src/llvm/llvm/utils/unittest/googletest\src/gtest-port.cc(272): error: Failed
Syntax error at index 30 in simple regular expression "is located 1 bytes to the left|AddressSanitizer failed to allocate": '|' is unsupported.
C:/src/llvm/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc(308): error: Death test: Ident((char*)malloc(n_megs << 20))[-1] = 0
    Result: died but not with expected error.
  Expected: is located 1 bytes to the left|AddressSanitizer failed to allocate
```

See gtest-port.h:
```
  #elif GTEST_OS_WINDOWS

// <regex.h> is not available on Windows.  Use our own simple regex
// implementation instead.
# define GTEST_USES_SIMPLE_RE 1
```

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D22257

llvm-svn: 275181
2016-07-12 15:33:25 +00:00
Etienne Bergeron 9c2a22000e [compiler-rt] Enhance function padding detection for function interception
Summary:
Many CRT (64-bits) functions contains a "hint-nop". The current padding
detection is not able to recognize the 10-bytes padding and the HotPatch
hooking technique cannot be used.

Other patterns may be discover and may be added later.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

Differential Revision: http://reviews.llvm.org/D22258

llvm-svn: 275180
2016-07-12 15:33:04 +00:00
Etienne Bergeron ef4b449124 fix incorrect constant (from http://reviews.llvm.org/D22111)
llvm-svn: 275136
2016-07-12 01:30:58 +00:00
Etienne Bergeron c9c5405b52 missing modifications for http://reviews.llvm.org/D21952
llvm-svn: 275124
2016-07-11 23:09:33 +00:00
Etienne Bergeron f5525670ad [compiler-rt] Refactor the interception code on windows.
Summary:
This is a cleanup and refactoring of the interception code on windows

Enhancement:
  * Adding the support for 64-bits code
  * Adding several hooking technique:
    * Detour
    * JumpRedirect
    * HotPatch
    * Trampoline
  * Adding a trampoline memory pool (64-bits) and release the allocated memory in unittests

Cleanup:
  * Adding unittests for 64-bits hooking techniques
  * Enhancing the RoundUpInstruction by sharing common decoder

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

Differential Revision: http://reviews.llvm.org/D22111

llvm-svn: 275123
2016-07-11 23:02:18 +00:00
Etienne Bergeron 0e6a1b3bd2 remove empty lines
llvm-svn: 275112
2016-07-11 21:57:11 +00:00
Etienne Bergeron ab42f4ddba [compiler-rt] Fix VisualStudio virtual folders layout
Summary:
This patch is a refactoring of the way cmake 'targets' are grouped.
It won't affect non-UI cmake-generators.

Clang/LLVM are using a structured way to group targets which ease
navigation through Visual Studio UI. The Compiler-RT projects
differ from the way Clang/LLVM are grouping targets.

This patch doesn't contain behavior changes.

Reviewers: kubabrecka, rnk

Subscribers: wang0109, llvm-commits, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21952

llvm-svn: 275111
2016-07-11 21:51:56 +00:00
Etienne Bergeron 1128db8fe1 [asan] Add exception handler to map memory on demand on Win64.
Memory will be committed on demand when exception happens while accessing
shadow memeory region.

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D21942

llvm-svn: 275107
2016-07-11 21:40:59 +00:00
Etienne Bergeron 81c0f32cf2 [compiler-rt] Refactor the interception code on windows.
[asan] Fix unittest Asan-x86_64-inline-Test crashing on Windows64

REAL(memcpy) was used in several places in Asan, while REAL(memmove) was not used.
This CL chooses to patch memcpy() first, solving the crash for unittest.

The crash looks like this:

projects\compiler-rt\lib\asan\tests\default\Asan-x86_64-inline-Test.exe
=================================================================
==22680==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000000 (pc 0x000000000000 bp 0x0029d555f590 sp 0x0029d555f438 T0)
==22680==Hint: pc points to the zero page.

AddressSanitizer can not provide additional info.
 SUMMARY: AddressSanitizer: access-violation (<unknown module>)
==22680==ABORTING

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D22232

llvm-svn: 275098
2016-07-11 20:37:12 +00:00
Kuba Brecka ddc3cc65cb [tsan] Add support for GCD IO channels on Darwin
This patch adds interceptors for dispatch_io_*, dispatch_read and dispatch_write functions. This avoids false positives when using GCD IO. Adding several test cases.

Differential Revision: http://reviews.llvm.org/D21889

llvm-svn: 275071
2016-07-11 15:57:50 +00:00
Etienne Bergeron 07d648fcaf whitespaces + re-indent
llvm-svn: 275023
2016-07-10 21:06:06 +00:00
Saleem Abdulrasool bcb8190f99 test: Use %clangxx in objc++ test files
These test in this change are objc++, but are built using %clang, not %clangxx.
The reason this works is the driver has been adding -lc++ for sanitizer enabled
builds. By making these tests use %clangxx, they no longer depend on the driver
linking to c++.  Doing so will allow us to prevent overlinking of libc++ for
applications.

llvm-svn: 274989
2016-07-09 21:14:36 +00:00
Derek Bruening dec4bd0838 [esan] Add __esan_report for mid-run data
Summary:
Adds a new public interface routine __esan_report() which can be used to
request profiling results prior to abnormal termination (e.g., for a server
process killed by its parent where the normal exit does not allow for
normal result reporting).

Implements this for the working-set tool.  The cache frag tool is left
unimplemented as it requires missing iteration capabilities.

Adds a new test.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D22098

llvm-svn: 274964
2016-07-09 04:13:25 +00:00
Alina Sbirlea 0efdda0956 Revert "Add runtime support for __cpu_model (__builtin_cpu_supports)"
This reverts commit r274873 until additional fixes are resolved.

llvm-svn: 274944
2016-07-08 22:22:43 +00:00
Alina Sbirlea 9ebebce2df Add runtime support for __cpu_model (__builtin_cpu_supports)
Summary:
This aims to add support for __cpu_model and address Bug 25510. It uses
the code from lib/Support/Host.cpp for cpu detection, and creates
__cpu_model with that info.

Tested on OSX, it builts successfully, but the current version does
*not* resolve Bug 25510. The __cpu_model symbol is present in the
library but it only gets loaded with -all_load. This patch will not land
until this issue is clarified.

Built on Linux as well (though libgcc is the default). The use of "asm"
required -std=gnu99, hence the cmake change. Corrections on better
addressing this are welcome.

Note: See additional comments on D20988 (committed as r271921).

Reviewers: llvm-commits, joerg, echristo, mehdi_amini

Subscribers: mehdi_amini

Differential revision: http://reviews.llvm.org/D21033

llvm-svn: 274873
2016-07-08 16:28:54 +00:00
Alina Sbirlea fb11f27253 Revert r274865-r274870
llvm-svn: 274872
2016-07-08 16:28:52 +00:00
Alina Sbirlea d6ce086f32 Added comments identifing code source
llvm-svn: 274870
2016-07-08 16:18:41 +00:00
Alina Sbirlea 13a4583714 Check cpuid supported for i386.
Summary:

Reviewers:

Subscribers:

llvm-svn: 274868
2016-07-08 16:18:39 +00:00
Alina Sbirlea 7847598113 Add default initialization. Add unit test.
llvm-svn: 274867
2016-07-08 16:18:38 +00:00
Alina Sbirlea 05241bfe7a clang-format it
llvm-svn: 274866
2016-07-08 16:18:36 +00:00
Alina Sbirlea b0b29c958a Add runtime support for __cpu_model (__builtin_cpu_supports)
Summary:
This aims to add support for __cpu_model and address Bug 25510. It uses the code from lib/Support/Host.cpp for cpu detection, and creates __cpu_model with that info.

Tested on OSX, it builts successfully, but the current version does *not* resolve Bug 25510. The __cpu_model symbol is present in the library but it only gets loaded with -all_load. This patch will not land until this issue is clarified.

Built on Linux as well (though libgcc is the default). The use of "asm" required -std=gnu99, hence the cmake change. Corrections on better addressing this are welcome.

Note: See additional comments on D20988 (committed as r271921).

Reviewers: llvm-commits, joerg, echristo, mehdi_amini

Subscribers: mehdi_amini

Differential Revision: http://reviews.llvm.org/D21033

llvm-svn: 274865
2016-07-08 16:18:34 +00:00
Etienne Bergeron fb5a24b4f0 [compiler-rt] Fix minimal stack reserved for unittest on MSVC build
Summary:
Some unittest were not able to run in 64-bit because they need more than
2MB of stack and the default allocated stack with MSVC linker is 1MB.

Reviewers: rnk

Subscribers: wang0109, chrisha, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D22101

llvm-svn: 274785
2016-07-07 18:41:08 +00:00
Etienne Bergeron 31f4672f93 [compiler-rt] Enhance unittest coverage for lib interception
Summary:
This patch is adding more unittests for testing the interception
of 32-bits code.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

Differential Revision: http://reviews.llvm.org/D22077

llvm-svn: 274775
2016-07-07 17:51:50 +00:00
Etienne Bergeron 9654f2afe3 [compiler-rt] Fix sanitizer memory allocator on win64.
Summary:
This patch is fixing unittests for sanitizer memory allocator.

There was two issues:
  1) The VirtualAlloc can't reserve twice a memory range.
     The memory space used by the SizeClass allocator is reserved
     with NoAccess and pages are commited on demand (using MmapFixedOrDie).

  2) The address space is allocated using two VirtualAlloc calls. The first one
     for the memory space, the second one for the AdditionnalSpace (after).

     On windows, they need to be freed separately.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21900

llvm-svn: 274772
2016-07-07 17:44:08 +00:00
Etienne Bergeron ec4b0e4ef4 [compiler-rt] Fix AllocatorCacheDeallocNewThread unittest
Summary:
The unittest was not freeing the mapped memory.


```
Repeating all tests (iteration 1) . . .

Note: Google Test filter = Allocator.AllocatorCacheDeallocNewThread
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Allocator
[ RUN      ] Allocator.AllocatorCacheDeallocNewThread
[       OK ] Allocator.AllocatorCacheDeallocNewThread (3 ms)
[----------] 1 test from Allocator (4 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (5 ms total)
[  PASSED  ] 1 test.

Repeating all tests (iteration 2) . . .

Note: Google Test filter = Allocator.AllocatorCacheDeallocNewThread
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Allocator
[ RUN      ] Allocator.AllocatorCacheDeallocNewThread
==4504==WARNING: SanitizerTool failed to mprotect 0x010000003000 (1099511640064) bytes at 0x010000000000 (error code: 48
7)
==4504==Sanitizer CHECK failed: D:/src/llvm/llvm/projects/compiler-rt/lib\sanitizer_common/sanitizer_allocator.h:329 ((kSpaceBeg)) == ((reinterpret_cast<uptr>( MmapFixedNoAccess(kSpaceBeg, TotalSpaceSize)))) (1099511627776, 0)
```

Reviewers: rnk

Subscribers: llvm-commits, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D22094

llvm-svn: 274764
2016-07-07 15:52:28 +00:00
Kuba Brecka 4446c216f5 [tsan] Avoid false positives with GCD data callbacks
This patch adds synchronization between the creation of the GCD data object and destructor’s execution. It’s far from perfect, because ideally we’d want to synchronize the destruction of the last reference (via dispatch_release) and the destructor’s execution, but intercepting objc_release is problematic.

Differential Revision: http://reviews.llvm.org/D21990

llvm-svn: 274749
2016-07-07 12:38:37 +00:00
Qin Zhao 7f92eab5af [esan|cfrag] Handle binaries built with -esan-aux-field-info=false
Summary:
Handles binaries built with -esan-aux-field-info=false and print less
information.

Updates test struct-simple.cpp.

Reviewers: aizatsky

Subscribers: llvm-commits, bruening, eugenis, kcc, zhaoqin, kubabrecka, vitalybuka

Differential Revision: http://reviews.llvm.org/D22020

llvm-svn: 274727
2016-07-07 03:20:24 +00:00
Derek Bruening 34913f3beb [esan|wset] Ensure SIGSEGV is not blocked
Summary:
Adds interception of sigprocmask and pthread_sigmask to esan so that the
working set tool can prevent SIGSEGV from being blocked.  A blocked SIGSEGV
results in crashes due to our lazy shadow page allocation scheme.

Adds new sanitizer helper functions internal_sigemptyset and
internal_sigismember.

Adds a test to workingset-signal-posix.cpp.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D22063

llvm-svn: 274672
2016-07-06 21:04:48 +00:00
Etienne Bergeron 01e8082418 Fix cmake generation on Apple for interception unittests
llvm-svn: 274671
2016-07-06 21:02:32 +00:00
Derek Bruening 24fe829825 [esan|wset] Further reduce flakiness of sampling test
Enhances the sampling test to try and reduce flakiness further by
increasing the workload to ensure a few samples are gathered.

llvm-svn: 274669
2016-07-06 20:27:44 +00:00
Etienne Bergeron 179feead53 [compiler-rt] Disable interception tests on Apple
Summary:
The CMake generation is not working on Apple.

This patch is disabling the generation until it's fixed.

Reviewers: rnk

Subscribers: tberghammer, chrisha, danalbert, llvm-commits, srhines

Differential Revision: http://reviews.llvm.org/D22066

llvm-svn: 274667
2016-07-06 20:15:50 +00:00
Derek Bruening eaa85136a5 [sanitizer] Handle null in internal_sigaction_syscall
Summary:
Adds support for nullptr as the action parameter to
internal_sigaction_syscall().

Reviewers: aizatsky

Subscribers: kubabrecka, vitalybuka, zhaoqin, kcc, eugenis, llvm-commits

Differential Revision: http://reviews.llvm.org/D22061

llvm-svn: 274665
2016-07-06 20:13:40 +00:00
Etienne Bergeron cc464d560c [compilter-rt] Add unittests for interception library
Summary:
This patch is adding unittests for the interception library.


Reviewers: rnk

Subscribers: majnemer, llvm-commits, wang0109, chrisha, tberghammer, danalbert, srhines

Differential Revision: http://reviews.llvm.org/D21980

llvm-svn: 274657
2016-07-06 19:15:11 +00:00
Etienne Bergeron 65c00a2b3e [asan Win64] Implement atomic_compare_exchange_strong for 8 bit
Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D21950

llvm-svn: 274634
2016-07-06 16:33:57 +00:00
Kuba Brecka fd995fe654 [tsan] Fix false positives with GCD dispatch_source_*
We already have interceptors for dispatch_source API (e.g. dispatch_source_set_event_handler), but they currently only handle submission synchronization. We also need to synchronize based on the target queue (serial, concurrent), in other words, we need to use dispatch_callback_wrap. This patch implements that.

Differential Revision: http://reviews.llvm.org/D21999

llvm-svn: 274619
2016-07-06 11:02:49 +00:00
David Majnemer 69898e6bc5 Attempt to reduce flakiness in workingset-samples.cpp
The test is matching against 'KB' but it looks like the output can be
'MB'.

llvm-svn: 274587
2016-07-06 00:12:43 +00:00
Ryan Govostes b395d7271d [asan] Update tests according to r274578
llvm-svn: 274579
2016-07-05 21:53:23 +00:00
Kuba Brecka c54b108cf8 [tsan] Synchronize leaving a GCD group with notifications
In the patch that introduced support for GCD barrier blocks, I removed releasing a group when leaving it (in dispatch_group_leave). However, this is necessary to synchronize leaving a group and a notification callback (dispatch_group_notify). Adding this back, simplifying dispatch_group_notify_f and adding a test case.

Differential Revision: http://reviews.llvm.org/D21927

llvm-svn: 274549
2016-07-05 13:48:54 +00:00
Kuba Brecka 09d3e53a93 [tsan] dispatch_once interceptor will cause a crash/deadlock when the original dispatch_once is used
Because we use SCOPED_TSAN_INTERCEPTOR in the dispatch_once interceptor, the original dispatch_once can also be sometimes called (when ignores are enabled or when thr->is_inited is false). However the original dispatch_once function doesn’t expect to find “2” in the storage and it will spin forever (but we use “2” to indicate that the initialization is already done, so no waiting is necessary). This patch makes sure we never call the original dispatch_once.

Differential Revision: http://reviews.llvm.org/D21976

llvm-svn: 274548
2016-07-05 13:39:54 +00:00
Qin Zhao 91ea3fb698 [esan|cfrag] Add struct array access report
Summary:
Adds struct array access counter report.

Updates test struct-simple.cpp.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, bruening, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D21595

llvm-svn: 274421
2016-07-02 03:25:55 +00:00
Etienne Bergeron 5393ddde91 [compiler-rt] Fix cmake to propagate debug info to runtime unittests
Summary:
The debug information is not present due to a mis named variabl in 
the cmake files.

Reviewers: rnk

Subscribers: kubabrecka, wang0109, llvm-commits, chrisha

Differential Revision: http://reviews.llvm.org/D21938

llvm-svn: 274386
2016-07-01 21:12:07 +00:00
Etienne Bergeron 3652622cef tab to whitespaces
llvm-svn: 274382
2016-07-01 20:34:25 +00:00
Kuba Brecka 4357f021e3 [tsan] Relax the "ignored-interceptors.mm" testcase. The test has been flaky because it's detecting a false positive race (coming from a system library) and sometimes that race is detected after we're printing "Done".
llvm-svn: 274346
2016-07-01 12:55:36 +00:00
Etienne Bergeron 5220d4e760 [compiler-rt] Re-active unittest previously broken on windows.
Summary: These tests are working fine.

Reviewers: rnk

Subscribers: kubabrecka, wang0109, llvm-commits, chrisha

Differential Revision: http://reviews.llvm.org/D21905

llvm-svn: 274265
2016-06-30 20:06:29 +00:00
Etienne Bergeron fb4ba14b70 [compiler-rt] Fix TLS resource leaking in unittest
Summary:
The thread specific key wasn't not released.
Running the unittest in loop will fail after 1024 iteraions.

```
 ./projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-i386-Test --gtest_filter=SanitizerCommon.PthreadDestructorIterations --gtest_repeat=2000 --gtest_break_on_failure
```

```
Repeating all tests (iteration 1023) . . .

Note: Google Test filter = SanitizerCommon.PthreadDestructorIterations
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SanitizerCommon
[ RUN      ] SanitizerCommon.PthreadDestructorIterations
/usr/local/google/home/etienneb/llvm/llvm/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_posix_test.cc:54: Failure
Value of: pthread_key_create(&key, &destructor)
  Actual: 11
Expected: 0
Aborted (core dumped)
```

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, chrisha

Differential Revision: http://reviews.llvm.org/D21902

llvm-svn: 274264
2016-06-30 19:56:14 +00:00
Etienne Bergeron 2d1938be0d [compiler-rt] Fix broken (flaky) unittests based on FlagParser.
Summary:
The FlagParser is populating a static global class with the
unrecognized flags when parsing. That global class has a 
dcheck that limit the number of unrecognized flag to 20.

```
class UnknownFlags {
  static const int kMaxUnknownFlags = 20;
  const char *unknown_flags_[kMaxUnknownFlags];
  int n_unknown_flags_;

  [...]

  void Report() {
    if (!n_unknown_flags_) return;
    Printf("WARNING: found %d unrecognized flag(s):\n", n_unknown_flags_);
    for (int i = 0; i < n_unknown_flags_; ++i)
      Printf("    %s\n", unknown_flags_[i]);
    n_unknown_flags_ = 0;
  }
};

UnknownFlags unknown_flags;
```

Unittests based on that class must reset the counter 'n_unknown_flags_' or
the next usage of that class may fail arbitrary. This can be done by
reporting the pending unknown flags.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21896

llvm-svn: 274234
2016-06-30 15:11:13 +00:00
Etienne Bergeron c8ee9d9614 [compiler-rt] Reset global variables in ThreadRegistryThreadedTest
Summary:
The unittest 'ThreadRegistryThreadedTest' is failing when running in loop.
There are global variables that need to be cleared.

To repro:
```
projects\compiler-rt\lib\sanitizer_common\tests\Release\Sanitizer-x86_64-Test.exe --gtest_filter=SanitizerCommon.ThreadRegistryThreadedTest  --gtest_repeat=2
```

Output:
```
Repeating all tests (iteration 1) . . .

Note: Google Test filter = SanitizerCommon.ThreadRegistryThreadedTest
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SanitizerCommon
[ RUN      ] SanitizerCommon.ThreadRegistryThreadedTest
[       OK ] SanitizerCommon.ThreadRegistryThreadedTest (1 ms)
[----------] 1 test from SanitizerCommon (1 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (2 ms total)
[  PASSED  ] 1 test.

Repeating all tests (iteration 2) . . .

Note: Google Test filter = SanitizerCommon.ThreadRegistryThreadedTest
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from SanitizerCommon
[ RUN      ] SanitizerCommon.ThreadRegistryThreadedTest
C:/src/llvm/llvm/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc(216): error: Value of: num_created[0]
  Actual: 2
Expected: 1
C:/src/llvm/llvm/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc(217): error: Value of: num_started[0]
  Actual: 2
Expected: 1
C:/src/llvm/llvm/projects/compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cc(220): error: Value of: num_created[i]
[...]
[  FAILED  ] SanitizerCommon.ThreadRegistryThreadedTest (294 ms)
[----------] 1 test from SanitizerCommon (294 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (299 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] SanitizerCommon.ThreadRegistryThreadedTest

 1 FAILED TEST
```

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21886

llvm-svn: 274231
2016-06-30 14:37:26 +00:00
Etienne Bergeron e6f424460a [compiler-rt] Fix broken unittest using alloca on MSVC.
Summary:
The alloca header is not present on windows.

This test was committed recently:
  http://reviews.llvm.org/D21509
  http://reviews.llvm.org/rL273889

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha, kubabrecka

Differential Revision: http://reviews.llvm.org/D21864

llvm-svn: 274230
2016-06-30 14:37:02 +00:00
Etienne Bergeron 94500cb532 [compiler-rt] Fix Sanitizer-common Unittests on win64
Summary:
This patch is fixing unittests that are broken on windows (64-bits).

Tests under 'SANITIZER_CAN_USE_ALLOCATOR64' are disabled.
A custom allocator for windows based on WinHeap API will replace these tests.

Tested on Win32/Win64 (Ninja and MSVC).
Tested on Linux 32-bit/64-bit clang.

```
C:\src\llvm\build64\projects\compiler-rt>lib\sanitizer_common\tests\Release\Sanitizer-x86_64-Test.exe
[==========] Running 101 tests from 12 test cases.
[----------] Global test environment set-up.
[----------] 51 tests from SanitizerCommon
[ RUN      ] SanitizerCommon.DefaultSizeClassMap
[       OK ] SanitizerCommon.DefaultSizeClassMap (1 ms)
[ RUN      ] SanitizerCommon.CompactSizeClassMap
[       OK ] SanitizerCommon.CompactSizeClassMap (1 ms)
[ RUN      ] SanitizerCommon.InternalSizeClassMap
[       OK ] SanitizerCommon.InternalSizeClassMap (1 ms)
[ RUN      ] SanitizerCommon.SizeClassAllocator32Compact
[       OK ] SanitizerCommon.SizeClassAllocator32Compact (828 ms)
[ RUN      ] SanitizerCommon.SizeClassAllocator32CompactMetadataStress
[       OK ] SanitizerCommon.SizeClassAllocator32CompactMetadataStress (914 ms)
[ RUN      ] SanitizerCommon.SizeClassAllocator32MapUnmapCallback

[...]

[----------] 4 tests from Symbolizer
[ RUN      ] Symbolizer.ExtractToken
[       OK ] Symbolizer.ExtractToken (0 ms)
[ RUN      ] Symbolizer.ExtractInt
[       OK ] Symbolizer.ExtractInt (0 ms)
[ RUN      ] Symbolizer.ExtractUptr
[       OK ] Symbolizer.ExtractUptr (0 ms)
[ RUN      ] Symbolizer.ExtractTokenUpToDelimiter
[       OK ] Symbolizer.ExtractTokenUpToDelimiter (0 ms)
[----------] 4 tests from Symbolizer (24 ms total)

[----------] Global test environment tear-down
[==========] 101 tests from 12 test cases ran. (5090 ms total)
[  PASSED  ] 101 tests.
```

Reviewers: rnk

Subscribers: chrisha, wang0109, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D21817

llvm-svn: 274174
2016-06-29 21:57:58 +00:00
Etienne Bergeron 30ece958db [compiler-rt] Fix the Asan unittest on Windows
Summary:
The build bot is broken because the runtime library doesn't have
debug information.

This is broken due to a recent change:
  http://reviews.llvm.org/D21554

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, chrisha

Differential Revision: http://reviews.llvm.org/D21862

llvm-svn: 274172
2016-06-29 21:54:50 +00:00
Etienne Bergeron f1d4e44d61 [compiler-rt] Fix passing debug information to unittest.
Summary:
On windows, the debug information was not present in the unittest executables,
which make them hard to debug.

The Sanitizer Unittests are compiled with a local clang build.
The link pass is also done by calling clang.

This pass is adding the appropriate flags to bring the right debug information
to these executables.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

Differential Revision: http://reviews.llvm.org/D21838

llvm-svn: 274153
2016-06-29 19:58:02 +00:00
Kuba Brecka 4d81bbdf53 [tsan] Stop extending the block’s lifetime in dispatch_group_async
The dispatch_group_async interceptor actually extends the lifetime of the executed block. This means the destructor of the block (and captured variables) is called *after* dispatch_group_leave, which changes the semantics of dispatch_group_async.  This patch fixes that.

Differential Revision: http://reviews.llvm.org/D21816

llvm-svn: 274117
2016-06-29 10:30:50 +00:00
Evgeniy Stepanov 465651fe3d [msan] Fix handling of padding in sendmsg control data.
llvm-svn: 274074
2016-06-28 22:42:31 +00:00
Chris Bieneman 42e22dcbb5 [CMake] In r273957, I deleted a line that shouldn't have been removed.
llvm-svn: 274030
2016-06-28 16:30:23 +00:00
Kuba Brecka f7b9075e52 Adapt the "objc-race.mm" test to use ignore_interceptors_accesses=1. All Obj-C/Darwin tests currently need this to avoid false positives.
llvm-svn: 274014
2016-06-28 13:56:09 +00:00
Kuba Brecka cdf257f4d8 Adding a comment to explain r273886 ("Stop unwinding the stack when a close-to-zero PC is found"). NFC.
llvm-svn: 274010
2016-06-28 12:53:20 +00:00
Chris Bieneman 990ff38786 [CMake] Check for androidabi in CMakeLists.txt not base-config-ix.cmake
COMPILER_RT_DEFAULT_TARGET_ABI is not set in base-config-ix.cmake, so we need to move this check into CMakeLists.txt.

llvm-svn: 273957
2016-06-27 22:52:05 +00:00
Chris Bieneman 90b46fba3d Revert "Parse the triple in base-config-ix to propagate ANDROID variable correctly"
This reverts commit r273914.

This commit broke bots building compiler-rt using LLVM_BUILD_EXTERNAL_COMPILER_RT. See:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_build/22221/console

llvm-svn: 273956
2016-06-27 22:52:03 +00:00
Sumanth Gundapaneni f0fa61ffcf Parse the triple in base-config-ix to propagate ANDROID variable correctly
The triple must be parsed in base-config-ix.cmake.
Otherwise, the cmake variable ANDROID won't be set and this
will confuse cmake to build unsupported targets targeted for
android.

Diferential revision: http://reviews.llvm.org/D21474

llvm-svn: 273914
2016-06-27 19:46:50 +00:00
Kuba Brecka 2621dea6eb [tsan] Add HB edges for GCD barrier blocks
Adding support for GCD barrier blocks in concurrent queues.  This uses two sync object in the same way as read-write locks do.  This also simplifies the use of dispatch groups (the notifications act as barrier blocks).

Differential Revision: http://reviews.llvm.org/D21604

llvm-svn: 273893
2016-06-27 16:49:23 +00:00
Kuba Brecka ca2668d038 [tsan] Treat non-barrier OSAtomic* functions as barriers to avoid false positives
The non-barrier versions of OSAtomic* functions are semantically mo_relaxed, but the two variants (e.g. OSAtomicAdd32 and OSAtomicAdd32Barrier) are actually aliases of each other, and we cannot have different interceptors for them, because they're actually the same function. Thus, we have to stay conservative and treat the non-barrier versions as mo_acq_rel.

Differential Revision: http://reviews.llvm.org/D21733

llvm-svn: 273890
2016-06-27 16:10:14 +00:00
Kuba Brecka 7d1ebed0c5 [asan] fix false dynamic-stack-buffer-overflow report with constantly-sized dynamic allocas, compiler-rt part
See the bug report at https://github.com/google/sanitizers/issues/691. When a dynamic alloca has a constant size, ASan instrumentation will treat it as a regular dynamic alloca (insert calls to poison and unpoison), but the backend will turn it into a regular stack variable. The poisoning/unpoisoning is then broken. This patch will treat such allocas as static.

Differential Revision: http://reviews.llvm.org/D21509

llvm-svn: 273889
2016-06-27 15:57:53 +00:00
Kuba Brecka 02478f4166 [sanitizer] Stop unwinding the stack when a close-to-zero PC is found
On OS X, we often get stack trace in a report that ends with a 0x0 frame.  To get rid of it, let's trim the stack trace when we find a close-to-zero value, which is obviously not a valid PC.

Differential Revision: http://reviews.llvm.org/D14656

llvm-svn: 273886
2016-06-27 15:32:18 +00:00
Dmitry Vyukov b3a51bdcd7 tsan: don't create sync objects on acquire
Creating sync objects on acquire is pointless:
acquire of a just created sync object if a no-op.

llvm-svn: 273862
2016-06-27 11:14:59 +00:00
Ryan Govostes d4492ee159 Move -ldl to the correct compiler invocation
llvm-svn: 273844
2016-06-27 05:44:47 +00:00
Kuba Brecka 30ad0c941a [tsan] Intercept libcxx __release_shared to avoid false positive with weak_ptrs and destructors in C++
There is a "well-known" TSan false positive when using C++ weak_ptr/shared_ptr and code in destructors, e.g. described at <https://llvm.org/bugs/show_bug.cgi?id=22324>. The "standard" solution is to build and use a TSan-instrumented version of libcxx, which is not trivial for end-users. This patch tries a different approach (on OS X): It adds an interceptor for the specific function in libc++.dylib, which implements the atomic operation that needs to be visible to TSan.

Differential Revision: http://reviews.llvm.org/D21609

llvm-svn: 273806
2016-06-26 08:14:01 +00:00
Peter Collingbourne c79ad577fb cfi: Start testing CFI in both standalone and devirtualization modes.
Differential Revision: http://reviews.llvm.org/D21123

llvm-svn: 273758
2016-06-25 00:24:22 +00:00
Evgeniy Stepanov dd9e03ed87 [msan] Intercept eventfd_read, eventfd_write.
llvm-svn: 273748
2016-06-24 23:32:30 +00:00
Evgeniy Stepanov c8679985ed [sanitizer] Add syscall handlers for sigaction and rt_sigaction.
llvm-svn: 273746
2016-06-24 23:09:44 +00:00
Ryan Govostes 6f92bd38d8 [asan] Improve global-registration.c test
Removes use of GNU language extensions from the test, and hopefully fixes the
link order on Linux.

llvm-svn: 273741
2016-06-24 22:39:23 +00:00
Peter Collingbourne cf55f217ba cfi: Apply pass rename to tests.
Differential Revision: http://reviews.llvm.org/D21055

llvm-svn: 273731
2016-06-24 21:22:02 +00:00
Evgeniy Stepanov c7509de7cc [msan] Fix syscall handlers for pipe, pipe2, socketpair.
These syscalls write two file descriptors into the output buffer, not one.

llvm-svn: 273728
2016-06-24 21:15:53 +00:00
Xinliang David Li 3e9bbddcbb fix a test bug when executed remotedly
llvm-svn: 273693
2016-06-24 17:42:51 +00:00
Ryan Govostes 00f607eef0 Change shared library load path to appease Android bot
llvm-svn: 273654
2016-06-24 06:49:01 +00:00
Ryan Govostes 0ec8ab680f [asan] Add failure logging to global-registration.c test case
llvm-svn: 273629
2016-06-23 23:26:25 +00:00
Reid Kleckner 02d5315237 Use CreateFileA and add a FIXME to switch to the wide variant
No functional change. Required to build with -DUNICODE, as is done in
http://reviews.llvm.org/D21643

llvm-svn: 273571
2016-06-23 15:40:42 +00:00
Chris Bieneman 38adadfe2a [CMake] Converting darwin_test_archs simple source to C
Using C instead of CXX here removes a configuration-time dependency on libcxx for the sanitizers. This should be NFC.

llvm-svn: 273505
2016-06-22 23:02:49 +00:00
Saleem Abdulrasool 590e85b575 builtins: tag with noexecstack
These routines do not require executable stacks.  However, by default ELFish
linkers may assume an executable stack on GNUish environments (and some non-GNU
ones too!).  The GNU extension to add a note to indicate a non-executable stack
is honoured by these environments to mark the stack as non-executable (the
compiler normally emits this directive on appropriate targets whenever
possible).  This allows normal builds from getting executable stacks due to
linking to the compiler rt builtins.

llvm-svn: 273500
2016-06-22 22:09:42 +00:00
Ryan Govostes 3c0f63c98b [asan] Fix global-registration.c on Linux
llvm-svn: 273476
2016-06-22 20:52:34 +00:00
Anna Zaks 0a494bd4d4 [asan] Relax a flaky invalid-pointer-pairs test
This test is flaky. Specifically, on some Mac configurations we see the
__sanitizer_ptr_cmp as the 0th frame. Let's relax it to not require that
f is in frame #0.

61396==ERROR: AddressSanitizer: invalid-pointer-pair: 0x01e00510 0x01e004d0
0 0x18f5a3 in __sanitizer_ptr_cmp ... libclang_rt.asan_osx_dynamic.dylib+0xaf5a3)
1 0xdd924 in f(char, char*, char*) ... invalid-pointer-pairs.cc:14:14

Differential Revision: http://reviews.llvm.org/D21588

llvm-svn: 273475
2016-06-22 20:52:21 +00:00
Ryan Govostes f66146914b [asan] Add a test case for global registration
This test case checks that globals from all object files are being registered
after they've been linked together. It also checks that globals from libraries
loaded at runtime are registered.

llvm-svn: 273464
2016-06-22 19:59:10 +00:00
Chris Bieneman 8a99ecd01c [CMake] NFC. An unset variable evaluates to false, so this else is unneeded
This change is mostly to enable me to do some experimentation with building runtime libraries (See: D20992). It is harmless because unset variables evaluate to false in conditional expressions.

llvm-svn: 273320
2016-06-21 21:28:40 +00:00
Dmitry Vyukov 42c06a933a Fix asan_win_dll_thunk.cc test
Add the two public functions I added in my last commit in asan_win_dll_thunk.cc

Author: blastrock (Philippe Daouadi)
Reviewed in http://reviews.llvm.org/D21557

llvm-svn: 273288
2016-06-21 17:28:06 +00:00
Etienne Bergeron 3d6a88c389 Change the shadow memory address for win64.
This is part of the effort for asan to support Windows 64 bit.

Patch by Wei Wang
Differential Revision: http://reviews.llvm.org/D21525

llvm-svn: 273270
2016-06-21 15:11:24 +00:00
Etienne Bergeron 48933772f7 [asan] Fix shifting compiler warnings when compiler in 64-bits
Summary:
The MSVC compiler complains about implicit conversion of 32-bits constant to
64-bit when using this shiting pattern  1 << (<64-bit expr>).

Reviewers: rnk

Subscribers: kcc, llvm-commits, wang0109, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21524

llvm-svn: 273267
2016-06-21 14:53:16 +00:00
Etienne Bergeron 7e2fc3b702 [compiler-rt] Split cflags and link flags to avoid warnings
Summary:
The MSVC compiler is complaining about invalid flags. The CFLAGS are passed
to the linker (i.e. /Gy-, ...).

Reviewers: rnk

Subscribers: llvm-commits, kubabrecka, chrisha

Differential Revision: http://reviews.llvm.org/D21554

llvm-svn: 273265
2016-06-21 14:46:32 +00:00
Etienne Bergeron b2f17d1719 trimming whitespaces
llvm-svn: 273263
2016-06-21 14:32:52 +00:00
Dmitry Vyukov 47b7c5c912 [asan] add primitives that allow coroutine implementations
This patch adds the __sanitizer_start_switch_fiber and
__sanitizer_finish_switch_fiber methods inspired from what can be found here
2ea64dd249 .

These methods are needed when the compiled software needs to implement
coroutines, fibers or the like. Without a way to annotate them, when the program
jumps to a stack that is not the thread stack, __asan_handle_no_return shows a
warning about that, and the fake stack mechanism may free fake frames that are
still in use.

Author: blastrock (Philippe Daouadi)
Reviewed in http://reviews.llvm.org/D20913

llvm-svn: 273260
2016-06-21 12:29:18 +00:00
Marcin Koscielnicki d731820f1e Revert "Revert "[MSan] Enable on PowerPC64.""
This reverts commit r269532.

The failures triggered by the first attempt should be fixed by r273250.

llvm-svn: 273251
2016-06-21 07:13:24 +00:00
Marcin Koscielnicki 613c252517 [sanitizers] [PowerPC] Intercept __tls_get_addr_opt.
On PowerPC, if binutils and glibc are new enough, the linker uses
an optimized code sequence to implement __tls_get_addr call stub,
which will end up calling __tls_get_addr_opt instead of __tls_get_addr.
Thus, we need to intercept it in addition to __tls_get_addr.

This symbol is actually an alias of __tls_get_addr - its only purpose
is that its presence in glibc triggers the optimization in linker.
This means we can make our own intercepting symbol an alias as well.

This patch will make the linker attempt optimization even on older
glibc's (since it sees a defined __tls_get_addr_opt symbol in msan)
- however, this is only a very minor performance problem (the linker
generated code will never recognize a filled static TLS descriptor,
always burning a few cycles), not a correctness problem.

This fixes MSan's dtls_test.c, allowing us to finally enable MSan
on PowerPC64.

llvm-svn: 273250
2016-06-21 07:09:36 +00:00
Evgeniy Stepanov ecfcc07a48 [msan] Don't check dstaddr in sendto() interceptor.
Dstaddr may contain uninitialized padding at the end (common
implementations accept larger addrlen and ignore the extra bytes).
Also, depending on the socket state, dstaddr argument may be ignored.

llvm-svn: 273205
2016-06-20 22:05:33 +00:00
Evgeniy Stepanov 843b651398 [msan] Allow uninitialized padding in struct msghdr.
llvm-svn: 273204
2016-06-20 21:44:14 +00:00
Etienne Bergeron 3ac879f9a6 Add missing decoding patterns toRoundUpToInstrBoundary
Summary:
The RoundUpToInstrBoundary determines intructions boundary and it's used to determine how to patch (intercept) functions.

The current x64-bit implementation is incomplete. This patch is adding patterns observed when trying to sanitize a 64-bit executable on my computer.

Thw two current functions not intercepted are:
```
RaiseExceptionStub:
000000007720C3B0 EB 06                jmp         RaiseException (07720C3B8h)  
000000007720C3B2 90                   nop  
000000007720C3B3 90                   nop  
000000007720C3B4 90                   nop  
000000007720C3B5 90                   nop  
000000007720C3B6 90                   nop  
000000007720C3B7 90                   nop  
RaiseException:
000000007720C3B8 FF 25 3A 18 09 00    jmp         qword ptr [__imp_RaiseException (07729DBF8h)]  
000000007720C3BE 8B 44 24 54          mov         eax,dword ptr [rsp+54h]  
000000007720C3C2 85 C0                test        eax,eax  
000000007720C3C4 0F 84 F5 05 00 00    je          Wow64NtCreateKey+12Fh (07720C9BFh)  
```

```
CreateThreadStub:
0000000077215A10 48 83 EC 48          sub         rsp,48h  
0000000077215A14 48 8B 44 24 78       mov         rax,qword ptr [rsp+78h]  
0000000077215A19 48 89 44 24 38       mov         qword ptr [rsp+38h],rax  
0000000077215A1E 8B 44 24 70          mov         eax,dword ptr [rsp+70h]  
```

Reviewers: rnk

Subscribers: wang0109, chrisha

Differential Revision: http://reviews.llvm.org/D21519

llvm-svn: 273176
2016-06-20 18:00:03 +00:00
Evgeniy Stepanov 352289b679 Hide send/sendto/sendmsg interptors under a flag.
A runtime flag to enable checking in send* interceptors.
Checking is enabled by default.

llvm-svn: 273174
2016-06-20 17:57:51 +00:00
Marcin Koscielnicki 463897f1a9 [sanitizers] [SystemZ] Add __tls_get_offset interceptor.
s390 is special again - instead of __tls_get_addr, it has __tls_get_offset
with special calling conventions: the result is TP relative, and
the argument is GOT-relative.  Since we need to get address of the caller's
GOT, which is in %r12, we have to use assembly like glibc does.

Aside of __tls_get_offset, glibc also implements a slightly saner
__tls_get_addr_internal, which takes a pointer as argument, but still
returns a TP-relative offset.  It is used for dlsym() called on TLS
symbols, so we have to intercept it was well.  Our __tls_get_offset
is also implemented by delegating to it.

Differential Revision: http://reviews.llvm.org/D19778

llvm-svn: 273041
2016-06-17 20:24:35 +00:00
Marcin Koscielnicki 655db0fd3a [sanitizer] [SystemZ] Enable TLS functionality.
This enables TLS knowledge for s390 in sanitizers.

Differential Revision: http://reviews.llvm.org/D19594

llvm-svn: 273040
2016-06-17 20:24:32 +00:00
Reid Kleckner 44e6e36299 Turn off -Wunused-parameter when building compiler-rt with clang on Windows, it is very noisy
It is turned on as part of "clang-cl /W4", which enables -Wextra.

llvm-svn: 273028
2016-06-17 18:30:37 +00:00
Reid Kleckner 652d70f3e1 Fix most MSVC warnings in compiler-rt profiling library
Here's the warnings and how they were fixed:

- InstrProfilingUtil.c(110): warning C4013: '_open_osfhandle' undefined; assuming extern returning int

Include io.h to get the prototype.

- warning C4005: 'FILE_MAP_EXECUTE': macro redefinition

Stop trying to support pre-XP versions of Windows, don't attempt to
define this macro.

- InstrProfilingWriter.c(271): warning C4221: nonstandard extension used: 'Data': cannot be initialized using address of automatic variable 'Header'
- InstrProfilingWriter.c(275): warning C4221: nonstandard extension used: 'Data': cannot be initialized using address of automatic variable 'Zeroes'

Turn this warning off. This is definitely legal in C++, all compilers
accept it, and I only have room for half of one language standard in my
brain.

- InstrProfilingValue.c(320): warning C4113: 'uint32_t (__cdecl *)()' differs in parameter lists from 'uint32_t (__cdecl *)(void)'

Fix this with an explicit (void) in the prototype.

- InstrProfilingMerge.c.obj : warning LNK4006: _VPMergeHook already defined in InstrProfilingMergeFile.c.obj; second definition ignored

Last remaining warning. This is from linking a selectany definition with
a strong definition. We need to sort out weak symbols in compiler-rt in
general, though.

llvm-svn: 273026
2016-06-17 18:12:50 +00:00
Reid Kleckner d0680ad717 Fix some warnings in the MSVC build
- Fixes warnings about the ignored -fms-compatibility-version flag.
- Fixes warnings about overriding /W4 with /W3 and back.
- Fixes a warning where PREFETCH() expanded to nothing in a braceless if
  block.

llvm-svn: 273021
2016-06-17 17:48:52 +00:00
Qin Zhao e24bc365e8 [esan|cfrag] Add the struct field size array in StructInfo
Summary:
Adds the struct field size array in the struct StructInfo.

Prints struct field size info in the report.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, bruening, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D21342

llvm-svn: 272988
2016-06-17 04:50:11 +00:00
Evgeniy Stepanov 3c17c73924 [msan] Intercept send/sendto/sendmsg.
send/sendmsg moved from tsan to sanitizer_common; sendto is new.

llvm-svn: 272980
2016-06-17 00:43:11 +00:00
Kostya Serebryany bf6a04fde8 [sanitizers] introduce yet another API function: __sanitizer_install_malloc_and_free_hooks
llvm-svn: 272943
2016-06-16 20:06:06 +00:00
Derek Bruening 91c88e6558 [esan] Use internal_mmap during initialization
Fixes another interceptor issue where an app with a static tcmalloc
library that prevents our early-calloc handling from triggering yet
does not have a static mmap crashes in our mmap interceptor.  The
solution is to call internal_mmap when REAL(mmap) is not yet set up.

llvm-svn: 272870
2016-06-16 03:19:58 +00:00
Evgeniy Stepanov 062c26f1f0 Merge two coverage tests undef UBSan into one.
Also replace mkdir -p with rm -rf && mkdir.

llvm-svn: 272839
2016-06-15 21:18:17 +00:00
Qin Zhao cd5fe14d89 [esan|cfrag] Minor cfrag report adjustment
Summary:
Reports the struct field access info only if it has been used at least
once.

Adds type printing size limit.

Formats the cache_frag.cpp with clang-format.

Reviewers: bruening

Subscribers: llvm-commits, eugenis, kcc, zhaoqin, vitalybuka, aizatsky, kubabrecka

Differential Revision: http://reviews.llvm.org/D21351

llvm-svn: 272810
2016-06-15 17:27:29 +00:00
Dmitry Vyukov 88f47d3521 tsan: intercept epoll_pwait
llvm-svn: 272779
2016-06-15 12:22:05 +00:00