Commit Graph

4851 Commits

Author SHA1 Message Date
Alexander Potapenko 79dc4420f0 Disable the ubsan-asan config on Darwin.
UBSan doesn't work together with ASan on Darwin yet, see http://llvm.org/bugs/show_bug.cgi?id=21112

llvm-svn: 218746
2014-10-01 08:53:00 +00:00
Kuba Brecka 12dee62b02 [compiler-rt] Re-enable the use of -gmlt for ASan tests on Darwin
The optimization for -gmlt/-gline-tables-only introduced in r218129 happened to break on Darwin and produce no line number information due to
an incompatibility with dsymutil. ASan tests have been failing because of that and we disabled the use of -gmlt for the tests in r218545. This patch re-enables the use of -gmlt, because we have conditionally disabled the incompatible optimization in LLVM, so -gmlt now works on Darwin. Once Darwin's dsymutil is modified to allow this optimization, we can re-enable the optimization in LLVM.

llvm-svn: 218716
2014-09-30 23:07:45 +00:00
Alexander Potapenko d775f3b5f0 [UBsan] Disable summary.cpp on Darwin. The test requires ubsan-asan, which does not work yet.
llvm-svn: 218675
2014-09-30 13:55:44 +00:00
Evgeniy Stepanov a9d434918e [asan] XFAIL one test on Android.
And add a missing return in main, just in case.

llvm-svn: 218674
2014-09-30 12:54:32 +00:00
Evgeniy Stepanov 3b7a461674 [asan] Run tests with the default compiler on Android.
llvm-svn: 218664
2014-09-30 11:12:41 +00:00
Evgeniy Stepanov fa413a977d [asan] Re-enable lsan_annotations test on Android.
Was fixed by r218605.

llvm-svn: 218663
2014-09-30 11:11:59 +00:00
Alexander Potapenko a3d4131cd5 [UBSan] Use <machine/endian.h> on Darwin.
llvm-svn: 218662
2014-09-30 10:07:37 +00:00
Kostya Serebryany da9d495d03 [asan] add a test for array cookie if the operator new is defined inside the class (the cookie should not be poisoned in such case); update the related comment in asan_poisoning.cc
llvm-svn: 218620
2014-09-29 19:40:56 +00:00
Evgeniy Stepanov 9e922e7d24 [sanitizer] Android build cleanup.
* Detect Android toolchain target arch and set correct runtime library name.
* Merged a lot of Android and non-Android code paths.
* Android is only supported in standalone build of compiler-rt now.
* Linking lsan-common in ASan-Android (makes lsan annotations work).
* Relying on -fsanitize=address linker flag when building tests (again,
  unification with non-Android path).
* Runtime library moved from lib/asan to lib/linux.

llvm-svn: 218605
2014-09-29 13:18:55 +00:00
Oliver Stannard 609e2e6a6e [compiler-rt] Do not use ldrexd or strexd on v7M
The ldrexd and strexd instructions are undefined for the ARMv7M
architecture, so we cannot use them to implement the
__sync_fetch_and_*_8 builtins. There is no other way to implement
these without OS support, so this patch #ifdef's these functions out
for M-class architectures.

There are no tests as I cannot find any existing tests for these
builtins.

I used the __ARM_ARCH_PROFILE predefine because __ARM_FEATURE_LDREX is
deprecated and not set by clang.

llvm-svn: 218601
2014-09-29 10:23:20 +00:00
Evgeniy Stepanov 3f11c0d79c [asan] Fix SELinux setup on Android-K.
On pre-L devices SELinux is set up in such a way that zygote wrapper
has to be in system_file context, not zygote_exec.

llvm-svn: 218599
2014-09-29 09:48:13 +00:00
Alexey Samsonov 987370b6bd Effectively revert r217284 on Darwin due to issues with -gmlt there
llvm-svn: 218545
2014-09-26 21:58:33 +00:00
Kuba Brecka 7e38e429b7 [compiler-rt] recommit of r218481: ASan debugging API for report info extraction and locating addresses
Reviewed at http://reviews.llvm.org/D4527

Fixed a test case failure on 32-bit Linux, I did right shift on intptr_t, instead it should have been uintptr_t.

llvm-svn: 218538
2014-09-26 19:15:32 +00:00
Petar Jovanovic c2e0427b94 [UBSan] Adding support of MIPS32
Changed files: 
config-ix.cmake: Enabled UBSan for MIPS32
sanitizer_stacktrace.cc: Program counter for MIPS32 is four byte aligned
and a delay slot so subtracted PC by 8 for getting call site address.
cast-overflow.cpp: Added big endian support for this test case.

Patch by Sagar Thakur.

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

llvm-svn: 218519
2014-09-26 14:16:06 +00:00
Kuba Brecka db22cd1721 [compiler-rt] revert r218481 due to test failure on sanitizer-x86_64-linux
llvm-svn: 218501
2014-09-26 05:25:37 +00:00
Kuba Brecka e892580415 [compiler-rt] fix failing debug_locate.cc test due to a leak
New test from r218481 fails on Linux due to LeakSanitizer reporting a leak, this patch frees the memory properly. 

llvm-svn: 218483
2014-09-26 00:20:37 +00:00
Kuba Brecka e37e089b66 [compiler-rt] ASan debugging API for report info extraction and locating addresses
Reviewed at http://reviews.llvm.org/D4527

This patch is part of an effort to implement a more generic debugging API, as proposed in http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074656.html, with first part reviewed at http://reviews.llvm.org/D4466. Now adding several new APIs: __asan_report_present, __asan_get_report_{pc,bp,sp,address,type,size,description}, __asan_locate_address. These return whether an asan report happened yet, the PC, BP, SP, address, access type (read/write), access size and bug description (e.g. "heap-use-after-free"), __asan_locate_address takes a pointer and tries to locate it, i.e. say whether it is a heap pointer, a global or a stack, or whether it's a pointer into the shadow memory. If global or stack, tries to also return the variable name, address and size. If heap, tries to return the chunk address and size. Generally these should serve as an alternative to "asan_describe_address", which only returns all the data in text form. Having an API to get these data could allow having debugging scripts/extensions that could show additional information about a variable/expression/pointer. Test cases in test/asan/TestCases/debug_locate.cc and test/asan/TestCasea/debug_report.cc.

llvm-svn: 218481
2014-09-25 23:53:57 +00:00
Kostya Serebryany 8a86fa37af [asan] disable a test that uses -coverage on Android
llvm-svn: 218475
2014-09-25 23:30:37 +00:00
Ehsan Akhgari 5bb7234b23 Add support for intercepting functions from msvcr110.dll
Summary: This finishes support for ASAN on MSVC2012.

Test Plan: |ninja check-asan| passes locally with this on MSVC2012.

Reviewers: timurrrr

Subscribers: llvm-commits

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

llvm-svn: 218465
2014-09-25 20:47:10 +00:00
Ehsan Akhgari 045423f26d Fix a mistake in r217762
Summary:
The extra macro definition needs to go into COMPILER_RT_GTEST_CFLAGS
in order to be used for gtests on MSVC2012.

Test Plan: This is part of the fixes necessary for the ASAN tests to pass with MSVC2012.

Reviewers: timurrrr

Subscribers: llvm-commits

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

llvm-svn: 218464
2014-09-25 20:42:49 +00:00
Alexander Potapenko bc4ce3a224 Follow-up for r217523: fix the dependencies for standalone compiler-rt build.
Patch by Kuba Brecka (kuba.brecka@gmail.com)

llvm-svn: 218444
2014-09-25 09:30:05 +00:00
Kostya Serebryany fd5e21adba [asan] make sanitizer tests depend on libclang_rt.profile since we now have a test that uses -coverage
llvm-svn: 218427
2014-09-24 23:54:04 +00:00
Kostya Serebryany 34ddf8725c [asan] don't instrument module CTORs that may be run before asan.module_ctor. This fixes asan running together -coverage
llvm-svn: 218421
2014-09-24 22:41:55 +00:00
Evgeniy Stepanov c07dc68852 [asan] Fix one test on Android-L.
index() is deprecated.

llvm-svn: 218312
2014-09-23 15:42:04 +00:00
Alexey Samsonov 7dd95610e5 UBSan: print 'undefined-behavior' instead of 'runtime-error' in report summary
llvm-svn: 218264
2014-09-22 19:39:46 +00:00
Alexander Potapenko 1aba330e52 [ASan] Introduce the dump_instruction_bytes flag to print the faulting instruction upon SIGSEGV
When dump_instruction_bytes=1 and the instruction pointer doesn't point to the zero page, ASan prints 16 bytes starting at the instruction point.

