Commit Graph

6175 Commits

Author SHA1 Message Date
Etienne Bergeron 502df06e21 [compiler-rt] Fix various typos in asan dll [NFC]
llvm-svn: 277345
2016-08-01 15:08:12 +00:00
Dimitry Andric 75534e23d0 XFAIL one sanitizer symbolizer test for FreeBSD
Summary:
Due to a QoI issuse in FreeBSD's libcxxrt-based demangler, one sanitizer
symbolizer test consistently appears to fail:

    Value of: DemangleSwiftAndCXX("foo")
      Actual: "float"
    Expected: "foo"

This is because libcxxrt's __cxa_demangle() incorrectly demangles the "foo"
identifier to "float".  It should return an error instead.

For now, XFAIL this particular test for FreeBSD, until we can fix libcxxrt
properly (which might take some time to coordinate with upstream).

Reviewers: rnk, zaks.anna, emaste

Subscribers: emaste, llvm-commits, kubabrecka

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

llvm-svn: 277297
2016-07-31 19:27:46 +00:00
Etienne Bergeron 0b2d71373b [compiler-rt] Add support for interception redirect exports.
Summary:
On windows, an export can be redirected to an other DLL.
This patch is adding the required support to the internal
GetProcAddress implementation.

This case was encountered by instrumenting chromium (win 64-bits)
using this GN configuration:
```
is_component_build = true
is_debug = false
enable_nacl = false
is_clang = true
is_asan = true
clang_base_path = "d:\src\llvm\ninja64"
clang_use_chrome_plugins = false
clang_version = "4.0.0"
```

The operating system is win7 (x64).
Visual Studio: 2015 Professional



Reviewers: rnk

Subscribers: llvm-commits, chrisha

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

llvm-svn: 277294
2016-07-31 17:56:26 +00:00
Adhemerval Zanella 4f9de1e7bf tsan: Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for tsan on aarch64.  As current
mappings for aarch64, 48-bit VMA also supports PIE executable.  This
limits the mapping mechanism because the PIE address bits
(usually 0aaaaXXXXXXXX) makes it harder to create a mask/xor value
to include all memory regions.  I think it is possible to create a
large application VAM range by either dropping PIE support or tune
current range.

It also changes slight the way addresses are packed in SyncVar structure:
previously it assumes x86_64 as the maximum VMA range.  Since ID is 14 bits
wide, shifting 48 bits should be ok.

Tested on x86_64, ppc64le and aarch64 (39 and 48 bits VMA).

llvm-svn: 277137
2016-07-29 12:45:35 +00:00
Dean Michael Berris 17a586e6de [compiler-rt][XRay] Address follow-up comments to initial interface and initialisation code
This addresses some comments from D21612, which contains the following changes:

- Update __xray_patch() and __xray_unpatch() API documentation to not imply asynchrony.
- Introduce a scope cleanup mechanism to make sure we can roll-back changes to the XRayPatching global atomic.
- Introduce a few more comments for potential extension points for other platforms (for the implementation details of patching and un-patching).

Reviewers: eugenis, rnk, kcc, echristo, majnemer

Subscribers: llvm-commits, mehdi_amini

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

llvm-svn: 277124
2016-07-29 07:11:58 +00:00
Etienne Bergeron 74999eb50f Fix broken build bot
The address resolution is ussing RTLD_NEXT and not RTLD_DEFAULT.
Which means &func may not be equivalent to dlsym("func").

llvm-svn: 276951
2016-07-28 01:35:32 +00:00
Etienne Bergeron 8c6eb1566c [compiler-rt] Fix warnings in interception code
Summary:
This patch is re-introducing the code to fix the
dynamic hooking on windows and to fix a compiler
warning on Apple.

Related patches:

* https://reviews.llvm.org/D22641
* https://reviews.llvm.org/D22610
* https://reviews.llvm.org/rL276311
* https://reviews.llvm.org/rL276490

Both architecture are using different techniques to
hook on library functions (memchr, strcpy,...). 

