Commit Graph

6705 Commits

Author SHA1 Message Date
Ivan A. Kosarev ec4880905d [Asan] Eliminate SHADOW_TO_MEM() macro
Differential Revision: https://reviews.llvm.org/D31592

llvm-svn: 299867
2017-04-10 19:13:47 +00:00
Vitaly Buka 30b4cfab1b [msan] Wrap sockaddr_in and socket for future IPv6 support.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299859
2017-04-10 17:56:37 +00:00
Vitaly Buka 9804c81c55 [msan] Reorder unittests for future parametrization.
Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 299858
2017-04-10 17:22:06 +00:00
Evgeniy Stepanov bacee5c04f [cfi] Accept weak definition of __cfi_check.
https://reviews.llvm.org/D31796 results in LLD emitting __cfi_check
as a weak symbol, while Gold keeps it strong. Accept both.

llvm-svn: 299804
2017-04-07 22:52:08 +00:00
Reid Kleckner bfad55fbc0 [builtins] Make some ISA macro checks work with MSVC
llvm-svn: 299786
2017-04-07 17:18:43 +00:00
Reid Kleckner 3ae87c4650 [builtins] Fix MSVC build
Avoid __attribute__((constructor)) in cpu_model.c.

Use more C99 _Complex emulation in divtc3.c. Joerg Sonnenberger added
this builtin just after the last round of C99 _Complex emulation landed
in r249514 (Oct 2015).

llvm-svn: 299784
2017-04-07 16:54:32 +00:00
Reid Kleckner 8c78ca2e8f [builtins] Get the builtins tests passing on Windows
Many things were broken:

- We stopped building most builtins on Windows in r261432 for reasons
  that are not at all clear to me. This essentially reverts that patch.

- Fix %librt to expand to clang_rt.builtins-$arch.lib on Windows instead
  of libclang_rt.builtins-$arch.a.

- Fix memory protection tests (trampoline, enable executable, clear
  cache) on Windows. One issue was that the MSVC incremental linker
  generates ILT thunks for functions with external linkage, so memcpying
  the functions into the executable stack buffer wasn't working. You
  can't memcpy an RIP-relative jump without fixing up the offset.

- Disable tests that rely on C99 complex library functions when using
  the MSVC CRT, which isn't compatible with clang's C99 _Complex.

In theory, these could all be separate patches, but it would not green
the tests, so let's try for it all at once. Hopefully this fixes the
clang-x64-ninja-win7 bot.

llvm-svn: 299780
2017-04-07 16:35:09 +00:00
Evgeniy Stepanov 0680968ff3 [asan] Fix dead stripping of globals on Linux (compiler-rt).
This is a re-land of r298173, r298169, r298159.

llvm-svn: 299698
2017-04-06 19:55:52 +00:00
Ivan Krasin e63dccd98d Revert r299672: Add a virtual destructor to a class with virtual methods.
Reason: breaks sanitizers builds.

Original Differential Revision: https://reviews.llvm.org/D317

llvm-svn: 299679
2017-04-06 18:22:25 +00:00
Dimitry Andric 01220bf9d2 Add __ffssi2 implementation to compiler-rt builtins
Summary:
During MIPS implementation work for FreeBSD, John Baldwin (jhb@FreeBSD.org)
found that gcc 6.x emits calls to __ffssi2() when compiling libc and some
userland programs in the base system.

Add it to compiler-rt's builtins, based off of the existing __ffsdi2()
implementation.  Also update the CMake files and add a test case.

Reviewers: howard.hinnant, weimingz, rengolin, compnerd

Reviewed By: weimingz

Subscribers: dberris, mgorny, llvm-commits, emaste

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

llvm-svn: 299675
2017-04-06 18:12:02 +00:00
Ivan Krasin 547aadcba8 Add a virtual destructor to a class with virtual methods.
Summary:
Recently, Clang enabled the check for virtual destructors
in the presence of virtual methods. That broke the bootstrap
build. Fixing it.

Reviewers: pcc

Reviewed By: pcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 299672
2017-04-06 17:58:45 +00:00
Francis Ricci 4cce35f0ce Enable builds of darwin lsan by default
Summary: Testing and asan leak detection are disabled by default.

Reviewers: kubamracek, kcc

Subscribers: srhines, llvm-commits, mgorny

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

llvm-svn: 299669
2017-04-06 17:41:26 +00:00
Craig Topper d3115972bf [TSan] Adjust expectation for check_analyze.sh
r299658 fixed a case where InstCombine was replicating instructions instead of combining. Fixing this reduced the number of pushes and pops in the __tsan_read and __tsan_write functions.

Adjust the expectations to account for this after talking to Dmitry Vyukov.

llvm-svn: 299661
2017-04-06 17:09:08 +00:00
Dean Michael Berris d41c5ffc3e [XRay][compiler-rt] Remove unused local variable
The local was only referenced in assertions.

Follow-up to D31345.

llvm-svn: 299644
2017-04-06 11:27:53 +00:00
Maxim Ostapenko e6b81315f7 Try to fix MAC buildbot after r299630
llvm-svn: 299632
2017-04-06 08:17:09 +00:00
Maxim Ostapenko 18afec1ba6 Try to fix windows buildbot after r299630
llvm-svn: 299631
2017-04-06 07:53:26 +00:00
Maxim Ostapenko fe863a6510 [lsan] Avoid segfaults during threads destruction under high load
This patch addresses two issues:

	* It turned out that suspended thread may have dtls->dtv_size == kDestroyedThread (-1)
	and LSan wrongly assumes that DTV is available. This leads to SEGV when LSan tries to
	iterate through DTV that is invalid.
	* In some rare cases GetRegistersAndSP can fail with errno 3 (ESRCH). In this case LSan
	assumes that the whole stack of a given thread is available. This is wrong because ESRCH
	can indicate that suspended thread was destroyed and its stack was unmapped. This patch
	properly handles ESRCH from GetRegistersAndSP in order to avoid invalid accesses to already
	unpapped threads stack.

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

llvm-svn: 299630
2017-04-06 07:42:27 +00:00
Dean Michael Berris 895171e6ee [XRay] [compiler-rt] Unwriting FDR mode buffers when functions are short.
Summary:
"short" is defined as an xray flag, and buffer rewinding happens for both exits
 and tail exits.

 I've made the choice to seek backwards finding pairs of FunctionEntry, TailExit
 record pairs and erasing them if the FunctionEntry occurred before exit from the
 currently exiting function. This is a compromise so that we don't skip logging
 tail calls if the function that they call into takes longer our duration.

 This works by counting the consecutive function and function entry, tail exit
 pairs that proceed the current point in the buffer. The buffer is rewound to
 check whether these entry points happened recently enough to be erased.

 It is still possible we will omit them if they call into a child function that
 is not instrumented which calls a fast grandchild that is instrumented before
 doing other processing.

Reviewers: pelikan, dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 299629
2017-04-06 07:14:43 +00:00
Weiming Zhao fbe67da29b [Builtins] Fix div0 error in udivsi3
Summary: Need to save `lr` before bl to aeabi_div0