llvm-svn: 218243
2014-09-22 11:58:52 +00:00
Alexey Samsonov 25c2224922 [UBSan] Introduce more flexible __ubsan_default_options function instead of UBSAN_DEFAULT_OPTIONS compile definition
llvm-svn: 218137
2014-09-19 18:54:52 +00:00
Alexey Samsonov 760750c44f [UBSan] Optionally report summary in UBSan error reports.
By default summary is not printed if UBSan is run in a standalone mode,
but is printed if it's combined with another sanitizer (like ASan).

llvm-svn: 218135
2014-09-19 18:33:45 +00:00
Evgeniy Stepanov a5d07482d9 [asan] asan_device_setup improvements.
* Allow user SEGV handler if Android-L-like setup is detected.
  Necessary for correctness.
* Change file context labels on the wrapper script to appease SELinux.

llvm-svn: 218124
2014-09-19 15:04:44 +00:00
Alexander Potapenko 53b85c25e0 [ASan] Print a hint when the program crashes accessing the zero page.
This may help some users figure out that the error report is valid.

llvm-svn: 218123
2014-09-19 12:37:00 +00:00
Saleem Abdulrasool 8bf8409be8 builtins: 80-column
Re-wrap a couple of lines.  NFC.

llvm-svn: 218096
2014-09-19 01:35:08 +00:00
Saleem Abdulrasool c5ff406f5f builtins: remove definition of __ARM_ARCH
__ARM_ARCH is part of the ACLE specification.  At least clang and GCC have
supported this part of the ACLE for some time now.  Let the compiler provide the
proper definition for the macro rather than try to guess it.

llvm-svn: 218095
2014-09-19 01:34:03 +00:00
Sergey Matveev 756afb2f82 [asan] Initialize logfile in asan_symbolize.py to sys.stdin.
llvm-svn: 218072
2014-09-18 20:01:28 +00:00
Sergey Matveev 4588de1c22 [asan] Fix a bug in asan_symbolize.py
Do not forget to add newlines between multiple symbolized lines corresponding to
a single input line (i.e. inlining).

llvm-svn: 218071
2014-09-18 19:16:44 +00:00
Dmitry Vyukov 59dce3d4d0 tsan: more careful handling of signals
On some tests we see that signals are not delivered
when a thread is blocked in epoll_wait. The hypothesis
is that the signal is delivered right before epoll_wait
call. The signal is queued as in_blocking_func is not set
yet, and then the thread just blocks in epoll_wait forever.
So double check pending signals *after* setting
in_blocking_func. This way we either queue a signal
and handle it in the beginning of a blocking func,
or process the signal synchronously if it's delivered
when in_blocking_func is set.

llvm-svn: 218070
2014-09-18 19:03:32 +00:00
Dmitry Vyukov c0ae07e98c tsan: fix signal_longjmp test in debug mode
In debug mode tsan checks that user accesses
access user memory. NULL is not user memory.
So the test fails. Allocate real inaccessible
memory for the test.

llvm-svn: 218069
2014-09-18 19:00:02 +00:00
Dmitry Vyukov 9767d2f8da tsan: fix double semicolon ;;
llvm-svn: 218067
2014-09-18 18:58:44 +00:00
Viktor Kutuzov ea66f5bc40 Enable Asan lit tests on FreeBSD.
Differential Revision: http://reviews.llvm.org/D5375

llvm-svn: 218042
2014-09-18 10:04:07 +00:00
Dmitry Vyukov 538ceee2b9 tsan: fix bug number in comment
llvm-svn: 217992
2014-09-17 22:57:57 +00:00
Alexey Samsonov 1947bf9921 PR20721: Don't let UBSan print inaccessible memory
Summary:
UBSan needs to check if memory snippet it's going to print resides
in addressable memory. Similar check might be helpful in ASan with
dump_instruction_bytes option (see http://reviews.llvm.org/D5167).

Instead of scanning /proc/self/maps manually, delegate this check to
the OS kernel: try to write this memory in a syscall and assume that
memory is inaccessible if the syscall failed (e.g. with EFAULT).

Fixes PR20721.

Test Plan: compiler-rt test suite

Reviewers: eugenis, glider

Reviewed By: glider

Subscribers: emaste, ygribov, llvm-commits, glider, rsmith

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

llvm-svn: 217971
2014-09-17 17:56:15 +00:00
Viktor Kutuzov 68b3e87263 Do not link the dyndd runtime library against libdl on FreeBSD
Differential Revision: http://reviews.llvm.org/D5207

llvm-svn: 217944
2014-09-17 07:54:46 +00:00
Viktor Kutuzov 308b93f6e4 Add FreeBSD support to the address sanitizer's deep_call_stack.cc test case
Differential Revision: http://reviews.llvm.org/D4562

llvm-svn: 217943
2014-09-17 07:31:37 +00:00
Dmitry Vyukov 6466f43688 tsan: fix crash when a program registers zillions of atexit callbacks
I don't remember that crash on mmap in internal allocator
ever yielded anything useful, only crashes in rare wierd untested situations.
One of the reasons for crash was to catch if tsan starts allocating
clocks using mmap. Tsan does not allocate clocks using internal_alloc anymore.
Solve it once and for all by allowing mmaps.

llvm-svn: 217929
2014-09-17 00:12:50 +00:00
Dmitry Vyukov 69c4d37b45 tsan: support longjmp out of signal handlers
Fixes https://code.google.com/p/thread-sanitizer/issues/detail?id=75

llvm-svn: 217908
2014-09-16 21:48:22 +00:00
Kostya Serebryany 9fa2fc8357 [sanitizer] Fix global constructor warning in sanitizer; patch by Samuel F Antao
llvm-svn: 217904
2014-09-16 20:49:55 +00:00
Joerg Sonnenberger ed35a3e717 Implement floatsitf, floatunstfsi, which perform
(signed/unsigned)integer to quad-precision conversion.

Submitted by GuanHong Liu.

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

llvm-svn: 217901
2014-09-16 20:34:41 +00:00
Evgeniy Stepanov 3905bb9150 [asan] De-flake one test.
This change replaces an in-test timeout with an unconditional blocking wait.
It speeds up normal execution significantly at the cost of hanging up indefinitely
in case of a failure. This is a very specific regression test and we don't
expect any failures in the future.

Another approach ould be increasing the timeout to ~8 seconds, which seems too
much for a lit test.

llvm-svn: 217870
2014-09-16 12:03:52 +00:00
Evgeniy Stepanov 6ef0106e43 [asan] Fix a comment in a test.
llvm-svn: 217869
2014-09-16 12:01:01 +00:00
Evgeniy Stepanov a59459de27 [asan] Fix a flaky test.
This test has a chance to hit some other random allocation
and get neither heap overflow nor SEGV.

Relax test condition to only check that there is no internal CHECK failure.

llvm-svn: 217769
2014-09-15 13:05:40 +00:00
Evgeniy Stepanov bc496dab07 [asan] Delay system log initialization on Android.
Writing to system log requires libc interceptors to be initialized.
Fixes crashes with verbosity=1 on newer Android builds.

llvm-svn: 217764
2014-09-15 11:37:40 +00:00
Ehsan Akhgari c4f23419bb Avoid calling strtoll and atoll in asan_str_test.cc on Windows for now
Summary:
These two functions are unavailable on MSVC2012, which breaks building the
ASAN tests with MSVC2012.  Since the tests required to run these functions
are disabled on Windows for now, avoid building them to fix the MSVC2012
builds.

Test Plan: This is needed in order to fix building the ASAN tests with MSVC2012.

Reviewers: timurrrr

Subscribers: llvm-commits

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

llvm-svn: 217763
2014-09-15 11:34:12 +00:00
Ehsan Akhgari 47d260962f Port the variadic std::tr1::tuple hack for building gtest for MSVC2012 to ASAN tests.
Summary: This is copied from llvm/utils/unittest/CMakeLists.txt.

Test Plan: This partly enables building ASAN tests with MSVC2012.

Reviewers: timurrrr

Subscribers: llvm-commits

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

llvm-svn: 217762
2014-09-15 11:33:50 +00:00
Evgeniy Stepanov 7a8330e7bf [asan] Fix path in test.
llvm-svn: 217754
2014-09-15 09:33:20 +00:00
Evgeniy Stepanov 207930d345 [asan] Disable wait4 test on Android.
https://code.google.com/p/memory-sanitizer/issues/detail?id=64

llvm-svn: 217753
2014-09-15 09:20:15 +00:00
Dmitry Vyukov e4b846e0d8 tsan: use growable vector for atexit callbacks
Most real programs setup much more than 1024 callbacks.

llvm-svn: 217713
2014-09-12 22:19:03 +00:00
Alexey Samsonov 0e8364e912 [UBSan] Don't overflow when calculating memory range that should be dumped
llvm-svn: 217703
2014-09-12 19:51:26 +00:00
Timur Iskhodzhanov 651725e191 [ASan/Win] Fix PR20918 -- SEH handler doesn't work with the MD runtime
llvm-svn: 217679
2014-09-12 14:01:30 +00:00
Timur Iskhodzhanov 92c0601d27 [ASan/Win] Rename asan_win_uar_thunk.lib to asan_win_dynamic_runtime_thunk.lib
It turned out that we have to bridge more stuff between the executable
and the ASan RTL DLL than just __asan_option_detect_stack_use_after_return.
See PR20918 for more details.

llvm-svn: 217673
2014-09-12 13:21:02 +00:00
Alexey Samsonov 74f07ed7fe Revert r217616. Problems and complexity it introduces negate its benefit
llvm-svn: 217652
2014-09-12 01:26:57 +00:00
Alexey Samsonov 5d2c0dfe4c [UBSan] Parse common flags from UBSAN_OPTIONS runtime variable even if
UBSan is combined with ASan.

llvm-svn: 217616
2014-09-11 18:20:11 +00:00
Evgeniy Stepanov e579c76bd5 [asan] Preserve existing LD_PRELOAD setting on Android.
llvm-svn: 217584
2014-09-11 12:20:29 +00:00
Alexey Samsonov 5c825967ea [TSan] Use common flags in the same way as all the other sanitizers
llvm-svn: 217559
2014-09-10 23:08:06 +00:00
Alexey Samsonov 611c906cb3 [Sanitizer] Get rid of Symbolizer::Get() and Symbolizer::GetOrNull().
We may as well just use Symbolizer::GetOrInit() in all the cases.
Don't call Symbolizer::Get() early in tools initialization: these days
it doesn't do any important setup work, and we may as well create the
symbolizer the first time it's actually needed.

llvm-svn: 217558
2014-09-10 22:45:09 +00:00
Alexey Samsonov 7f0f17b3fb [UBSan] Add noinline attribute to handlers that should never return.
FIx a problem reported by Jakub Jelinek: don't do early-exit from fatal
UBSan handlers: even if source location is disabled (i.e. acquired by
some other thread), we should continue the execution to make sure that:
a) some thread will print the error report before calling Die().
b) handler marked as noreturn will indeed not return.

