Commit Graph

6397 Commits

Author SHA1 Message Date
Adhemerval Zanella f2d3dbfaca [compiler-rt] [dfsan] Unify aarch64 mapping
This patch reorganize the platform specific mapping information to
export the application mask on a external variable. This exported
variable will be used by intrumentation phase to create code to be
used on architecture with multiple VMA range.
    
The patch creates a new header, dfsan_platform.h, and move all the
mapping information and also create function accessors to the
mapping value.

Also for aarch64 it initialize application exported mask to the 
value based on runtime VMA detection.

llvm-svn: 254197
2015-11-27 12:43:33 +00:00
Adhemerval Zanella 066c5f0f92 [compiler-rt] [tsan] Unify aarch64 mapping
This patch unify the 39 and 42-bit support for AArch64 by using an external
memory read to check the runtime detected VMA and select the better mapping
and transformation.  Although slower, this leads to same instrumented binary
to be independent of the kernel.

Along with this change this patch also fix some 42-bit failures with
ALSR disable by increasing the upper high app memory threshold and also
the 42-bit madvise value for non large page set.

llvm-svn: 254151
2015-11-26 13:10:47 +00:00
Xinliang David Li 463e5ab205 Sync up with master InstrProfData.inc
llvm-svn: 254113
2015-11-26 00:03:34 +00:00
Ivan Krasin 00de6bc9b7 sanitizer_common: remove noisy warning about symbolizer not found.
Summary:
In r251553, I added a warning that proved to be super noisy,
especially in case of MSan. Removing it for now, and I will
probably add some additional diagnostics for symbolizer, when
I better understand how to make it properly.

Reviewers: eugenis

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

llvm-svn: 254102
2015-11-25 22:00:20 +00:00
Chris Bieneman f1f46b5766 [CMake] [Darwin] libclang_rt.eprintf should be built with the same CFLAGS as the other darwin builtin libraries.
llvm-svn: 254082
2015-11-25 19:32:32 +00:00
Kuba Brecka 4aa4a73f17 [sanitizer] Fix a crash with DlAddrSymbolizer and unnamed symbols
Apparently, dladdr() can succeed but return a NULL pointer, in which case strdup will crash.  Let's not call strdup on NULL pointers.

llvm-svn: 254068
2015-11-25 13:11:38 +00:00
Kuba Brecka ad986d5141 [asan] Fix the atos-symbolizer-dyld-root-path.cc test case
Due to a typo, atos-symbolizer-dyld-root-path.cc is currently being skipped all the time. There's a few more typos/copy-paste-errors. Let's fix them and enable this test.

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

llvm-svn: 254058
2015-11-25 07:59:00 +00:00
Adhemerval Zanella 29ffb68259 [compiler-rt] [msan] Couple of fixes for msan with libc++
This patch adds some fixes for MSAN with libc++ for aarch64:

1. Adds the libmsan_loadable name for aarch64.
2. Fixes some pthread_attr_setstacksize for aarch64, since glibc sets
   the mininum stack size to be higher than the x86_64 default (16KB
   vs 128KB).
3. Fixes a swprintf null char constant definition.

llvm-svn: 254015
2015-11-24 20:28:48 +00:00
Kuba Brecka 8443d187e6 [tsan] Fix signal number definitions for OS X
On OS X, SIGBUS is 10 and SIGSYS is 12.

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

llvm-svn: 253983
2015-11-24 13:44:54 +00:00
Kuba Brecka 440d08600b [tsan] Implement basic GCD interceptors for OS X
We need to intercept libdispatch APIs (dispatch_sync, dispatch_async, etc.) to add synchronization between the code that submits the task and the code that gets executed (possibly on a different thread). This patch adds release+acquire semantics for dispatch_sync, and dispatch_async (plus their "_f" and barrier variants). The synchronization is done on malloc'd contexts (separate for each submitted block/callback). Added tests to show usage of dispatch_sync and dispatch_async, for cases where we expect no warnings and for cases where TSan finds races.

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

llvm-svn: 253982
2015-11-24 13:36:06 +00:00
Kuba Brecka 6cb7f7a923 [tsan] Fix stack_sync_reuse.cc test on OS X
The test relies on two variables in different frames to end up being on the same address. For some reason, this isn't true on OS X. This patch adds `__attribute__((aligned(64)))` to the variables, which actually makes the variables occupy the same address. This is still not a guarantee, but it's more likely to work (the test looks very fragile already).

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

llvm-svn: 253981
2015-11-24 13:29:15 +00:00
Kuba Brecka 941d0a756a [tsan] Replace pthread semaphore in signal_cond.cc with barrier_wait
Pthread semaphores are not available on OS X. Let's replace sem_wait/sem_post with barrier_wait, which makes the test pass on OS X. I know that sem_wait/sem_post is intercepted by TSan, whereas barrier_wait is TSan-invisible, but the purpose of the test is not affected by this.

Also, let's properly initialize the mutex and cond variables.

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

llvm-svn: 253980
2015-11-24 13:28:27 +00:00
Kuba Brecka 377cafbbbc [tsan] Fix CallocOverflow unit test on OS X
On OS X, interceptors don't work in unit tests, so calloc() calls the system allocator. We need to use user_calloc() instead.

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

llvm-svn: 253979
2015-11-24 13:27:33 +00:00
Xinliang David Li bd1e84bc84 sync up InstrProfData.inc with master
llvm-svn: 253943
2015-11-24 00:37:45 +00:00
Xinliang David Li 39f4c2ca3b [PGO] sync up target instrument decl between runtime and llvm (NFC)
llvm-svn: 253911
2015-11-23 20:07:09 +00:00
Xinliang David Li d200b27f08 [PGO] Unify section name, section symbol definitions (Darwin)
Replace hard-coded references to names to key section and section
 symbols with common macro definitions.

