Commit Graph

6605 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