Explicitly add "Die()" calls at the end of all fatal handlers to be
sure UBSan handlers don't introduce UB themselves.

llvm-svn: 217542
2014-09-10 20:43:36 +00:00
Alexey Samsonov b69d5dffc3 [UBSan] Add halt_on_error runtime flag
llvm-svn: 217535
2014-09-10 19:35:31 +00:00
Kuba Brecka fa2de77a14 Make compiler-rt tests work with relocatable SDKs on OS X
Reviewed at http://reviews.llvm.org/D4047

llvm-svn: 217523
2014-09-10 17:23:58 +00:00
Yuri Gorshenin 6118d07b00 [asan-assembly-instrumentation] Added end-to-end test for proper stack unwind for functions with inline assembly.
Summary: [asan-assembly-instrumentation] Added end-to-end test for proper stack unwind for functions with inline assembly.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 217487
2014-09-10 10:44:35 +00:00
Alexey Samsonov 513e8a911f Remove extra semicolon [-Wpedantic]
llvm-svn: 217407
2014-09-08 23:37:09 +00:00
Alexey Samsonov 90452df7b1 Report source location of returns_nonnull attribute in UBSan reports.
llvm-svn: 217400
2014-09-08 20:17:19 +00:00
Alexey Samsonov c7c3ae0a8b Revert accidental change
llvm-svn: 217391
2014-09-08 17:52:48 +00:00
Alexey Samsonov 8e1162c71d Implement nonnull-attribute sanitizer
Summary:
This patch implements a new UBSan check, which verifies
that function arguments declared to be nonnull with __attribute__((nonnull))
are actually nonnull in runtime.

To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs
(where applicable) and if function declaration has nonnull attribute specified
for a certain formal parameter, we compare the corresponding RValue to null as
soon as it's calculated.

Test Plan: regression test suite

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits, rnk

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

llvm-svn: 217389
2014-09-08 17:22:45 +00:00
Evgeniy Stepanov 256d5512e6 [msan] Fix wrong array index in io_submit interceptor.
llvm-svn: 217362
2014-09-08 09:28:25 +00:00
Evgeniy Stepanov 36974a7061 [msan] Make chained_origin_limits test faster.
llvm-svn: 217361
2014-09-08 09:04:45 +00:00
Saleem Abdulrasool c89ae72e43 builtins: replace section symbol with reference to spec
Removes a non-ascii character that was committed.

llvm-svn: 217353
2014-09-08 01:49:24 +00:00
Saleem Abdulrasool a0a5873e28 builtins: add AEABI div0 functions
Add the missing AEABI functions that are part of the base platform ABI
specification.  The provided implementation does the bare minimum to avoid
requiring libc headers.  This permits the use of compiler-rt on bare-metal
environments which conform to EABI.

llvm-svn: 217322
2014-09-06 21:34:02 +00:00
Saleem Abdulrasool b6a85b4f6a builtins: remove unnecessary COMPILER_RT_EXPORT
This macro did not do anything at this point, and is not particularly needed for
Windows unless building the builtins as a shared library.  NFC.

llvm-svn: 217321
2014-09-06 21:33:55 +00:00
Viktor Kutuzov 75e31aeb89 Support building tsan_test_util_linux.cc on FreeBSD
Differential Revision: http://reviews.llvm.org/D5210

llvm-svn: 217309
2014-09-06 07:59:05 +00:00
Viktor Kutuzov 1827415be4 Do not assume RLIM_INFINITY is always (rlim_t)-1in sanitizers code
Differential Revision: http://reviews.llvm.org/D5212

llvm-svn: 217308
2014-09-06 07:52:51 +00:00
Viktor Kutuzov dcb98e5dcc Intercept sigfillset() and sigemptyset() for sanitizers needs on FreeBSD
Differential Revision: http://reviews.llvm.org/D5206

llvm-svn: 217307
2014-09-06 07:46:55 +00:00
Viktor Kutuzov eead048ee9 Enable sanitizers' libignore on FreeBSD
Differential Revision: http://reviews.llvm.org/D5205

llvm-svn: 217306
2014-09-06 07:41:22 +00:00
Alexey Samsonov 62063b46fc Use "-gline-tables-only" instead of "-g" in sanitizer test suites.
We are interested in verifying that -gline-tables-only provides enough
debug information for verbose error reports and symbolized stack traces.

llvm-svn: 217284
2014-09-05 22:05:32 +00:00
Alexander Potapenko 869342c1cb [ASan] disable zero_page_pc.cc on Android.
Bug: https://code.google.com/p/address-sanitizer/issues/detail?id=336

llvm-svn: 217228
2014-09-05 06:26:08 +00:00
Kostya Serebryany 1fb81720ec [asan] relax the assertion around array cookie load; still need to extract a reproducer where this assertion fails...
llvm-svn: 217215
2014-09-05 01:16:30 +00:00
Alexey Samsonov f537aeaea1 [ASan] Remove the call to GetPageSizeCached from fast path of FastPoisonShadow
llvm-svn: 217194
2014-09-04 20:47:27 +00:00
Kostya Serebryany d147590492 [asan] trying to de-flake new_array_cookie_uaf_test.cc
llvm-svn: 217177
2014-09-04 18:02:59 +00:00
Justin Bogner cc0d7eeb6d profile: Avoid name collisions between instrumentation and runtime
The naming scheme we're using for counters in profile data shares a
prefix with some fixed names we use for the runtime, notably
__llvm_profile_data_begin and _end. Embarrassingly, this means a
function called begin() can't be instrumented.

This modifies the runtime names so as not to collide with the
instrumentation.

llvm-svn: 217166
2014-09-04 15:45:31 +00:00
Alexander Potapenko 7c3d581e8a [ASan] Remove the check for a double-SEGV from zero_page_pc.cc
Looks like the second crash doesn't happen on Mac.

llvm-svn: 217165
2014-09-04 15:40:25 +00:00
Viktor Kutuzov 2132b704ff Intercept _exit() for sanitizers' needs on FreeBSD
Differential Revision: http://reviews.llvm.org/D5171

llvm-svn: 217156
2014-09-04 14:24:27 +00:00
Viktor Kutuzov 3c821c0200 Fix building sanitizer_linux_libcdep.cc on FreeBSD
Differential Revision: http://reviews.llvm.org/D5166