On Apple, the function is not dynamically hooked and
the symbol always points to a valid function 
(i.e. can't be null). The REAL macro returns the
symbol.

On windows, the function is dynamically patch and the
REAL(...) function may or may not be null. It depend
on whether or not the function was hooked correctly.
Also, on windows memcpy and memmove are the same.

```
#if !defined(__APPLE__)
[...]
# define REAL(x) __interception::PTR_TO_REAL(x)
# define ASSIGN_REAL(dst, src) REAL(dst) = REAL(src)
[...]
#else  // __APPLE__
[...]
# define REAL(x) x
# define ASSIGN_REAL(x, y)
[...]
#endif  // __APPLE__

Reviewers: rnk

Subscribers: kcc, hans, kubabrecka, llvm-commits, bruno, chrisha

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

llvm-svn: 276885
2016-07-27 16:16:54 +00:00
Dmitry Vyukov 246e0283d4 tsan: don't deliver signals when they are blocked
When we delay signals we can deliver them when the signal
is blocked. This can be surprising to the program.
Intercept signal blocking functions merely to process
pending signals. As the result, at worst we will delay
a signal till return from the signal blocking function.

llvm-svn: 276876
2016-07-27 14:34:21 +00:00
Dean Michael Berris 9a0c446d9e Use RAII for ensuring that mprotect calls are undone
Summary: This fixes an mprotect leak identified in D21612.

Reviewers: echristo, rSerge

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 276833
2016-07-27 04:30:25 +00:00
Evgeniy Stepanov d140aec490 [asan] Remove zero FSR check on ARM.
The kernel on Nexus 5X returns error_code in ucontext which has
correct FSR_WRITE flag, but empty (zero) abort type field. Removing
the checks means that we will report all SEGVs as READ on very old
kernels, but will properly distinguish READ vs WRITE on moderately
old ones.

llvm-svn: 276803
2016-07-26 21:02:45 +00:00
Evgeniy Stepanov 08ef0e0175 [asan] Hardcode page size 4096 on Android.
EXEC_PAGESIZE lies.
sysconf() is broken in .preinit_array.

llvm-svn: 276802
2016-07-26 21:02:44 +00:00
Reid Kleckner cb42ea0b4f [sanitizer] Try to fix LargeMmapAllocator test on Windows
This test attempts to allocate 100 512MB aligned pages of memory. This
is implemented in the usual way by allocating size + alignment bytes and
aligning the result. As a result, this test allocates 51.2GB of memory.
Windows allocates swap for all memory allocated, and our bots do not
have this much swap available.

Avoid the failure by using a more reasonable alignment, like 16MB, as we
do on 32-bit.

llvm-svn: 276779
2016-07-26 17:59:09 +00:00
Xinliang David Li c5307c6993 Define compatibility flag if not defined with -std=c++
llvm-svn: 276708
2016-07-25 23:12:53 +00:00
Chris Bieneman 56e3827e92 Revert "Enable cross-compilation across architectures on android"
This reverts commit r276333.

As I commented in the review (https://reviews.llvm.org/D22415), this change isn't needed because CMAKE_C_FLAGS is implicitly added by CMake to the command line for all C source files.

With this patch enabled CMAKE_C_FLAGS is duplicated on all C sources, and applied to ASM sources, which is not ideal.

I sent an email about this to llvm-commits on the commit thread. I suspect the problem the patch author was actually seeing is that CMAKE_C_FLAGS isn't applied to ASM files, and the builtins library has quite a few of those. The correct solution there is to specify CMAKE_ASM_FLAGS with whatever flags need to be passed to the compiler when compiling ASM files.

If there are other problems with flag propagation, please let me know.

llvm-svn: 276683
2016-07-25 20:25:38 +00:00
Bruno Cardoso Lopes 1f849e3b84 Revert r276539 "Silence -Wpointer-bool-conversion warning after r276324"
Some bots are not happy with the change.
This reverts commit d307ca28083065851ad969444f3c063562f2d4bd.

llvm-svn: 276541
2016-07-24 01:27:07 +00:00
Bruno Cardoso Lopes bd36338449 Silence -Wpointer-bool-conversion warning after r276324
sanitizer_common_interceptors.inc:667:12: warning: address of function 'memchr' will always evaluate to 'true' [-Wpointer-bool-conversion]
  if (REAL(memchr)) {
  ~~       ^~~~~~

llvm-svn: 276539
2016-07-24 01:09:03 +00:00
Bruno Cardoso Lopes fb4358d15b Revert "fix https://reviews.llvm.org/D22610" and "[compiler-rt] Fix memmove/memcpy overlap detection on windows"
This currently fails ~500 tests on Darwin:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/20456/

This reverts commit 4cfee0dff1facb8fa2827d25c5943bfef96d1a8f and
dbd91205d578cb61ab77be06087e9f65ba8a7ec8.

llvm-svn: 276490
2016-07-22 23:02:34 +00:00
Kostya Serebryany d251e94a01 [sanitizer] revert r276383 while investigating failures on bot
llvm-svn: 276456
2016-07-22 19:02:59 +00:00
Reid Kleckner ff3ea5f4f8 Try to fix more Windows portability issues in sanitizer tests
Add a %stdcxx11 lit substitution for -std=c++11. Windows defaults to
-std=c++14 when VS 2015 is used because the STL requires it. Harcoding
-std=c++11 in the ASan tests actually downgrades the C++ standard level,
leading to test failures.

Relax a FileCheck pattern in use-after-scope-types.cc.

Disable the sanitizer_common OOM tests. They fail on bots with low swap,
and cause other concurrently running tests to OOM.

llvm-svn: 276454
2016-07-22 18:41:22 +00:00
Xinliang David Li f0e0a74f87 [Profile] cleanup: do not reference name directly of vars shared between rt and llvm
llvm-svn: 276385
2016-07-22 04:08:16 +00:00
Kostya Serebryany 5bc01c108d [sanitizer] refactor TransferBatch to hide the implementation. NFC
llvm-svn: 276383
2016-07-22 02:21:12 +00:00
Kostya Serebryany bfd69e0580 [sanitizer] allocator: introduce kUseSeparateSizeClassForBatch (false by default). When true, it will cause all TransferBatches to be allocated on a separate dedicated size class, which improves security and may potentially simplify memory reclamation. However in the current state this may cause up to 3% extra memory usage. Subsequent changes should bring this overhead down
llvm-svn: 276377
2016-07-22 01:13:13 +00:00
Xinliang David Li e953933a9f [Profile] deprecate __llvm_profile_override_default_filename (part2)
This eliminates unncessary calls and init functions.

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

llvm-svn: 276355
2016-07-21 23:19:18 +00:00
Kostya Serebryany 88e95bf38c [sanitizer] trying to fix Mac bots
llvm-svn: 276346
2016-07-21 22:18:36 +00:00
Kostya Serebryany 395386f910 [sanitizer] better allocator stats (with rss)
llvm-svn: 276343
2016-07-21 21:38:40 +00:00
Etienne Bergeron 901b0dc96a [compiler-rt] Add support for relative offset adjustment in interception
Summary:
Some instructions can only be copied if the relative offset is adjusted.

This patch adds support for two common instruction.
It's quite common to have a indirect load in the prologue 
(loading the security cookie).

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 276336
2016-07-21 21:08:54 +00:00
Francis Ricci 283d8df277 Enable cross-compilation across architectures on android
Summary:
This patch fixes cross-architecture compilation,
by allowing flags like -target and --sysroot to be set for
architecture testing and compilation.

Reviewers: tberghammer, srhines, danalbert, beanz, compnerd

Subscribers: tberghammer, llvm-commits, danalbert

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

llvm-svn: 276333
2016-07-21 21:05:14 +00:00
Reid Kleckner f6d5475e20 Disable thread safe statics in clang-cl, they call the CRT
Also remove the needless static that was using them.

llvm-svn: 276327
2016-07-21 20:03:37 +00:00
Etienne Bergeron 29539a0b7d [compiler-rt] Fix interception of memcpy/memmove on win64
Summary:
This patch is fixing running interception unittests for memcpy/memmove on
windows 64.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276324
2016-07-21 19:49:11 +00:00
Kostya Serebryany 35eeea707e [sanitizer] allocator: remove kPopulateSize and only use SizeClassMap::MaxCached; ensure that TransferBatch size is a power of two, refactor TransferBatch creation/destruction into separate functions.
llvm-svn: 276318
2016-07-21 18:47:53 +00:00
Reid Kleckner db81b3e0b2 Fix clang-cl warning and crash in sanitizers
Make kStderrFd a macro to avoid dynamic initialization of the
report_file global. This actually causes a crash at runtime, because
ASan initializes before static initializers run.

Remove an unused variable in asan_win.cc.

llvm-svn: 276314
2016-07-21 18:31:01 +00:00
Etienne Bergeron 2c781262b8 fix https://reviews.llvm.org/D22610
AppleClang can't compile the assignment expression.

llvm-svn: 276311
2016-07-21 17:58:04 +00:00
Etienne Bergeron aa76a0cf91 [compiler-rt] Fix memmove/memcpy overlap detection on windows
Summary:
The memcpy and memmove functions are the same on windows.
The overlap detection logic is incorrect.

printf-1 test:
```
stdin>:2:114: note: possible intended match here
==877412==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x0000002bf2a8,0x0000002bf2ad) and [0x0000002bf2a9, 0x0000002bf2ae) overlap
```                                                                                                                 ^

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276299
2016-07-21 16:06:54 +00:00
Dean Michael Berris 938c5031ab [compiler-rt][XRay] re-submitting r276117, with fixes for build breakage due to extraneous and missing dependencies and attempts to build on unsupported OSes
Summary:
This is a fixed-up version of D21612, to address failure identified post-commit.

Original commit description:

This patch implements the initialisation and patching routines for the XRay runtime, along with the necessary trampolines for function entry/exit handling. For now we only define the basic hooks for allowing an implementation to define a handler that gets run on function entry/exit. We expose a minimal API for controlling the behaviour of the runtime (patching, cleanup, and setting the handler to invoke when instrumenting).

Fixes include:
- Gating XRay build to only Linux x86_64 and with the right dependencies in case it is the only library being built
- Including <cstddef> to fix std::size_t issue

Reviewers: kcc, rnk, echristo

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 276251
2016-07-21 07:39:55 +00:00
Xinliang David Li e3fc4d0fdd [Profile] bug fix: profile dir not recursively created
llvm-svn: 276234
2016-07-21 03:38:07 +00:00
Etienne Bergeron d4528b2ea1 [compiler-rt] Fix broken SymInitialize unittest
Summary:
By adding the initialisation of the symbolisation library (DbgHelp)
we are swapping the order in which both warnings are produced.

We can't use CHECK-NEXT as the dbghelp warning is multiline.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 276228
2016-07-21 02:32:37 +00:00
Xinliang David Li bfc4c24952 Sync up with llvm copy /NFC
llvm-svn: 276198
2016-07-20 22:29:16 +00:00
Kostya Serebryany 9835a81529 [sanitizers] split sanitizer_allocator.h into a number of smaller .h files; NFC
llvm-svn: 276195
2016-07-20 22:06:41 +00:00
Hans Wennborg ae4e6fe990 Revert r276117 "[XRay] Basic initialization and flag definition for XRay runtime"
and also the follow-up "[xray] Only build xray on Linux for now"

Two build errors were reported on the llvm-commits list:

	[ 88%] Building CXX object lib/xray/CMakeFiles/clang_rt.xray-x86_64.dir/xray_flags.cc.o
	/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/lib/xray/xray_init.cc:23:10: fatal error: 'llvm/Support/ELF.h' file not found
  #include "llvm/Support/ELF.h"
					 ^

and

	In file included from /w/src/llvm.org/projects/compiler-rt/lib/xray/xray_interface.cc:16:
	/w/src/llvm.org/projects/compiler-rt/lib/xray/xray_interface_internal.h:36:8: error:
				no type named 'size_t' in namespace 'std'
		std::size_t Entries;
		~~~~~^

llvm-svn: 276186
2016-07-20 21:37:38 +00:00
Reid Kleckner 8367634c7a [xray] Only build xray on Linux for now
Should fix the Windows buildbots, and maybe some other non-Linux Unix
bots too.

XRay currently depends on sanitizer_common, so associate it with the
"build sanitizers" option and remove the option for separately
controlling the XRay build.

llvm-svn: 276124
2016-07-20 14:58:07 +00:00
Dean Michael Berris e1c81d10d7 [compiler-rt] [XRay] Basic initialization and flag definition for XRay runtime
Summary:
This patch implements the initialisation and patching routines for the XRay runtime, along with the necessary trampolines for function entry/exit handling. For now we only define the basic hooks for allowing an implementation to define a handler that gets run on function entry/exit. We expose a minimal API for controlling the behaviour of the runtime (patching, cleanup, and setting the handler to invoke when instrumenting).

Depends on D19904

Reviewers: echristo, kcc, rnk

Subscribers: rnk, mehdi_amini, llvm-commits

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

llvm-svn: 276117
2016-07-20 14:14:50 +00:00
Dmitry Vyukov 080dcf7aa8 tsan: fix windows build
It's only asan that installs vectored SEH handler to map memory lazily.

llvm-svn: 276112
2016-07-20 12:50:49 +00:00
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 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
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
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
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 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
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
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
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
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
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
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 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
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
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 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
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
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
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
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
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
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 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 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 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
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
Etienne Bergeron 89200ccefa In asan on Windows 64-bit, this is one of the broken things
that makes allocation fail. "UL" is 32-bit and shift by 40 will make
the value overflow and become 0.

Patch by Wei Wang

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

llvm-svn: 272689
2016-06-14 18:05:45 +00:00
Vedant Kumar 8e2dd518af [profile] Update a warning message (NFC)
It's possible for a merge pool specifier to appear anywhere in a
filename pattern. Update the warning to reflect this.

llvm-svn: 272685
2016-06-14 17:23:13 +00:00
Adhemerval Zanella c0c6835096 [sanitizer] Revert new GLIBC msghdr/cmsghdr definitions
GLIBC reverted the POSIX conformance changes for msghdr/cmsghdr [1],
so there is no need to fix it on sanitizers.

[1] https://sourceware.org/git/?p=glibc.git;a=commit;h=78880cc185dc521855a58001a28e3059722d8e85

llvm-svn: 272678
2016-06-14 15:22:37 +00:00
Derek Bruening f6f149da29 [sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors.  The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.

Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up.  This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.

Adds a test that emulates an instrumented allocator.

Reviewers: aizatsky

Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 272676
2016-06-14 15:15:38 +00:00
Nico Weber be7aa544f0 Revert r272591, http://lab.llvm.org:8011/builders/clang-x64-ninja-win7 has been broken since this landed.
llvm-svn: 272659
2016-06-14 12:39:22 +00:00
Derek Bruening c4c649e25a [sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors.  The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.

Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up.  This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.

Adds a test that emulates an instrumented allocator.

Reviewers: aizatsky

Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 272591
2016-06-13 21:50:00 +00:00
Derek Bruening db176c11dc Revert "[sanitizer][esan] Add internal_sigaction_syscall"
This reverts commit r272553.

The iOS build fails to link.

llvm-svn: 272557
2016-06-13 16:16:49 +00:00
Derek Bruening 19a4b8d8f8 [sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors.  The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.

Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up.  This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.

Adds a test that emulates an instrumented allocator.

Reviewers: aizatsky

Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 272553
2016-06-13 15:42:39 +00:00
Jeroen Ketema af0bbd92a2 [builtins] Make SOFT_FP versions of floatdidf and floatundidf compile
llvm-svn: 272551
2016-06-13 15:24:16 +00:00
Jeroen Ketema 0b748f220b [builtins] replace tabs by spaces and remove whitespace at end of line NFC
llvm-svn: 272550
2016-06-13 15:21:04 +00:00
Xinliang David Li 153e8b6c85 [profile] cleanup file setting code
Differential Revision: http://reviews.llvm.org/D21219

llvm-svn: 272428
2016-06-10 20:35:01 +00:00
Qin Zhao a4a7220db1 [esan|cfrag] Add the struct field offset array in StructInfo
Summary:
Adds the struct field offset array in the struct StructInfo.

Prints struct size and field offset info in the report.

Reviewers: aizatsky

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

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

llvm-svn: 272363
2016-06-10 02:10:34 +00:00
Xinliang David Li e2ce2e0020 [profile] in-process merging support part-3
Differential Revision: http://reviews.llvm.org/D21056

llvm-svn: 272227
2016-06-08 23:43:56 +00:00
Vedant Kumar 17af892d6f [profile] Hide some external symbols in InstrProfData.inc
Differential Revision: http://reviews.llvm.org/D21116

llvm-svn: 272167
2016-06-08 16:39:43 +00:00
Xinliang David Li f88d3b9afb [profile] Pass extra build flags (feature enabling macros) to Darwin build
Differential Revision: http://reviews.llvm.org/D21119

llvm-svn: 272162
2016-06-08 16:21:35 +00:00
Vedant Kumar 33b8b64aef [profile] Un-hide two symbols
- lprofCurFilename was intended to have external visibility. This is
  pending further discussion.
- The raw version number doesn't need to be hidden: hiding it may make
  it easier to accidentally combine FE/IR profiles.

See the mailing list discussion on r272081.

llvm-svn: 272089
2016-06-08 01:33:15 +00:00
Vedant Kumar b202ad6518 [profile] Hide a few external symbols (NFCI)
There are still a few external symbols visible from InstrProfData.inc.
The plan for dealing with those isn't as straightforward, so I'll try it
in a separate commit.

llvm-svn: 272081
2016-06-08 00:44:38 +00:00
Derek Bruening ff5cafa2ec [esan] Intercept calloc to avoid deadlocks with tcmalloc
Summary:
When tcmalloc initializes before esan, esan's initialization ends up
calling back into tcmalloc due to the calloc done by dlsym.  This results
in a deadlock.  We avoid this by special-casing this single allocation.

Intercepting calloc also gives us the opportunity to act on its zeroing as
stores by the application.

Reviewers: aizatsky

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

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

llvm-svn: 272076
2016-06-08 00:00:27 +00:00
Kuba Brecka 688c3d3bf1 [asan] Turn LSan-related #if’s into regular if’s in ASan initializer
Removing some preprocessor #if’s in favor of regular if’s. However, we need to declare empty stub functions to avoid linker errors.

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

llvm-svn: 272047
2016-06-07 19:13:38 +00:00
Adhemerval Zanella 2c8fc6f8c9 [sanitizer] Fix build for new GLIBC msghdr/cmsghdr definition
GLIBC now follows POSIX [1] for both msghdr and cmsghdr definitions,
which means that msg_iovlen, msg_controllen, and cmsg_len are no
longer size_t but sockelen_t for 64-bits architectures. The final struct
size does not change, since paddings were added.

This patch fixes the build issue against GLIBC 2.24 socket.h header by
using the same definition for internal __sanitizer_msghdr and
__sanitizer_cmsghdr.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/

llvm-svn: 272008
2016-06-07 13:19:38 +00:00
Kostya Serebryany 712fc9803a [sanitizer] Initial implementation of a Hardened Allocator
Summary:
This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator.
It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast.
The following were implemented:
- additional consistency checks on the allocation function parameters and on the heap chunks;
- use of checksum protected chunk header, to detect corruption;
- randomness to the allocator base;
- delayed freelist (quarantine), to mitigate use after free and overall determinism.
Additional mitigations are in the works.

Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc

Subscribers: kubabrecka, filcab, llvm-commits

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

llvm-svn: 271968
2016-06-07 01:20:26 +00:00
Xinliang David Li 0891b6d59b [profile] code cleanup /NFC
Address review feedback for better
readability.

llvm-svn: 271922
2016-06-06 18:31:29 +00:00
Kuba Brecka 304b2c2a45 [tsan] Switch to InternalAlloc everywhere __libc_malloc is currently used
This patch replaces all uses of __libc_malloc and friends with the internal allocator.

It seems that the only reason why we have calls to __libc_malloc in the first place was the lack of the internal allocator at the time. Using the internal allocator will also make sure that the system allocator is never used (this is the same behavior as ASan), and we don’t have to worry about working with unknown pointers coming from the system allocator.

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

llvm-svn: 271916
2016-06-06 18:18:47 +00:00
Etienne Bergeron 7a1bafd6ae This patch attempts to primitive support for Win64 asan
Some known issues are:

When "head" include instructions that involve branching, the "cut and paste" approach may break down in a way that function interception still work but calling back the original function does not work.
The jmp [rip -8] saves some bytes in the "head" but finding the safe zone of 0xCC is not implemented yet. So it may stomp on preceding codes.
The shadow offset is not working yet on Win64. More complexity maybe involved since there are some differences regarding virtual address space between Window 8 and Windows 8.1/10.

Patch by: Wang Wei

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

llvm-svn: 271915
2016-06-06 18:09:54 +00:00
Kuba Brecka cdf3492191 [tsan] On OS X, optimize main thread’s ThreadState accesses
This is a very simple optimization that gets about 10% speedup for certain programs. We’re currently storing the pointer to the main thread’s ThreadState, but we can store the state directly in a static variable, which avoid the load acquire.

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

llvm-svn: 271906
2016-06-06 16:27:38 +00:00
Xinliang David Li 5cd1f94d4f [profile] in-process mergeing support (part-2)
(Part-1 merging API is in profile runtime)

This patch implements a portable file opening API
with exclusive access for the process. In-process
profile merge requires profile file update to be
atomic/fully sychronized.

llvm-svn: 271864
2016-06-06 03:17:58 +00:00
Kuba Brecka 312071943c [tsan] On OS X, build Go runtime with -mmacosx-version-min
We're not building the Go runtime with -mmacosx-version-min, which means it'll have a minimum deployment target set to the system you're building on. Let's make the code compile (and link) with -mmacosx-version-min=10.7.

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

llvm-svn: 271833
2016-06-05 15:15:36 +00:00
Derek Bruening c1c67d651d [esan] Initialize runtime during early interceptors
Summary:
Adds initialization of esan's runtime library during any early interceptors
that are sometimes called prior to the official __esan_init() invocation
(we see this with apps using tcmalloc).

Adds handling of interceptors called during interceptor initialization.

Reviewers: aizatsky

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

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

llvm-svn: 271744
2016-06-03 22:30:10 +00:00
Qin Zhao bc929e4765 [esan|cfrag] Compute the struct field access difference ratio
Summary:
Computes the struct field access variation based on each field access
count.

Adds a flag to control the report thresholds.

Updates struct-simple.cpp with variance report output.

Reviewers: aizatsky

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

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

llvm-svn: 271734
2016-06-03 20:48:17 +00:00
Derek Bruening 328e899301 [esan] Specify which tool via a global variable
Summary:
Adds a global variable to specify the tool, to support handling early
interceptors that invoke instrumented code, thus requiring shadow memory to
be initialized prior to __esan_init() being invoked.

Reviewers: aizatsky

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

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

llvm-svn: 271714
2016-06-03 19:40:08 +00:00
Derek Bruening e78e4a6e94 [esan|wset] Add 8-level working set snapshot accumulation
Summary:
Adds a new option -snapshot_step controlling the frequency distribution for
an 8-level series of samples using each bit of each shadow byte.
Implements accumulation from each level to the next higher level at the
specified frequency.

Adds storage of the 8 series of samples using CircularBuffer instances.
Fixes an error in the circular buffer data structure where a static
object's destructor will be called too early.

Prints the results out at the end in a simple manner to give us something
to start with.

Updates the workingset-samples test to test the new feature.

Reviewers: aizatsky

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

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

llvm-svn: 271683
2016-06-03 16:27:50 +00:00
Derek Bruening 07814769a8 [esan] Add sideline itimer support
Summary:
Adds support for creating a separate thread for performing "sideline"
actions on a periodic basis via an itimer.  A new class SidelineThread
implements this feature, exposing a sampling callback to the caller.

Adds initial usage of sideline sampling to the working set tool.  For now
it simply prints the usage at each snapshot at verbosity level 1.  Adds a
test of this behavior.  Adds a new option -record_snapshots to control
whether we sample and a new option -sample_freq to control the periodicity
of the sampling.

Reviewers: aizatsky

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

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

llvm-svn: 271682
2016-06-03 16:14:07 +00:00
Dmitry Vyukov 0f7e949a42 tsan: rely on AnnotateRWLockCreateStatic to detect linker-initialized mutexes
The new annotation was added a while ago, but was not actually used.
Use the annotation to detect linker-initialized mutexes instead
of the broken IsGlobalVar which has both false positives and false
negatives. Remove IsGlobalVar mess.

llvm-svn: 271663
2016-06-03 11:48:27 +00:00
Derek Bruening a601c2ada2 [esan] Ensure internal_sigaction() bypasses interceptors
Summary:
Implements real_sigaction() which it turns out is required for
internal_sigaction() to bypass the libc interceptors.

Without real_sigaction(), our internal_sigaction() calls during init happen
to work due to the EsanDuringInit check in COMMON_INTERCEPTOR_ENTER (though
even here it does not feel right for an "internal_" call to go through the
interceptor).  The real problem is when we call internal_sigaction() after
we're initialized, which only happens on an unhandled SIGSEGV for which the
app has no handler: then we'll spin in an infinite loop as our attempts to
remove our own handler repeatedly fail.  It's not easy to add a test for
that, unfortunately.

Reviewers: aizatsky

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

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

llvm-svn: 271626
2016-06-03 04:30:47 +00:00
Derek Bruening 0b04950116 [esan] Add support for log_exe_name
Summary:
Adds the call needed to cache the binary name to support the sanitizer
option log_exe_name for usable log file results when running multiple
applications.  Adds a test.

Reviewers: aizatsky

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

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

llvm-svn: 271586
2016-06-02 20:50:30 +00:00
Dmitry Vyukov 1ae44e6a2b tsan: clean up dynamic TLS memory between reuse
Currently the added test produces false race reports with glibc 2.19,
because DLTS memory is reused by pthread under the hood.

Use the DTLS machinery to intercept new DTLS ranges.
__tls_get_addr known to cause issues for tsan in the past,
so write the interceptor more carefully.

Reviewed in http://reviews.llvm.org/D20927

llvm-svn: 271568
2016-06-02 19:18:22 +00:00
Qin Zhao 4175a6d580 [esan|cfrag] Add struct info registration
Summary:
Adds StructInfo to CacheFragInfo to match the LLVM's EfficiencySanitizer
structs.

Uses StructHashMap to keep track of the struct info used by the app.

Adds registerStructInfo/unregisterStructInfo to add/remove struct infos
to/from StructHashMap.

updates test struct-simple.cpp with more C structs.

Reviewers: aizatsky, filcab

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

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

llvm-svn: 271564
2016-06-02 18:45:25 +00:00
Ivan Krasin 048155c399 UBSan: crash less often on corrupted Vtables.
Summary:
This CL adds a weak check for a Vtable prefix: for a well-formed
Vtable, we require the prefix to be within [-1<<20; 1<<20].

Practically, this solves most of the known cases when UBSan segfaults
without providing any useful diagnostics.

Reviewers: pcc

Subscribers: kubabrecka

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

llvm-svn: 271560
2016-06-02 18:36:12 +00:00
Kostya Serebryany 3e7bf586f8 [asan] fix arm build
llvm-svn: 271474
2016-06-02 04:01:58 +00:00
Kostya Serebryany 5a7159c416 [asan] add an interface function __sanitizer_print_memory_profile (a basic memory profiler; asan/Linux-only for now)
llvm-svn: 271463
2016-06-02 01:21:52 +00:00
Xinliang David Li 96dad78963 [profile] Fix PR/27917
Skip the last (possibly) incomplete node from padding bytes.

llvm-svn: 271349
2016-05-31 23:12:13 +00:00
Qin Zhao 9e39638375 [esan|cfrag] Add the skeleton to handle the cfrag argument
Summary:
Adds the struct declaration for the cache-fragmentation tool variable
passed to the runtime library.

Updates test struct-simple.cpp.

Reviewers: aizatsky, bruening

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

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

llvm-svn: 271337
2016-05-31 21:27:39 +00:00
Chris Bieneman 5c3112cebe [CMake] Update to requiring CMake 3.4.3
Summary:
This is as per the discussions on developer lists:

http://lists.llvm.org/pipermail/llvm-dev/2016-April/098780.html
http://lists.llvm.org/pipermail/llvm-dev/2016-May/100058.html

Subscribers: llvm-commits

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

llvm-svn: 271327
2016-05-31 20:21:42 +00:00
Xinliang David Li b6d5f0b86f Local var name change /NFC
llvm-svn: 271304
2016-05-31 17:41:06 +00:00
Derek Bruening b7e38d8821 [esan] Add circular buffer data structure
Summary:
Adds a new class, CircularBuffer, for holding a wrap-around fixed-size
sequence of a primitive data type.  This will be used initially by the
working set tool.

Adds a unit test for CircularBuffer, including infrastructure support to
include esan headers and to link with the esan library by pretending to
want the working set tool.

Reviewers: aizatsky, filcab

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

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

llvm-svn: 271286
2016-05-31 14:44:49 +00:00
Derek Bruening 8ef3f0fa5b [esan|wset] Iterate all memory to compute the total working set
Summary:
Adds iteration of all application memory in an efficient manner using
shadow faults.  Shadow memory starts out inaccessible and we mark it
writable one page at a time on each fault when the instrumentation touches
it.  This allows iteration over just the mapped shadow memory, saving
significant time.

Adds a process-end iteration and pretty-printing of the final result.

Adds a new test and updates the existing tests.

Reviewers: aizatsky, filcab

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

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

llvm-svn: 271277
2016-05-31 13:41:07 +00:00
Derek Bruening 8e74c1084b [esan] Intercept and chain signal handlers
Summary:
In preparation for fault-based shadow memory iteration, we add support for
our own signal handler by adding app signal handler interception as well as
chaining for SIGSEGV.  This is done in a simple manner: we do not honor the
app's alternate stack nor any sigaction flags for SIGSEGV.

Adds a new test of transparency in app signal handling.

Reviewers: aizatsky

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

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

llvm-svn: 271272
2016-05-31 13:21:03 +00:00
Benjamin Kramer d53e3655e2 __builtin_ia32_storeups is no more. Replace it with xmmintrin.h intrinsic.
llvm-svn: 271257
2016-05-31 09:16:40 +00:00
Kuba Brecka 75b3da75b5 [asan] Fix a deadlock halt_on_error-signals.c when `reporting_thread_tid_` is 0
A signal can be delivered after TryLock but before StartReporting in ScopedInErrorReport, causing a deadlock.  Fixing this by statically initializing reporting_thread_tid_ to kInvalidTid.

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

llvm-svn: 271256
2016-05-31 08:47:18 +00:00
Benjamin Kramer 1539cd326e Update asan_win_dll_thunk.cc to fix the windows buildbot.
llvm-svn: 271203
2016-05-30 10:00:54 +00:00
Benjamin Kramer 4acc312e47 Add __sanitizer_set_report_fd to the internal list of symbols.
Otherwise it will get the wrong visibility in the resulting library.

llvm-svn: 271202
2016-05-30 09:39:47 +00:00
Kostya Serebryany e31e778160 [sanitizers] introduce a common run-time option dedup_token_length to help with report deduplication, off by default for now. See https://github.com/google/sanitizers/issues/684
llvm-svn: 271085
2016-05-28 01:25:44 +00:00
Derek Bruening 909d32955b [esan] Add handling of large stack size rlimits
Summary:
Adds detection of large stack size rlimits (over 1 TB or unlimited), which
results in an mmap location that our shadow mapping does not support.  We
re-exec the application in this situation.  Adds a test of this behavior.

Adds general detection of mmap regions outside of our app regions.  In the
future we want to try to adaptively handle these but for now we abort.

Moves the existing Linux-specific mmap code into a platform-specific file
where the new rlimit code lives.

Reviewers: eugenis

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

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

llvm-svn: 271079
2016-05-28 00:25:16 +00:00
Kostya Serebryany d9a451ab0d [sanitizer] Move termination functions in their own file
Summary:
As suggested by kcc@ in http://reviews.llvm.org/D20084#441418, move the CheckFailed and Die functions, and their associated callback functionalities in their own separate file.
I expended the build rules to include a new rule that would not include those termination functions, so that another project can define their own.
The tests check-{a,t,m,ub,l,e,df}san are all passing.

Reviewers: llvm-commits, kcc

Subscribers: kubabrecka

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

llvm-svn: 271055
2016-05-27 21:57:17 +00:00
Kostya Serebryany 54b7162692 [sanitizers] trying to fix Windows build
llvm-svn: 271050
2016-05-27 21:35:58 +00:00
Etienne Bergeron 00f3f6e296 This patch is activating the build of Asan on Windows 64-bits.
It's fixing compilation errors. The runtime is not yet working.

Missing features:

OverrideFunction for x64
an equiv function for inline asm (atomic_compare_exchange_strong)
shadow memory offset needs to be adjusted
RoundUpToInstrBoundary for x64
They will be implemented by subsequent patches.

Patch by Wei Wang.

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

llvm-svn: 271049
2016-05-27 21:29:31 +00:00
Kostya Serebryany 1508f591b3 [sanitizers] introduce __sanitizer_set_report_fd so that we can re-route the sanitizer logging to another fd from inside the process
llvm-svn: 271046
2016-05-27 21:23:05 +00:00
Sean Silva e5e819b7d7 [profile] Avoid unused variable warning.
llvm-svn: 270969
2016-05-27 06:15:13 +00:00
Xinliang David Li 274cb1d224 Add portable macro in common header
llvm-svn: 270928
2016-05-26 22:15:12 +00:00
Xinliang David Li b033220085 Add segment prefix for darwin
llvm-svn: 270875
2016-05-26 17:21:24 +00:00
Vitaly Buka 132639120a Init tsan with .preinit_array section
Summary: Some libraries, like OpenSSL, runs code from .init section.

Reviewers: kcc, eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 270873
2016-05-26 17:05:36 +00:00
Xinliang David Li a290c9b47a Fix windows bot failure
llvm-svn: 270864
2016-05-26 16:21:11 +00:00
Xinliang David Li 555cf5efbd [profile] pre-allocate a small counter set in profile runtime
Tested with relavant benchmarks in SPEC2006

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

llvm-svn: 270862
2016-05-26 16:06:36 +00:00
Xinliang David Li 65971297a0 [profile] Add early checking to bypass node pointer update
llvm-svn: 270766
2016-05-25 21:27:02 +00:00
Sean Silva 5cf73b09cd [profile] Don't return `Node` when it is null.
The max warning check was masking the "return 0" codepath.

See the thread "Warnings and compile-time failure on 458.sjeng" for more
info.

llvm-svn: 270762
2016-05-25 21:08:38 +00:00
Qin Zhao 7e4933f430 [esan][cfrag] Add skeleton for cache fragmentation tool support
Summary:
Adds cache_frag.h and cache_frag.cpp for the cache fragmentation tool.

Updates test struct-simple.cpp.

Reviewers: aizatsky

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

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

llvm-svn: 270737
2016-05-25 17:49:00 +00:00
Xinliang David Li 7f08d12b0b [profile] Further cleanup/refactor file handling code
Also get rid of the redundant strncpy calls.

llvm-svn: 270730
2016-05-25 17:30:15 +00:00
Teresa Johnson c249167e90 Fix braced initializer list (NFC)
After r270617 I am getting an error when building:

projects/compiler-rt/lib/profile/InstrProfilingFile.c:33:36:
error: missing field 'PidChars' initializer
[-Werror,-Wmissing-field-initializers]
lprofFilename lprofCurFilename = {0};
                                   ^

Fix the aggregate initializer.

llvm-svn: 270697
2016-05-25 13:58:54 +00:00
Derek Bruening 88639859db Add working set base runtime library
Summary:
Adds the base runtime library for the working set tool.
Adds slowpath code for updating the shadow memory.

To be added in the future:
+ Scan memory and report the total size.
+ Take samples for intermediate values.

Reviewers: aizatsky

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

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

llvm-svn: 270650
2016-05-25 02:04:04 +00:00
Derek Bruening 7004e06b80 [esan] Add compilation unit init/exit routines.
Summary:
Adds processCompilationUnitInit and processCompilationUnitExit
for compilation unit init/exit.

Adds a tool-specific argument passed to esan_init.

Adds the dtor and esan_exit called from the dtor.

A test will be added separately (adding it here results in failure until
the corresponding compilation patch is in place).

Reviewers: aizatsky

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

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

llvm-svn: 270624
2016-05-24 22:22:20 +00:00
Xinliang David Li 315e49d213 [profile] clean up profile file handling code
Differentianl Revision: http://reviews.llvm.org/D20572

llvm-svn: 270617
2016-05-24 21:29:18 +00:00
Evgeniy Stepanov 7b6f275b6a [asan] Workaround LD_PRELOAD bug in the Android linker.
llvm-svn: 270616
2016-05-24 21:25:00 +00:00
Xinliang David Li 41518945e3 Fix typo in comment
llvm-svn: 270524
2016-05-24 02:37:07 +00:00
Xinliang David Li 51fe002e67 [profile] clean up file initialization code
Also added more documentation.

llvm-svn: 270519
2016-05-24 01:23:09 +00:00
Xinliang David Li 66a891962b [profile] clean up runtime warnings.
o make warning message more meaningful to users.
 o add suggestion to fix the problem
 o limit the max number of output.

llvm-svn: 270483
2016-05-23 20:08:58 +00:00
Xinliang David Li 7b41393497 [profile] initialize static pool properly
Remove dependency on runtime initializer to avoid
issues related to initialization order.

llvm-svn: 270371
2016-05-22 16:36:03 +00:00
Xinliang David Li 9235d9f6d7 bug fix: trim section specifier name length
llvm-svn: 270350
2016-05-22 01:21:31 +00:00
Xinliang David Li 31023d3061 Fix a typo (darwin only)
llvm-svn: 270339
2016-05-21 23:27:18 +00:00
Xinliang David Li 2a99857e1a Fix typo
llvm-svn: 270338
2016-05-21 23:06:39 +00:00
Xinliang David Li 4e8754d2cb [profile] Static counter allocation for value profiling (part-2)
Differential Revision: http://reviews.llvm.org/D20460

llvm-svn: 270337
2016-05-21 22:55:45 +00:00
Kuba Brecka 0287e17d09 [tsan] Don't abort when a deadlock detector finds a mutex cycle longer than 10
In one of the already existing apps that I'm testing TSan on, I really see a mutex path that is longer than 10 (but not by much, something like 11-13 actually). Let's raise this to 20 and weaken the assertion so we don't crash.

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

llvm-svn: 270319
2016-05-21 08:31:13 +00:00
Derek Bruening a85de06dd2 [esan] Add custom flag support
Summary:
Adds custom flag support to EfficiencySanitizer's runtime library.

Adds an initial flag cache_line_size which will be used by multiple tools.

Reviewers: aizatsky, vitalybuka

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

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

llvm-svn: 270256
2016-05-20 19:26:52 +00:00
Derek Bruening c7f4922524 [esan] Extend shadow mapping to cover low libraries
Summary:
Adds support for app libraries starting slightly below 0x7f00'00000000 (the
mmap ASLR range extends down to 0x7efb'f8000000 for reasonable stack
limits) by switching to a shadow mapping offset of 0x1300'00000000.

Reviewers: aizatsky

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

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

llvm-svn: 270255
2016-05-20 19:19:06 +00:00
Sean Silva 357b0e3a7c Use C-style comment.
I think we allow use of C99 for libprofile, but use a C-style comment
for consistency.

llvm-svn: 270187
2016-05-20 06:13:07 +00:00
Xinliang David Li fb320a1137 Fix bot failure
llvm-svn: 270186
2016-05-20 05:40:07 +00:00
Xinliang David Li 690c31f104 [profile] PROF_ERR, PROF_WARN
1) Move common prefix to the macro def
 2) Introduced PROF_WARN
 3) Make error message unconditionally printed out.

llvm-svn: 270185
2016-05-20 05:15:42 +00:00
Xinliang David Li 71eddbf540 [profile] Remove anther malloc use
llvm-svn: 270181
2016-05-20 04:52:27 +00:00
Sean Silva b01e4b7727 Add #include for PS4 getenv shim.
llvm-svn: 270179
2016-05-20 03:43:39 +00:00
Sean Silva 29e434769e Small typo and whitespace fix.
llvm-svn: 270177
2016-05-20 03:25:15 +00:00
Xinliang David Li 5f153e686e [profile] entry eviction support in value profiler
Differential revision: http://reviews.llvm.org/D20408

llvm-svn: 270141
2016-05-19 21:35:34 +00:00
Benjamin Kramer f9679e89a1 Revert "[sanitizer] Move *fstat to the common interceptors"
This reverts commit r269981. Breaks msan tests on linux
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24019/steps/test%20standalone%20compiler-rt/logs/stdio

llvm-svn: 270076
2016-05-19 16:03:10 +00:00
Kuba Brecka ed29c21d5d [tsan] Add support for GCD's dispatch_after and dispatch_after_f
We're missing interceptors for dispatch_after and dispatch_after_f. Let's add them to avoid false positives. Added a test case.

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

llvm-svn: 270071
2016-05-19 15:31:42 +00:00
Kuba Brecka 4087675948 Revert r270038 ("Change preprocessor `#if` to regular `if` for CAN_SANITIZE_LEAKS")
llvm-svn: 270044
2016-05-19 11:21:34 +00:00
Kuba Brecka b5cb227b98 [asan] Change preprocessor `#if` to regular `if` for CAN_SANITIZE_LEAKS
llvm-svn: 270038
2016-05-19 10:43:51 +00:00
Vedant Kumar 3afe657030 Reapply^3 "[ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC"
Sync up with "(llvm) Use Error in InstrProf and Coverage".