llvm-svn: 253907
2015-11-23 19:48:25 +00:00
Xinliang David Li 7c7f120178 [PGO] Unify section name, section symbol definitions (Linux)
Replace hard-coded references to names to key section and section
 symbols with common macro definitions.

llvm-svn: 253897
2015-11-23 18:56:03 +00:00
Xinliang David Li 6376db52fe [PGO] Unify raw profile header definition
Replace duplicate definition raw header with
 common definition in InstrProfData.inc.

llvm-svn: 253896
2015-11-23 18:36:40 +00:00
Xinliang David Li 66c32f0183 [PGO] Use the alignment macro newly introduced (NFC)
llvm-svn: 253895
2015-11-23 18:09:18 +00:00
Xinliang David Li ac604eeff1 Sync up template file with master (NFC)
llvm-svn: 253894
2015-11-23 18:03:25 +00:00
Xinliang David Li a1bebf2987 [PGO] Unify per-function control data definition
Replace duplicate definition per-func profile control data
 with common definition in InstrProfData.inc.

llvm-svn: 253891
2015-11-23 17:50:53 +00:00
Xinliang David Li 5c7fa27b00 [PGO] Use common definition of value profile kind
Replace duplicate definition value profile kind definitions
 with common definition in InstrProfData.inc.

llvm-svn: 253890
2015-11-23 17:43:10 +00:00
Xinliang David Li e95d7fac58 [PGO] Use common definition of raw magic and version
- Replace duplicate definition and use of magic in profile runtime
- Replace hard coded version reference in profile runtime

llvm-svn: 253885
2015-11-23 17:26:53 +00:00
Xinliang David Li 0ca5bd4a46 [PGO] Start use InstrProf template file in compiler-rt/lib/profile
- Replace use of __llvm_profile_value_data with common data structure.
- Remve duplicate InstrProfValueNode

llvm-svn: 253883
2015-11-23 17:09:40 +00:00
Xinliang David Li 19c1922c04 Sync up InstrProfData.inc with master
llvm-svn: 253881
2015-11-23 17:06:44 +00:00
Kuba Brecka 2f8d345adc [tsan] Modify the tls_race.cc and tls_race2.cc tests to pass on OS X
On OS X, __thread variables are lazily heap-allocated (with malloc). Therefore, they're recognized as heap blocks (which is what they are) and not as TLS variables in TSan reports. Figuring out if a heap block is a TLS or not is difficult (in malloc interceptor we could analyze the caller and then mark the object), so let's instead modify the tests so that we expect the report to say "Location is heap block" instead of "Location is TLS".

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

llvm-svn: 253858
2015-11-23 08:17:17 +00:00
Xinliang David Li e90daa1dac [PGO] Make InstrProfData.inc available to compiler-rt.
This will enable a series of cleanup/refactoring.

llvm-svn: 253852
2015-11-23 05:47:05 +00:00
Xinliang David Li ab94e71dc6 Fix a bug introduced in cleanup
llvm-svn: 253847
2015-11-23 05:16:28 +00:00
Xinliang David Li 6fe18f4fba [PGO] Compiler-rt cleanup -- introduces macros for various macros
This makes code more readable and be made more portable in the future.
There is no functional change.

llvm-svn: 253845
2015-11-23 04:38:17 +00:00
Joerg Sonnenberger 47174a5a2c Add a generic version of __divtc3.c for long double complex division.
Mark the unit test as applying to all platforms.

llvm-svn: 253831
2015-11-22 19:13:49 +00:00
Joerg Sonnenberger 6719bd7d2a Use cabsl for long double, not cabs.
llvm-svn: 253829
2015-11-22 18:53:43 +00:00
Joerg Sonnenberger 132069c167 Move prototypes for the double-double helpers into the common header.
llvm-svn: 253828
2015-11-22 18:49:56 +00:00
Joerg Sonnenberger 0a22a96dc6 Don't use implementation namespace for include guard. Fix spacing.
llvm-svn: 253827
2015-11-22 18:48:32 +00:00
Kuba Brecka 6bbb8519e2 [tsan] Fix __cxa_guard_* interceptors on OS X
This patch fixes the __cxa_guard_acquire, __cxa_guard_release and __cxa_guard_abort interceptors on OS X. They apparently work on Linux just by having the same name, but on OS X, we actually need to use TSAN_INTERCEPTOR.

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

llvm-svn: 253776
2015-11-21 12:53:34 +00:00
Kuba Brecka 5cbe122439 [tsan] Fix detached threads in unit tests on OS X
We need to call the intercepted version of pthread_detach. Secondly, PTHREAD_CREATE_JOINABLE and PTHREAD_CREATE_DETACHED are not 0 and 1 on OS X, so we need to properly pass these constants and not just a bool.

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

llvm-svn: 253775
2015-11-21 12:41:36 +00:00
Kuba Brecka 4e6adaac4c [tsan] Make tsan_test_util_posix.cc call pthread interceptors on OS X
The tsan_test_util_posix.cc implementation of mutexes call pthread APIs directly, which on OS X don't end up calling the intercepted versions and we miss the synchronization. This patch changes the unit tests to directly call the intercepted versions. This fixes several test failures on OS X.

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

llvm-svn: 253774
2015-11-21 12:38:54 +00:00
Xinliang David Li f7185dcccd Fix -Wpointer-sign warning
llvm-svn: 253770
2015-11-21 07:26:46 +00:00
Xinliang David Li 2d5bf07c1d [PGO] Implement a more robust/readable Writer callback interface
(patch suggested by silvas)

With this patch, the IO information is wrapped in struct
ProfDataIOVec, and interface of writerCallback takes a vector
of IOVec and a pointer to writer context pointer.

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