llvm-svn: 217148
2014-09-04 13:58:59 +00:00
Evgeniy Stepanov e9ca1c72be [msan] Fix fork test on centos-6.5.
Missing <atomic> header.

llvm-svn: 217142
2014-09-04 11:07:42 +00:00
Evgeniy Stepanov bb91e02efd [msan] Make origin tracking fork-safe.
Chained origins make plain memory stores async-signal-unsafe.
We already disable it inside signal handlers.
This change grabs all origin-related locks before fork() and releases
them after fork() to avoid a deadlock in the child process.

llvm-svn: 217140
2014-09-04 10:36:14 +00:00
Alexander Potapenko 9d24aa0fa8 [ASan] allow deadly signals to be received in signal handlers
(previously ASan would just crash upon the second SEGV)
Other tools do not use this code yet.

llvm-svn: 217137
2014-09-04 09:34:22 +00:00
Alexey Samsonov 2428359e23 Fixup test case after r217079
llvm-svn: 217111
2014-09-03 23:46:12 +00:00
Kostya Serebryany fb5d6852c6 [asan] remove debug print
llvm-svn: 217101
2014-09-03 22:58:03 +00:00
Alexey Samsonov c8d8ca0bd6 Fix fast stack unwind on ARM to support code generated with GCC.
http://reviews.llvm.org/D4692

Patch by Maxim Ostapenko!

llvm-svn: 217079
2014-09-03 21:10:44 +00:00
Dmitry Vyukov f8cfdd9207 tsan: handle early signals
The second part of the fix of
https://code.google.com/p/thread-sanitizer/issues/detail?id=71

llvm-svn: 217031
2014-09-03 12:25:22 +00:00
Evgeniy Stepanov f1741f52ad [msan] Fix origin_history_per_stack_limit=0 behavior.
It disables the per-stack limit.

llvm-svn: 217030
2014-09-03 12:15:59 +00:00
Dmitry Vyukov 26411d6929 tsan: more precise handling of atexit callbacks
Fixes issue https://code.google.com/p/thread-sanitizer/issues/detail?id=74

llvm-svn: 216906
2014-09-02 14:22:31 +00:00
Dmitry Vyukov 8bbb17dcc3 tsan: disable getpwent interceptors
There interceptors do not seem to be strictly necessary for tsan.
But we see cases where the interceptors consume 70% of execution time.
Memory blocks passed to fgetgrent_r are "written to" by tsan several times.
First, there is some recursion (getgrnam_r calls fgetgrent_r), and each
function "writes to" the buffer. Then, the same memory is "written to"
twice, first as buf and then as pwbufp (both of them refer to the same addresses).

llvm-svn: 216904
2014-09-02 12:51:11 +00:00
Dmitry Vyukov 1841219abd tsan: restructure signal handling to allow recursive handling
Fixes issue
https://code.google.com/p/thread-sanitizer/issues/detail?id=71

llvm-svn: 216903
2014-09-02 12:27:45 +00:00
Dmitry Vyukov dc1caa7cb8 tsan: address comments in r214912
See http://reviews.llvm.org/D4794

llvm-svn: 216900
2014-09-02 09:34:34 +00:00
Alexander Potapenko 3ae9193371 [libsanitizer] Fix the Android build.
llvm-svn: 216885
2014-09-01 15:38:16 +00:00
Evgeniy Stepanov 21202ba8dd [asan] Update asan_device_setup to support Android L Preview.
llvm-svn: 216884
2014-09-01 15:37:50 +00:00
Alexander Potapenko a909e493f1 [libsanitizer] Make sanitizer_unwind_posix.cc a libcdep source file.
Guard the source with #if SANITIZER_POSIX to fix compilation on Windows.
use it only in 

llvm-svn: 216882
2014-09-01 13:07:50 +00:00
Dmitry Vyukov 34fb3799a3 tsan: fix false positive related to signal handlers
Users expect synchronization between sigaction and arrival
of the signal. See the test for details.

llvm-svn: 216878
2014-09-01 12:46:42 +00:00
Alexander Potapenko 4d84996186 [ASan] Small refactoring - split the slow unwinding logic into sanitizer_unwind_posix.cc
This allows the slow unwinder to be used on OSX (it's disabled for now, see
https://code.google.com/p/address-sanitizer/issues/detail?id=137 for details)

llvm-svn: 216877
2014-09-01 12:43:03 +00:00
Dmitry Vyukov aa8fa60ba8 tsan: unbreak windows build
Currently it fails with:

# Testing race detector.
race_windows_amd64.syso:gotsan.cc:(.text+0x4d89): undefined reference to `__imp_SymGetModuleBase64'
race_windows_amd64.syso:gotsan.cc:(.text+0x4d90): undefined reference to `__imp_SymFunctionTableAccess64'
race_windows_amd64.syso:gotsan.cc:(.text+0x4dd8): undefined reference to `__imp_StackWalk64'
x86_64-w64-mingw32/bin/ld.exe: race_windows_amd64.syso
: bad reloc address 0x10 in section `.data'
collect2.exe: error: ld returned 1 exit status

llvm-svn: 216875
2014-09-01 11:44:59 +00:00
Kostya Serebryany c148f7c3af [asan] enable poison_array_cookie back
llvm-svn: 216705
2014-08-29 01:16:18 +00:00
Kostya Serebryany ac77055272 [asan] introduce __asan_load_cxx_array_cookie: check that the array cookie address is properly poisoned and return the cookie value. If not, return 0 to avoid infinite loop of DTORs (in case of use-after-free). Calls to this function will be inserted by clang (separate change)
llvm-svn: 216692
2014-08-28 22:28:04 +00:00
Kostya Serebryany 1e3b338606 [asan] disable poison_array_cookie while I am investigating a false positive on chromium (I suspect that LLVM looses nosanitizer metadata; no test yet)
llvm-svn: 216684
2014-08-28 20:24:05 +00:00
Timur Iskhodzhanov f77d20b1a9 [ASan/Win] Add a test case for r216663 [-Zl vs LIBCMT vs asan_win_uar_thunk]
llvm-svn: 216665
2014-08-28 13:20:23 +00:00
Timur Iskhodzhanov 737370da20 [ASan/Win] Add the -Zl flag to avoid /DEFAULTLIB:libcmt directive in the asan_win_uar_thunk object file
This directive results in 'symbol already defined' when linking DLLs that use -MD

llvm-svn: 216663
2014-08-28 12:28:04 +00:00
Alexander Potapenko 2164fa3b9b [ubsan] Follow-up for r216657: fixed the line numbers in the test.
llvm-svn: 216661
2014-08-28 10:25:17 +00:00
Alexander Potapenko 53cce89a81 [UBSan] Temporarily disable checks for stack traces in UBSan reports on Darwin
to make the tests green.
Slow stack unwinding is disabled in libsanitizer on Darwin now.

llvm-svn: 216657
2014-08-28 09:25:06 +00:00
Alexander Potapenko 83061238d4 [ASan] Whitespace fix. No functionality change.
llvm-svn: 216544
2014-08-27 13:43:18 +00:00
Evgeniy Stepanov 5d321d759d [asan] Add asprintf negative test.
llvm-svn: 216542
2014-08-27 12:46:58 +00:00
Timur Iskhodzhanov 6add9fe958 [ASan/Win] Enable building the MD runtime by default
llvm-svn: 216534
2014-08-27 10:17:20 +00:00
Evgeniy Stepanov 8f4e736080 [asan] Restore asan-rt name on linux back to pre-r216380.
There is no reason to have different library names for shared and static
cases on linux. It also breaks Android where we install the shared asan-rt
library into the system and should keep the old name.

This change reverts most of r216380 limiting it to win32 targets only.

llvm-svn: 216533
2014-08-27 09:46:54 +00:00
Kostya Serebryany 9455c5ab81 [asan] add a test for poison_array_cookie=1
llvm-svn: 216494
2014-08-26 22:05:12 +00:00
Sergey Matveev 08347ca4fd [lsan] Implement the public allocator interface in standalone LSan.
llvm-svn: 216459
2014-08-26 14:28:28 +00:00
Sergey Matveev 93a2906e80 [lsan] Implement __sanitizer_print_stack_trace() in standalone LSan.
llvm-svn: 216454
2014-08-26 12:52:41 +00:00
Timur Iskhodzhanov 47030475a0 [ASan/Win] Disable warning C4391: incorrect return type for intrinsic function
This warning makes it a bit hard to define strlen and wcslen interceptors in an elegant yet portable way

llvm-svn: 216450
2014-08-26 12:33:00 +00:00
Timur Iskhodzhanov 81885731a8 [ASan/Win] Rename asan_dll_thunk.cc to asan_win_dll_thunk.cc
llvm-svn: 216448
2014-08-26 10:21:37 +00:00
Timur Iskhodzhanov 6903e10ddf [ASan/Win] Add an extra thunk.lib to handle stack-use-after-return option
With this patch, "check-asan" passes all the tests with both MT and MD ASan RTL if you set COMPILER_RT_BUILD_SHARED_ASAN to ON
(PR20214)

llvm-svn: 216447
2014-08-26 10:08:24 +00:00
Kostya Serebryany 74bd6bc9f9 [sanitizer] move mlock interceptor from asan/tsan/msan to common; no functionality change intended
llvm-svn: 216407
2014-08-25 20:57:59 +00:00
Timur Iskhodzhanov dc8caada51 [ASan/Win] Add /DEBUG to the MD RTL link flags
llvm-svn: 216387
2014-08-25 16:45:53 +00:00
Timur Iskhodzhanov 2311f4dfaa [ASan] Replace CMake if/APPEND/endif with append_if
llvm-svn: 216386
2014-08-25 16:40:39 +00:00
Timur Iskhodzhanov 0a88b25c43 [ASan/Win] Intercept memory allocation functions in the MD CRT
llvm-svn: 216382
2014-08-25 13:19:05 +00:00
Timur Iskhodzhanov ea3ce790dc [ASan] Rename the ASan dynamic RT
Reviewed at http://reviews.llvm.org/D5026

llvm-svn: 216380
2014-08-25 11:44:06 +00:00
Alexey Samsonov 2ccbc621df [UBSan] Add support for printing backtraces to all UBSan handlers
llvm-svn: 216289
2014-08-22 21:42:04 +00:00
Alexander Potapenko ea2402ebf4 [ubsan] Follow-up for r216263: fix the expected line number.
llvm-svn: 216266
2014-08-22 12:44:16 +00:00
Timur Iskhodzhanov 220ddacf8d [ASan/Win] Land the trivial bits of -MD RTL support (PR20214)
llvm-svn: 216265
2014-08-22 12:38:07 +00:00
Timur Iskhodzhanov f2d24473fe [ASan] Use check_library_exists to determine if libc/libstdc++ are available
llvm-svn: 216264
2014-08-22 12:26:34 +00:00
Alexander Potapenko 66ae9712c5 [ubsan] Do not run Function/function.cpp on Darwin where -fsanitize=function is not supported.
llvm-svn: 216263
2014-08-22 11:09:10 +00:00
Alexander Potapenko 373863d31e Follow-up for r215436: use SIZE_T for strlen and wcslen interceptors.
llvm-svn: 216184
2014-08-21 16:12:46 +00:00
Timur Iskhodzhanov a14ef30443 [ASan] Turns out we should always intercept __cxa_throw
At least check-asan works with this change.

If the change breaks anything, we'll need to add:
a) a comment describing why we have to use INTERCEPT_FUNCTION rather than
   ASAN_INTERCEPT_FUNC