Reviewers: rengolin, compnerd

Reviewed By: compnerd

Subscribers: llvm-commits

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

llvm-svn: 299628
2017-04-06 06:13:39 +00:00
Evgeniy Stepanov 7e94d38374 [cfi] Fix symbol lookup hack in cross-dso cfi to handle LLD binaries.
llvm-svn: 299604
2017-04-06 00:34:45 +00:00
Maxim Ostapenko f73b73d04d [asan] Move AsanCheckDynamicRTPrereqs check under flag
The patch addresses https://github.com/google/sanitizers/issues/786. Currently AsanCheckDynamicRTPrereqs prevents
dynamic ASan runtime from running in some important environments e.g. cowbuilder and fakeroot that may also work with interposition.
Let's allow users to switch off the check given that they know what they do.

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

llvm-svn: 299188
2017-03-31 06:36:37 +00:00
Kuba Mracek 0bf5ec2812 [tsan] Add interceptor for xpc_connection_cancel to avoid false positives
TSan reports a false positive when using xpc_connection_cancel. We're missing a happens-before edge from xpc_connection_cancel to the event handler on the same connection.

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

llvm-svn: 299086
2017-03-30 15:48:25 +00:00
Kuba Mracek fe7e91b003 [asan] Implement "scribble" flags, which overwrite free'd memory with 0x55
This patch implements "Malloc Scribble" in ASan via "max_free_fill_size" and "free_fill_byte" flags, which can be used to overwrite free()'d memory. We also match the behavior of MallocScribble and MallocPreScribble env vars on macOS (see https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html), which is a helpful tool to detect use-after-free bugs that happen in non-instrumented code.

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

llvm-svn: 299085
2017-03-30 15:44:57 +00:00
Francis Ricci 2aa23e892c Enable leak detection on linux-i686 by default
Summary:
This is already assumed by the test suite, and by
asan_flags.cc.

Reviewers: m.ostapenko, vitalybuka, kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 299082
2017-03-30 14:05:46 +00:00
Maxim Ostapenko f29aec76dd [sanitizer] Move fread and fwrite interceptors to sanitizer_common
{M, T, E}San have fread and fwrite interceptors, let's move them to sanitizer_common to enable ASan checks as well.

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

llvm-svn: 299061
2017-03-30 07:25:33 +00:00
Kuba Mracek 8ed2928d2c [asan] Support line numbers in StackVarDescr
When -fsanitize-address-use-after-scope is used, the instrumentation produces line numbers in stack frame descriptions. This patch make sure the ASan runtime supports this format (ParseFrameDescription needs to be able to parse "varname:line") and prepares lit tests to allow line numbers in ASan report output.

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

llvm-svn: 299043
2017-03-30 00:41:09 +00:00
Kostya Serebryany 2203ee08dd [sanitizers] Fix get_groups interceptor in sanitizer (https://reviews.llvm.org/D31332, patch by Martin Liška)
llvm-svn: 299036
2017-03-29 22:59:28 +00:00
Francis Ricci a79b8a22b4 Move current thread data out of lsan_common on linux
Summary:
Now that we have a platform-specific non-common lsan file, use
it to store non-common lsan data.

Reviewers: kubamracek

Subscribers: llvm-commits

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

llvm-svn: 299032
2017-03-29 21:49:47 +00:00
Francis Ricci 1aa20001ed Remove failing check from platform specific darwin lsan initializer
Summary:
We currently don't have any platform specific darwin
lsan modules, don't force failure if they don't exist.

Reviewers: kubamracek

Subscribers: llvm-commits

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

llvm-svn: 299031
2017-03-29 21:49:13 +00:00
Filipe Cabecinhas e144b72372 Add allocator_frees_and_returns_null_on_realloc_zero=false flag for compatibility with allocators which allow a realloc(p, 0) and don't free the pointer.
Summary:
I know of two implementations that do this (ASan is not protecting against accessing the returned memory for now, just like malloc(0)):
SIE libc on the PS4
dlmalloc has a flag for this

This allows us to properly support this behaviour.

Reviewers: vsk, kcc

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 299016
2017-03-29 18:17:22 +00:00
Dean Michael Berris 9b57ca171d [XRay] [compiler-rt] Write buffer length to FDR log before writing buffer.
Summary:
Currently the FDR log writer, upon flushing, dumps a sequence of buffers from
its freelist to disk. A reader can read the first buffer up to an EOB record,
but then it is unclear how far ahead to scan to find the next threads traces.

There are a few ways to handle this problem.
1. The reader has externalized knowledge of the buffer size.
2. The size of buffers is in the file header or otherwise encoded in the log.
3. Only write out the portion of the buffer with records. When released, the
   buffers are marked with a size.
4. The reader looks for memory that matches a pattern and synchronizes on it.

2 and 3 seem the most flexible and 2 does not rule 3 out.

This is an implementation of 2.

In addition, the function handler for fdr more aggressively checks for
finalization and makes an attempt to release its buffer.

Reviewers: pelikan, dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 298982
2017-03-29 05:56:37 +00:00
Dean Michael Berris cf791cf389 [XRay][compiler-rt] Add an end-to-end test for FDR Logging
Summary:
This change exercises the end-to-end functionality defined in the FDR
logging implementation. We also prepare for being able to run traces
generated by the FDR logging implementation from being analysed with the
llvm-xray command that comes with the LLVM distribution.

This also unblocks D31385, D31384, and D31345.

Reviewers: kpw, pelikan

Subscribers: llvm-commits, mgorny

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

llvm-svn: 298977
2017-03-29 05:19:24 +00:00
Weiming Zhao d8ca74176e [Builtin] Unxfail tests for armhf
Summary:
Originally, a few tests fail for armhf target due to:
1) COMPILER_RT_ARMHF_TARGET was not set when building the lib
2) COMPILER_RT_ABI should not be defined as `__attribute__((pcs("aapcs")))` for armhf when building for both lib and tests

This address https://bugs.llvm.org//show_bug.cgi?id=32261

mulsc3_test.c is a newly exposed issue, which will be addressed separately.

Reviewers: rengolin, compnerd

Reviewed By: compnerd

Subscribers: aemerson, llvm-commits, mgorny

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

llvm-svn: 298974
2017-03-29 03:36:46 +00:00
Francis Ricci 99a84b163f Postpone lsan tls allocation until required
Summary:
This prevents InternalAlloc from being called before the sanitizers
are fully initialized.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 298947
2017-03-28 21:56:45 +00:00
Francis Ricci ab85292261 Enable i386 builds for darwin lsan
Summary:
Now that __thread is no longer used for lsan on darwin, i386 builds
can be enabled.

Reviewers: kcc, kubamracek

Subscribers: danalbert, srhines, mgorny, llvm-commits

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