llvm-svn: 253764
2015-11-21 04:16:42 +00:00
Matthias Braun b6a9fee9da Mention new InstrProfilingWriter file in clang_{darwin|linux}.mk
I hope this fixes our internal buildbots (rdar://23614130)

llvm-svn: 253735
2015-11-20 23:09:49 +00:00
Anna Zaks f30f351faf [asan] Disable the test on i386 Darwin.
This test checks if we can print a backtrace from the death callback. On old
OS X versions, backtrace is not able to symbolicate the trace past the ASan
runtime because we build with -fomit-frame-pointer.

llvm-svn: 253729
2015-11-20 22:55:22 +00:00
Peter Collingbourne d198896240 Re-enable CFI tests on Windows.
Clang driver was fixed in r253707.

llvm-svn: 253712
2015-11-20 21:16:00 +00:00
Chris Bieneman 01ec64499c [CMake] Add iOS simulator to the supported OS list for the profile library.
We already support this in autoconf and it ships in Apple Clang.

llvm-svn: 253709
2015-11-20 20:56:02 +00:00
Xinliang David Li bc6d21d990 [PGO] Fix buildbot failure on FreeBSD (when building __x86_64__ lib)
There seems to be a problem in system header (stdint.h) of FreeBSD
where uint8_t nor uint16_t are defined.  Explicitly define the key
types as done for FreeBSD i386. 

llvm-svn: 253703
2015-11-20 20:28:38 +00:00
Anna Zaks a44def276c [compiler-rt] Do not pull in min and max macros from windows.h
This should fix Windows buildbot breakage triggered by r253690.

llvm-svn: 253701
2015-11-20 20:18:06 +00:00
Xinliang David Li 78c4a44d36 [PGO] Profile runtime name cleanups
Value profile enumerator change to match LLVM code
ProfData new member field name change to match LLVM code
ProfData member type change to match LLVM code
Do not use lower case for types that are internal to implementation (not exposed to APIs)
There is no functional change. This is a preparation patch to enable more code sharing
in follow up patches

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

llvm-svn: 253700
2015-11-20 19:41:02 +00:00
Chris Bieneman 8085475db2 [compiler-rt][cmake] Fix not lipo libclang_rt.cc_kext.a when building on OS X
Summary:

Fix r252525 - cmake configure failed to connect target builtins to target compiler-rt  because of early return call.

Patch by: Jacky Tsao (cao.zhong1)

Reviewers: beanz

Subscribers: llvm-commits

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

llvm-svn: 253692
2015-11-20 18:45:42 +00:00
Anna Zaks e310f11223 [asan] On OS X, write error reports into Crash Report.
The Crash Report is going to add app specific info if it is stored in the magical buffer.

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

llvm-svn: 253691
2015-11-20 18:42:07 +00:00
Anna Zaks c54cf07fd7 [compiler-rt] Add internal implementations for strlcat and strlcpy
The compiler-rt should make use of strlcpy() rather than strncpy(). Using internal_strncpy() may be fine with appropriate bounds checking or enforcement of nul-termination elsewhere, but it's just good practice these days to avoid using strncpy() in new code.

A patch by Jeremy Sequoia!

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

llvm-svn: 253690
2015-11-20 18:42:05 +00:00
Anna Zaks 8d225205e3 [asan] Fix the deadlocks introduced by "On OS X, log reports to syslog and os_trace" commit
[asan] On OS X, log reports to syslog and os_trace, has been reverted in r252076 due to deadlocks on earlier versions of OS X. Alexey has also noticed deadlocks in some corner cases on Linux. This patch, if applied on top of the logging patch (http://reviews.llvm.org/D13452), addresses the known deadlock issues.

(This also proactively removes the color escape sequences from the error report buffer since we have to copy the buffer anyway.)

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

llvm-svn: 253689
2015-11-20 18:42:01 +00:00
Anna Zaks 2ce9f9447c Reapply: [asan] On OS X, log reports to syslog and os_trace
When ASan currently detects a bug, by default it will only print out the text
of the report to stderr. This patch changes this behavior and writes the full
text of the report to syslog before we terminate the process. It also calls
os_trace (Activity Tracing available on OS X and iOS) with a message saying
that the report is available in syslog. This is useful, because this message
will be shown in the crash log.

For this to work, the patch makes sure we store the full report into
error_message_buffer unconditionally, and it also strips out ANSI escape
sequences from the report (they are used when producing colored reports).

I've initially tried to log to syslog during printing, which is done on Android
right now. The advantage is that if we crash during error reporting or the
produced error does not go through ScopedInErrorReport, we would still get a
(partial) message in the syslog. However, that solution is very problematic on
OS X. One issue is that the logging routine uses GCD, which may spawn a new
thread on its behalf. In many cases, the reporting logic locks threadRegistry,
which leads to deadlocks.

Reviewed at http://reviews.llvm.org/D13452

(In addition, add sanitizer_common_libcdep.cc to buildgo.sh to avoid
build failures on Linux.)

llvm-svn: 253688
2015-11-20 18:41:44 +00:00
Xinliang David Li b83ab8508e Speculatively fix MIPS build bot failures
MIPS build bots failed due to lack of 64bit atomic operations.
The fix is to disable VP for MIPS target until a better solution
is found.

llvm-svn: 253687
2015-11-20 18:31:45 +00:00
Alexey Samsonov 3e49a7bc32 [TSan] Fix custom scripts that validate TSan on non-standard buildbot.
llvm-svn: 253682
2015-11-20 18:13:03 +00:00
Reid Kleckner fad356c4ac Speculativley try to fix FreeBSD buildbots, which apparently cannot use stdint.h
llvm-svn: 253681
2015-11-20 18:11:50 +00:00
Hans Wennborg 43db5b7daa Disable the cfi tests on Windows
They are currently broken and there seems to be no bot coverage
for this configuration so it's essentially unspported.

llvm-svn: 253673
2015-11-20 16:29:53 +00:00
Kuba Brecka 1f73ba6053 [sanitizer] Implement internal_fork and internal_forkpty for OS X
On Linux, we have internal_fork that forks without invoking user's pthread_atfork handlers, which is important for spawning external symbolizers. Let's implement this for OS X as well (using __fork). This patch also adds internal_forkpty which re-implements forkpty and uses __fork in it as well.

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

llvm-svn: 253666
2015-11-20 14:28:33 +00:00
Kuba Brecka e08533577f [tsan] Replace POSIX semaphores with pthread condition variables in vptr_benign_race.cc
OS X doesn't support POSIX semaphores (but it does have the API for it, which returns ENOSYS - "Function not implemented").

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

llvm-svn: 253665
2015-11-20 14:17:43 +00:00
Kuba Brecka 1a26ff7d17 [tsan] Fix deadlock_detector_stress_test.cc testcase for OS X
On OS X, we don't have pthread spinlocks, let's just use a regular mutex instead. Secondly, pthread_rwlock_t is much larger (200 bytes), so `char padding_[64 - sizeof(pthread_rwlock_t)]` actually underflows.

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

llvm-svn: 253659
2015-11-20 11:13:36 +00:00
Kuba Brecka 8aa56d3cc8 [tsan] Make tests that use CLOCK_MONOTONIC portable
Several tests rely on CLOCK_MONOTONIC, which doesn't exist on OS X. This patch fixes these tests by either disabling them (in case of cond_version.c which doesn't make sense on OS X), or by porting the test to also work on OS X.

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

llvm-svn: 253658
2015-11-20 11:07:16 +00:00
George Burgess IV 362352c6be Attempt to fix build breakage caused by r253646.
Apparently check_c_compiler_flag isn't a thing everywhere. Not being
incredibly well-versed in cmake, I'm hoping that check_cxx_compiler_flag
serves a similar purpose. :)