llvm-svn: 270022
2016-05-19 03:55:20 +00:00
Sean Silva aa705eccbe Fix typo.
llvm-svn: 270005
2016-05-19 00:12:02 +00:00
Xinliang David Li 4617aa7827 [profile] Allow max vals per site to be controllable at runtime
llvm-svn: 269993
2016-05-18 22:34:05 +00:00
Mike Aizatsky 522afdd77e [sanitizer] Move *fstat to the common interceptors
Summary:
Adds *fstat to the common interceptors.

Removes the now-duplicate fstat interceptor from msan/tsan
This adds fstat to asan/esan, which previously did not intercept it.

Resubmit of http://reviews.llvm.org/D20318 with ios build fixes.

Reviewers: eugenis, vitalybuka, aizatsky

Subscribers: zaks.anna, kcc, bruening, kubabrecka, srhines, danalbert, tberghammer

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

llvm-svn: 269981
2016-05-18 20:49:49 +00:00
Xinliang David Li 32173153a4 [profile] add runtime variable documentation
llvm-svn: 269964
2016-05-18 17:44:57 +00:00
Francis Ricci 233a364bd8 [sanitizer] Allow dlopen/dlclose interception to be disabled from cmake
Summary:
dlopen and dlclose interception are broken when RUNPATH is used:
https://llvm.org/bugs/show_bug.cgi?id=27790