llvm-svn: 298946
2017-03-28 21:56:44 +00:00
Francis Ricci f1c2f2a668 Fix missing sanitizer platform include
llvm-svn: 298884
2017-03-27 20:22:02 +00:00
Francis Ricci 2609fd319f Fix comment in lsan_linux.cc
llvm-svn: 298879
2017-03-27 19:44:11 +00:00
Francis Ricci 3e564e985f Move lsan allocator cache from lsan_common_linux to lsan_linux
Having this function in common seems to trigger a lot of unrelated
test failures. Given that this isn't really common code anyway,
move this to a new linux-specific lsan file.

llvm-svn: 298878
2017-03-27 19:42:37 +00:00
Bill Seurer 467afc5f84 [powerpc] deactivate ManyThreadsTest asan test on powerpc64
This test case occassionally hangs when run on powerpc.  This is also a
problem on AArch64 (see https://bugs.llvm.org/show_bug.cgi?id=24389).
Reactivate this when the problem is fixed.

This could also be related to the same problem as with the tests
ThreadedOneSizeMallocStressTest, ThreadedMallocStressTest, and several
others that do not run reliably on powerpc.

llvm-svn: 298873
2017-03-27 18:36:06 +00:00
Francis Ricci d668a018f7 Use pthreads for thread-local lsan allocator cache on darwin
Summary:
This patch allows us to move away from using __thread on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 298848
2017-03-27 14:07:50 +00:00
Ismail Donmez a2e33e60d2 Fix build error:
In file included from /home/abuild/rpmbuild/BUILD/llvm/projects/compiler-rt/lib/xray/tests/unit/xray_fdr_log_printer_tool.cc:15:
../projects/compiler-rt/lib/xray/tests/../xray_fdr_logging_impl.h:221:21: error: use of undeclared identifier 'CLOCK_MONOTONIC'
  wall_clock_reader(CLOCK_MONOTONIC, &TS);
                    ^
1 error generated.

llvm-svn: 298837
2017-03-27 10:17:03 +00:00
Dean Michael Berris 1dcec25487 [XRay][compiler-rt] Use sanitizer_common's atomic ops
Instead of std::atomic APIs for atomic operations, we instead use APIs
include with sanitizer_common. This allows us to, at runtime, not have
to depend on potentially dynamically provided implementations of these
atomic operations.

Fixes http://llvm.org/PR32274.

llvm-svn: 298833
2017-03-27 07:13:35 +00:00
Kuba Mracek a1737293fc [tsan] Only Acquire/Release GCD queues if they're not NULL
While it's usually a bug to call GCD APIs, such as dispatch_after, with NULL as a queue, this often "somehow" works and TSan should maintain binary compatibility with existing code. This patch makes sure we don't try to call Acquire and Release on NULL queues, and add one such testcase for dispatch_after.

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

llvm-svn: 298820
2017-03-26 20:59:23 +00:00
Dmitry Vyukov 8096a8c86f tsan: add new mutex annotations
There are several problems with the current annotations (AnnotateRWLockCreate and friends):
- they don't fully support deadlock detection (we need a hook _before_ mutex lock)
- they don't support insertion of random artificial delays to perturb execution (again we need a hook _before_ mutex lock)
- they don't support setting extended mutex attributes like read/write reentrancy (only "linker init" was bolted on)
- they don't support setting mutex attributes if a mutex don't have a "constructor" (e.g. static, Java, Go mutexes)
- they don't ignore synchronization inside of lock/unlock operations which leads to slowdown and false negatives
The new annotations solve of the above problems. See tsan_interface.h for the interface specification and comments.

Reviewed in https://reviews.llvm.org/D31093

llvm-svn: 298809
2017-03-26 15:27:04 +00:00
Kuba Mracek e598c0d8e1 Follow-up for r298738: Use "0" instead of "false" because the variable is uptr.
llvm-svn: 298741
2017-03-24 21:12:24 +00:00
Kuba Mracek 44df297598 Fix an uninitialized field in tsan_block_context_t/AllocContext in tsan_libdispatch_mac.cc.
llvm-svn: 298738
2017-03-24 20:57:33 +00:00
Weiming Zhao a78ae8a172 Revert "builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA."
This reverts commit c3709191b6d36c4c936173f4a9a29a734b12cb15.
(commit by mistake)

llvm-svn: 298715
2017-03-24 17:08:35 +00:00
Weiming Zhao 19bf8bfa15 builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA.
Summary:
Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation
mode (-mthumb, -marm), it reflect's capability of given CPU.

Due to this:
 - use  __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB
 - use '.thumb' directive consistently  in all affected files
 - decorate all thumb functions using
   DEFINE_COMPILERRT_THUMB_FUNCTION()

---------
Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 !

Reviewers: weimingz, rengolin, compnerd

Subscribers: aemerson, dim

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

llvm-svn: 298713
2017-03-24 17:06:00 +00:00
Martin Pelikan 1730dc789e [XRay] [compiler-rt] Plug a file descriptor leak in a failure case.
Summary: Fd needs to be closed before the number gets out of scope.

Reviewers: dberris

Subscribers: llvm-commits

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

llvm-svn: 298685
2017-03-24 05:02:51 +00:00
Kuba Mracek 1082904d20 Fix a warning when running the GotsanRuntimeCheck test on Darwin.
llvm-svn: 298684
2017-03-24 03:57:27 +00:00
Alex Shlyapnikov d6848fc58f Add strtok interceptor for ASAN for Windows.
Summary: Fixes test broken by D30384

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 298658
2017-03-23 23:20:47 +00:00
Alex Shlyapnikov 4ab77b9f28 [asan] Add an interceptor for strtok
Summary:
This change addresses https://github.com/google/sanitizers/issues/766. I
tested the change with make check-asan and the newly added test case.

Reviewers: ygribov, kcc, alekseyshl

Subscribers: kubamracek, llvm-commits

Patch by mrigger

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

llvm-svn: 298650
2017-03-23 21:39:52 +00:00
Alex Shlyapnikov 86abf9aeb3 Bypass potential libc's sysconf interceptors
Summary:
sysconf(_SC_PAGESIZE) is called very early during sanitizer init and
any instrumented code (sysconf() wrapper/interceptor will likely be
instrumented) calling back to sanitizer before init is done will
most surely crash.

2nd attempt, now with glibc version checks (D31092 was reverted).

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits

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

llvm-svn: 298613
2017-03-23 15:57:58 +00:00
Francis Ricci dc13921fbc Factor lsan allocator cache accesses into a function
Summary:
This patch is the first step towards allows us to move away from using
__thread for the allocator cache on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

This will be followed by patches to move the function into OS-specific files.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 298537
2017-03-22 18:42:43 +00:00
Dmitry Vyukov 28264edea3 tsan: fix a typo
s/covert_morder/convert_morder/

llvm-svn: 298492
2017-03-22 09:31:17 +00:00
Dean Michael Berris 6ba6673dfd [XRay][compiler-rt] Remove dependency on <system_error>
Summary:
Depending on C++11 <system_error> introduces a link-time requirement to
C++11 symbols. Removing it allows us to depend on header-only C++11 and
up libraries.

Partially fixes http://llvm.org/PR32274 -- we know there's more invasive work
to be done, but we're doing it incrementally.

Reviewers: dblaikie, kpw, pelikan

Subscribers: llvm-commits

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

llvm-svn: 298480
2017-03-22 04:40:32 +00:00
Chandler Carruth 985f1a9417 Revert r298274: "Use pthreads for thread-local lsan allocator cache on darwin"
This fixes a failure currently present on the upstream linux boxes (and
reproduces for me as well):
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/1130/steps/64-bit%20check-asan-dynamic/logs/stdio

llvm-svn: 298382
2017-03-21 15:31:15 +00:00
Dmitry Vyukov de033e6cdb tsan: support __ATOMIC_HLE_ACQUIRE/RELEASE flags
HLE flags can be combined with memory order in atomic operations.
Currently tsan runtime crashes on e.g. IsStoreOrder(mo) in atomic store
if any of these additional flags are specified.

Filter these flags out.
See the comment as to why it is safe.

llvm-svn: 298378
2017-03-21 14:28:55 +00:00
Vitaly Buka 40b0b46746 Revert "Bypass potential libc's sysconf wrappers for sysconf(_SC_PAGESIZE) call"
Bot can't find <sys/auxv.h>

This reverts commit r298305.

llvm-svn: 298343
2017-03-21 06:55:32 +00:00
Alex Shlyapnikov a7291b3730 Bypass potential libc's sysconf wrappers for sysconf(_SC_PAGESIZE) call
Summary:
sysconf(_SC_PAGESIZE) is called very early, during sanitizer init and
any instrumented code (a wrapper/interceptor will likely be instrumented)
calling back to sanitizer before init is done will most surely crash.

Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 298305
2017-03-20 21:03:28 +00:00
Evgeniy Stepanov 3bf85d3124 Revert r298174, r298173, r298169, r298159.
Revert "Fix sanitizer tests with LLVM_TOOL_LLD_BUILD=OFF."
Revert "[asan] Remove gc-sections test with bfd."
Revert "[asan] Disable globals-gc test with ld.bfd."
Revert "[asan] Fix dead stripping of globals on Linux (compiler-rt)"

OOM in gold linker.

llvm-svn: 298287
2017-03-20 18:45:27 +00:00
Francis Ricci b91a5eabb3 Use pthreads for thread-local lsan allocator cache on darwin
Summary:
This patch allows us to move away from using __thread on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 298274
2017-03-20 17:06:42 +00:00
Francis Ricci d7b08a6c73 Revert "Use pthreads for thread-local lsan allocator cache on darwin"
This is still failing stack-use-after-return on linux-aarch64.

This reverts commit 5b350130fc4bf6f70c078a5d97096df98a17a057.

llvm-svn: 298246
2017-03-20 13:45:29 +00:00
Francis Ricci 9971b76d20 Use pthreads for thread-local lsan allocator cache on darwin
Summary:
This patch allows us to move away from using __thread on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 298214
2017-03-19 15:02:43 +00:00
Evgeniy Stepanov 79ee0c1813 [asan] Fix dead stripping of globals on Linux (compiler-rt)
Runtime support for the new instrumentation of globals based on !associated, and a bunch of tests.

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

llvm-svn: 298159
2017-03-17 22:17:38 +00:00
Rong Xu cf1f6fb1b2 Resubmit r295469 [PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write
And also r295364 [PGO] remove unintended debug trace. NFC
I removed the test case: it's hard to write synchronized test b/w processes
in this framework. I will revisit the test-case later.

llvm-svn: 298113
2017-03-17 18:41:33 +00:00
Dean Michael Berris 4cb8e11884 [XRay][compiler-rt] Add missing include to <string>
Fixes a build break when using clang-3.9.1 (reported upstream,
post-commit review of D30850).

llvm-svn: 298039
2017-03-17 03:38:12 +00:00
Dean Michael Berris edb0b93bad [XRay][compiler-rt] Add missing include for <functional>
Fixes http://llvm.org/PR32313

llvm-svn: 298037
2017-03-17 02:36:17 +00:00
Juergen Ributzka eecb0ec2ea Revert "[PowerPC] Fix sanitizer frame unwind on 32-bit ABIs"
This broke GreenDragon:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/29210/

llvm-svn: 298029
2017-03-17 01:15:39 +00:00
Bill Seurer 6c0f69da68 [PowerPC] Fix sanitizer frame unwind on 32-bit ABIs
This fixes many sanitizer problems with -m32.  It is really intended
for gcc but patches to the sanitizers make their way through llvm
first.

ref:  https://gcc.gnu.org/ml/gcc-patches/2017-02/msg00855.html
llvm-svn: 297995
2017-03-16 21:14:13 +00:00
Vitaly Buka bccdba0c1d [compiler-rt] Add undefined "dup" symbol into internal symbolizer white-list.
llvm-svn: 297924
2017-03-16 01:17:31 +00:00
Evgeniy Stepanov d3332fc92f [msan] Intercept getloadavg.
llvm-svn: 297923
2017-03-16 01:06:22 +00:00
Kostya Serebryany ec3ceb1ce5 [asan] trying to fix the windows build
llvm-svn: 297918
2017-03-15 23:53:12 +00:00
Kostya Serebryany 82a41dd6c4 [asan] add one more argument to __sanitizer_print_memory_profile, remove a redundant weak definition.
llvm-svn: 297914
2017-03-15 23:27:14 +00:00
Rong Xu b85cc09329 [PGO] Value profile support for value ranges
This patch adds profile run time support to profile a range of values.
This interface will be used in profiling the size of memory intrinsic calls.

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

llvm-svn: 297895
2017-03-15 21:46:31 +00:00
Dean Michael Berris 5d892ab02e Add NO_EXEC_STACK_DIRECTIVE to xray assembly files.
Summary: Add NO_EXEC_STACK_DIRECTIVE to xray assembly files

Reviewers: dberris, javed.absar

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 297894
2017-03-15 21:18:47 +00:00
Reid Kleckner 029dbd5e97 Fix -Wstring-conversion instance
llvm-svn: 297879
2017-03-15 19:50:02 +00:00
Alex Lorenz d2677c8ed5 [compiler-rt][builtins] Ignore the deprecated warning for
CFPropertyListCreateFromXMLData that's used in __isOSVersionAtLeast

I forgot to add the pragmas in r297760.

llvm-svn: 297827
2017-03-15 12:13:20 +00:00
Dean Michael Berris c6ee33852b [XRay] [compiler-rt] Refactor logic for xray fdr logging. NFC.
Summary:
Separated the IO and the thread local storage state machine of logging
from the writing of log records once the contents are deterministic.

Finer granularity functions are provided as inline functions in the same
header such that stack does not grow due to the functions being separated.

An executable utility xray_fdr_log_printer is also implemented to use the
finest granularity functions to produce binary test data in the FDR format
with a relatively convenient text input.

For example, one can take a file with textual contents layed out in rows
and feed it to the binary to generate data that llvm-xray convert can then
read. This is a convenient way to build a test suite for llvm-xray convert
to ensure it's robust to the fdr format.

Example:

$cat myFile.txt
NewBuffer : { time = 2 , Tid=5}
NewCPU : { CPU =1 , TSC = 123}
Function : { FuncId = 5, TSCDelta = 3, EntryType = Entry }
Function : { FuncId = 5, TSCDelta = 5, EntryType = Exit}
TSCWrap : { TSC = 678 }
Function : { FuncId = 6, TSCDelta = 0, EntryType = Entry }
Function : { FuncId = 6, TSCDelta = 50, EntryType = Exit }
EOB : { }
$cat myFile.txt | ./bin/xray_fdr_log_printer > /tmp/binarydata.bin
$./bin/llvm-xray convert -output-format=yaml -output=- /tmp/binarydata.bin

yaml format comes out as expected.

Reviewers: dberris, pelikan

Reviewed By: dberris

Subscribers: llvm-commits, mgorny

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

llvm-svn: 297801
2017-03-15 03:12:01 +00:00
Dean Michael Berris 66443d80f1 [XRay][compiler-rt] Support TSC emulation even for x86_64
Summary:
Use TSC emulation in cases where RDTSCP isn't available on the host
running an XRay instrumented binary. We can then fall back into
emulation instead of not even installing XRay's runtime functionality.
We only do this for now in the naive/basic logging implementation, but
should be useful in even FDR mode.

Should fix http://llvm.org/PR32148.

Reviewers: pelikan, rnk, sdardis

Subscribers: llvm-commits

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

llvm-svn: 297800
2017-03-15 02:28:00 +00:00
Dean Michael Berris 601afaf089 Fix a build break with xray
Summary: Building compiler-rt with clang 3.7 broken, could not find mkstemp

Reviewers: dberris, bkramer

Reviewed By: dberris

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

llvm-svn: 297794
2017-03-14 23:49:12 +00:00
Evgeniy Stepanov a4238e4cdb [msan] Intercept wcsncpy, wcsnlen.
llvm-svn: 297793
2017-03-14 23:48:37 +00:00
Dimitry Andric e773b2d341 After rL297370 and rL297383, instead of a platform check, explicitly
check for the existence of RTLD_DEEPBIND, since this constant is only
supported for glibc >= 2.3.4.  This fixes builds for FreeBSD and other
platforms that do not have RTLD_DEEPBIND.

llvm-svn: 297763
2017-03-14 18:18:14 +00:00
Alex Lorenz ca1fab5d66 [compiler-rt][builtins] __isOSVersionAtLeast should load CoreFoundation
symbols dynamically

The CoreFoundation symbols uses by __isOSVersionAtLeast should be loaded at
runtime to ensure that the programs that don't use @available won't have to be
linked to CoreFoundation.

The Clang frontend IRGen library will need to emit a CoreFoundation symbol
when @available is used to ensure that programs that actually use @available
are linked to CoreFoundation.

rdar://31039554

llvm-svn: 297760
2017-03-14 17:53:37 +00:00
Vedant Kumar c5d628400f [ubsan] Add nullability handlers to interface file
llvm-svn: 297749
2017-03-14 16:36:03 +00:00
Vedant Kumar f2d04e628d [ubsan] Add diagnostic handlers for nullability errors
Add 'nullability_arg' and 'nullability_return' diagnostic handlers, and
also add a TypeCheckKind for null assignments to _Nonnull. With this in
place, we can update clang to use the nicer handlers for nullability
diagnostics.

The alternative to this approach is to update the existing 'nonnull_arg'
and 'nonnull_return' handlers to accept a boolean parameter. However,
versioning the existing handlers would cause code size bloat, and the
complexity cost of introducing new handlers into the runtime is low.

I will add tests for this, and all of -fsanitize=nullability, into
check-ubsan once the clang side of the changes is in.

llvm-svn: 297748
2017-03-14 16:32:27 +00:00
Filipe Cabecinhas 51c5396de8 Some ASan bots (AArch64 at least) use SEGV for a unit test error instead of SIGBUS
llvm-svn: 297728
2017-03-14 10:26:37 +00:00
Filipe Cabecinhas f7c7c11312 [asan] Split SIGSEGV / SIGBUS handling so we can handle only one of them and not the other.
Summary: This is useful in some platforms where one of these signals is special.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 297665
2017-03-13 21:06:41 +00:00
Alex Lorenz c630f349b8 [compiler-rt][builtins] Ignore the deprecated warning for
CFPropertyListCreateFromXMLData that's used in __isOSVersionAtLeast

llvm-svn: 297613
2017-03-13 11:00:44 +00:00
Erik Pilkington eea05ec3f3 Silence a pedantic warning, NFC
llvm-svn: 297515
2017-03-10 21:38:59 +00:00
Erik Pilkington 0490e1c5f4 Reapply r297382: "[compiler-rt][builtins] Add __isOSVersionAtLeast()"
Looks like the problem was a case-insensitive include of dispatch/dispatch.h.

llvm-svn: 297392
2017-03-09 17:02:16 +00:00
Erik Pilkington 4d297df95c Revert "[compiler-rt][builtins] Add __isOSVersionAtLeast()"
This reverts r297382, it was causing build failures.

llvm-svn: 297388
2017-03-09 15:58:26 +00:00
Maxim Ostapenko c206800218 [sanitizer] Fix android buildbots after r297370
llvm-svn: 297383
2017-03-09 14:40:15 +00:00
Erik Pilkington 6fa97926e9 [compiler-rt][builtins] Add __isOSVersionAtLeast()
This predicate compares the host's marketing OS version to one passed as
argument. Currently, only darwin targets are supported. This is done by parsing
the SystemVersion.plist file.

Also added in this patch is some lit testing infrastructure for builtins, which
previously had none. This part of the patch was written by Alex Lorenz (with
some minor modifications).

This patch is part of a feature I proposed here:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html

Differential revision: https://reviews.llvm.org/D30136

llvm-svn: 297382
2017-03-09 14:17:36 +00:00
Maxim Ostapenko 76630d43f6 [sanitizer] Bail out with warning if user dlopens shared library with RTLD_DEEPBIND flag
People keep hitting on spurious failures in malloc/free routines when using sanitizers
with shared libraries dlopened with RTLD_DEEPBIND (see https://github.com/google/sanitizers/issues/611 for details).
Let's check for this flag and bail out with warning message instead of failing in random places.

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

llvm-svn: 297370
2017-03-09 10:47:38 +00:00
Francis Ricci 0504863383 Use correct function signature for strerror_r interceptor
There are two possible return values for strerror_r:

On OS X, the return value is always `int`.
On Linux, the return value can be either `char *` or `int`, depending
on the value of:
`(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE`

Because OS X interceptors require a matching function signature,
split out the two cases into separate interceptors, using the above
information to determine the correct signature for a given build.

llvm-svn: 297315
2017-03-08 22:51:03 +00:00
Tim Shen 0243eac2d8 [XRay] [compiler-rt] Stub out architectures we don't do arg1 logging on.
rL297000 forgot to include code for three architectures that appeared
since I wrote the first version. This gives them the same treatment as ARMs
have for now - write stubs and wait for someone to actually implement it.

Patched by pelikan (Martin Pelikán)!

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

llvm-svn: 297003
2017-03-06 08:26:21 +00:00
Dean Michael Berris a814c94163 [XRay] [compiler-rt] Allow logging the first argument of a function call.
Summary:
Functions with the LOG_ARGS_ENTRY sled kind at their beginning will be handled
in a way to (optionally) pass their first call argument to your logging handler.

For practical and performance reasons, only the first argument is supported, and
only up to 64 bits.

Reviewers: javed.absar, dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 297000
2017-03-06 07:25:41 +00:00
Evgeniy Stepanov b6fe13f26b [msan] Test for _mm_getcsr and _mm_setcsr (r296848).
llvm-svn: 296849
2017-03-03 01:13:23 +00:00
Francis Ricci 7cd7d9bc8e Revert "Use pthreads for thread-local lsan allocator cache on darwin"
Reverting due to revert of prerequisite patch r296706

This reverts commit 6e1f23078c1acc44295065d28167043c4d31ddd1.

llvm-svn: 296720
2017-03-02 00:12:58 +00:00
Francis Ricci 923a320441 Use pthreads for thread-local lsan allocator cache on darwin
Summary:
This patch allows us to move away from using __thread on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 296707
2017-03-01 23:18:15 +00:00
Filipe Cabecinhas 9a563daff5 Restrict usage of MemoryMappingLayout to platforms which support it
llvm-svn: 296657
2017-03-01 19:20:13 +00:00
Filipe Cabecinhas 74ad311556 Reapply r296419: [asan] Print a "PC is at a non-executable memory region" message if that's the case
Summary: Points the user to look at function pointer assignments.

Reviewers: kcc, eugenis, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 296653
2017-03-01 18:52:11 +00:00
Dean Michael Berris fbe64b65a8 [XRay] [compiler-rt] [NFC] Annotate unused variables for the compiler.
Summary:
Use a common definition of a "this variable is unused" annotation for useless
variables only present for their lambda global initializers, to silence gcc's
warning.

Reviewers: dberris

Reviewed By: dberris

Subscribers: llvm-commits

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

llvm-svn: 296449
2017-02-28 08:48:46 +00:00
Dean Michael Berris 427215ce5e [XRay][compiler-rt] Switch default XRay 'patch_premain' to false
Summary:
Currently, we assume that applications built with XRay would like to
have the instrumentation sleds patched before main starts. This patch
changes the default so that we do not patch the instrumentation sleds
before main. This default is more helpful for deploying applications in
environments where changing the current default is harder (i.e. on
remote machines, or work-pool-like systems).

This default (not to patch pre-main) makes it easier to selectively run
applications with XRay instrumentation enabled, than with the current
state.

Reviewers: echristo, timshen

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 296445
2017-02-28 08:10:01 +00:00
Filipe Cabecinhas 6e36c11d2a Revert r296419 since the strings appear to need some tweaking.
llvm-svn: 296428
2017-02-28 02:45:46 +00:00
Filipe Cabecinhas cd643f6324 [asan] Print a "PC is at a non-executable memory region" message if that's the case
Summary: Points the user to look at function pointer assignments.

Reviewers: kcc, eugenis, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 296419
2017-02-28 00:56:43 +00:00
Benjamin Kramer 782e98e8aa [xray] Unbreak unittest after r295967.
llvm-svn: 295969
2017-02-23 13:13:27 +00:00
Benjamin Kramer 7654191e70 [Xray] fix building the runtime with GCC.
GCC has a warning about enum bitfields that cannot be disabled. Do the
ugly thing and go through uint8_t for all the values.

llvm-svn: 295967
2017-02-23 12:49:41 +00:00
Kuba Mracek c90b79c585 Re-commit of r295318, which was reverted due to AArch64 flakiness. Moving the test to Darwin only.
llvm-svn: 295801
2017-02-22 01:13:34 +00:00
Tim Shen 01fb2c87b9 [XRay] Change the ppc trampoline asm file into a different name, to not collide with the cc file. NFC.
llvm-svn: 295795
2017-02-22 00:19:43 +00:00
Vitaly Buka 5d6631d8b4 [compiler-rt] Prevent symbolizer from starting itself.
Summary:
If symbolizer was instrumented with sanitizer and crash, it may
try to call itself again causing infinite recursion of crashing processes.

Reviewers: eugenis

Subscribers: kubamracek, llvm-commits, dberris

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

llvm-svn: 295771
2017-02-21 21:39:24 +00:00
Etienne Bergeron 0eec53cb41 [compiler-rt][asan] Fix incorrect macro preventing ICF with MSVC
Summary:
The DLL thunks are stubs added to an instrumented DLL to redirect ASAN API calls
to the real ones in the main executable. These thunks must contain dummy
code before __asan_init got called. Unfortunately, MSVC linker is doing ICF and is
merging functions with the same body.


In our case, this two ASAN thunks were incorrectly merged:
```
asan_interface.inc:16
INTERFACE_FUNCTION(__asan_before_dynamic_init)
```
```
sanitizer_common_interface.inc:16
INTERFACE_FUNCTION(__sanitizer_verify_contiguous_container)
```

The same thunk got patched twice. After the second patching, calls to
`__asan_before_dynamic_init` are redirected to `__sanitizer_verify_contiguous_container`
and trigger a DCHECK on incorrect operands/

The problem was caused by the macro that is only using __LINE__ to prevent
collapsing code.
```
 #define INTERCEPT_SANITIZER_FUNCTION(name)
   extern "C" __declspec(noinline) void name() {
   volatile int prevent_icf = (__LINE__ << 8); (void)prevent_icf;
```

The current patch is adding __COUNTER__ which is safer than __LINE__.

Also, to precent ICF (guarantee that code is different), we are using a unique attribute:
  - the name of the function

Reviewers: rnk

Reviewed By: rnk

Subscribers: llvm-commits, kubamracek, chrisha, dberris

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

llvm-svn: 295761
2017-02-21 20:04:47 +00:00
Renato Golin fc1ccec9bb [RT ARM] Avoid Linux include with a redefinition
To avoid depending on kernel headers, we just repeat the single define
we need, which is likely never going to change.

Patch by Joakim Sindholt <opensource@zhasha.com>

llvm-svn: 295738
2017-02-21 17:40:26 +00:00
Etienne Bergeron fc68c2c777 [compiler-rt][asan] Add support for desallocation of unhandled pointers
Summary: On windows 10, the ucrt DLL is performing allocations before the function hooking and there are multiple allocations not handled by Asan. When a free occur at the end of the process, asan is reporting desallocations not malloc-ed.

Reviewers: rnk, kcc

Reviewed By: rnk, kcc

Subscribers: kcc, llvm-commits, kubamracek, chrisha, dberris

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

llvm-svn: 295730
2017-02-21 16:09:38 +00:00
Diana Picus 99141cc7ca Revert "[tsan] Provide external tags (object types) via debugging API"
This reverts commit r295318 as the test is flaky on AArch64.

llvm-svn: 295667
2017-02-20 15:26:12 +00:00
Renato Golin 18342e39e6 Revert "[PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write"
Revert "[PGO] remove unintended debug trace. NFC"

This reverts commit r295469, r295364, as they are unstable on ARM/AArch64.

llvm-svn: 295664
2017-02-20 15:03:12 +00:00
Dean Michael Berris 773c2ab9d6 [XRay][compiler-rt] Allow for defining defaults at compile-time
Summary:
Currently, defaulted options cannot be overriden easily. As an example,
we always patch the binary pre-main unless the user defines the option
at the commandline to inhibit this behaviour. This change allows for
building different versions of the XRay archive with different defaults
(whether to patch pre-main, or whether to use FDR mode by default, etc.)
and giving that choice at link-time.

For now we don't create different archives that have different defaults,
but those could be added in later revisions. This change just enables
the possibility.

Reviewers: pelikan, kcc

Subscribers: llvm-commits

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

llvm-svn: 295534
2017-02-18 02:09:51 +00:00
Rong Xu 1ba2cacc96 [PGO] remove unintended debug trace. NFC
llvm-svn: 295469
2017-02-17 17:42:16 +00:00
Francis Ricci f891e90b35 Revert "Use pthreads for thread-local lsan allocator cache on darwin"
This caused a failure in Linux-x86_64 stack-use-after-return

This reverts commit 1f9563141e999016d13ac3fc6a50fde690381e82.

llvm-svn: 295449
2017-02-17 14:42:30 +00:00
Francis Ricci 01159f5c58 Use pthreads for thread-local lsan allocator cache on darwin
Summary:
This patch allows us to move away from using __thread on darwin,
which is requiring for building lsan for darwin on ios version 7
and on iossim i386.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 295413
2017-02-17 04:32:19 +00:00
Francis Ricci a0921f68ab Fix build breakage from moving kInvalidTid to lsan_common
llvm-svn: 295409
2017-02-17 03:34:56 +00:00
Francis Ricci 571c05a550 Use pthreads to store current thread id on darwin
Summary:
__thread is not supported by all darwin versions and architectures,
use pthreads instead to allow for building darwin lsan on iossim.

Reviewers: kubamracek, kcc

Subscribers: llvm-commits

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

llvm-svn: 295405
2017-02-17 03:23:07 +00:00
Rong Xu 72f1e5440e [PGO] Suspend SIGKILL for PR_SET_PDEATHSIG in profile-write
Summary:
We found a nondeterministic behavior when doing online profile merging
for multi-process applications. The application forks a sub-process and
sub-process sets to get SIGKILL when the parent process exits,

The first process gets the lock, and dumps the profile. The second one
will mmap the file, do the merge and write out the file. Note that before
the merged write, we truncate the profile.

Depending on the timing, the child process might be terminated
abnormally when the parent exits first. If this happens:
(1) before the truncation, we will get the profile for the main process
(2) after the truncation, and before write-out the profile,  we will get
0 size profile.
(3) after the merged write, we get merged profile.

This patch temporarily suspend the SIGKILL for PR_SET_PDEATHSIG
before profile-write and restore it after the write.

This patch only applies to Linux system.

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: xur, llvm-commits

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

llvm-svn: 295364
2017-02-16 19:21:31 +00:00
Vitaly Buka 78395f23dc [sanitizers] DefaultSymbolizer should not be destroyed as as symbolizer
can be accessed after the static destroyed.

llvm-svn: 295348
2017-02-16 18:35:38 +00:00
Kuba Mracek 3e81c2675e [tsan] Provide external tags (object types) via debugging API
In D28836, we added a way to tag heap objects and thus provide object types into report. This patch exposes this information into the debugging API.

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

llvm-svn: 295318
2017-02-16 14:02:32 +00:00
Vitaly Buka f813697f05 [sanitizers] Fix formatting of the shell script.
llvm-svn: 295299
2017-02-16 08:47:27 +00:00
Vitaly Buka 69068dd50e [sanitizers] Redirect pthread calls to interceptors.
It's needed if libcxx is build without disabling threads.

llvm-svn: 295296
2017-02-16 08:06:17 +00:00
Vitaly Buka e4465dba20 Extract *.a to *.bc conversion into separate script.
Reviewers: eugenis

Subscribers: llvm-commits, kubamracek

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

llvm-svn: 295272
2017-02-16 02:12:18 +00:00
Tim Shen c6ce73b114 Re-commit r295017, since we have a potential fix of the tests, r295248, landed.
Differential Revision: https://reviews.llvm.org/D29742

llvm-svn: 295251
2017-02-15 22:40:29 +00:00
Tim Shen b39372859f [XRay] Fix gtest error code comparison. NFC.
llvm-svn: 295248
2017-02-15 22:30:54 +00:00
Etienne Bergeron b69639e217 [compiler-rt][asan|win] Fix ASAN exception handler missing import
Summary:
This patch is adding a missing ASAN API redirection from an instrumented DLL.
The bug was introduced here:
  https://reviews.llvm.org/D29463

This is causing this chromium bug:
  https://bugs.chromium.org/p/chromium/issues/detail?id=692580

Reviewers: rnk

Reviewed By: rnk

Subscribers: kubamracek, dberris, llvm-commits, chrisha, thakis

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

llvm-svn: 295232
2017-02-15 20:48:04 +00:00
Sagar Thakur ea831e4c46 [Compiler-rt][XRAY][MIPS] Support xray on mips/mipsel/mips64/mips64el
Summary: Adds support for xray on mips/mipsel/mips64/mips64el.

Reviewed by sdardis, dberris
Differential: D27699

llvm-svn: 295166
2017-02-15 10:54:09 +00:00
Xinliang David Li f2d9481028 [PGO] Delay profile dir creation until write
Differential Revision: http://reviews.llvm.org/D29960

llvm-svn: 295108
2017-02-14 21:39:55 +00:00
Tim Shen 6edc4883fe Revert r295017 "Re-commit r294826 and r294781, with a fix on the cmake file to only"
llvm-svn: 295097
2017-02-14 19:48:13 +00:00
Etienne Bergeron 0ce53e4b9f [compiler-rt][asan|win] Fix flaky unittest due to large allocations
Summary:
Coverage is using large arrays which requires large allocations.
These allocations are flaky and often failing on win64.

We are using the 32-bits size until this gets a better fix.

Reviewers: rnk

Reviewed By: rnk

Subscribers: llvm-commits, kubamracek, chrisha, dberris

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

llvm-svn: 295086
2017-02-14 18:57:17 +00:00
Tim Shen b94588eb88 Re-commit r294826 and r294781, with a fix on the cmake file to only
compile on powerpc64le.

I cannot locally reproduce this test failure:
http://lab.llvm.org:8011/builders/sanitizer-ppc64le-linux/builds/1363/steps/test%20standalone%20compiler-rt/logs/stdio

Let's see how the buildbot goes.

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

llvm-svn: 295017
2017-02-14 02:05:47 +00:00
Francis Ricci 8187c7b06b Add cmake build support for lsan on OS X
Summary:
Adds a new cmake flag 'COMPILER_RT_ENABLE_LSAN_OSX', which enables lsan
compilation and is turned off by default. Patches to fix build errors
when this flag is enabled will be uploaded soon.

This is part of an effort to port LSan to OS X, but LSan on OS X does not
currently work or pass tests currently.

Reviewers: kubamracek, kcc, glider, alekseyshl

Reviewed By: kubamracek

Subscribers: danalbert, srhines, mgorny, llvm-commits

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

llvm-svn: 295012
2017-02-14 00:56:53 +00:00
Francis Ricci 7cda03e6d1 Use pthreads to manage thread-local storage on darwin for leak sanitizer
Summary:
__thread is supported on Darwin, but is implemented dynamically via
function calls to __tls_get_addr. This causes two issues when combined
with leak sanitizer, due to malloc() interception.

- The dynamic loader calls malloc during the process of loading
  the sanitizer dylib, while swapping a placeholder tlv_boostrap
  function for __tls_get_addr. This will cause tlv_bootstrap to
  be called in DisabledInThisThread() via the asan allocator.

- The first time __tls_get_addr is called, it allocates memory
  for the thread-local object, during which it calls malloc(). This
  call will be intercepted, leading to an infinite loop in the asan
  allocator, in which the allocator calls DisabledInThisThread,
  which calls tls_get_addr, which calls into the allocator again.

Reviewers: kcc, glider, kubamracek

Subscribers: llvm-commits

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

llvm-svn: 294994
2017-02-13 22:20:07 +00:00
Francis Ricci 259ad9cf08 Disable darwin interception of non-darwin functions
Summary: Fixes build issues when compiling lsan for darwin.

Reviewers: kubamracek, kcc, rnk

Subscribers: llvm-commits

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

llvm-svn: 294984
2017-02-13 21:06:13 +00:00
Francis Ricci 7406f0f54f Add lsan function stubs for darwin
Summary:
This patch provides stubs for all of the lsan platform-specific
functions which need to be implemented for darwin. Currently
all of these functions are stubs, for the purpose of fixing
compilation.

Reviewers: kcc, glider, kubamracek

Subscribers: mgorny, llvm-commits

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

llvm-svn: 294983
2017-02-13 21:03:15 +00:00
Weiming Zhao a164f470e6 [Builtin][ARM] Fix subsf3vfp for non-HF target
Reviewers: rengolin, compnerd

Reviewed By: compnerd

Subscribers: hans, aemerson

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

llvm-svn: 294886
2017-02-12 05:10:25 +00:00
NAKAMURA Takumi eb7dcc8c68 sancov.py: [Py3] Get rid of "print" statement. Use print() or write() instead.
Differential Revision: https://reviews.llvm.org/D27405

llvm-svn: 294880
2017-02-12 00:26:28 +00:00
Vitaly Buka 579ca307ab Re-submit r294826 "Fix -Wsign-compare" reverted in r294842 by mistake.
Fix -Wsign-compare - this might not be quite right, but preserves behavior

llvm-svn: 294868
2017-02-11 19:39:05 +00:00
Vitaly Buka d8230247c9 This reverts commits r294826 and r294781 as they break linking on powerpc.
Revert "Fix -Wsign-compare - this might not be quite right, but preserves behavior"
Revert "[XRay] Implement powerpc64le xray."

This reverts commit r294826.
This reverts commit r294781.

llvm-svn: 294842
2017-02-11 12:34:27 +00:00
David Blaikie 9730789ae6 Fix -Wsign-compare - this might not be quite right, but preserves behavior
llvm-svn: 294826
2017-02-11 06:07:59 +00:00
NAKAMURA Takumi a2eb926e8a sancov.py: [Py3] Use sys.stdout.buffer for bytes.
This is part of https://reviews.llvm.org/D27405

llvm-svn: 294812
2017-02-11 00:16:02 +00:00
Dimitry Andric c18de74165 Remove struct_rtentry_sz on FreeBSD
Summary:
Since struct rtentry is an internal kernel-only structure on FreeBSD,
and SIOCADDRT and SIOCDELRT are not supported anyway, stop including
socketvar.h and attempting to get at the definition of struct rtentry,
and move the line with struct_rtentry_sz to the SANIZER_LINUX block.

Reviewers: kcc, kutuzov.viktor.84, emaste

Reviewed By: kcc, emaste

Subscribers: emaste, llvm-commits, kubamracek

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

llvm-svn: 294806
2017-02-10 23:48:40 +00:00
Kostya Serebryany 4b3ea2d776 s390 CVE-2016-2143 whitelist for RHEL kernels
Summary: This patch adds whitelist for RHEL6 and RHEL7 kernels that are known to have the CVE fixed.

Reviewers: koriakin, kcc

Reviewed By: kcc

Subscribers: kubamracek

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

llvm-svn: 294799
2017-02-10 22:50:44 +00:00
Kostya Serebryany 5b53a2f292 Fix AddressSanitizer on s390 (31-bit)
Summary:
GET_CALLER_PC doesn't work properly on 31-bit s390, as pointers are 31-bit, the MSB bit can be set when the return address is copied into integer.
This causes e.g. errors like:
    #0 0xfdadb129  (<unknown module>)
    #1 0x7da5e1d1 in __asan::GetStackTraceWithPcBpAndContext(__sanitizer::BufferedStackTrace*, unsigned long, unsigned long, unsigned long, void*, bool) ../../../../../libsanitizer/asan/asan_stack.h:50
    #2 0x7da5e1d1 in __asan::ErrorGeneric::Print() ../../../../../libsanitizer/asan/asan_errors.cc:482
    #3 0x7db178d5 in __asan::ErrorDescription::Print() ../../../../../libsanitizer/asan/asan_errors.h:360
    #4 0x7db178d5 in __asan::ScopedInErrorReport::~ScopedInErrorReport() ../../../../../libsanitizer/asan/asan_report.cc:167
    #5 0x7db178d5 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ../../../../../libsanitizer/asan/asan_report.cc:397
    #6 0x7dadb14f in __interceptor_memcmp ../../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:626
    #7 0x400cf5 in main /home/jakub/gcc/gcc/testsuite/c-c++-common/asan/memcmp-1.c:14
    #8 0x7d807215 in __libc_start_main (/lib/libc.so.6+0x1a215)
    #9 0x4007ed  (/home/jakub/gcc/obj/gcc/testsuite/memcmp-1.exe+0x4007ed)

The actual return PC inside __interceptor_memcmp was 0x7dadb129 rather than 0xfdadb129.

Reviewers: koriakin, kcc

Reviewed By: kcc

Subscribers: kubamracek

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

llvm-svn: 294793
2017-02-10 22:26:19 +00:00