and
b) a test case.

llvm-svn: 216177
2014-08-21 13:33:39 +00:00
Alexey Samsonov 6d2022b2e0 Fix latent bug in try_compile macro and use CMAKE_EXE_LINKER_FLAGS
when testing for supported architectures, as suggested by Andy Gibbs.

llvm-svn: 216083
2014-08-20 17:12:58 +00:00
Peter Collingbourne 82ff058cf9 DFSan's set label function should avoid writing to the shadow memory when the write would not change the value in memory.
When writing a label to shadow memory, don't write if the value is already set to the value being written.  This dramatically reduces real memory consumption in programs with sparse use of labels.

Test Plan: It would be nice to test that unnecessary writes are skipped, but I do not see how a unit test could do this.

Patch by Sam Kerner!

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

llvm-svn: 215961
2014-08-19 01:47:33 +00:00
Alexey Samsonov 2e39027931 [LSan] Parse common flags from LSAN_OPTIONS even if LSan is combined with
another sanitizer.

A user may run both LSan and LSan+ASan. It is weird to pass path to leak
suppression file (or other common sanitizer flags, like "verbosity") in
"LSAN_OPTIONS" in the first case and in "ASAN_OPTIONS" in the second case.

llvm-svn: 215949
2014-08-18 23:39:47 +00:00
Alexey Samsonov 00c02b297a Add regression test for PR15823
llvm-svn: 215941
2014-08-18 22:11:14 +00:00
Alexey Samsonov 591d15272e [TSan] Add -lpthread to the test which uses pthread_ functions
llvm-svn: 215939
2014-08-18 22:09:17 +00:00
Justin Bogner 8da47ac82e profile: Improve error messages on bad GCDA files
llvm-svn: 215933
2014-08-18 20:47:32 +00:00
Hans Wennborg 4834653872 sanitizer_printf.cc: guard the va_copy hack on _MSC_VER
llvm-svn: 215932
2014-08-18 20:23:16 +00:00
Hans Wennborg a2d4b09a55 Revert "[ASan/Win] Remove a hack that seems not to be required with VS2013 anymore" (r215708)
This is still needed for VS2012.

llvm-svn: 215930
2014-08-18 19:55:35 +00:00
Alexey Samsonov cd21e2f7e4 [TSan] Initialize flags as early as possible. Disables back coredump, accidentally enabled in r215479. Add a test.
llvm-svn: 215763
2014-08-15 19:53:51 +00:00
Timur Iskhodzhanov 48e21c07c1 Follow-up to r215724: fix a lint warning
llvm-svn: 215725
2014-08-15 16:10:02 +00:00
Timur Iskhodzhanov 5c84264194 [ASan/Win] Introduce a new macro for malloc-like function attributes; also, clang-format the definitions of these functions
llvm-svn: 215724
2014-08-15 16:08:53 +00:00
Timur Iskhodzhanov 3e00116dc1 [ASan/Win] Remove one more reference to __interception::GetRealFunctionAddress (follow-up to r215707)
llvm-svn: 215722
2014-08-15 15:41:03 +00:00
Timur Iskhodzhanov f8b1cd210d [ASan/Win] We don't really need to use .CRT to call __asan_init when using -MD
llvm-svn: 215719
2014-08-15 14:44:17 +00:00
Timur Iskhodzhanov cc01fad1d9 [ASan/Win] Remove a hack that seems not to be required with VS2013 anymore
llvm-svn: 215708
2014-08-15 13:45:23 +00:00
Timur Iskhodzhanov 750f1cf9e4 [ASan/Win] Remove old, unused and non-functional code that will be re-written soon
llvm-svn: 215707
2014-08-15 12:56:52 +00:00
Timur Iskhodzhanov 893beb96a2 [ASan/Win] Slightly update&relax test expectations to work with both -MT and -MD (in progress, PR20214) CRTs
llvm-svn: 215641
2014-08-14 13:11:39 +00:00
Timur Iskhodzhanov 7040f13639 [ASan/Win] Mark tests that require -MT asan_dll_thunk as such
llvm-svn: 215638
2014-08-14 13:02:51 +00:00
Dmitry Vyukov 5f86aaa27b tsan: fix unaligned memory access routine
It was possimitically handling an aligned 8-byte access as 2 4-byte accesses.

llvm-svn: 215546
2014-08-13 13:20:23 +00:00
Alexey Samsonov de443c5002 [UBSan] Add returns-nonnull sanitizer.
Summary:
This patch adds a runtime check verifying that functions
annotated with "returns_nonnull" attribute do in fact return nonnull pointers.
It is based on suggestion by Jakub Jelinek:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140623/223693.html.

Test Plan: regression test suite

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 215485
2014-08-13 00:26:40 +00:00
Alexey Samsonov 5a32f79af3 [MSan] Disable coredump for 64-bit binaries.
llvm-svn: 215482
2014-08-12 22:37:47 +00:00
Alexey Samsonov 34e2b280da [TSan] Share the code the setup code calling getrlim/setrlim with sanitizer_common
llvm-svn: 215481
2014-08-12 22:31:19 +00:00
Alexey Samsonov d2d2457823 [Sanitizer] Make disable_coredump a common flag and use it in TSan
llvm-svn: 215479
2014-08-12 22:07:48 +00:00
Alexey Samsonov b9ec65cd4d [Sanitizer] Kill deprecated allocator interfaces in ASan, MSan and TSan in favor of
a unified interface in <sanitizer/allocator_interface.h>.