llvm-svn: 253648
2015-11-20 05:02:08 +00:00
George Burgess IV b47c02f39b Silence "unrecognised -std=c99" warning on MSVC.
Thanks to angelsl for the patch!

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

llvm-svn: 253646
2015-11-20 03:37:12 +00:00
Alexey Samsonov 145e4d6471 Tell clang-format that (most) sanitizers are written using Google style guide.
llvm-svn: 253608
2015-11-19 22:11:10 +00:00
Kuba Brecka c7157bfd55 [tsan] Replace new/delete with a local variable in ThreadSpecificDtors unit test
On OS X, this unit test (ThreadSpecificDtors) fails, because the new and delete operators actually call the overridden operators, which end up using TLVs and crash. Since C++'s new and delete is not important in this test, let's just replace them with a local variable. This fixes the test on OS X.

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

llvm-svn: 253583
2015-11-19 17:50:07 +00:00
Kuba Brecka 153594694b [tsan] Implement "%env_tsan_opts" substitution to inherit default TSAN_OPTIONS
We already have %env_asan_opts for ASan, let's implement the same for TSan.

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

llvm-svn: 253579
2015-11-19 17:28:46 +00:00
Alexey Samsonov 89d7ff5de6 [LSan] Fix tests with some libstdc++ implementations.
Summary:
Newer libstdc++ has global pool, which is filled with objects
allocated during libstdc++ initialization, and never released.
Using use_globals=0 in the lit tests results in these objects
being treated as leaks.

Fix this by porting several tests to plain C, and introducing
a simple sanity test case for __lsan::ScopedDisabler.

Reviewers: kcc, ygribov

Subscribers: llvm-commits

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

llvm-svn: 253576
2015-11-19 17:18:02 +00:00
Kuba Brecka f503d51e5b [tsan] For OS X thread finalization, remove g_thread_finalize_key in favor of libpthread hooks
On OS X, the thread finalization is fragile due to thread-local variables destruction order. I've seen cases where the we destroy the ThreadState too early and subsequent thread-local values' destructors call interceptors again. Let's replace the TLV-based thread finalization method with libpthread hooks. The notification PTHREAD_INTROSPECTION_THREAD_TERMINATE is called *after* all TLVs have been destroyed.

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

llvm-svn: 253560
2015-11-19 12:06:20 +00:00
Kuba Brecka 9eb6df9f1e [tsan] Recognize frames coming from "libclang_rt.tsan_*" module as internal
On OS X, we build a dylib of the TSan runtime, which doesn't necessarily need to contain debugging symbols (and file and line information), so llvm-symbolizer might not be able to find file names for TSan internal frames.  FrameIsInternal currently only considers filenames, but we should simply treat all frames within `libclang_rt.tsan_osx_dynamic.dylib` as internal.  This patch treats all modules starting with `libclang_rt.tsan_` as internal, because there may be more runtimes for other platforms in the future.

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

llvm-svn: 253559
2015-11-19 12:03:48 +00:00
Kuba Brecka 6e90edf803 [tsan] Mark tests that need pthread barriers with "UNSUPPORTED: darwin"
Several testcases need pthread barriers (e.g. all bench_*.cc which use test/tsan/bench.h) which are not available on OS X. Let's mark them with "UNSUPPORTED: darwin".

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

llvm-svn: 253558
2015-11-19 12:02:02 +00:00
Kuba Brecka efd92b3d16 [tsan] Handle dispatch_once on OS X
Reimplement dispatch_once in an interceptor to solve these issues that may produce false positives with TSan on OS X:

