Commit Graph

7182 Commits

Author SHA1 Message Date
Xinliang David Li e5e4713a56 Re install test reverted by r268866
llvm-svn: 268964
2016-05-09 19:51:50 +00:00
Xinliang David Li b5a2b3a429 Fix variable visibility
llvm-svn: 268952
2016-05-09 19:01:19 +00:00
Renato Golin 553429898e [InstrProf] Delete unstable test on ARM. See PR27667
llvm-svn: 268866
2016-05-07 20:17:33 +00:00
Renato Golin 26642b4035 Revert "[profile] Simplify value profile writing"
This reverts commit r268840, as it breaks Thumb2 self-hosting. There is something
unstable in the profiling for Thumb2 that needs to be sorted out before we continue
implementing these changes to the profiler. See PR27667.

llvm-svn: 268864
2016-05-07 20:07:09 +00:00
Xinliang David Li 4b30c79723 [profile] Simplify value profile writing
With this patch, value data are longer pre-collected
before writing. The code is simplified and requires
less heap space for dumping.

llvm-svn: 268840
2016-05-07 02:50:11 +00:00
Dmitry Vyukov 144eafd9ee tsan: fix a crash
Fixes crash reported in:
https://bugs.chromium.org/p/v8/issues/detail?id=4995

The problem is that we don't have a processor in a free interceptor
during thread exit.

The crash was introduced by introduction of Processors.
However, previously we silently leaked memory which wasn't any better.

llvm-svn: 268782
2016-05-06 19:35:22 +00:00
Xinliang David Li bedb81e09f Revert r268608 -- unexplained darwin bot failure
llvm-svn: 268779
2016-05-06 19:26:56 +00:00
Renato Golin 039f2ac354 [InstProf] Temporarily removing a test that fails/passes on different configurations (PR27667)
llvm-svn: 268748
2016-05-06 16:44:56 +00:00
Renato Golin 00966ed8b9 XFAILing a test on ARM. See PR27667
llvm-svn: 268745
2016-05-06 15:34:54 +00:00
Kuba Brecka 12aaa1c955 Revert r268716. This has caused test failures in MSan on Linux.
llvm-svn: 268723
2016-05-06 10:23:10 +00:00
Kuba Brecka a609e37ebd [sanitizer] Fix a crash when demangling Swift symbols
To invoke the Swift demangler, we use dlsym to locate swift_demangle. However, dlsym malloc's storage and stores it in thread-local storage. Since allocations from the symbolizer are done with the system allocator (at least in TSan, interceptors are skipped when inside the symbolizer), we will crash when we try to deallocate later using the sanitizer allocator again.

To fix this, let's just not call dlsym from the demangler, and call it during initialization.

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

llvm-svn: 268716
2016-05-06 08:54:58 +00:00
Maxim Ostapenko 6dccd5bc1f [asan] Bail out on stack overflow in recovery mode.
In recovery mode, when ASan detects stack overflow (say, when infinite recursion detected),
it tries to continue program execution and hangs on repetitive error reports. There isn't any
sense to do it, we can just bail out on stack overflow error, because the program would crash soon anyway.

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

llvm-svn: 268713
2016-05-06 07:09:22 +00:00
Xinliang David Li ac96ea422b [profile] Remove another unneeded field in raw profile reader
DataValueSize is now removed. The change is consolidated
with previous raw version bump.

llvm-svn: 268704
2016-05-06 02:13:12 +00:00
Xinliang David Li 2516bcd01c Add a test of VP with shared lib
llvm-svn: 268612
2016-05-05 06:28:12 +00:00
Xinliang David Li 0c09036232 IR value profile testing cleanup
llvm-svn: 268608
2016-05-05 05:41:02 +00:00
Xinliang David Li 2cb6f0ce29 Sync up with master file
llvm-svn: 268603
2016-05-05 04:07:45 +00:00
Mike Aizatsky c826e634cc [sanitizer] Move stat/__xstat to the common interceptors
Summary:
Adds stat/__xstat to the common interceptors.

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

Resubmit of http://reviews.llvm.org/D19875 with win build fixes.

Reviewers: aizatsky, eugenis

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

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

llvm-svn: 268466
2016-05-03 23:43:45 +00:00
Mike Aizatsky 7e72f66bf2 Revert "[sanitizer] Move stat/__xstat to the common interceptors"
This reverts commit 268440 because it breaks the windows bot.

http://lab.llvm.org:8011/builders/sanitizer-windows/builds/21425/steps/build%20compiler-rt/logs/stdio

llvm-svn: 268448
2016-05-03 21:49:56 +00:00
Mike Aizatsky 3eb521d417 [sanitizer] Move stat/__xstat to the common interceptors
Summary:
Adds stat/__xstat to the common interceptors.

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

Reviewers: aizatsky, eugenis

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

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

llvm-svn: 268440
2016-05-03 21:22:06 +00:00
Chris Bieneman aa3d2c13bf [CMake] NFC. Add support for testing the compiler without testing the linker
Summary:
One of the big limitations we have in the compiler-rt build system today is that we cannot bootstrap building the builtins because you need a fully functional toolchain to pass CMake's tests.

This change adds support for compile only tests.

It is NFC because nothing is using the compile-only tests yet.

I believe this is the last separable part of D16653.

Reviewers: samsonov

Subscribers: llvm-commits

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

llvm-svn: 268427
2016-05-03 19:48:11 +00:00
Derek Bruening 2a14132285 [esan] Use do-while rather than braces for empty interceptors
Summary:
Replaces {} with a do..while sequence in esan's empty interceptors to allow
natural use with a trailing semicolon.  The sequence uses each argument to
avoid warnings.

Reviewers: filcab

Subscribers: kubabrecka, llvm-commits, zhaoqin

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

llvm-svn: 268426
2016-05-03 19:44:32 +00:00
Dmitry Vyukov 7a1b7addf8 tsan: update tsan_analyze to what tip clang generates
We used to depend on host gcc. But some distributions got
new gcc recently which broke the check. Generally, we can't
depend that an arbitrary host gcc generates something stable.

Switch to clang.
This has an additional advantage of catching regressions in
clang codegen.

llvm-svn: 268382
2016-05-03 13:59:41 +00:00
Vitaly Buka 8742943cb0 Relax stack check as on some platforms demanglers fail
Summary:
  On Windows (already fixed) and FreeBSD we have stacks traces without
  operator().

Reviewers: eugenis

Subscribers: llvm-commits

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

llvm-svn: 268332
2016-05-02 23:34:40 +00:00
Vitaly Buka 9102fc20f8 Add another failing use-after-scope test
Summary:
  Use after scope is not detected if array larger then 8 bytes.

Subscribers: kubabrecka

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

llvm-svn: 268330
2016-05-02 23:12:04 +00:00
Kostya Serebryany 9d91336a83 [compiler-rt] adjust platform_limits_linux.cc #include of posix_types
Summary:
Hello,

Building a recent gcc on a powerpc-linux system advertsing:

 Red Hat Enterprise Linux Server release 5.10 (Tikanga)

we stumbled on a compilation error on a file originating
from compiler-rt/lib/sanitizer-common.

sanitizer_platform_limits_linux.cc #includes asm/posix_types.h,
which, on our system, uses __kernel_fd_set and associated macros.
These aren't defined at the point of their use, and the compilation
fails with symptoms like:

  In file included from ../../../../src/libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cc:29:0:
  /usr/include/asm/posix_types.h:72:51: error: '__kernel_fd_set' has not been declared
  static __inline__ void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
  ...

The attached patch is a suggestion to fix this, by including linux/posix_types.h
instead of asm/posix_types.h. linux/posix_types defines the necessary types and
macros, then #includes asm/posix_types.h.

We have been using it locally for gcc without problems for a couple of years
on powerpc, x86 and x86_64-linux platforms. It is still needed for gcc-6 on
our powerpc host and applies cleanly on the compiler-rt trunk.

Comments ?

Thanks much in advance for your feedback,

With Kind Regards,

Olivier


Reviewers: llvm-commits, kcc

Subscribers: kcc, kubabrecka

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

llvm-svn: 268283
2016-05-02 19:10:48 +00:00
Kostya Serebryany d83c96fa44 [scan-build] fix logic error warning emitted on compiler-rt code base
Summary:
Fix a "called c++ object pointer is null" warning emitted by Clang
Static Analyzer on the following file:
- lib/asan/asan_suppressions.cc.

Signed-off-by: Apelete Seketeli <apelete@seketeli.net>

Reviewers: kcc

Subscribers: Eugene.Zelenko, kubabrecka, llvm-commits

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

llvm-svn: 268282
2016-05-02 19:07:20 +00:00
Kuba Brecka a90528bb89 [sanitizer] Fix a crash in SizeClassAllocator32 with an out-of-range pointer
This happens on a 64-bit platform that uses SizeClassAllocator32 (e.g. ASan on AArch64). When querying a large invalid pointer, `__sanitizer_get_allocated_size(0xdeadbeefdeadbeef)`, an assertion will fail.  This patch changes PointerIsMine to return false if the pointer is outside of [kSpaceBeg, kSpaceBeg + kSpaceSize).

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