Reviewers: kutuzov.viktor.84, samsonov, dvyukov, eugenis, kcc

Subscribers: kcc, filcab, kubabrecka, compnerd, llvm-commits

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

llvm-svn: 269947
2016-05-18 16:05:52 +00:00
Kuba Brecka daac6a0083 [sanitizer] Fix a crash when demangling Swift symbols, take 3
The previous patch (r269291) was reverted (commented out) because the patch caused leaks that
were detected by LSan and they broke some lit tests.  The actual reason was that dlsym allocates
an error string buffer in TLS, and some LSan lit tests are intentionally not scanning TLS for
root pointers.  This patch simply makes LSan ignore the allocation from dlsym, because it's
not interesting anyway.

llvm-svn: 269917
2016-05-18 13:00:20 +00:00
Sagar Thakur 7bec3a94c6 [LSAN] Fix test swapcontext.cc on MIPS
There is no frame validity check in the slow unwinder like there is in the fast unwinder due to which lsan reports a leak even for heap allocated coroutine in the test swapcontext.cc. Since mips/linux uses slow unwindwer instead of fast unwinder, the test fails for mips/linux. Therefore adding the checks before unwinding fixes the test for mips/linux.

Reviewed by aizatsky.
Differential: http://reviews.llvm.org/D19961