llvm-svn: 215469
2014-08-12 20:28:20 +00:00
Hans Wennborg a03feadeb2 Fix the CMake build when setting MACOSX_DEPLOYMENT_TARGET
If we don't reset CMAKE_OSX_DEPLOYMENT_TARGET, it will end up in
CFLAGS together with the -mmacosx-version-min that we set,
and the compiler errors about the conflict.

llvm-svn: 215468
2014-08-12 20:03:33 +00:00
Timur Iskhodzhanov 6963686c47 [ASan] Use more appropriate return types for strlen/wcslen to avoid MSVC warnings
llvm-svn: 215436
2014-08-12 11:02:53 +00:00
Timur Iskhodzhanov de1718d355 [ASan/Win] Fix PR18987: warning about overriding '/MD' with '/MT'
llvm-svn: 215435
2014-08-12 09:44:56 +00:00
Alexey Samsonov 968a358974 [ASan] Add new options for asan_symbolize.py script.
The patch adds new features in asan-symbolizer script which are helpful for using ASan on embedded systems:

1) add cross-compile prefix for binutils
2) define path to sysroot with sanitized binaries

Features are enabled by command line options.
The patch also extends command line interface with help option.

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

Patch by Maria Guseva!

llvm-svn: 215381
2014-08-11 20:02:49 +00:00
Alexey Samsonov 266ba5586d Fix build on some architectures caused by r215247.
llvm-svn: 215380
2014-08-11 19:57:56 +00:00
Saleem Abdulrasool a0d65971d4 builtins: add signature to some assembly routines
Add a helpful description and a signature for the functions implemented in
assembly for the integral math routines.  NFC.

llvm-svn: 215296
2014-08-09 20:17:43 +00:00
Saleem Abdulrasool 6063983c30 builtins: correct __umodsi3, __udivsi3 on ARM
When building the builtins for a modern CPU (idiv support), __umodsi3 was
completely incorrect as it would behave as __udivmosi3, which takes a tertiary
parameter which is a pointer.

__udivsi3 was also incorrect, returning the remainder in r1.  Although this
would not result in any crash or invalid behaviour as r1 is a caller saved
register in AAPCS, this is unnecessary.  Simply perform the division ignoring
the remainder.

llvm-svn: 215295
2014-08-09 20:17:37 +00:00
Alexey Samsonov 408d2152c4 Fixup Android tests build rules
llvm-svn: 215264
2014-08-09 00:23:11 +00:00
Alexey Samsonov 68b9e74592 [CMake] Determine which compiler-rt libraries are supported on
a given platform in a top-level CMakeLists.txt to use it both
in lib/ and in test/ subdirectories. Move architecture/platform
checks to config-ix.

llvm-svn: 215247
2014-08-08 22:01:20 +00:00
Timur Iskhodzhanov 255958391d [ASan/Win] Print out a big warning and continue without checking for success if SymInitialize() fails
llvm-svn: 215203
2014-08-08 13:25:55 +00:00
Viktor Kutuzov 7a27160780 Support getting process maps for sanitizers needs on FreeBSD in 32-bit mode
Differential Revision: http://reviews.llvm.org/D4807

llvm-svn: 215185
2014-08-08 06:21:09 +00:00
Evgeniy Stepanov f5c1f8ac84 [sanitizer] Intercept timerfd_settime, timerfd_gettime.
llvm-svn: 215112
2014-08-07 14:21:42 +00:00
Evgeniy Stepanov 37e069c2ac [msan] Fix fcvt interceptor.
fcvt() result can be heap-allocated and must be unpoisoned.

llvm-svn: 215106
2014-08-07 12:45:55 +00:00
Viktor Kutuzov c68a37c531 Add FreeBSD support to the address sanitizer's malloc_context_size.cc test case
Differential Revision: http://reviews.llvm.org/D4665

llvm-svn: 215081
2014-08-07 04:58:41 +00:00
Alexey Samsonov 71b471fa09 [TSan] Try to fix Go runtime build
llvm-svn: 215000
2014-08-06 23:13:23 +00:00
Viktor Kutuzov a37ad099e8 Segregate FreeBSD-specific parts from sanitizer_procmaps_linux.cc
Differential Revision: http://reviews.llvm.org/D4555

llvm-svn: 214955
2014-08-06 10:16:52 +00:00
Dmitry Vyukov 70db9d4d72 tsan: allocate vector clocks using slab allocator
Vector clocks is the most actively allocated object in tsan runtime.
Current internal allocator is not scalable enough to handle allocation
of clocks in scalable way (too small caches). This changes transforms
clocks to 2-level array with 512-byte blocks. Since all blocks are of
the same size, it's possible to cache them more efficiently in per-thread caches.

llvm-svn: 214912
2014-08-05 18:45:02 +00:00
Timur Iskhodzhanov 0575694729 [ASan/Win] Handle SEH exceptions even with -GS
This is a follow-up to r213654, r213656, r213667 and r213668.

llvm-svn: 214861
2014-08-05 13:26:26 +00:00
Alexander Kornienko c3f7bcbd48 The test doesn't export ASAN_OPTIONS, so $ASAN_OPTIONS should not be used in RUN lines.
llvm-svn: 214855
2014-08-05 11:12:23 +00:00
Alexey Samsonov ff24fd2516 [UBSan] Allow to suppress reports from vptr checker for specified types.
Based on http://reviews.llvm.org/D4702 by Byoungyoung Lee!

llvm-svn: 214833
2014-08-05 01:24:22 +00:00
Alexey Samsonov ae1764854e [Sanitizer] Turn SuppressionContext::Init() into InitIfNecessary().
Suppression context might be used in multiple sanitizers working
simultaneously (e.g. LSan and UBSan) and not knowing about each other.

llvm-svn: 214831
2014-08-05 00:43:23 +00:00
Kostya Serebryany e9f24a9b3b [asan] poison array cookies only on 64-bit arch
llvm-svn: 214713
2014-08-04 12:59:45 +00:00
Kostya Serebryany 522c35eb80 [asan] introduce __asan_poison_cxx_array_cookie. This is asan-rt part of PR19838 (Left OOB accesses on new[]-allocated arrays with array cookies are not detected). No tests yet. They will follow once I commit the clang part.
llvm-svn: 214711
2014-08-04 12:43:13 +00:00
Kostya Serebryany 1cd57ebb6b [asan] intercept sized operator delete[]
llvm-svn: 214704
2014-08-04 10:10:50 +00:00
Alexey Samsonov d9ad5cec0c [ASan] Use metadata to pass source-level information from Clang to ASan.
Instead of creating global variables for source locations and global names,
just create metadata nodes and strings. They will be transformed into actual
globals in the instrumentation pass (if necessary). This approach is more
flexible:
1) we don't have to ensure that our custom globals survive all the optimizations
2) if globals are discarded for some reason, we will simply ignore metadata for them
   and won't have to erase corresponding globals
3) metadata for source locations can be reused for other purposes: e.g. we may
   attach source location metadata to alloca instructions and provide better descriptions
   for stack variables in ASan error reports.

No functionality change.

llvm-svn: 214604
2014-08-02 00:35:50 +00:00
Viktor Kutuzov f164bee0e0 Add FreeBSD support to the address sanitizer's deep_stack_uaf.cc test case
Differential Revision: http://reviews.llvm.org/D4668

llvm-svn: 214544
2014-08-01 19:37:05 +00:00
Viktor Kutuzov 62308221bc Fix the waitid sanitizer interceptor to work on FreeBSD in 32-bit mode
Differential Revision: http://reviews.llvm.org/D4670

llvm-svn: 214543
2014-08-01 19:33:14 +00:00
Ehsan Akhgari 9e5b6a08d4 [ASan] Support the asan_loadN/asan_storeN functions in the DLL thunk library
Summary:
This is required for linking DLLs with large functions exceeding
san-instrumentation-with-call-threshold.  One such function is
vp9_fdct16x16_sse2 in libvpx.

Reviewers: timurrrr

Subscribers: llvm-commits

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

llvm-svn: 214532
2014-08-01 18:04:53 +00:00
Alexey Samsonov 19fc293782 [Sanitizer] Don't try to parse unspecified suppressions file
llvm-svn: 214421
2014-07-31 19:06:47 +00:00
Evgeniy Stepanov 1cd9e019da [asan] End-to-end test for REP MOVS instrumentation.
Patch by Yuri Gorshenin.

llvm-svn: 214396
2014-07-31 09:12:20 +00:00
Dmitry Vyukov b7e8e5cdc0 tsan: use MADV_NOHUGEPAGE only if it is supported by platform
Fixes build failure on an old system:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-centos-6.5/builds/7555/steps/build/logs/stdio