llvm-svn: 268243
2016-05-02 15:23:01 +00:00
Kuba Brecka d052a57900 [sanitizer] Don't reuse the main thread in ThreadRegistry
There is a hard-to-reproduce crash happening on OS X that involves terminating the main thread (dispatch_main does that, see discussion at http://reviews.llvm.org/D18496) and later reusing the main thread's ThreadContext. This patch disables reuse of the main thread. I believe this problem exists only on OS X, because on other systems the main thread cannot be terminated without exiting the process.

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

llvm-svn: 268238
2016-05-02 15:06:08 +00:00
Marcin Koscielnicki ee587cba0e [ASan] Add shadow offset for SystemZ.
This is the compiler-rt counterpart to D19650.

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

llvm-svn: 268162
2016-04-30 10:02:12 +00:00
Filipe Cabecinhas 30cba35a84 Finally fix invalid-pointer-pairs.cc. This time the demangle on the Windows buildbot.
llvm-svn: 268160
2016-04-30 08:34:40 +00:00
Kuba Brecka 9ccde5ace4 [tsan] Return 0 from malloc_size for non-malloc'd pointers
In http://reviews.llvm.org/D19100, I introduced a bug: On OS X, existing programs rely on malloc_size() to detect whether a pointer comes from heap memory (malloc_size returns non-zero) or not. We have to distinguish between a zero-sized allocation (where we need to return 1 from malloc_size, due to other binary compatibility reasons, see http://reviews.llvm.org/D19100), and pointers that are not returned from malloc at all.

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

llvm-svn: 268157
2016-04-30 07:14:41 +00:00
Filipe Cabecinhas 486c5d6ae9 Fix test's memory leaks.
llvm-svn: 268138
2016-04-29 23:42:34 +00:00
Filipe Cabecinhas dd754ef857 Try to fix clang-cmake-aarch64-42vma by removing a memory leak (have a global var capture it).
llvm-svn: 268114
2016-04-29 21:33:12 +00:00
Filipe Cabecinhas 04d61050ea [asan] Assert in __sanitizer_ptr_{sub,cmp} if one of the pointers was freed.
Summary:
This (partially) implements the check mentioned at
http://kristerw.blogspot.co.uk/2016/04/dangling-pointers-and-undefined-behavior.html
(via John Regehr)

Quoting:
"That the behavior is undefined follows from C11 6.2.4 "Storage
durations of objects"
  The lifetime of an object is the portion of program execution during
  which storage is guaranteed to be reserved for it. An object exists, has
  a constant address, and retains its last-stored value throughout its
  lifetime. If an object is referred to outside of its lifetime, the
  behavior is undefined. The value of a pointer becomes indeterminate when
  the object it points to (or just past) reaches the end of its lifetime.
and 7.22.3 "Memory management functions" that says that free ends the
lifetime of objects
  The lifetime of an allocated object extends from the allocation until
  the deallocation.
"

We can probably implement this for stack variables too, but I think this
is a good start to see if there's interest in this check.
We can also hide this behind a flag, too.

Reviewers: samsonov, kcc, rsmith, regehr

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 268097
2016-04-29 20:37:34 +00:00
Marcin Koscielnicki 14824b1c52 [sanitizers] [SystemZ] Mark kernel 3.12.58+ as safe from CVE-2016-2143.
llvm-svn: 268046
2016-04-29 14:59:19 +00:00
Evgeniy Stepanov 01c7450ec5 [msan] Tests for vector compare intrinsics.
llvm-svn: 267967
2016-04-29 01:20:05 +00:00
Marcin Koscielnicki a0193ecfe1 [ASan] [SystemZ] Mark segv_read_write.c as UNSUPPORTED.
On s390*-linux, sigcontext just doesn't contain any information that could
be used to recover the type of access, so there's no way to fix this, short
of emulating the faulting instruction.

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

llvm-svn: 267960
2016-04-29 00:43:20 +00:00
Marcin Koscielnicki 174f8b1981 [ASan] Reenable __builtin_setjmp test on PowerPC, disable on SystemZ.
Since __builtin_setjmp has been fixed by rL267943, the test now works
on PowerPC.  Enable it.

On the other hand, the SystemZ backend doesn't currently support
__builtin_setjmp.  Disable it.

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

llvm-svn: 267946
2016-04-28 22:23:19 +00:00
Chris Bieneman 257fe3ab99 [CMake] Adding another missing include. NFC.
This also works fine today, but will break with my upcoming refactoring.

llvm-svn: 267941
2016-04-28 21:16:45 +00:00
Chris Bieneman 551ccac7e4 [CMake] Updating Apple CMake cache file
Changing the Apple CMake cache file to better match the way Apple Clang builds are built.

llvm-svn: 267913
2016-04-28 18:24:29 +00:00
Chris Bieneman 1dd58a7018 [CMake] Adding some missing CMake includes. NFC.
This happens to be working now because the includes exist in another CMake file that is included before this one. That will change with upcoming refactoring.

llvm-svn: 267912
2016-04-28 18:22:01 +00:00
Vedant Kumar 6a2ec9fc57 [test/asan] Update a test case to work with old Darwin SDK's
On Darwin, MAP_ANONYMOUS is a synonym for MAP_ANON. However, some SDK's
don't define MAP_ANONYMOUS. Use MAP_ANON to work around this.

(As a point of interest, the situation is exactly reversed on Linux.)

llvm-svn: 267907
2016-04-28 17:48:35 +00:00
Peter Collingbourne f730de619f Update visibility flags for CFI tests.
Differential Revision: http://reviews.llvm.org/D18813

llvm-svn: 267902
2016-04-28 17:09:09 +00:00
Kuba Brecka dc7b607b09 [tsan] Fix Darwin GCD support after separation of Processor and ThreadState
Recent TSan changes (r267678) which factor out parts of ThreadState into a Processor structure broke worker threads on OS X.  This fixes it by properly calling ProcCreate for GCD worker threads and by replacing some CHECKs with RAW_CHECK in early process initialization.  CHECK() in TSan calls the allocator, which requires a valid Processor.

llvm-svn: 267864
2016-04-28 09:26:30 +00:00
Marcin Koscielnicki 0bec2fef8e [MSan] [PowerPC] Dereference function descriptors when recording stack origins.
Differential Revision: http://reviews.llvm.org/D19543

llvm-svn: 267795
2016-04-27 21:24:24 +00:00
Marcin Koscielnicki 66f0deacb5 [sanitizers] Get the proper symbol version when long double transition is involved.
On linux, some architectures had an ABI transition from 64-bit long double
(ie. same as double) to 128-bit long double.  On those, glibc symbols
involving long doubles come in two versions, and we need to pass the
correct one to dlvsym when intercepting them.

A few more functions we intercept are also versioned (all printf, scanf,
strtold variants), but there's no need to fix these, as the REAL() versions
are never called.

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

llvm-svn: 267794
2016-04-27 21:24:21 +00:00
Derek Bruening 41939466d1 [sanitizer] Add early call handling to strchr + strrchr interceptors
Summary:
The strchr and strrchr interceptors are sometimes invoked too early
for their REAL() counterparts to be initialized.  We have seen this in
hooks invoked from tcmalloc on the dlsym() used in initializing
interceptors.  A special check is added to use internal_ routines for
this situation.

Reviewers: vitalybuka, aizatsky, filcab

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

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

llvm-svn: 267793
2016-04-27 21:20:46 +00:00
Mike Aizatsky ccd318dc7e [sanitizers] read/write page fault detection on mac.
Summary: Resubmit of http://reviews.llvm.org/D19495 enabled only on intel.

Subscribers: kubabrecka

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

llvm-svn: 267750
2016-04-27 18:02:21 +00:00
Marcin Koscielnicki b7b5ac60c4 [sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.
In short, CVE-2016-2143 will crash the machine if a process uses both >4TB
virtual addresses and fork().  ASan, TSan, and MSan will, by necessity, map
a sizable chunk of virtual address space, which is much larger than 4TB.
Even worse, sanitizers will always use fork() for llvm-symbolizer when a bug
is detected.  Disable all three by aborting on process initialization if
the running kernel version is not known to contain a fix.

Unfortunately, there's no reliable way to detect the fix without crashing
the kernel.  So, we rely on whitelisting - I've included a list of upstream
kernel versions that will work.  In case someone uses a distribution kernel
or applied the fix themselves, an override switch is also included.

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

llvm-svn: 267747
2016-04-27 17:42:00 +00:00
Reid Kleckner a16ef7633b Un-XFAIL tests on Windows after fixing PR27492
Private symbols in PDBs do not have parameter types in their names so we
have to drop the parens from the lambda call operator.

llvm-svn: 267735
2016-04-27 16:38:03 +00:00
Dmitry Vyukov 914b399736 tsan: fix windows support
UnmapOrDie used to do MEM_DECOMMIT and so worked
on partial regions. But r263160 changed it to use
MEM_RELEASE and MEM_RELEASE can only work with
whole regions mapped by VirtualAlloc. This broke
windows as:

FATAL: ThreadSanitizer CHECK failed: gotsan.cc:8296 "((mbi.AllocationBase == addr && "Windows cannot unmap part of a previous mapping")) != (0)" (0x0, 0x0)

Restore the previous behavior.

llvm-svn: 267730
2016-04-27 15:55:05 +00:00
Dmitry Vyukov 4592eb0534 tsan: fix darwin Go support
os_trace turns out to be a macro that creates static object.
Function-static objects use __cxa_atexit and __dso_handle
which are not present in Go runtime.

llvm-svn: 267720
2016-04-27 14:28:42 +00:00
Dmitry Vyukov 221e2c61ec tsan: fix windows Go support
Unmap can't unmap arbitrary regions on windows.

llvm-svn: 267716
2016-04-27 14:03:14 +00:00
Dmitry Vyukov 51c294a9e8 tsan: fix darwin Go build
syslog_lock is not defined in Go build.

llvm-svn: 267714
2016-04-27 13:40:05 +00:00
Dmitry Vyukov 3e0315c044 tsan: make windows shadow mapping a bijection
CheckShadowMapping function started catching that
mem->shadow->mem mapping is not bijection.
Make it bijection.

llvm-svn: 267713
2016-04-27 13:34:01 +00:00
Dmitry Vyukov 5aac22fc23 tsan: fix build
error: implicit declaration of function 'abort' is invalid in C99
llvm-svn: 267710
2016-04-27 12:59:35 +00:00
Dmitry Vyukov 30452f820b tsan: fix darwin Go build
Ifdef out global variables with destructors.
This requires runtime support that is not provided by Go runtime
(in particular _dso_handle symbol).

llvm-svn: 267709
2016-04-27 12:56:16 +00:00
Dmitry Vyukov 3efe395788 tsan: change tsan/Go interface for obtaining the current Processor
Current interface assumes that Go calls ProcWire/ProcUnwire
to establish the association between thread and proc.
With the wisdom of hindsight, this interface does not work
very well. I had to sprinkle Go scheduler with wire/unwire
calls, and any mistake leads to hard to debug crashes.
This is not something one wants to maintian.
Fortunately, there is a simpler solution. We can ask Go
runtime as to what is the current Processor, and that
question is very easy to answer on Go side.
Switch to such interface.

llvm-svn: 267703
2016-04-27 12:30:48 +00:00
Dmitry Vyukov a785640e83 tsan: fix windows build
warning: '__sanitizer::uptr __sanitizer::GetPreferredBase(const char*)' defined but not used
llvm-svn: 267682
2016-04-27 08:41:31 +00:00
Dmitry Vyukov f52c7c7abf tsan: fix windows build
llvm-svn: 267681
2016-04-27 08:39:32 +00:00
Dmitry Vyukov 3c65833a51 tsan: add missing file
llvm-svn: 267680
2016-04-27 08:34:55 +00:00
Dmitry Vyukov 066fefcbf3 tsan: fix compiler warning
tsan_debugging.cc: In function ‘void* __tsan_get_current_report()’:
tsan_debugging.cc:61:18: warning: cast from type ‘const __tsan::ReportDesc*’
                         to type ‘void*’ casts away qualifiers [-Wcast-qual]
   return (void *)rep;

llvm-svn: 267679
2016-04-27 08:28:08 +00:00
Dmitry Vyukov d87c7b321a tsan: split thread into logical and physical state
This is reincarnation of http://reviews.llvm.org/D17648 with the bug fix pointed out by Adhemerval (zatrazz).

Currently ThreadState holds both logical state (required for race-detection algorithm, user-visible)
and physical state (various caches, most notably malloc cache). Move physical state in a new
Process entity. Besides just being the right thing from abstraction point of view, this solves several
problems:

Cache everything on P level in Go. Currently we cache on a mix of goroutine and OS thread levels.
This unnecessary increases memory consumption.

Properly handle free operations in Go. Frees are issue by GC which don't have goroutine context.
As the result we could not do anything more than just clearing shadow. For example, we leaked
sync objects and heap block descriptors.

This will allow to get rid of libc malloc in Go (now we have Processor context for internal allocator cache).
This in turn will allow to get rid of dependency on libc entirely.

Potentially we can make Processor per-CPU in C++ mode instead of per-thread, which will
reduce resource consumption.
The distinction between Thread and Processor is currently used only by Go, C++ creates Processor per OS thread,
which is equivalent to the current scheme.

llvm-svn: 267678
2016-04-27 08:23:02 +00:00
Mohit K. Bhakkad 3ad70b4b5b [Compiler-rt][CFI] Enabling CFI for MIPS64
Reviewers: eugenis

Subscribers: jaydeep, sagar, Sanitizers

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

llvm-svn: 267674
2016-04-27 05:49:42 +00:00
Mike Aizatsky a3060c1159 [sanitizers] rewriting test assuming assert() changes coverage.
Summary:
On windows platform assert() call creates two distinct CFG edges
which are coverage-instrumented. Simply calling assert would
change coverage numbers on the platform.

Subscribers: kubabrecka

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

llvm-svn: 267610
2016-04-26 21:56:14 +00:00
Marcin Koscielnicki 3f9d7a217d [sanitizers] [NFC] Add defines for the various PowerPC ABIs.
Differential Revision: http://reviews.llvm.org/D19542

llvm-svn: 267586
2016-04-26 18:44:13 +00:00
Chris Bieneman 380ebd0b2c [CMake] [PR27403] Fix COMPILER_RT_ENABLE_IOS when using Xcode from the App Store.
This change modifies find_darwin_sdk_dir to set a variable if a Darwin "Internal" SDK is present which allows CMake to disable components that require internal-only APIs.

This mechanism is then used to disable TSan when an internal SDK is not present.

llvm-svn: 267575
2016-04-26 17:53:25 +00:00
Marcin Koscielnicki 7ecdeb7ac3 [sanitizer] [SystemZ] Add ptrace support bits.
Differential Revision: http://reviews.llvm.org/D19134

llvm-svn: 267548
2016-04-26 10:41:30 +00:00
Marcin Koscielnicki f98076b6a1 [sanitizer] [SystemZ] Implement internal_clone.
Differential Revision: http://reviews.llvm.org/D19159

llvm-svn: 267547
2016-04-26 10:41:19 +00:00
Mehdi Amini 9163f4997a Revert "[sanitizers] read/write page fault detection on mac."
This reverts commit r267477.
It broke our bots that enables the AArch64 backends, it seems that
this code is using a Darwin *X86 specific* field.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 267526
2016-04-26 07:03:11 +00:00
Marcin Koscielnicki 9135ff9247 [MSan] Use COMMON_INTERCEPTOR_ENTER in libdl interceptors.
This fixes fails in test/msan/dlerror.cc - when real dlerror calls strcmp,
our strcmp interceptor now skips poison checking, since it's called in
interceptor context.  Strictly speaking, only the dlerror change is
necessary to fix the fail, but let's also change the other two just in case.

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

llvm-svn: 267486
2016-04-25 22:25:49 +00:00
Mike Aizatsky f2bee298a0 [sanitizers] read/write page fault detection on mac.
Subscribers: kubabrecka

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

llvm-svn: 267477
2016-04-25 21:44:43 +00:00
Derek Bruening 3441644245 [esan] Fix uninitialized warning from interception context
The interception context is not used by esan, but the compiler complains
about it being uninitialized all the same.  We set it to null to avoid the
warning.

llvm-svn: 267376
2016-04-25 03:56:20 +00:00
Derek Bruening 8d97011eb2 [esan] EfficiencySanitizer libc interceptors
Summary:
Adds libc interceptors to the runtime library for the new
EfficiencySanitizer ("esan") family of tools.  The interceptors cover
the memory operations in most common library calls and will be shared
among all esan tools.

Reviewers: aizatsky

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

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

llvm-svn: 267293
2016-04-23 16:41:24 +00:00
Kostya Serebryany 3884f1a5bd [sanitizer] add a function MmapNoAccess that mmaps a protected region *somewhere*; use MmapNoAccess in the Allocator when SpaceBeg is not a constant. In this mode the allocator will be a bit more hardened
llvm-svn: 267256
2016-04-23 00:05:24 +00:00
Kostya Serebryany 99ed605799 [sanitizer] rename MmapNoAccess to MmapFixedNoAccess; NFC
llvm-svn: 267253
2016-04-22 23:46:53 +00:00
Kostya Serebryany 58bc64432c [sanitizer] partially un-revert r267094: Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point.
llvm-svn: 267252
2016-04-22 23:35:00 +00:00
Kostya Serebryany c2eb17db37 [sanitizer] revert r267203 as it breaks aarch64 bots
llvm-svn: 267251
2016-04-22 23:27:15 +00:00
Kostya Serebryany d4f275cecb [sanitizer] allow zero first parameter in MmapNoAccess; This is a part of r267094 that has been reverted
llvm-svn: 267203
2016-04-22 20:05:52 +00:00
Renato Golin e48f7e6f2d Revert "[LSAN] Fix test swapcontext.cc on MIPS"
This reverts commit r266716, as it breaks the self-hosting on Thumb2 buildbot.

llvm-svn: 267158
2016-04-22 14:56:30 +00:00
Renato Golin aa673486c4 Revert "[sanitizer] Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point."
This reverts commit r267094, because it broke a lot of MSAN tests in AArch64.
Being NFC and all, this needs some deeper investigation before it goes in again.

llvm-svn: 267136
2016-04-22 11:18:14 +00:00
Sagar Thakur b1c51f6a94 [ASAN] Use struct instead of array in sancov.py
Summary: When using 32-bit python with 64-bit asan the pc array in sancov.py cannot fit in 64-bit pc's because the type-code 'L' for
arrays in python corresponds to the C type long which is only of 4 bytes. Because of this some of the coverage tool tests fail on
mips. To fix these test possible solutions are to use 64-bit python or use struct.unpack with the 'Q' type-code. We have used
struct.unpack with 'Q' type code since it is not appropriate to have a 64-bit python on all hosts.

Reviewed by kcc, aizatsky

Differential: http://reviews.llvm.org/D18817
llvm-svn: 267126
2016-04-22 09:20:22 +00:00
Kostya Serebryany d55d0875d2 [sanitizer] Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point.
llvm-svn: 267094
2016-04-22 01:08:54 +00:00
Evgeniy Stepanov 988ebe9f34 [asan] Disable one test on windows.
Patch by Vitaly Buka.

llvm-svn: 267088
2016-04-22 00:34:10 +00:00
Evgeniy Stepanov 4c0f6afbab Enable stack-use-after-scope tests.
Fix and enable working stack-use-after-scope tests.
Add more failing tests for the feature, for fix later.

PR27453.

Patch by Vitaly Buka.

llvm-svn: 267084
2016-04-22 00:10:23 +00:00
Derek Bruening af7aaae1bc [esan] EfficiencySanitizer base runtime library
Summary:
Adds the initial version of a runtime library for the new
EfficiencySanitizer ("esan") family of tools.  The library includes:

+ Slowpath code via callouts from the compiler instrumentation for
  each memory access.

+ Registration of atexit() to call finalization code.

+ Runtime option flags controlled by the environment variable
  ESAN_OPTIONS.  The common sanitizer flags are supported such as
  verbosity and log_path.

+ An initial simple test.

Still TODO: common code for libc interceptors and shadow memory mapping,
and tool-specific code for shadow state updating.

Reviewers: eugenis, vitalybuka, aizatsky, filcab

Subscribers: filcab, vkalintiris, kubabrecka, llvm-commits, zhaoqin, kcc

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

llvm-svn: 267060
2016-04-21 21:32:25 +00:00
Evgeniy Stepanov 0e97e036d3 [asan] Mark strdup test as unsupported on arm/linux.
llvm-svn: 267028
2016-04-21 18:18:09 +00:00
Kuba Brecka bf8b5f8dd2 [tsan] Rename ReportThread->pid to ReportThread->os_id
The field "pid" in ReportThread is used to store the OS-provided thread ID (pthread_self or gettid). The name "pid" suggests it's a process ID, which it isn't. Let's rename it.

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

llvm-svn: 266994
2016-04-21 14:49:25 +00:00
Kuba Brecka 586d93bd8b [sanitizer] Use pthread_threadid_np as thread ID on OS X
Let's use pthread_threadid_np which returns a more reasonable ID than pthread_self (which is actually a stack pointer). The numbers from pthread_threadid_np are already used in other tools, e.g. in LLDB, and often appear in logs, so it's much more useful than pthread_self.

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

llvm-svn: 266991
2016-04-21 14:38:41 +00:00
Kostya Serebryany e63db09bea [sanitizer] update the sanitizer_allocator_testlib
llvm-svn: 266934
2016-04-20 23:28:06 +00:00
Evgeniy Stepanov 033c5d55c1 [asan] Increase LocatePcInTrace threshold.
Not sure what changed, but on my machine this is literally one byte
short. Only happens when malloc_context_size <= 2 due to the special
case in GET_STACK_TRACE definition (see asan_stack.h):
StackTrace::GetCurrentPc() on the right (context size > 2) branch
returns the address that is 200-something bytes from the return
address it is later matched to, while the same call on the left
branch is 321 bytes away from it.

This fixes the double-free test on my machine.

llvm-svn: 266932
2016-04-20 22:45:25 +00:00
Evgeniy Stepanov 5d71bc5252 [asan] Add __strdup interceptor.
This happens on Linux when building as C (not C++) with optimization.

llvm-svn: 266931
2016-04-20 22:45:23 +00:00
Evgeniy Stepanov 32773333cb [msan] Implement GetPageSize in the test.
Instead of calling a sanitizer_common function, implement GetPageSize in the
test directly. MSan runtime does not export __sanitizer::* symbols, and the
current code breaks when the test and the runtime library are in the separate
link units (ex. when the test is built as a shared library).

llvm-svn: 266910
2016-04-20 20:32:18 +00:00
Saleem Abdulrasool de120799a0 builtins: fix -Werror,-Wunused-variable warning
This removes the unused variable `flags`.  NFC

llvm-svn: 266892
2016-04-20 17:43:43 +00:00
Saleem Abdulrasool 28e1b977d4 builtins: remove use of __attribute__((pcs("aapcs"))) on Windows
Windows does not honour the __attribute__((pcs)) on ARM.  Although this will
result in ABI mismatches, compiler-rt should largely be unneeded for resolving
dependencies as we generate MS ABI compliant library calls now for the most
part.

llvm-svn: 266891
2016-04-20 17:43:40 +00:00
Chuang-Yu Cheng e480455fd6 Always inlining PrintCurrentStackSlow of tsan library to fix tail-call issue
The real problem is that sanitizer_print_stack_trace obtains current PC and
expects the PC to be in the stack trace after function calls. We don't
prevent tail calls in sanitizer runtimes, so this assumption does not
necessary hold.

We add "always inline" attribute on PrintCurrentStackSlow to address this
issue, however this solution is not reliable enough, but unfortunately, we
don't see any simple, reliable solution.

Reviewers: samsonov hfinkel kbarton tjablin dvyukov kcc

http://reviews.llvm.org/D19148

Thanks Hal, dvyukov, and kcc for invaluable discussion, I have even borrowed
part of dvyukov's summary as my commit message!

llvm-svn: 266869
2016-04-20 10:28:41 +00:00
Maxim Ostapenko 71630b9ea7 [sanitizer] Fix 'dyld: Symbol not found: _dyldVersionNumber' link error on old Darwin systems.
This patch fixes https://github.com/google/sanitizers/issues/669. On older Darwin systems (in particular, Darwin 10),
dyld doesn't export '_dyldVersionNumber' symbol so we would have 'undefined reference' error in sanitzer library. Although
sanitizers support was added to LLVM on OS X 10.7+ where '_dyldVersionNumber' symbol is already exported, GCC users still
may want use them on older systems.

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

llvm-svn: 266868
2016-04-20 10:22:37 +00:00
Mandeep Singh Grang 04ccbd4053 [compiler-rt] Remove unwanted --check-prefix=CHECK from unit tests. NFC.
Summary:
Removed unwanted --check-prefix=CHECK from the following unit tests:
      test/asan/TestCases/Posix/start-deactivated.cc
      test/tsan/Darwin/ignored-interceptors.mm

 Patch by: Mandeep Singh Grang (mgrang)

Reviewers: samsonov, kcc, dvyukov, eugenis

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

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

Reviewers: samsonov, earthdok, kcc
Subscribers: llvm-commits, mohit.bhakkad, jaydeep
Differential: http://reviews.llvm.org/D18690
llvm-svn: 266716
2016-04-19 06:00:35 +00:00
Marcin Koscielnicki c5d2ff8099 [msan] Don't hardcode 4kiB page size in msan_test.cc.
This breaks the valloc test on PowerPC, which has 64kiB pages.  Since
getting page size portably is nontrivial, and there's already a function
for that in __sanitizer, just use it.  Unfortunately, sanitizer_common.h
conflicts with the interface headers inclucded by msan_test.cc (and a few
of its own macros), so we have to declare it manually.

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

llvm-svn: 266688
2016-04-18 22:21:02 +00:00
Kostya Serebryany d8ce87f850 Additional test for use-after-scope
Summary: Test that asan detects access to the dead variable captured by lambda.

Reviewers: aizatsky, kcc

Subscribers: llvm-commits

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

llvm-svn: 266676
2016-04-18 21:36:34 +00:00
Marcin Koscielnicki 3f89541a7d [MSan] [PowerPC] Add loadable library name for testing.
Differential Revision: http://reviews.llvm.org/D19217

llvm-svn: 266646
2016-04-18 18:21:41 +00:00
Marcin Koscielnicki 48f32510da [asan] [SystemZ] Add slop for stack address detection.
On s390, siginfo reports the faulting address with page granularity -
we need to mask off the low bits of sp before comparison.

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

llvm-svn: 266593
2016-04-18 09:01:19 +00:00
Alex Denisov a3f5c4c047 Replace hardcoded comment at 'lit.site.cfg.in'
At the moment almost every lit.site.cfg.in contains two lines comment:

  ## Autogenerated by LLVM/Clang configuration.
  # Do not edit!

The patch adds variable LIT_SITE_CFG_IN_HEADER, that is replaced from
configure_lit_site_cfg with the note and some useful information.

llvm-svn: 266520
2016-04-16 07:03:45 +00:00
Anna Zaks 8f8d3db940 [sanitizers] Fixup to r266494; the Unit test should not run on Windows
The test is failing on Windows because we do not have a definition for
DemangleSwiftAndCXX nor DemangleCXXABI, which I am replacing, on Windows.

llvm-svn: 266499
2016-04-16 00:32:16 +00:00
Anna Zaks 50154d4ec4 [sanitizers] Fixup r266494; make it build on Linux.
llvm-svn: 266497
2016-04-16 00:12:46 +00:00
Anna Zaks 60469e2ac0 [sanitizers] Teach the internal demangler about Swift names
Add support for Swift names when symbolicating sanitizer traces. This is
now relevant since TSan and ASan support have been added to Swift on OS X.

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

llvm-svn: 266494
2016-04-15 23:51:00 +00:00
Marcin Koscielnicki b5e4804aee [sanitizer] [SystemZ] Enable UBSan.
sanitizer_common is now in good enough shape on s390x to support UBSan
- all tests passing.  Let's enable it.

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

llvm-svn: 266483
2016-04-15 22:25:04 +00:00
Marcin Koscielnicki 604d873aa1 [sanitizers] [SystemZ] Introduce sanitizer_linux_s390.cc.
This file will contain s390-specific code.  For now, let's move the s390
version of internal_mmap here.

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

llvm-svn: 266482
2016-04-15 22:11:10 +00:00
Marcin Koscielnicki 0a91cf8a84 Revert "[sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143."
This reverts commit r266297.

llvm-svn: 266470
2016-04-15 20:00:12 +00:00
Renato Golin 1f42286364 [TSAN] Make tsan tests more portable (take 3)
Some tests didn't merge stderr with stdout.

Patch by Maxim Kuvyrkov.

llvm-svn: 266426
2016-04-15 12:34:00 +00:00
George Burgess IV 908dacf91d Fix StaticAnalyzer complaints. NFC.
Clang's StaticAnalyzer seems to (correctly) complain about code like:

    T *p = calloc(sizeof(U), N);

...Where T and U are different types.

This patch removes some instances of this pattern from compiler-rt.

Patch by Apelete Seketeli.
Differential Revision: http://reviews.llvm.org/D19085

llvm-svn: 266388
2016-04-14 23:58:26 +00:00
Marcin Koscielnicki 9e09355477 [sanitizer] [SystemZ] Fix stack traces.
On s390, the return address is in %r14, which is saved 14 words from
the frame pointer.

Unfortunately, there's no way to do a proper fast backtrace on SystemZ
with current LLVM - the saved %r15 in fixed-layout register save
area points to the containing frame itself, and not to the next one.
Likewise for %r11 - it's identical to %r15, unless alloca is used
(and even if it is, it's still useless).  There's just no way to
determine frame size / next frame pointer.  -mbackchain would fix that
(and make the current code just work), but that's not yet supported
in LLVM.  We will thus need to XFAIL some asan tests
(Linux/stack-trace-dlclose.cc, deep_stack_uaf.cc).

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

llvm-svn: 266371
2016-04-14 21:19:27 +00:00
Marcin Koscielnicki 20bf94209e [sanitizer] [SystemZ] Add/fix kernel and libc type definitions.
This is the first part of upcoming asan support for s390 and s390x.
Note that there are bits for 31-bit support in this and subsequent
patches - while LLVM itself doesn't support it, gcc should be able
to make use of it just fine.

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

llvm-svn: 266370
2016-04-14 21:17:19 +00:00
Ed Maste fe2b70637c [sanitizer] remove FreeBSD PS_STRINGS fallback
The PS_STRINGS constant can easily be incorrect with mismatched
kernel/userland - e.g. when building i386 sanitizers on FreeBSD/amd64
with -m32. The kern.ps_strings sysctl was introduced over 20 years ago
as the supported way to fetch the environment and argument string
addresses from the kernel, so the fallback is never used.

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

llvm-svn: 266305
2016-04-14 14:17:42 +00:00
Renato Golin 37e64f352c Revert "Make tsan tests more portable (take 2)"
This reverts commit r266294, as it broke some buildbots again. :/

llvm-svn: 266300
2016-04-14 13:31:22 +00:00
Marcin Koscielnicki c8dda336bb [sanitizer] [SystemZ] Abort if the kernel might be vulnerable to CVE-2016-2143.
In short, CVE-2016-2143 will crash the machine if a process uses both >4TB
virtual addresses and fork().  ASan, TSan, and MSan will, by necessity, map
a sizable chunk of virtual address space, which is much larger than 4TB.
Even worse, sanitizers will always use fork() for llvm-symbolizer when a bug
is detected.  Disable all three by aborting on process initialization if
the running kernel version is not known to contain a fix.

Unfortunately, there's no reliable way to detect the fix without crashing
the kernel.  So, we rely on whitelisting - I've included a list of upstream
kernel versions that will work.  In case someone uses a distribution kernel
or applied the fix themselves, an override switch is also included.

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

llvm-svn: 266297
2016-04-14 12:56:24 +00:00
Marcin Koscielnicki 0ffa9eaa4a [sanitizer] [SystemZ] Add virtual space size.
This teaches sanitizer_common about s390 and s390x virtual space size.
s390 is unusual in that it has 31-bit virtual space.

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

llvm-svn: 266296
2016-04-14 12:56:15 +00:00
Marcin Koscielnicki 545e507c43 [sanitizer] [SystemZ] Implement internal_mmap.
mmap on s390 is quite a special snowflake: since it has too many
parameters to pass them in registers, it passes a pointer to a struct
with all the parameters instead.

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

llvm-svn: 266295
2016-04-14 12:51:45 +00:00
Renato Golin 17b8b06252 Make tsan tests more portable (take 2)
Using stderr more uniformily, avoiding potential races when scanning stdout
and stderr output.

Patch by Maxim Kuvyrkov.

llvm-svn: 266294
2016-04-14 12:10:21 +00:00
Dmitry Vyukov 909d080d98 asan: fix build
Some bots failed with:

sanitizer_quarantine.h:104:7: error: unused typedef 'assertion_failed__104' [-Werror,-Wunused-local-typedef]
      COMPILER_CHECK(kPrefetch <= ARRAY_SIZE(b->batch));

Replace COMPILER_CHECK with CHECK.

llvm-svn: 266291
2016-04-14 11:40:08 +00:00
Dmitry Vyukov a7de697ae6 asan: fix out-of-bounds access in quarantine
llvm-svn: 266288
2016-04-14 09:52:33 +00:00
Kuba Brecka 173c690a61 [tsan] Fix size reporting for OS X zone allocator with 0-sized allocations
The custom zone implementation for OS X must not return 0 (even for 0-sized allocations). Returning 0 indicates that the pointer doesn't belong to the zone. This can break existing applications. The underlaying allocator allocates 1 byte for 0-sized allocations anyway, so returning 1 in this case is okay.

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

llvm-svn: 266283
2016-04-14 09:05:19 +00:00
Evgeniy Stepanov b70a2dd157 [asan] Prefer alloc-dealloc-mismatch to new-delete-type-mismatch.
With -fsized-deallocation, new[] vs delete mismatch is reported as
new-delete-type-mismatch. This is technically true, but
alloc-dealloc-mismatch describes it better.

llvm-svn: 266246
2016-04-13 21:04:27 +00:00
Betul Buyukkurt 785b5a8950 [PGO] Fix the buildbots for r266229.
llvm-svn: 266240
2016-04-13 20:02:07 +00:00
Evgeniy Stepanov 691ef096d0 [safestack] Fix stack canary test on Mac.
Disable FORTIFY_SOURCE and explicitly disable stack protector in the
no-stack-protector run.

llvm-svn: 266106
2016-04-12 18:48:41 +00:00
Kuba Brecka 41dd5296b3 [tsan] Fix a crash with dispatch_source_set_cancel_handler(NULL) on OS X
We need to handle the case when handler is NULL in dispatch_source_set_cancel_handler and similar interceptors.

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

llvm-svn: 266080
2016-04-12 15:18:11 +00:00
Evgeniy Stepanov ddb499a453 [safestack] A test for stackprotector canaries.
llvm-svn: 266006
2016-04-11 22:28:13 +00:00
Kuba Brecka 036d060044 [sanitizer] Restore stderr when using forkpty() to spawn external symbolizer
In `AtosSymbolizer`, we're using `forkpty()` to create a new pseudo-terminal to communicate with the `atos` tool (we need that to avoid output buffering in interactive mode). This however redirects both stdout and stderr into a single stream, so when we read the output, we can't distinguish between errors and standard replies. Let's save&restore stderr to avoid that.

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

llvm-svn: 265923
2016-04-11 09:27:09 +00:00
Kuba Brecka 7b6f400090 [tsan] Replace 'not' with '%deflake' in gcd-apply-race.mm Darwin test.
llvm-svn: 265919
2016-04-11 08:38:35 +00:00
Evgeniy Stepanov eb37fcbc87 [sanitizer] Fix sem_init_glibc.cc test on __HAVE_64B_ATOMIC arches.
glibc can use one of 2 layouts for semaphores: architectures that
don't HAVE_64B_ATOMIC use an uint32_t field with semaphore value,
then a private field, then a waiting thread count field - this is
the layout currently assumed by the test. However, HAVE_64B_ATOMIC
arches use a fused uint64_t field that contains the value in low bits
and waiting thread count in high bits, followed by a private field.

This resulted in taking private field from the wrong offset on 64-bit
atomic platforms (the test still passed, but didn't actually test
the private field). On big-endian platforms, this resulted in a fail,
since the first 4 bytes overlay the thread count field, and not
the value field.

Found while porting ASan to s390x.

Patch by Marcin Kościelnicki.

llvm-svn: 265715
2016-04-07 20:26:28 +00:00
Mike Aizatsky 87b30a0ef2 [sancov] updaing android test after enabling cc edge pruning
llvm-svn: 265714
2016-04-07 20:21:21 +00:00
Derek Bruening a7685389c8 [sanitizer] Add early call handling to strlen interceptor
Summary:
The strlen interceptor is sometimes invoked too early for REAL(strlen) to
be initialized.  A special check is added to use internal_strlen for this
situation.

Reviewers: dim

Subscribers: llvm-commits, samsonov

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

Change-Id: I3acc58f4abbae1904f25324abd84efea67aad0a2
llvm-svn: 265705
2016-04-07 18:07:09 +00:00
Mike Aizatsky 66505137eb [sancov] updaing android test
llvm-svn: 265692
2016-04-07 16:22:34 +00:00
Kuba Brecka 79cb643b20 [tsan] Remove long sleeps from fork tests
On one of our testing machines, we're running the tests under heavy load, and especially in the fork-based TSan tests, we're seeing timeouts when a test uses sleep(10), assuming that calling fork() on another thread will finish sooner than that. This patch removes a timeout and makes another one longer.

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

llvm-svn: 265666
2016-04-07 12:10:28 +00:00
Kuba Brecka 74f7f399ac [tsan] Add support for OS X OSAtomic* functions
OS X provides atomic functions in libkern/OSAtomic.h. These provide atomic guarantees and they have alternatives which have barrier semantics. This patch adds proper TSan support for the functions from libkern/OSAtomic.h.

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

llvm-svn: 265665
2016-04-07 12:05:09 +00:00
Kuba Brecka 06bbca9ec4 [tsan] Add TSan __tsan_atomic* functions to tsan_interface.h
To avoid using the public header (tsan_interface_atomic.h), which has different data types, let's add all the __tsan_atomic* functions to tsan_interface.h. 

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

llvm-svn: 265663
2016-04-07 11:59:36 +00:00
Kuba Brecka 399af93242 [tsan] Add interceptors for dispatch_apply
Adding an interceptor with two more release+acquire pairs to avoid false positives with dispatch_apply.

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

llvm-svn: 265662
2016-04-07 11:52:51 +00:00
Kuba Brecka e316bb61b3 [tsan] Add XPC support (OS X)
XPC APIs have async callbacks, and we need some more happen-before edges to avoid false positives. This patch add them, plus a test case (sorry for the long boilerplate code, but XPC just needs all that).

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

llvm-svn: 265661
2016-04-07 11:47:11 +00:00
Kuba Brecka cecb7faea2 [tsan] Add support for dispatch event sources
GCD has APIs for event sources, we need some more release-acquire pairs to avoid false positives in TSan.

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

llvm-svn: 265660
2016-04-07 11:38:53 +00:00
Kuba Brecka 33c15c91a6 [tsan] Fix synchronization in dispatch_sync
In the interceptor for dispatch_sync, we're currently missing synchronization between the callback and the code *after* the call to dispatch_sync. This patch fixes this by adding an extra release+acquire pair to dispatch_sync() and similar APIs. Added a testcase.

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

llvm-svn: 265659
2016-04-07 11:33:44 +00:00
Kuba Brecka aafb41ae47 [tsan] Fix Darwin tests (missing FileCheck's)
A little embarrassing, but we're missing the call to FileCheck in several Darwin tests. Let's fix this.

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

llvm-svn: 265658
2016-04-07 11:31:02 +00:00
Mike Aizatsky 5d4d715b99 [sancov] removing flaky test case (win)
llvm-svn: 265627
2016-04-07 00:23:02 +00:00
Mike Aizatsky 49a68258f5 [sancov] enabling coverage edge pruning by default.
Differential Revision: http://reviews.llvm.org/D18845

llvm-svn: 265614
2016-04-06 23:24:16 +00:00
Sean Silva 9af25704d2 Another place for CMAKE_HOST_UNIX
If we don't create the target, don't try to add it as a dependency.

After r265595, we were only creating the SanitizerLintCheck when
`CMAKE_HOST_UNIX` was true.

CMake was emitting a warning:
  The dependency target "SanitizerLintCheck" of target "check-ubsan" does not
  exist.

llvm-svn: 265613
2016-04-06 23:18:09 +00:00
Xinliang David Li 5d2e06a34b sync up with master copy
llvm-svn: 265609
2016-04-06 22:30:14 +00:00
Sean Silva 3e85ddc011 Use `CMAKE_HOST_UNIX` to check the host.
`UNIX` is for the target.

llvm-svn: 265595
2016-04-06 20:19:31 +00:00
Yabin Cui c7db569cc1 [tsan] Fix freebsd build.
Summary:
Freebsd doesn't have <sys/personality.h>, so call personality() only in
SANITIZER_LINUX.

Reviewers: llvm-commits, dvyukov, zatrazz, rengolin, beanz

Subscribers: beanz, emaste

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

llvm-svn: 265378
2016-04-05 05:37:48 +00:00
Yabin Cui e3f558ba14 [tsan] Disable randomized address space on aarch64 linux.
Summary:
After patch https://lkml.org/lkml/2015/12/21/340 is introduced in
linux kernel, the random gap between stack and heap is increased
from 128M to 36G on 39-bit aarch64. And it is almost impossible
to cover this big range. So we need to disable randomized virtual
space on aarch64 linux.

Reviewers: llvm-commits, zatrazz, dvyukov, rengolin

Subscribers: aemerson, rengolin, tberghammer, danalbert, srhines

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

llvm-svn: 265366
2016-04-04 23:48:25 +00:00
Reid Kleckner 80fc4bc68a Apply suggestion from HJ Lu to avoid misaligned stack in test
Fixes PR27191

llvm-svn: 265322
2016-04-04 18:27:32 +00:00
Kuba Brecka 428a9f95a4 [asan,tsan] Make Darwin-specific tests more stable (use ignore_interceptors_accesses=1 for GCD tests and printf instead of NSLog).
llvm-svn: 265300
2016-04-04 14:54:05 +00:00
Dmitry Vyukov 0d9b7bc9ad tsan: fix ignore handling in signal handlers
We've reset thr->ignore_reads_and_writes, but forget to do
thr->fast_state.ClearIgnoreBit(). So ignores were not effective
reset and fast_state.ignore_bit was corrupted if signal handler
itself uses ignores.

Properly reset/restore fast_state.ignore_bit around signal handlers.

llvm-svn: 265288
2016-04-04 10:52:59 +00:00
Kuba Brecka d0e83a6eb2 [sanitizer] Make AtosSymbolizer more resilient when symbolicating a zero address
llvm-svn: 265269
2016-04-03 19:13:03 +00:00
Reid Kleckner 1992ac75db Fix warnings uncovered by building with clang-cl
Move ifdefs to avoid unused static helpers. Move alignment attribute so
that it is respected in GCC and MSVC.

llvm-svn: 265153
2016-04-01 17:09:12 +00:00
Reid Kleckner a8e5c0c200 Fix a load of -Wunknown-pragma warnings from clang-cl
llvm-svn: 265152
2016-04-01 17:09:08 +00:00
Chris Bieneman 17bcc439d6 [CMake] Provide the ability to skip stripping when generating dSYMs
For debugging it is useful to be able to generate dSYM files but not strip the executables. This change adds the ability to skip stripping by setting COMPILER_RT_EXTERNALIZE_DEBUGINFO_SKIP_STRIP=On.

llvm-svn: 265057
2016-03-31 21:17:19 +00:00
Paul Robinson d993522d28 Update copyright year to 2016.
llvm-svn: 264948
2016-03-30 22:38:50 +00:00
Ryan Govostes e0f41da049 [asan] Mark the initialization-bug.cc unsupported on OS X Yosemite and older
This test should fail on OS X Yosemite and older, and pass on OS X El Capitan
and newer as well as on other platforms.

llvm-svn: 264938
2016-03-30 22:21:58 +00:00
Reid Kleckner 747dc2eb61 [cmake] Get the MSVC version by running cl rather than relying on MSVC_VERSION
MSVC_VERSION comes from the _MSC_VER macro, which won't correspond to
the STL version if the host compiler is clang-cl.

llvm-svn: 264901
2016-03-30 18:31:14 +00:00
Vedant Kumar 62f0576c5c [profile] Remove quotes around env variable, NFC
llvm-svn: 264824
2016-03-30 04:36:10 +00:00
Vedant Kumar 989bc4bfd6 [profile] Test error reporting by writing to a temp directory
This test case is meant to check whether verbose error logging works. It
does this by _failing_ to write a profile to a path corresponding to a
directory. Make this clearer by writing to a temporary directory.

Patch suggested by Sean Silva!

llvm-svn: 264817
2016-03-30 01:30:47 +00:00
Sean Silva 2c6d2b3c5e [libprofile] Make this test express intent a bit better.
This also makes it work on PS4 a bit better.
For running the libprofile tests on PS4, we are sneaking environment
variables through on the command line, so the extra argument for
LLVM_PROFILE_FILE was messing up the simple `argc < 2` check.

llvm-svn: 264812
2016-03-30 00:25:15 +00:00
Xinliang David Li bd54f5bd25 Fix comment in test
llvm-svn: 264792
2016-03-29 21:53:08 +00:00
Vedant Kumar dcafeddfb7 [profile] Make a test work if run by the super-user
llvm-svn: 264773
2016-03-29 19:24:58 +00:00
Ryan Govostes 89daa29fa6 [asan] Make the Darwin/dead-strip.c test require El Capitan or newer
llvm-svn: 264766
2016-03-29 18:54:29 +00:00
Chris Bieneman ac400900da [Darwin] [Builtins] Cleaning up OS X exclude lists. NFC.
This just gets rid of a bunch of empty object file warnings. It doesn't impact the generated archives.

llvm-svn: 264751
2016-03-29 17:34:13 +00:00
Chris Bieneman 8de525696f [Darwin] [Builtins] Remove multi3 from the exclude list.
This addresses PR27077. For some historical reason Darwin wasn't shipping multi3 in the compiler builtin library or in the OS builtin library. This caused building ffmpeg to fail because Polly was generating calls to multi3. It is easy enough to just add the builtin.

llvm-svn: 264750
2016-03-29 17:24:23 +00:00
Chris Bieneman c4613f457a [Darwin] [Builtins] Cleaning up 10.4 exclude lists NFC
This just gets rid of a bunch of empty object file warnings. It doesn't impact the generated archives.

llvm-svn: 264749
2016-03-29 17:24:21 +00:00
Sean Silva c9d546c291 [libprofile] Use one fewer -mllvm option in this test.
AFAIK there is still no way to avoid `-mllvm -disable-vp=false`
currently.

llvm-svn: 264682
2016-03-28 22:23:03 +00:00
Adam Nemet fadba5d4d4 [PGO] More comments how function pointers for indirect calls are mapped
to function names

Summary:
Hopefully this will make it easier for the next person to figure all
this out...

Reviewers: bogner, davidxl

Subscribers: davidxl, cfe-commits

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

llvm-svn: 264680
2016-03-28 22:16:29 +00:00
Sean Silva c2feac75fd [libprofile] Handle '\\' in __llvm_profile_recursive_mkdir
This is implicitly needed at least by gcc-flag-compatibility.test

The thing that needs it is the `\` preceding the "default.profraw"
appended internally by clang when doing `-fprofile-use=`.

Clang uses `\` because is uses sys::path::append which will use `\` on a
Windows host. This is wrong, but I don't think there's an easy way to
solve it (maybe just always using `/` since places that accept `\` also
tend to accept `/`, but not the other way around).

llvm-svn: 264665
2016-03-28 21:32:46 +00:00
Ryan Govostes dc91fe5d8b [asan] Add runtime support for __asan_(un)register_image_globals
This change introduces routines that register and unregister all
instrumented globals in a loaded executable image.

These routines are only implemented on Darwin, where globals metadata
is expected to be placed in the __DATA,__asan_globals section.

Review: http://reviews.llvm.org/D16841
llvm-svn: 264644
2016-03-28 20:28:17 +00:00
Kuba Brecka 0d026d9e9e [tsan] Fix a crash when exiting the main thread (e.g. dispatch_main)
This patch fixes the custom ThreadState destruction on OS X to avoid crashing when dispatch_main calls pthread_exit which quits the main thread.

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

llvm-svn: 264627
2016-03-28 19:36:25 +00:00
Sean Silva 7434e1d01f [libprofile] Make this test not depend on previous runs.
llvm-svn: 264626
2016-03-28 19:34:22 +00:00
Sean Silva 7d27e77820 [libprofile] Make this test a bit more specific
llvm-svn: 264625
2016-03-28 19:25:19 +00:00
Adam Nemet a68d755774 [PGO] Update r264612 to use C-style comment
llvm-svn: 264615
2016-03-28 18:47:44 +00:00
Adam Nemet 42a6fe199f [PGO] Comment how function pointers for indirect calls are mapped to function names
Summary:
Hopefully this will make it easier for the next person to figure all
this out...

Reviewers: bogner, davidxl

Subscribers: llvm-commits

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

llvm-svn: 264612
2016-03-28 18:29:36 +00:00
Kuba Brecka 2f5d8ff14a Fix-up for OS X test failure after r264451 ("Add memset, memmove, and memcpy to the common interceptors")
llvm-svn: 264571
2016-03-28 10:21:35 +00:00
Xinliang David Li f6d61afc14 Make vp merge test more robust
llvm-svn: 264521
2016-03-26 20:44:03 +00:00
Sean Silva d63f1f1ff2 [libprofile] Adjust dummy condition to be more forgiving.
On PS4, we have to fake environment variables by passing extra command
line arguments, so the dummy test `argc > 1` was failing.
The condition is just a dummy condition that the compiler can't fold
away, so the number is arbitrary as long as the condition is false.

Increase the number it compares against.

llvm-svn: 264491
2016-03-26 04:01:57 +00:00
Sean Silva 58cba2b27d [libprofile] Add some missing `env` prefixes on commands.
llvm-svn: 264490
2016-03-26 03:37:45 +00:00
Richard Smith 11598143f4 Stop depending on the keys in a hash table being in a particular order.
llvm-svn: 264488
2016-03-26 03:06:42 +00:00
Kostya Serebryany b48f8f09b1 [asan] bump the scariness score of read-after-frees (based on feedback from the Chrome security team)
llvm-svn: 264481
2016-03-26 00:00:19 +00:00
Vedant Kumar 5a697bbda3 [profile] Add integration test to validate PGO function names
Differential Revision: http://reviews.llvm.org/D18485

llvm-svn: 264480
2016-03-25 23:56:23 +00:00
Derek Bruening e988af9073 [sanitizer] Add memset, memmove, and memcpy to the common interceptors
Summary:
Currently, sanitizer_common_interceptors.inc has an implicit, undocumented
assumption that the sanitizer including it has previously declared
interceptors for memset and memmove.  Since the memset, memmove, and memcpy
routines require interception by many sanitizers, we add them to the
set of common interceptions, both to address the undocumented assumption
and to speed future tool development.  They are intercepted under a new
flag intercept_intrin.

The tsan interceptors are removed in favor of the new common versions.  The
asan and msan interceptors for these are more complex (they incur extra
interception steps and their function bodies are exposed to the compiler)
so they opt out of the common versions and keep their own.

Reviewers: vitalybuka

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264451
2016-03-25 19:33:45 +00:00
Reid Kleckner 3b0290570b [asan] Intercept all Heap* related imports from ucrtbase.dll
ucrtbase.dll appears to be built with some kind of cross-module
inlining, because there are calls to imported Heap* routines sprinkled
throughout the code. This inlining defeats our attempts to hotpatch
malloc, _malloc_base, and related functions. Failing to intercept an
allocation or deallocation results in a crash when the program attempts
to deallocate or reallocate memory with the wrong allocator.

This change patches the IAT of ucrtbase.dll to replace the addresses of
the imported Heap* functions with implementations provided by ASan.  We
don't globally intercept the win32 Heap* functions because they are
typically used by system DLLs that run before ASan initializes.
Eventually, we may want to intercept them, but for now I think this is
the minimal change that will keep ASan stable.

Reviewers: samsonov

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

llvm-svn: 264327
2016-03-24 20:19:48 +00:00
Kuba Brecka 5ac97845b1 Follow-up for r264261, adding a comment explaining what the testcase does.
llvm-svn: 264271
2016-03-24 13:20:38 +00:00
Kuba Brecka 3bab18d4af [tsan] Fix fork() and fork-based tests for OS X
On OS X, fork() under TSan asserts (in debug builds only) because REAL(fork) calls some intercepted functions, which check that no internal locks are held via CheckNoLocks(). But the wrapper of fork intentionally holds some locks. This patch fixes that by using ScopedIgnoreInterceptors during the call to REAL(fork). After that, all the fork-based tests seem to pass on OS X, so let's just remove all the UNSUPPORTED: darwin annotations we have.

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

llvm-svn: 264261
2016-03-24 11:54:33 +00:00
Kuba Brecka 46b9363683 [tsan] Use direct syscalls for internal_mmap and internal_munmap on OS X
On OS X, internal_mmap just uses mmap, which can invoke callbacks into libmalloc (e.g. when MallocStackLogging is enabled). This can subsequently call other intercepted functions, and this breaks our Darwin-specific ThreadState initialization. Let's use direct syscalls in internal_mmap and internal_munmap. Added a testcase.

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

llvm-svn: 264259
2016-03-24 11:50:21 +00:00
Derek Bruening b584410b80 [sanitizer] Add strnlen to the common interceptors
Summary:
Adds strnlen to the common interceptors, under the existing flag
intercept_strlen.

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

Adds a new test of strnlen to the sanitizer_common test cases.

Reviewers: samsonov

Subscribers: zhaoqin, llvm-commits, kcc

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

llvm-svn: 264195
2016-03-23 21:24:28 +00:00
Reid Kleckner 03d703bb62 [asan] Export new and delete operators on Windows
This is necessary to support the dynamic CRT (/MD) with VS2015. In
VS2015, these symbols are no longer imported from a DLL, they provided
statically by msvcrt.lib. This means our approach of hotpatching the DLL
no longer works.

By exporting the symbols, we end up relying on the same mechanism that
we use to intercept symbols in the static CRT (/MT) case. The ASan
runtime always needs to appear first on the link line, and the linker
searches for symbol definitions from left to right. This means we can
stop hotpatching operator new and delete in the CRT, which is nice.

I think that the only reason we weren't exporting the symbols already is
because MSVC doesn't allow you to do it directly with
__declspec(dllexport). Instead, we can use
`#pragma comment(linker, "/export:foo")`, which is most of what the
attribute does under the hood. It does mean we have to write down the
mangled names of the operators, but that's not too bad.

llvm-svn: 264190
2016-03-23 20:45:52 +00:00
Renato Golin c8622e8cde Revert "[tsan] Disable randomized address space on linux aarch64."
This reverts commits r264068 and r264079, and they were breaking the build and
weren't reverted in time, nor they exhibited expected behaviour from the
reviewers. There is more to discuss than just a test fix.

llvm-svn: 264150
2016-03-23 11:24:30 +00:00
Derek Bruening bffdcde03d Test commit to verify repository access and fix a typo.
llvm-svn: 264112
2016-03-22 22:32:03 +00:00
Yabin Cui 28f367d7b3 [tsan] Fix check-tsan build by using CHECK_NE.
Reviewers: llvm-commits, srhines, dvyukov

Subscribers: srhines

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

llvm-svn: 264079
2016-03-22 18:12:18 +00:00
Yabin Cui 909e600abd [tsan] Disable randomized address space on linux aarch64.
Summary:
After patch https://lkml.org/lkml/2015/12/21/340 is introduced in
linux kernel, the random gap between stack and heap is increased
from 128M to 36G on 39-bit aarch64. And it is almost impossible
to cover this big range. So I think we need to disable randomized
virtual space on aarch64 linux.

Reviewers: kcc, llvm-commits, eugenis, zatrazz, dvyukov, rengolin

Subscribers: rengolin, aemerson, tberghammer, danalbert, srhines, enh

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

llvm-svn: 264068
2016-03-22 17:16:26 +00:00
Reid Kleckner d83633f552 [asan] Add ucrtbase.dll to the list of DLLs to intercept
Reduces number of test failures in check-asan-dynamic with VS 2015.

llvm-svn: 264061
2016-03-22 15:46:50 +00:00
Reid Kleckner 2310c658d8 [asan] Add one more x86 encoding to the interceptor for strrchr
llvm-svn: 264060
2016-03-22 15:46:43 +00:00
Kuba Brecka a2d28299bd [tsan] Change nullptr to NULL in one Darwin test.
Depending on the version of libcxx, nullptr might not be available. Let's use NULL instead.

llvm-svn: 264058
2016-03-22 14:59:46 +00:00
Reid Kleckner f2be78c07e Move -fms-compatibility-version=19 into target cflags
This reduces cflags duplication and allows us to build
sanitizer_common/tests with clang and the VS 2015 STL.

llvm-svn: 264017
2016-03-22 01:14:36 +00:00
Reid Kleckner 2ea051e699 [asan] Relax strdup test check lines
On the buildbot, strdup appears as frame 1 instead of frame 0. Either is
an acceptable user experience.

llvm-svn: 264016
2016-03-22 01:04:33 +00:00
Reid Kleckner ea4ae806bb Wrap 81 character line to satisfy linter
llvm-svn: 264014
2016-03-22 00:53:04 +00:00
Reid Kleckner 23d0fde535 [asan] Intercept strdup on Windows
Some unit tests were failing because we didn't intercept strdup.  It
turns out it works just fine on 2013 and 2015 with a small patch to the
interception logic.

llvm-svn: 264013
2016-03-22 00:52:47 +00:00
Reid Kleckner 79d2451cd7 [asan] Also apply r264006 to asan_win_dynamic_runtime_thunk.cc
llvm-svn: 264011
2016-03-22 00:34:53 +00:00
Reid Kleckner c35d402aeb Fix coverage-related asan tests for VS 2015
printf is an inline function in VS 2015, giving these tests an
unexpected extra point of coverage. This change works around that by
avoiding printf.

llvm-svn: 264010
2016-03-22 00:11:51 +00:00
Reid Kleckner 81f7729c3d [asan] Set the unhandled exception filter slightly later during startup
VS 2015 moved the priority of their exception filter initializer from
XIY to XCAA. We now set ours to XCAB, which makes it run after both CRT
versions but before user constructors, as it should.

Fixes null_deref.cc and a variety of related tests with VS 2015. Only 4
failures remain.

llvm-svn: 264006
2016-03-21 23:51:21 +00:00
Reid Kleckner ed051774ba [asan] Add new _*_base interceptors for VS 2015
There are some places in the CRT (such as mbctype) that directly call
_malloc_base. If you are incrementally linking a binary with ASan from
before this change, this change appears to result in a linker error.
Retrying the link succeeds for some reason.

llvm-svn: 264005
2016-03-21 23:51:17 +00:00
Evgeniy Stepanov 7923ce692e [asan] Add strrchr to asan_win_dll_thunk.
"dll_host.cc" test says there is a mismatch.

llvm-svn: 263998
2016-03-21 22:42:15 +00:00
Evgeniy Stepanov accf390a75 [sanitizer] Add strchr* to the common interceptors
Adds strchr, strchrnul, and strrchr to the common interceptors, under a new
common flag intercept_strchr.

Removes the now-duplicate strchr interceptor from asan and all 3
interceptors from tsan. Previously, asan did not intercept strchrnul, but
does now; previously, msan did not intercept strchr, strchrnul, or strrchr,
but does now.

http://reviews.llvm.org/D18329

Patch by Derek Bruening!

llvm-svn: 263992
2016-03-21 21:36:17 +00:00
Mike Aizatsky 5d17878101 [sanitizier] initializing common flags.
Summary: Without SetDefaults() CommonFlags contain garbage.

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

llvm-svn: 263985
2016-03-21 20:53:20 +00:00
Reid Kleckner 21aca4897d [asan] Disable thread-safe static initilization with VS 2015
ASan interceptors contain local statics which run before the CRT is
initialized. Thread-safe statics appear to rely on CRT-internal state,
and will crash without this flag.

llvm-svn: 263979
2016-03-21 20:08:59 +00:00
Reid Kleckner a4192a743a [asan] Pass -fms-compatibility-version=19 with VS 2015
This resolves errors about char16_t and char32_t when compiling 2015 STL
headers with clang.

llvm-svn: 263973
2016-03-21 19:37:30 +00:00
Reid Kleckner d2f05f52b4 [asan] Update hotpatch code for VS 2015 memset implementation
In VS 2015, the memset fill parameter is zero extended from one byte
instead of being copied wholesale.

The issue reproduces with existing tests if you use VS2015.

llvm-svn: 263966
2016-03-21 18:23:07 +00:00
Kuba Brecka 2e084e7292 [tsan] Adding a test case for r263939 ("Add some NULL pointer checks into the debugging API")
llvm-svn: 263946
2016-03-21 16:05:42 +00:00
Kuba Brecka 4b3833df7d [tsan] Add some NULL pointer checks into the debugging API
`__tsan_get_report_thread` and others can crash if a stack trace is missing, let's add the missing checks.

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

llvm-svn: 263939
2016-03-21 12:12:44 +00:00
Devin Coughlin 7704720d41 [tsan] Build TSan dylibs for iOS-style simulators
Update the compiler-rt cmake to build TSan dylibs for iOS-style simulators when the
corresponding COMPILER_RT_ENABLE_FOO_OS setting is enabled.

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

Part of rdar://problem/24048382

llvm-svn: 263910
2016-03-20 17:35:45 +00:00
Saleem Abdulrasool 61e970607e builtins: make __clear_cache work on Linux-ARM
__clear_cache on Android is identical to the version on Linux.  Use __linux__
instead of __ANDROID__ as __linux__ is defined for Linux and Android.

llvm-svn: 263833
2016-03-18 21:06:06 +00:00
Saleem Abdulrasool fb21509509 builtins: port __clear_cache to Windows ARM
Support __clear_cache on Windows on ARM using the `FlushInstructionCache`
library call.

llvm-svn: 263832
2016-03-18 21:06:03 +00:00
Mike Aizatsky 6d8a876159 [sancov] common flags initialization.
Summary:
Introducing InitializeCommonFlags accross all sanitizers to simplify
common flags management.

Setting coverage=1 when html_cov_report is requested.

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

llvm-svn: 263820
2016-03-18 19:28:07 +00:00
Kuba Brecka 911e229f30 [tsan] Add interceptor for pthread_cond_timedwait_relative_np
On OS X, we have pthread_cond_timedwait_relative_np. TSan needs to intercept this API to avoid false positives when using condition variables.

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

llvm-svn: 263782
2016-03-18 10:54:11 +00:00
Sagar Thakur 01b325ab92 [TSAN] Fix build bot failure for powerpc64le
race_on_mutex.c passes for powerpc64le too after revision 263778. So removing the XFAIL marker.

llvm-svn: 263779
2016-03-18 07:55:44 +00:00
Sagar Thakur b2ef71e591 [TSAN] Relax the expected output of race_on_mutex.c
The stack trace produced by TSan on MIPS is:

  Previous write of size 8 at 0x0120ed2930 by thread T1:
    #0 memset
/home/slt/LLVM/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:678
(race_on_mutex.c.tmp+0x0120071808)
    #1 __GI___pthread_mutex_init
/build/glibc-g99ldr/glibc-2.19/nptl/pthread_mutex_init.c:84
(libpthread.so.0+0x000000d634)
    #2 <null>
/home/slt/LLVM/llvm/projects/compiler-rt/test/tsan/race_on_mutex.c:11 (race_on_mutex.c.tmp+0x01200ea59c)

Reviewers: samsonov, dvyukov
Subscribers: llvm-commits, mohit.bhakkad, jaydeep
Differential: http://reviews.llvm.org/D17796
llvm-svn: 263778
2016-03-18 05:41:20 +00:00
Alexey Samsonov 5c966a2063 [CMake] Remove bash-ism in SanitizerLintCheck
llvm-svn: 263751
2016-03-17 21:41:08 +00:00
Kuba Brecka 493028e8e2 Removing a non-intentional debug output that got committed in r263695.
llvm-svn: 263698
2016-03-17 09:27:40 +00:00
Kuba Brecka 4c80867ecf [sanitizer] On OS X, verify that interceptors work and abort if not, take 2
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.

TSan unit tests run with a statically linked runtime, where interceptors don't work. To avoid aborting the process in this case, the patch replaces `DisableReexec()` with a weak `ReexecDisabled()` function which is defined to return true in unit tests.

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

llvm-svn: 263695
2016-03-17 08:37:25 +00:00
Kuba Brecka 46bf454d18 [tsan] Detect uses of uninitialized, destroyed and invalid mutexes
This patch adds a new TSan report type, ReportTypeMutexInvalidAccess, which is triggered when pthread_mutex_lock or pthread_mutex_unlock returns EINVAL (this means the mutex is invalid, uninitialized or already destroyed).

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

llvm-svn: 263641
2016-03-16 15:39:20 +00:00
Mohit K. Bhakkad beb155b4fa [ASAN] Add support for mips/mips64 android
Patch by Duane Sand

Reviewers: samsonov

Subscribers: duanesand, jaydeep, sagar, llvm-commits, filcab.

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

llvm-svn: 263621
2016-03-16 08:23:10 +00:00
Alexey Samsonov 9b4bbeabcc [ASan] Make sure unittest works if sized-delete is enabled by default.
llvm-svn: 263575
2016-03-15 19:07:56 +00:00
Kuba Brecka 0fb87f77ae Revert r263551 due to a test failure.
llvm-svn: 263553
2016-03-15 15:53:39 +00:00
Kuba Brecka 69b5943a05 [sanitizer] On OS X, verify that interceptors work and abort if not
On OS X 10.11+, we have "automatic interceptors", so we don't need to use DYLD_INSERT_LIBRARIES when launching instrumented programs. However, non-instrumented programs that load TSan late (e.g. via dlopen) are currently broken, as TSan will still try to initialize, but the program will crash/hang at random places (because the interceptors don't work). This patch adds an explicit check that interceptors are working, and if not, it aborts and prints out an error message suggesting to explicitly use DYLD_INSERT_LIBRARIES.

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

llvm-svn: 263551
2016-03-15 14:30:28 +00:00
Nico Weber 39a02a7bed Fix bad regression from r263077 when building with MSVC.
That change did:

  -#if defined(__BIG_ENDIAN__)
  +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

If __BYTE_ORDER__ and __ORDER_BIG_ENDIAN__ aren't defined, like
they are with MSVC, this condition is true (0 == 0).

Fixes PR26919.

llvm-svn: 263324
2016-03-12 01:57:31 +00:00
Nico Weber 4b4e75886c Disable a test that started failing recently; see PR26919.
llvm-svn: 263311
2016-03-12 00:23:33 +00:00
Reid Kleckner 60e53cdcb7 Fix order of arguments to fputs
This time actually tested on Linux, where the test is not XFAILed.

llvm-svn: 263294
2016-03-11 21:07:48 +00:00
Reid Kleckner 3b07caef66 Switch to fputs stderr to try to fix output buffering issues
llvm-svn: 263293
2016-03-11 20:54:14 +00:00
Reid Kleckner 7a2113882f Make printf-4 more robust to strlen interception after r263177
The CHECK line was matching stack-buffer-overflow from puts calling
strlen, which is not the bug the test is trying to catch.

llvm-svn: 263282
2016-03-11 19:11:15 +00:00
Mohit K. Bhakkad f4cc1fc7e9 [Sanitizer][MIPS] internal lstat and fstat for mips64
Reviewers: dvyukov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263218
2016-03-11 10:51:03 +00:00
Mohit K. Bhakkad ac4bd45f02 [Compiler-rt] Fix ioctl codes for MIPS in sanitizer_ioctl_test
Reviewers: samsonov

Subscribers: jaydeep, sagar, llvm-commits

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

llvm-svn: 263199
2016-03-11 05:57:20 +00:00
Alexey Samsonov 54411d5042 Fix ASan test cases after r263177
llvm-svn: 263195
2016-03-11 05:04:49 +00:00
Alexey Samsonov ed3d347e25 [sanitizer] Add strlen to the common interceptors
Summary:
Adds strlen to the common interceptors, under a new common flag
intercept_strlen.  This provides better sharing of interception code among
sanitizers and cleans up the inconsistent type declarations of the
previously duplicated interceptors.

Removes the now-duplicate strlen interceptor from asan, msan, and tsan.
The entry check semantics are normalized now for msan and asan, whose
private strlen interceptors contained multiple layers of checks that
included impossible-to-reach code.  The new semantics are identical to the
old: bypass interception if in the middle of init or if both on Mac and not
initialized; else, call the init routine and proceed.

Patch by Derek Bruening!

Reviewers: samsonov, vitalybuka

Subscribers: llvm-commits, kcc, zhaoqin

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

llvm-svn: 263177
2016-03-11 00:45:49 +00:00
Alexey Samsonov 92a46991b5 [UBSan] Improve bufferization of UBSan error reports.
Summary:
Use InternalScopedString more extensively. This reduces the number of
write() syscalls, and reduces the chance that UBSan output will be
mixed with program output.

Reviewers: vitalybuka

Subscribers: kcc, llvm-commits

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

llvm-svn: 263176
2016-03-11 00:37:02 +00:00
Reid Kleckner ad04914a53 [Windows] Fix UnmapOrDie and MmapAlignedOrDie
Now ASan can return virtual memory to the underlying OS. Portable
sanitizer runtime code needs to be aware that UnmapOrDie cannot unmap
part of previous mapping.

In particular, this required changing how we implement MmapAlignedOrDie
on Windows, which is what Allocator32 uses.

The new code first attempts to allocate memory of the given size, and if
it is appropriately aligned, returns early. If not, it frees the memory
and attempts to reserve size + alignment bytes. In this region there
must be an aligned address. We then free the oversized mapping and
request a new mapping at the aligned address immediately after. However,
a thread could allocate that virtual address in between our free and
allocation, so we have to retry if that allocation fails. The existing
thread creation stress test managed to trigger this condition, so the
code isn't totally untested.

Reviewers: samsonov

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

llvm-svn: 263160
2016-03-10 20:47:26 +00:00
Dimitry Andric b45bf0af91 Retrieve command line arguments and environment correctly on FreeBSD
Summary:
Recently I saw the test `TestCases/Posix/print_cmdline.cc` failing on
FreeBSD, with "expected string not found in input".  This is because
asan could not retrieve the command line arguments properly.

In `lib/sanitizer_common/sanitizer_linux.cc`, this is taken care of by
the `GetArgsAndEnv()` function, but it uses `__libc_stack_end` to get at
the required data.  This variable does not exist on BSDs; the regular
way to retrieve the arguments and environment information is via the
`kern.ps_strings` sysctl.

I added this functionality in sanitizer_linux.cc, as a separate #ifdef
block in `GetArgsAndEnv()`.  Also, `ReadNullSepFileToArray()` becomes
unused due to this change.  (It won't work on FreeBSD anyway, since
`/proc` is not mounted by default.)

Reviewers: kcc, emaste, joerg, davide

Subscribers: llvm-commits, emaste

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

llvm-svn: 263157
2016-03-10 20:22:02 +00:00
Filipe Cabecinhas cf36b5fd32 [sanitizer_common tests] Make Darwin a Posix system and bring the stable-runtime definition from ASan tests.
Summary: This is an initial setup in order to move some additional tests from Linux onto Posix.
I also moved decorate_proc_maps onto the Linux directory

Finally added msan's definition for "stable-runtime".
Only a test requires it, and its commit message (r248014) seems to imply
that AArch64 is problematic with MSan.

Reviewers: samsonov, rengolin, t.p.northover, eugenis

Subscribers: llvm-commits

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

llvm-svn: 263142
2016-03-10 18:46:23 +00:00
Kuba Brecka 28a3b7de06 Follow-up fix for r263126. Apparently `printf("%p", NULL)` can output 0x0, (nil) or (null) on different platforms.
llvm-svn: 263137
2016-03-10 18:09:57 +00:00
Kuba Brecka a1496f7c37 [tsan] Add TSan debugger APIs
Currently, TSan only reports everything in a formatted textual form. The idea behind this patch is to provide a consistent API that can be used to query information contained in a TSan-produced report. User can use these APIs either in a debugger (via a script or directly), or they can use it directly from the process (e.g. in the __tsan_on_report callback). ASan already has a similar API, see http://reviews.llvm.org/D4466.

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

llvm-svn: 263126
2016-03-10 17:00:29 +00:00
Filipe Cabecinhas 721447c873 [test/asan/closed-fds] Properly quote log_path for shell invocation.
llvm-svn: 263106
2016-03-10 11:51:59 +00:00
Alexey Samsonov c1424fc7c8 sanitizer: Fix endianness checks for gcc
Summary:
__BIG_ENDIAN__ and __LITTLE_ENDIAN__ are not supported by gcc, which
eg. for ubsan Value::getFloatValue will silently fall through to
the little endian branch, breaking display of float values by ubsan.
Use __BYTE_ORDER__ == __ORDER_BIG/LITTLE_ENDIAN__ as the condition
instead, which is supported by both clang and gcc.

Noticed while porting ubsan to s390x.

Patch by Marcin Kościelnicki!

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

llvm-svn: 263077
2016-03-09 23:39:40 +00:00
Xinliang David Li 5f58c27d79 Fix test failure on darwin-i386
llvm-svn: 263065
2016-03-09 21:45:37 +00:00
Xinliang David Li d4312d8af0 Fix a minor bug in test
llvm-svn: 263028
2016-03-09 17:13:18 +00:00
Filipe Cabecinhas 1ecfbdefcd [test/sanitizer-common] Linux/sanitizer_set_death_callback_test.cc -> Posix/sanitizer_set_death_callback_test.cc
llvm-svn: 263018
2016-03-09 15:39:49 +00:00
Filipe Cabecinhas 42bba2eb2a [test/sanitizer-common] Move getpass.cc from Linux into Posix
llvm-svn: 263017
2016-03-09 15:39:43 +00:00