1) there is a racy load inside an inlined part of dispatch_once,
2) the fast path in dispatch_once doesn't perform an acquire load, so we don't properly synchronize the initialization and subsequent uses of whatever is initialized,
3) dispatch_once is already used in a lot of already-compiled code, so TSan doesn't see the inlined fast-path.

This patch uses a trick to avoid ever taking the fast path (by never storing ~0 into the predicate), which means the interceptor will always be called even from already-compiled code. Within the interceptor, our own atomic reads and writes are not written into shadow cells, so the race in the inlined part is not reported (because the accesses are only loads).

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

llvm-svn: 253552
2015-11-19 10:35:35 +00:00
Yury Gribov dd679b334b [asan] Enable halt_on_error tests on ARM targets.
Differential Revision: http://reviews.llvm.org/D14751

llvm-svn: 253549
2015-11-19 08:36:26 +00:00
Xinliang David Li e8efaeae4d [PGO] Minor cleanups (from review feedback)
1. fix naming problem of file/buffer writer
2. change BufferOrFile to WriterCtx
3. move writer and writerctx together

llvm-svn: 253545
2015-11-19 07:21:47 +00:00
Reid Kleckner 4029426b17 [msan] Don't unpoison phdrs on dlopen(NULL, 0)
Summary:
dlopen(NULL, ...) is intended to give you back a handle to the
executable for use with dlsym. Casting it to link_map and using it with
ForEachMappedRegion results in a crash.

We also shouldn't unpoison the globals of a DSO that is already in
memory. This ensures that we don't do it for the executable, but in
general, MSan may have false negatives if the DSO is already loaded.

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 253530
2015-11-19 00:55:45 +00:00
Xinliang David Li b035bd03e4 Fix format in comments.
llvm-svn: 253510
2015-11-18 22:09:41 +00:00
Xinliang David Li c5c32cbec2 [PGO] Minor cleanups (formating, comments etc) (NFC)
1. Added missing public API decl in InstrProfiling.h
2. Clang formatting fix
3. Added more comments for new VP code
4. refactor the VP allocation code to make it more readable.

llvm-svn: 253508
2015-11-18 21:54:40 +00:00
Mike Aizatsky b2c5e1b263 Removing memory leak to appease windows bots.
Differential Revision: http://reviews.llvm.org/D14785

llvm-svn: 253507
2015-11-18 21:44:33 +00:00
Xinliang David Li 6e55716509 Fix format of previous patch (NFC)
llvm-svn: 253503
2015-11-18 21:11:46 +00:00
Xinliang David Li 1d8d46ae39 [PGO] Refactor File and Buffer API profile writing code
With this change, Buffer API and File API implementations
are unified.

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

llvm-svn: 253500
2015-11-18 21:08:03 +00:00
Mike Aizatsky 52025af820 Disable gvn non-local speculative loads under asan.
Summary: Fix for https://llvm.org/bugs/show_bug.cgi?id=25550

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

llvm-svn: 253499
2015-11-18 20:43:20 +00:00
Xinliang David Li 13cd7f3cf7 Fix for loop initial decl used outside c99 mode error
llvm-svn: 253496
2015-11-18 20:20:15 +00:00
Betul Buyukkurt e7891d033e [PGO] Fix the build failures due to 253483 and 253489.
llvm-svn: 253492
2015-11-18 19:39:20 +00:00
Betul Buyukkurt b8dc674f65 [PGO] Removed an extra ')' in the LLVM_ALIGNAS(x) macro.
llvm-svn: 253489
2015-11-18 19:11:31 +00:00
Betul Buyukkurt 808385f1ae [PGO] Runtime support for value profiling.
This change adds extends the data structures and adds in the routines
for handling runtime calls for value profiling. The profile data format
is modified and the version number is incremented.

llvm-svn: 253483
2015-11-18 18:12:35 +00:00
Kuba Brecka b2b07aa925 [tsan] Skip malloc/free interceptors when we're inside symbolizer on OS X
Symbolizers can call malloc/realloc/free/..., which we don't want to intercept. This is already implemented on Linux, let's do it for OS X as well.

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

llvm-svn: 253460
2015-11-18 14:50:40 +00:00
Yury Gribov 4c3baeb686 [asan] Use proper macro in runline.
llvm-svn: 253457
2015-11-18 13:38:45 +00:00
Alexey Samsonov 1f4cb4d3d4 [TSan] List only amd64 asm file in Makefile.old (attempt 2)
llvm-svn: 253416
2015-11-18 00:56:37 +00:00
Alexey Samsonov 3408ea64ed [TSan] List only amd64 asm file in Makefile.old
llvm-svn: 253407
2015-11-18 00:31:00 +00:00
Alexey Samsonov de6fb1d9c7 [ASan] Be consistent and refer to reported issues as "errors" in hints.
llvm-svn: 253406
2015-11-18 00:24:32 +00:00
Yury Gribov 6689df85ee [asan] Enable halt_on_error tests on OS X.
llvm-svn: 253342
2015-11-17 16:34:39 +00:00
Dmitry Vyukov 3dd7fe6d86 tsan: replace macro check with constant check
As per comments in 252892 commit.

llvm-svn: 253216
2015-11-16 15:55:38 +00:00
Adhemerval Zanella 2f7f5e3535 [compiler-rt] [tsan] Enable intercept setjmp/longjmp for AArch64
This patch adds assembly routines to enable setjmp/longjmp for aarch64
on linux.  It fixes:

 * test/tsan/longjmp2.cc
 * test/tsan/longjmp3.cc
 * test/tsan/longjmp4.cc
 * test/tsan/signal_longjmp.cc

I also checked with perlbench from specpu2006 (it fails to run
with missing setjmp/longjmp intrumentation).