llvm-svn: 214394
2014-07-31 08:24:59 +00:00
Alexey Samsonov 89b17bb7bc [Sanitizer] Hoist the code parsing suppressions file into sanitizer_common.
Remove corresponding bits from LSan and TSan runtimes. No functionality change.

llvm-svn: 214344
2014-07-30 21:53:30 +00:00
Alexey Samsonov 77f646c623 [Sanitizer] Make "suppressions" and "print_suppressions" common runtime flags.
No functionality change.

llvm-svn: 214343
2014-07-30 21:33:04 +00:00
Alexey Samsonov 34a4c6e12f [Sanitizer] Make SuppressionContext a singleton class, residing in sanitizer_common.
Convert TSan and LSan to the new interface. More changes will follow:
1) "suppressions" should become a common runtime flag.
2) Code for parsing suppressions file should be moved to SuppressionContext::Init().

llvm-svn: 214334
2014-07-30 20:54:37 +00:00
Evgeniy Stepanov c3478490ed [asan] XFAIL sized-delete test on Android.
llvm-svn: 214303
2014-07-30 12:39:30 +00:00
Kostya Serebryany e7532e59c0 [asan] rename new-delete-size-mismatch to new-delete-type-mismatch and make the report more verbose
llvm-svn: 214299
2014-07-30 11:20:37 +00:00
Kostya Serebryany 69852a843c [asan] add a feature to detect new-delete-size-mismatch (when used with -Xclang -fsized-deallocation). Not yet on Mac. Also, remove some unused code.
llvm-svn: 214296
2014-07-30 09:48:23 +00:00
Evgeniy Stepanov 5c72938c39 [msan] Use SIGHUP instead of SIGUSR1 in test.
Apparently, SIGUSR1 does not work on x86_64+ArchLinux for some reason.

For more details, see:
https://groups.google.com/forum/#!topic/llvm-dev/4Ag1FF4M2Dw

llvm-svn: 214289
2014-07-30 08:17:58 +00:00
Alexey Samsonov 96591cd1f1 [UBSan] Introduce ScopedReport object.
This object is used to encapsulate all actions that need to be
done before/after printing UBSan diagnostics. Currently these
actions are:
* locking a mutex to ensure that UBSan diagnostics from several
threads won't mix with each other and with other sanitizers' 
reports
* killing a program once the report is printed (if necessary).

Use this object in all UBSan handlers. Unify the way we implement
fatal and non-fatal handlers by making all the handlers simple
one-liners that redirect __ubsan_handle_foo(_abort)? to
handleFooImpl().

llvm-svn: 214279
2014-07-30 01:49:19 +00:00
Alexey Samsonov 64a5f0fa1a [UBSan] Allow to override runtime flags defaults by providing
compile definition UBSAN_DEFAULT_OPTIONS when building the runtime.
This mirrors similar ASan functionality.

llvm-svn: 214259
2014-07-30 00:01:41 +00:00
Alexey Samsonov 6ae5bac794 [UBSan] Move all runtime flags parsing to ubsan_flags.cc.
No functionality change.

llvm-svn: 214258
2014-07-29 23:49:20 +00:00
Alexey Samsonov 20c5c7b723 [UBSan] Get pc/bp for stack unwinding as early as possible.
This will ensure that stack frames in error reports will not
contain internal UBSan failures, and frame #0 will be the
actual place in the program where the error happens.

llvm-svn: 214245
2014-07-29 23:22:41 +00:00
Alexey Samsonov 17edc9230e [UBSan] Build part of UBSan runtime that can be linked into C programs with -fno-rtti flag.
llvm-svn: 214232
2014-07-29 21:52:25 +00:00
Alexey Samsonov 8b9d18e4fe [UBSan] Try to enable pipefail in UBSan lit tests to make them behave more predictably
llvm-svn: 214149
2014-07-29 00:30:01 +00:00
Alexey Samsonov 4462ec6c02 Exclude ASM from CompilerRT languages as an attempt to fix CMake failure in standalone mode
llvm-svn: 214130
2014-07-28 22:04:19 +00:00
Dmitry Vyukov 3baf5b390d tsan: add a useful debug check
llvm-svn: 214082
2014-07-28 13:54:18 +00:00
Saleem Abdulrasool 3a2d6a3096 builtins: make ARM compilation with GAS work again
The LLVM IAS seems to accept wide instructions for add and sub in ARM mode even
though it is not permitted.  This uses a macro to ensure that the wide modifier
is only applied when building in THUMB mode.

This repairs building with GCC/GAS in ARM mode.

llvm-svn: 214046
2014-07-27 02:01:24 +00:00
Saleem Abdulrasool b6690c34cf builtins: move macro definitions into assembly.h
The macro definitions are shared across multiple files.  Define them once in the
assembly.h header rather than redefining it in each file.

llvm-svn: 214045
2014-07-27 02:01:20 +00:00
Saleem Abdulrasool 31306b1571 builtins: whitespace
llvm-svn: 214044
2014-07-27 02:01:15 +00:00
Saleem Abdulrasool b72a2fdd72 builtins: avoid multiple definitions of symbols
The architecture specific implementation of routines would be built and included
along with the generic implementation.  This would result in multiple
definitions of those symbols.

The linker is free to select either of the two.  Most of the time, this
shouldn't be too terrible as the forward iteration should catch the architecture
version due to the ordering.  Rather than relying on the linker and build
infrastructure ordering things in a specific manner, only provide the
architecture version when available.

This reduces the size of compiler-rt, simplifies inspection of the library
implementations, and guarantees that the desired version is selected at a
slightly complex build system.

llvm-svn: 214040
2014-07-26 23:44:22 +00:00
Saleem Abdulrasool 24c68b26d8 builtins: add missed files from previous commits
This adds missed files in SVN r214033 for alignment and corrects a change from
SVN r214034 for fixing compilation with GCC.

llvm-svn: 214039
2014-07-26 23:44:18 +00:00
Saleem Abdulrasool 12ae9a8704 builtins: move the readonly constants into rodata
Place the floating point constants into the read-only data section.  This was
already being done for x86_64, this simply mirrors the behaviour for i686.

llvm-svn: 214034
2014-07-26 21:08:41 +00:00
Saleem Abdulrasool 15a906cf37 builtins: correct constant alignments
MMX/SSE instructions expect 128-bit alignment (16-byte) for constants that they
reference.  Correct the alignment on the constant values.  Although it is quite
possible for the data to end up aligned, there is no guarantee that this will
occur unless it is explicitly aligned to the desired location.  If the data ends
up being unaligned, the resultant binary would fault at runtime due to the
unaligned access.

As an example, the follow would fault previously:
  cc -c lib/builtins/x86_64/floatundidf.S -o floatundidf.o
  cc -c test/builtins/Unit/floatundidf_test.c -o floatundidf_test.c
  ld -m elf_x86_64 floatundidf.o floatundidf_test.o -lc -o floatundidf

However, if the object files were reversed, the data would end up aligned and
the problem would go unnoticed.

llvm-svn: 214033
2014-07-26 21:08:34 +00:00
Dmitry Vyukov 7b70cadae9 tsan: advise shadow for 0x7f region to not use huge pages
see the comment for justification

llvm-svn: 214030
2014-07-26 17:41:10 +00:00
Dmitry Vyukov 5b1b02eb29 tsan: improve shadow flush benchmark
allow to specify access stride

llvm-svn: 214029
2014-07-26 16:40:33 +00:00
Dmitry Vyukov 4baa65518b tsan: reduce internal allocator region from 16M to 1M
16M regions can waste almost 1G for nothing.
Since region size is used only during initial heap growth,
it's unclear why we even need such huge regions.

llvm-svn: 214027
2014-07-26 10:17:26 +00:00
Dmitry Vyukov 07fdaf97e4 tsan: remove meta from internal allocator
I am puzzled why it is even there.

llvm-svn: 214026
2014-07-26 10:06:11 +00:00
Nick Lewycky 1f30f5aef7 Satisfy -Wparentheses.
llvm-svn: 214017
2014-07-26 05:07:41 +00:00
Saleem Abdulrasool 7618240aa9 builtins: re-enable building assembly sources
Re-apply SVN r213684 which was reverted in SVN r213724 since it broke the
build bots.  Add a tweak to enable inclusion of the assembly sources in
standalone build as well.

Original commit message:

This patch address the PR20360. The CMake assembler build system
ignores the .S assembly files in builtins library build. This patch
fixes the issue.

llvm-svn: 214013
2014-07-26 04:04:02 +00:00
Saleem Abdulrasool 93efc78a04 builtins: make the x86_64 compatible with GAS
The .rodata directive was added on the IA-64 (Itanium) platform.  The LLVM IAS
supports the .rodata on i386 and x86_64 as well.  There is no reason to really
restrict compilation of the builtins to just clang.  By explicitly indicating
that the data is meant to be pushed into the .rodata section via the .section
.rodata, the assembly is made compatible with clang and gcc (with GAS).