llvm-svn: 269882
2016-05-18 06:09:26 +00:00
Mike Aizatsky 41c2afe5d9 Revert "[sanitizer] Move *fstat to the common interceptors"
This reverts commit http://reviews.llvm.org/rL269856

llvm-svn: 269863
2016-05-17 23:28:56 +00:00
Mike Aizatsky 924acb50c9 [sanitizer] Move *fstat to the common interceptors
Summary:
Adds *fstat to the common interceptors.

Removes the now-duplicate fstat interceptor from msan/tsan
This adds fstat to asan/esan, which previously did not intercept it.

Reviewers: eugenis, vitalybuka, aizatsky

Subscribers: tberghammer, danalbert, srhines, kubabrecka, bruening, kcc

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

llvm-svn: 269856
2016-05-17 22:26:50 +00:00
Anna Zaks 7d47c990e6 [tsan] Ensure mmap respects ignore_interceptors_accesses
The ignore_interceptors_accesses setting did not have an effect on mmap, so
let's change that. It helps in cases user code is accessing the memory
written to by mmap when the synchronization is ensured by the code that
does not get rebuilt.

(This effects Swift interoperability since it's runtime is mapping memory
which gets accessed by the code emitted into the Swift application by the
compiler.)

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

llvm-svn: 269855
2016-05-17 22:24:55 +00:00
Derek Bruening 1f6d861ac2 [esan] Fix isShadowMem endpoint bug
Fixes a bug in checking the endpoint of a shadow region and removes an
invalid check (both introduced in http://reviews.llvm.org/rL269198).

llvm-svn: 269834
2016-05-17 20:44:09 +00:00
Mike Aizatsky 599eef49e5 [sanitizers] disabling LateInitialize call to fix the build.
http://reviews.llvm.org/rL269291 introduced a memory leak.
Disabling offending call temprorary rather than rolling back the chain
of CLs.

llvm-svn: 269799
2016-05-17 18:44:21 +00:00
Maxim Ostapenko 02c21b3ef9 [asan] Don't raise false alarm to recv/recvfrom when MSG_TRUNC is present.
Fix https://llvm.org/bugs/show_bug.cgi?id=27673.

Currenty ASan checks the return value of real recv/recvfrom to see if the written bytes fit in the buffer. That works fine most of time.
However, there is an exception: (from the RECV(2) man page)

MSG_TRUNC (since Linux 2.2)
    ... return the real length of the packet or datagram, even when it was longer than the passed buffer. ...

Some programs combine MSG_TRUNC, MSG_PEEK and a single-byte buffer to peek the incoming data size without reading (much of) them. In this case,
the return value is usually longer than what's been written and ASan raises a false alarm here. To avoid such false positive reports,
we can use min(res, len) in COMMON_INTERCEPTOR_WRITE_RANGE checks.

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

llvm-svn: 269749
2016-05-17 07:38:27 +00:00
Sean Silva cfec6c6a28 Avoid leak. Free before resetting.
llvm-svn: 269724
2016-05-16 23:28:35 +00:00
Xinliang David Li 21d38c5eaf [profile] Add portability macro for atomic fetch_and_add
This is another enabler patch to support value profiling
without dynamic memory allocation.

llvm-svn: 269719
2016-05-16 23:01:03 +00:00
Vedant Kumar 533a88a5c9 Revert "Reapply^2 "[ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC""
This reverts commit r269696. The llvm commit does not pass the MSVC bot.

llvm-svn: 269702
2016-05-16 21:05:05 +00:00
Vedant Kumar cd5efa593b Reapply^2 "[ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC"
Sync up with "(llvm) Use Error in InstrProf and Coverage".

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

llvm-svn: 269696
2016-05-16 20:50:36 +00:00
Xinliang David Li f90425e73b [profile] minor code restructuring /NFC
This is one of the enabler patch to allow value profiler to 
allocate counter statically.

llvm-svn: 269689
2016-05-16 20:33:30 +00:00
Paul Robinson 595b969c67 [PS4] Change the names of some "environmental" things to what our
licensees actually see in the toolchain we deliver to them.  This will
reduce the set of local patches we have to maintain.  The triple is
not changing.  (The term ORBIS is an internal code name for PS4.)

llvm-svn: 269672
2016-05-16 17:22:32 +00:00
Etienne Bergeron 3df2879232 [compiler-rt] Fix multi-configuration output paths
Summary:
When using a multi-configuration build (i.e. MSVC) the output path where
libraries are dropped is incorrect.

Example:
```
C:\src\llvm\examples>d:\src\llvm\build\Release\bin\clang-cl.exe -fsanitize=address test.cc
LINK : fatal error LNK1181: cannot open input file 'd:\src\llvm\build\Release\bin\..\lib\clang\3.9.0\lib\windows\clang_rt.asan-i386.lib'
```

The dropped executable path contains the configuration 'Release':
```
'd:\src\llvm\build\Release\bin\..\lib\clang\3.9.0\lib\windows\Release\clang_rt.asan-i386.lib'
```


The variable 'RUNTIME_OUTPUT_DIRECTORY' is used to specify the output directory.
But CMAKE is appending the current configuration (i.e. Debug, Release).

see: https://cmake.org/cmake/help/v3.0/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html
```
"Multi-configuration generators (VS, Xcode) append a per-configuration subdirectory to the specified directory."
```

To avoid this problem, the configuration specific variable must be set:
'RUNTIME_OUTPUT_DIRECTORY_DEBUG', 'RUNTIME_OUTPUT_DIRECTORY_RELEASE', and so on.

Reviewers: ddunbar, chapuni, rnk

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 269658
2016-05-16 14:58:07 +00:00
Maxim Ostapenko 187043f61e [asan] Fix asan initialization failure with newer (2.23+) glibc in use.
This patch tries to fix https://llvm.org/bugs/show_bug.cgi?id=27310 by using the same hack for malloc as we use for calloc: allocate corresponding memory from internal buffer when ASan is not initialized.
This way we could avoid nasty '==6987==AddressSanitizer CHECK failed: ../../../../libsanitizer/asan/asan_rtl.cc:556 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0)' errors in
environments with glibc 2.23+ in use, where _dl_signal_error, called from dlsym for undefined symbols calls malloc in order to get a buffer for error message.

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

llvm-svn: 269633
2016-05-16 07:20:53 +00:00
Xinliang David Li 6c7bddb28b Use __builtin_alloca with __GNUC__
llvm-svn: 269592
2016-05-15 16:41:58 +00:00
Xinliang David Li fedb0fd907 Fix FreeBSD build failure
llvm-svn: 269587
2016-05-15 04:26:17 +00:00
Xinliang David Li 23a66e45ed [profile] Eliminate dynamic memory allocation for vp writing
This is part-3 of the effort to eliminate dependency on
libc allocator in instr profiler runtime. With this change,
the profile dumper is completely free of malloc/calloc. 
Value profile instr API implementation is the only remaining
piece with calloc dependency.

llvm-svn: 269576
2016-05-14 20:12:42 +00:00
Chandler Carruth a3cd590644 Revert "Reapply "[ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC""
This reverts commit r269493 as the corresponding LLVM commit was
reverted due to lots of warnings. See the review thread for the original
LLVM commit (r269491) for details.

llvm-svn: 269550
2016-05-14 05:40:00 +00:00
Xinliang David Li a16c754e17 minor cleanup -- reset buffer pointer
llvm-svn: 269533
2016-05-14 03:16:47 +00:00
Vedant Kumar be1b4e4dc6 Reapply "[ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC"
Sync up with "(llvm) Use Error in InstrProf and Coverage".

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

llvm-svn: 269493
2016-05-13 21:51:06 +00:00
Vedant Kumar bd3c2f25fa Revert "(HEAD -> master, origin/master, origin/HEAD) [ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC"
This reverts commit r269464. It fails two llvm-profdata tests.

llvm-svn: 269469
2016-05-13 20:10:49 +00:00
Vedant Kumar 6ecc10ab80 [ProfileData] (compiler-rt) Use Error in InstrProf and Coverage, NFC
Sync up with "(llvm) Use Error in InstrProf and Coverage".

llvm-svn: 269464
2016-05-13 20:01:38 +00:00
Xinliang David Li 609fae3893 [profile] Eliminate dynamic memory allocation for buffered writer
With this change, dynamic memory allocation is only used
for testing purpose. This change is one of the many steps to
make instrument profiler dynamic allocation free.

llvm-svn: 269453
2016-05-13 18:26:26 +00:00
Xinliang David Li d1dadf6bcf [profile] Code refactoring
Move runtime specific code from the common header file
to runtime source.

llvm-svn: 269357
2016-05-12 21:43:49 +00:00
Xinliang David Li 911af1ce15 Minor code refactoring /NFC
llvm-svn: 269351
2016-05-12 21:18:41 +00:00
Kuba Brecka a4c5bef998 More fixup for r269288 and r269296. Adding the missing 'return'.
llvm-svn: 269310
2016-05-12 16:58:19 +00:00
Kuba Brecka 11d3926cf6 [sanitizer] Allow nullptr in Swift demangler
The introduction of the Swift demangler now causes an assertion failure when we
try to demangle nullptr, but we used to allow that (and return nullptr back).
This situation is rare, but it can still happen.  Let's allow nullptr.

llvm-svn: 269302
2016-05-12 15:54:33 +00:00
Daniel Sanders 9ede03d4f2 [mips][sanitizer_common] Don't use `ld` in internal_clone() on 32-bit MIPS.
Summary:
On a 32-bit MIPS, the `ld` instruction does not exist. However, GAS has an `ld`
macro that expands to a pair of `lw` instructions which load to a pair of
registers (reg, and reg+1). This macro is not available in the Integrated
Assembler and its use causes -fintegrated-as builds to fail. Even if it were
available, the behaviour on 32-bit MIPS would be incorrect since the current
usage of `ld` causes the code to clobber $5 (which is supposed to hold
child_stack). It also clobbers $k0 which is reserved for kernel use.

Aside from enabling builds with the integrated assembler, there is no functional
change since internal_clone() is only used by StopTheWorld() which is only used
by 64-bit sanitizers.

Reviewers: kcc, sagar

Subscribers: mohit.bhakkad, jaydeep, sagar, llvm-commits

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

llvm-svn: 269297
2016-05-12 14:21:33 +00:00
Kuba Brecka 00dde7563e Fixup for r269288. SleepForSeconds is not available in nolibc builds, let's add an internal_sleep.
llvm-svn: 269296
2016-05-12 14:08:56 +00:00
Kuba Brecka 3a0736e279 Fixup for r269291, which broke the Go TSan build. Let's not use the symbolizer in Go builds.
llvm-svn: 269293
2016-05-12 13:28:45 +00:00
Kuba Brecka 5bdf86ec7c [sanitizer] Fix a crash when demangling Swift symbols, take 2
To invoke the Swift demangler, we use dlsym to locate swift_demangle. However, dlsym malloc's storage and stores it in thread-local storage. Since allocations from the symbolizer are done with the system allocator (at least in TSan, interceptors are skipped when inside the symbolizer), we will crash when we try to deallocate later using the sanitizer allocator again.

To fix this, let's just not call dlsym from the demangler, and call it during initialization. The dlsym function calls malloc, so it needs to be only used after our allocator is initialized. Adding a Symbolizer::LateInitialize call that is only invoked after all other initializations.

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

llvm-svn: 269291
2016-05-12 13:11:03 +00:00
Kuba Brecka 3f6f8de238 [sanitizer] On OS X, exit the forked process gracefully when login_tty fails
We're using forkpty to spawn the atos symbolizer. In some cases, login_tty (part of forkpty) can fail due to security measures (sandboxing). In this case, we should exit with a status code instead of completely crashing the spawned process. Even processing a failed CHECK() is problematic here, because we're post-fork and pre-exec where a lot of things don't work (for multithreaded processes, for OS X GUI apps, etc.).

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

llvm-svn: 269289
2016-05-12 12:53:43 +00:00
Kuba Brecka e0c8256781 [sanitizer] Break infinite recursion in case of recursive failed CHECKs
While debugging ASan and TSan, I sometimes get a recursion during a failed CHECK processing.  CheckFailed can call a lot of code (printing, unwinding a stack trace, symbolicating, ...) and this can fail another CHECK. This means I sometimes see a crash due to a infinite recursion stack overflow. Let's stop after 10 failed CHECKs and just kill the process immediately. I also added a Sleep(2) call before the trap, so that other threads still get a chance to print their failed CHECKs.

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

llvm-svn: 269288
2016-05-12 12:49:53 +00:00
Xinliang David Li 667de6a84e [profile] profile writing cleanup
Do not precompute value counts for all sites. This 
eliminates one more use of dynamic allocation 
in profiler writer.

llvm-svn: 269254
2016-05-11 23:21:22 +00:00
Xinliang David Li eb836a3dec cleanup: Enforce caller to set total size to avoid redundant size compute
llvm-svn: 269237
2016-05-11 21:16:11 +00:00
Evgeniy Stepanov 556e963e4e [asan] Don't use libcorkscrew on Android L+.
ASan runtime library used libcorkscrew from Android platform for
stack unwinding. Since Android L, this is both unnecessary (the
libgcc unwinder has been fixed) and impossible (the library is not
there any more). Don't even try.

This should have not effect on modern Android devices other than
removing a message about failing to open the library with
ASAN_OPTIONS=verbosity=1.

llvm-svn: 269233
2016-05-11 20:53:43 +00:00
Evgeniy Stepanov feb73c8566 [sanitizer] Move *stat to the common interceptors
Adds *stat to the common interceptors.

Removes the now-duplicate *stat interceptor from msan/tsan/esan.
This adds *stat to asan, which previously did not intercept it.

Patch by Qin Zhao.

llvm-svn: 269223
2016-05-11 20:02:15 +00:00
Derek Bruening 1658c089fd [esan] EfficiencySanitizer shadow memory
Summary:
Adds shadow memory mapping support common to all tools to the new
Efficiencysanitizer ("esan") family of tools.  This includes:

+ Shadow memory layout and mapping support for 64-bit Linux for any
  power-of-2 scale-down (1x, 2x, 4x, 8x, 16x, etc.) that ensures that
  shadow(shadow(address)) does not overlap shadow or application
  memory.

+ Mmap interception to ensure the application does not map on top of
  our shadow memory.

+ Init-time sanity checks for shadow regions.

+ A test of the mmap conflict mechanism.

Reviewers: aizatsky, filcab

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

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

llvm-svn: 269198
2016-05-11 15:47:54 +00:00
Dmitry Vyukov 2498629e34 tsan: fix another crash due to processors
Another stack where we try to free sync objects,
but don't have a processors is:

  //   ResetRange
  //   __interceptor_munmap
  //   __deallocate_stack
  //   start_thread
  //   clone

Again, it is a latent bug that lead to memory leaks.
Also, increase amount of memory we scan in MetaMap::ResetRange.
Without that the test does not fail, as we fail to free
the sync objects on stack.

llvm-svn: 269041
2016-05-10 11:19:50 +00:00
Xinliang David Li e9a8574da1 Reapply r268840: [profile] Simplify value profile writing
Revert r268864 that reverted 268840 after underlying problem
is fixed for arm bot.

llvm-svn: 268992
2016-05-10 00:17:31 +00:00
Marcin Koscielnicki a407f543c0 [MSan] Add a test for vararg with lots of non-vararg arguments.
This is a testcase for http://llvm.org/PR27646, hitting the bug on x86_64,
aarch64, mips.

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

llvm-svn: 268981
2016-05-09 21:53:47 +00:00
Chris Bieneman c49e5e336b [CMake] Support platform building builtins without a full toolchain
Summary:
This patch adds support for building lib/builtins without a fully functioning toolchain. It allows you to bootstrap a cross-compiler, which previously couldn't be done with CMake.

This patch contains the following specific changes:

* Split builtin-specific code out of config-ix.cmake into builtin-config-ix.cmake
* Split some common CMake functionality needed by both builtins and sanitizers into base-config-ix.cmake
* Made lib/builtins/CMakeLists.txt able to be a top-level CMake configuration

I have tested this on Darwin targeting embedded Darwin, and on FreeBSD x86_64 targeting FreeBSD AArch64.

This patch depends on http://reviews.llvm.org/D19692, and is the last part of http://reviews.llvm.org/D16653.

Reviewers: samsonov, iains, jroelofs

Subscribers: compnerd, aemerson, tberghammer, danalbert, srhines, emaste, llvm-commits

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

llvm-svn: 268977
2016-05-09 21:45:52 +00:00
Xinliang David Li b5a2b3a429 Fix variable visibility
llvm-svn: 268952
2016-05-09 19:01:19 +00:00
Renato Golin 26642b4035 Revert "[profile] Simplify value profile writing"
This reverts commit r268840, as it breaks Thumb2 self-hosting. There is something
unstable in the profiling for Thumb2 that needs to be sorted out before we continue
implementing these changes to the profiler. See PR27667.

llvm-svn: 268864
2016-05-07 20:07:09 +00:00