llvm-svn: 253205
2015-11-16 13:55:19 +00:00
Yury Gribov bdf8751609 [asan] Restored asynch signal test.
llvm-svn: 253204
2015-11-16 13:54:32 +00:00
Kuba Brecka 04d512133f Reverting r253080 ([tsan] Don't demangle names not starting with "_Z").
This caused bot failures on ARM, e.g. http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9068

llvm-svn: 253129
2015-11-14 10:42:08 +00:00
Kostya Serebryany fb484cedb4 [asan] add an experimental flag protect_shadow_gap. If set to false, the shadow gap will not be mprotect-ed and all hell may break loose. But this makes CUDA's cuInit() pass.
llvm-svn: 253108
2015-11-14 00:50:23 +00:00
Xinliang David Li b6c81d2b92 [PGO] Ensure profile section symbols are created (linux)
- This is to handle a corner case where profile lib is linked
  in but non of the modules are instrumented (On linux, since
  we avoided the overhead to emit runtime hook use functions so
  this is the side effect of that size optimization).
- Added a profile runtime test case to cover all scenarios of
  shared library builds. 

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

llvm-svn: 253098
2015-11-13 22:33:07 +00:00
Kuba Brecka 1f219dcb98 [tsan] Don't demangle names not starting with "_Z"
I noticed that when a symbol is named just "x", it gets demangled to "long long". On POSIX, AFAIK, mangled names always start with "_Z", so lets just require that.

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

llvm-svn: 253080
2015-11-13 20:47:29 +00:00
Kuba Brecka 7291b88e9a [tsan] Fix finalization of detached threads on OS X
Currently, we crash on finalization of detached threads, because we'll try to clear the ThreadState twice.

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

llvm-svn: 253079
2015-11-13 20:45:27 +00:00
Kuba Brecka d07e069d79 [tsan] Fix a typo in tsan_test_util.h
There is a typo in tsan_test_util.h, it shouldn't be `APPLE`, but `__APPLE__`.

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

llvm-svn: 253078
2015-11-13 20:42:57 +00:00
Kuba Brecka 52d02ab9d9 [tsan] Expect memmove interceptor to be called from memcpy
On OS X, memcpy and memmove are actually aliases of the same function, so the memmove interceptor can be invoked on a call to memcpy. This patch updates the tests to expect either memmove or memcpy on a stack trace.

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

llvm-svn: 253077
2015-11-13 20:41:37 +00:00
Kuba Brecka 6c0b367297 [tsan] Mark dl_iterate_phdr.cc test as unsupported on OS X
The dl_iterate_phdr is not present on OS X.

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

llvm-svn: 253076
2015-11-13 20:40:02 +00:00
Kuba Brecka 770dac4382 [tsan] Don't require full paths to be present on stack traces
The OS X symbolizers (namely AtosSymbolizer) don't return full file paths, only file names. This patch modifies `mutexset*.cc` tests not to require a path to be present in the symbol on the stack trace.

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

llvm-svn: 253075
2015-11-13 20:36:08 +00:00
Chris Bieneman 4f7f57e166 [CMake] [macho_embedded] [builtins] Always use OS X sysroot, even for arm.
Turns out that there are some checks in the backend that change code generation for armv7 if you are building against an iOS sys root. For the macho_embedded builtins we really don't want that.

llvm-svn: 253064
2015-11-13 19:14:58 +00:00
Yury Gribov 7e3c7ee0b1 [asan] Fixed invalid check in test.
llvm-svn: 253037
2015-11-13 12:49:58 +00:00
Yury Gribov eed2daa80c [asan] Dump test output in case of error in single-threaded mode.
llvm-svn: 253035
2015-11-13 12:07:15 +00:00
Yury Gribov a085297030 [asan] Fix test to properly handle collisions.
llvm-svn: 253025
2015-11-13 10:32:13 +00:00
Yury Gribov b2f75136d1 [asan] Fix silly error when reporting multiple ASan errors in parallel.
llvm-svn: 253022
2015-11-13 09:46:12 +00:00
Yury Gribov 1e89f53902 [asan] Get rid of rand_r (not available on all targets).
llvm-svn: 253021
2015-11-13 09:43:30 +00:00
Kuba Brecka 49fd0c138d [tsan] Add global symbolication support into AtosSymbolizer
This patch adds support for symbolication of globals (implements `SymbolizeData`) for `AtosSymbolizer` on OS X.

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

llvm-svn: 253015
2015-11-13 06:45:49 +00:00
Martell Malone 5b7658c1a4 compiler-rt: add make solution to bootstrap mingw-w64
Differential Revision: http://reviews.llvm.org/D14290

llvm-svn: 252976
2015-11-13 00:21:34 +00:00
Chris Bieneman 14679e9f68 [CMake] [Darwin] Forcing -fPIC on for all darwin builtins except macho_embedded
We need to add -fPIC to the flags for the builtins in case PIC was turned off at a higher level. We also want to set ENABLE_PIC to Off when building the macho_embedded builtins so the top-level settings don't impact that build.

llvm-svn: 252966
2015-11-12 22:37:03 +00:00
Chris Bieneman 73d0562542 [CMake] [Darwin] [Builitins] Removing muloti4 from the blacklists for arm.
llvm-svn: 252965
2015-11-12 22:37:01 +00:00
Chris Bieneman 77e5eea728 [CMake] [Darwin] [Builtins] Sorting and uniquing blacklists. NFC.
llvm-svn: 252964
2015-11-12 22:36:57 +00:00
Reid Kleckner b8e3bff98a [Windows] Fix halt_on_error-1.c test on Windows with %env_asan_opts
llvm-svn: 252958
2015-11-12 21:58:28 +00:00
Evgeniy Stepanov 833c75e554 [asan] Mark halt_on_error-torture test unsupported on android.
Android libc is missing rand_r until API 21. ASan supports API 19.

llvm-svn: 252930
2015-11-12 19:30:38 +00:00
Chris Bieneman b3df467fc8 [CMake] [builtins] Removing a few non-source files from the arm list.
I was a little too aggressive about adding sources from the arm subdirectory.

llvm-svn: 252929
2015-11-12 19:27:29 +00:00
Chris Bieneman 7beed7eb6c [CMake] Actually adding the TODO comment I mentioned in r252927.
Turns out you need to save before committing.

llvm-svn: 252928
2015-11-12 19:17:05 +00:00
Chris Bieneman a2151fdceb [CMake] [builtins] Adding missing architecture-specific builtins.
Also added a TODO comment to make the build system throw an error if the CMakeLists gets out of sync again.

llvm-svn: 252927
2015-11-12 19:15:56 +00:00
Dmitry Vyukov b8da794ca1 tsan: fix windows Go build
Go build does not link in whatever library provides these symbols:

# runtime/race
race_windows_amd64.syso:gotsan.cc:(.text+0x578f): undefined reference to `__sanitizer::DumpProcessMap()'
race_windows_amd64.syso:gotsan.cc:(.text+0xee33): undefined reference to `EnumProcessModules'
race_windows_amd64.syso:gotsan.cc:(.text+0xeeb9): undefined reference to `GetModuleInformation'

llvm-svn: 252922
2015-11-12 18:50:19 +00:00
Dmitry Vyukov 8455cf0142 tsan: fix windows Go build
CompareModulesBase is an unused function.

llvm-svn: 252907
2015-11-12 16:29:24 +00:00
Kuba Brecka af9525dfff [tsan] Add global symbolication support into DlAddrSymbolizer
`DlAddrSymbolizer` is used on OS X when we're running inside a sandbox that prevents us from spawning an external symbolizer. This patch adds support for symbolication of globals (implements `SymbolizeData`) for `DlAddrSymbolizer`.

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

llvm-svn: 252899
2015-11-12 15:19:40 +00:00
Kuba Brecka 3ecce92a52 [tsan] Allow symbolizers that don't obtain global symbol sizes
The default symbolizer, `llvm-symbolizer` provides sizes for global symbols. On OS X, we want to also allow using `atos` (because it's available everywhere and users don't need to copy/install it) and `dladdr` (it's the only available option when running in a sandbox). However, these symbolizers do not supply the symbol sizes, only names and starting addresses. This patch changes the reporting functions to hide the size of the symbol when this value is unavailable, and modifies tests to make this part of the report "optional".

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

llvm-svn: 252896
2015-11-12 14:34:17 +00:00
Dmitry Vyukov bab2216dbb tsan: disable abort_on_error for Go
It does not work as expected.
Go runtime handles SIGABRT and crashes with a loud message.

llvm-svn: 252892
2015-11-12 14:03:20 +00:00
Kuba Brecka e342469c0a [tsan] Add a Darwin-specific lit test directory
Differential Revision: http://reviews.llvm.org/D14610

llvm-svn: 252887
2015-11-12 13:27:55 +00:00
Dmitry Vyukov 110094017c tsan: fix Go build on linux
librt is not linked in in Go build.

llvm-svn: 252877
2015-11-12 11:54:25 +00:00
Kuba Brecka ba85da8482 [asan] Remove system_malloc_zone
This seems to be dead code – `system_malloc_zone` is initialized as null and we never assign to it. This code is apparently currently never executed (in ASan), but is causes trouble for the TSan OS X port. Let's replace the checks with `COMMON_MALLOC_ENTER` (`ENSURE_ASAN_INITED()`).

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

llvm-svn: 252876
2015-11-12 11:29:21 +00:00
Dmitry Vyukov 317e98b1a2 tsan: fix unused function warning in Go build
llvm-svn: 252875
2015-11-12 11:14:35 +00:00
Dmitry Vyukov 1421ed42a6 tsan: fix mac Go build
cur_thread does not exist in Go.

llvm-svn: 252874
2015-11-12 11:12:18 +00:00
Kuba Brecka 14fb164a8e [tsan] Filter OS X architectures for unit testing
The TSan unit test build currently fails if we're also building the iOS parts of compiler-rt, because `TSAN_SUPPORTED_ARCH` contains ARM64. For unit tests, we need to filter this only to host architecture(s).

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

llvm-svn: 252873
2015-11-12 11:00:38 +00:00
Dmitry Vyukov 1041aabbb0 tsan: fix flakiness of sleep_sync2 test
llvm-svn: 252869
2015-11-12 10:24:22 +00:00
Kostya Serebryany 673283cc7c [sanitizer coverage] reset global counters in __sanitizer_reset_coverage
llvm-svn: 252815
2015-11-11 22:44:25 +00:00
Chris Bieneman 66c126a042 [CMake] [Darwin] [Builtins] Force setting the flags we care about at the end of the compiler command line
Setting CMAKE_*_FLAGS isn't sufficient here because CMAKE_*_FLAGS_${CMAKE_BUILD_TYPE} can override the flags, and there is no way to safely clear that because it is a cached variable (<sarcasm> YAY! </sarcasm>).

llvm-svn: 252807
2015-11-11 21:38:35 +00:00
Evgeniy Stepanov 77ef54288a [asan] Remove a flaky test.
llvm-svn: 252805
2015-11-11 21:37:12 +00:00
Reid Kleckner 99f23473a1 [Windows] Add exports for dll_host test broken by r252071 and r251071
llvm-svn: 252784
2015-11-11 19:34:01 +00:00
Dmitry Vyukov 3ed274e3ce tsan: fix unused variable in Go build
llvm-svn: 252746
2015-11-11 16:09:20 +00:00
Diego Novillo a245e40a55 Revert r252683 - "Sancov in C++."
This reverts commits r252683 and r252689. This tool should not live here. See
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/311862.html
for discussion.

llvm-svn: 252744
2015-11-11 15:54:31 +00:00
Yury Gribov 8fbd938641 [ASan] Improve portability of new tests.
llvm-svn: 252742
2015-11-11 15:42:26 +00:00
Kuba Brecka fcbb0ec06e [tsan] Rename tsan_test_util_linux.cc to tsan_test_util_posix.cc
Differential Revision: http://reviews.llvm.org/D14575

llvm-svn: 252741
2015-11-11 15:42:00 +00:00
Jay Foad 305586257c Implement some TLS support for PowerPC64.
Summary: This is enough to get the asan static_tls.cc test case working.

Reviewers: eugenis, samsonov

Subscribers: llvm-commits

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

llvm-svn: 252738
2015-11-11 15:37:47 +00:00
Kuba Brecka c603d25a19 Fixing #include order in tsan_new_delete.cc. Follow-up commit for r252284.
llvm-svn: 252735
2015-11-11 15:15:14 +00:00
Kuba Brecka c47620a838 [tsan] Add TSan unit test support for OS X
This patch enables building and running TSan unit tests on OS X.

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

llvm-svn: 252731
2015-11-11 14:53:57 +00:00
Jay Foad 6de11a494f Fix #if tests for PTRACE_GETREGS and others.
Summary:
On PowerPC64 Linux PTRACE_GETREGS is a #define and PT_GETREGS is not.
On other systems it's the other way round. Extend the #ifs to check for
both PTRACE_* and PT_*.

This fixes test/sanitizer_common/TestCases/Linux/ptrace.cc when msan is
enabled for PowerPC64.

Reviewers: zatrazz, kcc, eugenis, samsonov

Subscribers: llvm-commits

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

llvm-svn: 252730
2015-11-11 14:41:17 +00:00
Yury Gribov 159727d417 [ASan] Add stress test for asynch signals in nonhalting mode.
Differential Revision: http://reviews.llvm.org/D14241

llvm-svn: 252729
2015-11-11 14:02:33 +00:00
Yury Gribov e76a7c41e9 [Asan] Added missing hunk to previous commit.
llvm-svn: 252724
2015-11-11 12:23:59 +00:00
Yury Gribov 468d955b98 [ASan] Enable optional ASan recovery.
Differential Revision: http://reviews.llvm.org/D12318

llvm-svn: 252723
2015-11-11 11:59:38 +00:00
Dmitry Vyukov e38d3c8f9f sanitizer: speedup coverage by 33%
Atomic RMW is not necessary in InitializeGuardArray.
It is supposed to run when no user code runs.
And if user code runs concurrently, then the atomic
RMW won't help anyway. So replace it with non-atomic RMW.

InitializeGuardArray takes more than 50% of time during re2 fuzzing:

real	0m47.215s
51.56% a.out a.out [.] __sanitizer_reset_coverage

6.68%  a.out  a.out                [.] __sanitizer_cov
3.41%  a.out  a.out                [.] __sanitizer::internal_bzero_aligned16(void*, unsigned long)
1.79%  a.out  a.out                [.] __asan::Allocator::Allocate(unsigned long, unsigned long,
With this change:

real 0m31.661s
26.21% a.out a.out [.] sanitizer_reset_coverage
10.12% a.out a.out [.] sanitizer_cov

5.38%  a.out  a.out                [.] __sanitizer::internal_bzero_aligned16(void*, unsigned long)
2.53%  a.out  a.out                [.] __asan::Allocator::Allocate(unsigned long, unsigned long,
That's 33% speedup.

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

llvm-svn: 252715
2015-11-11 09:36:26 +00:00
Ismail Pazarbasi 26f70505f3 Implement `internal_start/join_thread` on Mac OS X
Summary: Depends on D9637

Test Plan:

Reviewers: kcc, glider, samsonov

Subscribers: llvm-commits

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

llvm-svn: 252696
2015-11-11 02:44:19 +00:00
Ismail Pazarbasi fcb8c7e407 [tsan] Pass correct interposed function prefix to report function
Summary:
On Darwin, interposed functions are prefixed with "wrap_". On Linux,
they are prefixed with "__interceptor_".

Reviewers: dvyukov, samsonov, glider, kcc, kubabrecka

Subscribers: zaks.anna, llvm-commits

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

llvm-svn: 252695
2015-11-11 02:38:38 +00:00
Mike Aizatsky a543f77bdb Disabling sancov.cc on windows.
It can't be built due to cxxabi missing. Will
fix later.

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

llvm-svn: 252689
2015-11-11 02:01:16 +00:00
Mike Aizatsky 125e636b96 Sancov in C++.
Summary:
First batch of sancov.py rewrite in C++.
Supports "-print" and "-covered_functions" commands.

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

llvm-svn: 252683
2015-11-11 01:26:57 +00:00
Chris Bieneman 45c40fff66 [CMake] [macho_embedded] Only set sys root if the variable is set, this prevents passing empty -isysroot arguments
This is a minor cleanup to the macho_embedded builtins.

llvm-svn: 252619
2015-11-10 17:26:40 +00:00
Chris Bieneman 9a6afeb84d [CMake] Cleaning up flags for Darwin builtins
* Setting CMAKE_*_FLAGS_${BUILD_TYPE} isn't really needed since we're setting the same value everywhere
* functions sanitize variables differently from macros, darwin_add_embedded_builtin_libraries should be a macro otherwise it won't alter the variables.

llvm-svn: 252618
2015-11-10 17:26:35 +00:00
Xinliang David Li 854dad77ec Rollback 252570 for further investigation
llvm-svn: 252575
2015-11-10 00:58:22 +00:00