This will enable building these routines on the Linux buildbots via CMake.

llvm-svn: 214012
2014-07-26 04:03:59 +00:00
Alexey Samsonov e87e5ce5d6 [UBSan] Initialize symbolizer inside __ubsan::Init().
We used to initialize symbolizer lazily, but this doesn't work in
various sandboxed environments. Instead, let's be consistent with
the rest of sanitizers.

llvm-svn: 214006
2014-07-26 01:41:45 +00:00
Alexey Samsonov 1440105338 [Sanitizer] Simplify Symbolizer creation interface.
Get rid of Symbolizer::Init(path_to_external) in favor of
thread-safe Symbolizer::GetOrInit(), and use the latter version
everywhere. Implicitly depend on the value of external_symbolizer_path
runtime flag instead of passing it around manually.

No functionality change.

llvm-svn: 214005
2014-07-26 01:37:23 +00:00
Alexey Samsonov f51b9488c6 [DFSan] Fixup for r213980
llvm-svn: 213997
2014-07-26 00:49:36 +00:00
Alexey Samsonov 6eb53d6460 [UBSan] Call UBSan initialization as early as possible.
Specifically, use .preinit_array initialization on Linux and dynamic global
initializer on another platforms. Historically UBSan didn't have any
initialization code and its runtime was stateless. This is no longer the
case - UBSan relies on some non-trivial functionality from sanitizer_common
(e.g. online symbolization) and is now configurable by runtime flags.
Additionally, we've dropped support for enabling UBSan only for a few shared
objects, so UBSan is now always linked into the main executable, so now
we can use similar initialization as all the rest sanitizers.

llvm-svn: 213983
2014-07-25 22:24:34 +00:00
Alexey Samsonov 2178054216 [Sanitizer] Introduce SANITIZER_CAN_USE_PREINIT_ARRAY definition and use it across sanitizers.
Get rid of ASAN_USE_PREINIT_ARRAY and LSAN_USE_PREINIT_ARRAY - just always
use .preinit_array if it's available. This mode seems stable enough, and
we've been relying on default values of these macro for a long time.

llvm-svn: 213980
2014-07-25 22:05:02 +00:00
Dmitry Vyukov 6819cf4974 tsan: query RSS every 100ms
Now that it become faster, it's OK to query it every 100ms again.

llvm-svn: 213943
2014-07-25 13:48:25 +00:00
Dmitry Vyukov fe17080c88 tsan: fix and make faster GetRSS
It is currently broken because it reads a wrong value from profile (heap instead of total).
Also make it faster by reading /proc/self/statm. Reading of /proc/self/smaps
can consume more than 50% of time on beefy apps if done every 100ms.

llvm-svn: 213942
2014-07-25 13:47:57 +00:00
Viktor Kutuzov d712403b98 Allow initialization of Asan interceptors before the general Asan initialization takes place on FreeBSD
Differential Revision: http://reviews.llvm.org/D4496

llvm-svn: 213941
2014-07-25 12:45:36 +00:00
Viktor Kutuzov 2fde54f48c Support traversing ELF objects for sanitizers needs on FreeBSD in 32-bit mode
Differential Revision: http://reviews.llvm.org/D4656

llvm-svn: 213940
2014-07-25 12:29:04 +00:00
Alexander Potapenko 08cfa79d87 [lsan] Follow-up for r213518: replace MAP_ANONYMOUS with MAP_ANON
(despite it's deprecated on Linux) to remove the ifdefs.

llvm-svn: 213929
2014-07-25 08:57:51 +00:00
Viktor Kutuzov 545ff90d47 Add FreeBSD support to Asan test cases that use mmap() with MAP_ANON
Differential Revision: http://reviews.llvm.org/D4561

llvm-svn: 213858
2014-07-24 12:05:13 +00:00
Alexey Samsonov 16ea3268b2 Build libcxx-tsan only if TSan is supported on host architecture
llvm-svn: 213791
2014-07-23 20:07:26 +00:00
Alexey Samsonov db615d565d Fix unused-variable warning
llvm-svn: 213786
2014-07-23 19:40:54 +00:00
Alexey Samsonov bfa711c8b0 [UBSan] Add the ability to dump call stacks to -fsanitize=vptr
This change introduces the first UBSan-specific runtime flag: print_stacktrace
(off by default). It can be set in UBSAN_OPTIONS to unwind and print call stacks
in addition to diagnostic messages. For now these stacks are printed only
in vptr checker.

This change is based on http://reviews.llvm.org/D4410 by Byoungyoung Lee!

llvm-svn: 213783
2014-07-23 18:44:54 +00:00
Alexey Samsonov cd875aa551 [UBSan] Introduce UBSAN_OPTIONS environment variable.
If UBSan is run in a standalone mode (w/o any other sanitizer), it
still uses functions from sanitizer_common, some of which depend on
the value of runtime flags. Allow to override the default values of these
flags with UBSAN_OPTIONS variable. In particular, UBSAN_OPTIONS=symbolize=0
can be used to turn off online symbolization.

llvm-svn: 213782
2014-07-23 18:32:55 +00:00
Renato Golin bb3d7b5e81 Revert "Include assembly files in builtins library build"
This reverts commit r213684, since it was breaking the compiler-rt
build and the sanitizers' bot.

llvm-svn: 213724
2014-07-23 04:46:23 +00:00
Alexey Samsonov ad63cfd7e5 [Sanitizer] Disable Wframe-larger-than on PowerPC hosts
llvm-svn: 213702
2014-07-22 23:10:13 +00:00
Renato Golin 8c714213d5 Fix incompatible assembly in ARM builtins library
Convert the CBNZ backward branch instruction to CMP and BNE
avoiding illegal backwards branch and making the assembly code
in synh-ops.h to be UAL compliant.

Patch by: Sumanth Gundapaneni

llvm-svn: 213685
2014-07-22 20:59:41 +00:00
Renato Golin aad0347c8b Include assembly files in builtins library build
The CMake assembler build system ignores the .S assembly files in builtins
library build. This patch fixes the issue.

Patch by: Sumanth Gundapaneni

llvm-svn: 213684
2014-07-22 20:59:38 +00:00
Timur Iskhodzhanov 4bea5a83bd [ASan/Win tests] Bring back -GS- as SEH tests fail otherwise
llvm-svn: 213668
2014-07-22 16:09:11 +00:00
Timur Iskhodzhanov 74487a7c32 [ASan/Win tests] Don't generate debug info where it is not needed
Otherwise it results in flaky tests

llvm-svn: 213667
2014-07-22 15:53:10 +00:00
Timur Iskhodzhanov cb5bf58f3d [ASan/Win] Add SEH handling to the DLL thunk as well
llvm-svn: 213656
2014-07-22 14:02:53 +00:00
Timur Iskhodzhanov 6d4a6cd68f [ASan/Win] Handle SEH exceptions (best-effort, similar to longjmp)
llvm-svn: 213654
2014-07-22 13:44:18 +00:00
Timur Iskhodzhanov f2b96e3009 [ASan/Win] Add handling of C++ exceptions to the RTL
Also add a longjmp() test

llvm-svn: 213649
2014-07-22 12:37:51 +00:00
Timur Iskhodzhanov 8f41c3eb74 [ASan] Simplify exception/longjmp tests even further
llvm-svn: 213646
2014-07-22 12:25:51 +00:00
Timur Iskhodzhanov 723c81ff80 [ASan] Split throw_catch tests into two files: throw/catch + longjmp
Also add some more assertions into these tests

llvm-svn: 213642
2014-07-22 11:46:24 +00:00
Alexey Samsonov d6906e4ffe [MSan] Fix strncpy interceptor
llvm-svn: 213590
2014-07-22 00:10:08 +00:00
Alexey Samsonov a89ad664b1 [ASan] Fix __asan_describe_address and add a test for it.
llvm-svn: 213583
2014-07-21 21:33:46 +00:00
Alexey Samsonov 4532489752 Adjust gen_dynamic_list for PowerPC function descriptors
llvm-svn: 213577
2014-07-21 19:01:03 +00:00
Alexander Potapenko 96008ea849 [lsan] Allow using ucontext.h in the test on OSX.
llvm-svn: 213523
2014-07-21 13:35:09 +00:00
Alexander Potapenko e816521c00 [lsan] Define MAP_ANONYMOUS as MAP_ANON for OSX in the test.
llvm-svn: 213518
2014-07-21 13:12:44 +00:00