Commit Graph

6281 Commits

Author SHA1 Message Date
Evgeniy Stepanov ec3e436a36 Switch to 64-bit allocator on android/aarch64.
This uses the "very compact" size class mapping that fits in the
39-bit address space.

llvm-svn: 281371
2016-09-13 19:05:33 +00:00
Evgeniy Stepanov b48348fec5 [asan] Re-poison all redzones on activation.
When running with start_deactivated=1 in ASAN_OPTIONS, heap redzones
are not poisoned until the first instrumented module is loaded. This
can cause false negatives even on memory allocated after activation,
because redzones are normally poisoned only once when a new allocator
region is mapped.

This change attempts to fix it by iterating over all existing
allocator chunks and poisoning their redzones.

llvm-svn: 281364
2016-09-13 18:38:40 +00:00
Kostya Serebryany 9a830b9433 [sanitizer] replace CHECK with CHECK_XY in two places for better diagnostics
llvm-svn: 281255
2016-09-12 20:39:13 +00:00
Filipe Cabecinhas 74f490d331 [asan] Ease dealing with tagged enum ErrorDescription with some macros.
Summary:
Added a macro to enumerate the (error name, error member name) pairs. This way,
when adding an error, we only need to add the pair to one place (plus add its
implementation, or course).

Reviewers: kcc, samsonov

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 281237
2016-09-12 17:12:02 +00:00
Filipe Cabecinhas 64150ea00d [asan] Cleanup: Move tid into ErrorBase, add const to BufferedStackTrace, be consistent in constructor arguments and member order.
Summary: As mentioned in D24394, I'm moving tid to ErrorBase, since basically all errors need it.
Also mentioned in the same review are other cleanups like adding const
to BufferedStackTrace and make sure constructor orders are consistent.

Reviewers: vitalybuka, kcc, eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 281236
2016-09-12 17:10:44 +00:00
Keno Fischer 8dc0e0943b [sanitizer] Add interceptor for ttyname_r
Reviewers: eugenis

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 281116
2016-09-09 23:09:34 +00:00
Kostya Serebryany 58560a05ad [sanitizer] fix an allocator bug where the allocated memory may overlap with the free array (kudos to Kostya Korcthinsky). Also make sure that the allocator does not mmap more than requested. Test both.
llvm-svn: 281103
2016-09-09 21:42:33 +00:00
Filipe Cabecinhas def8d5fcd4 [asan] Store access_size in the {Stack,Global}AddressDescription objects
Summary:
This is important information when we want to describe errors, and should be
part of these descriptions. Otherwise, we need to know the access size when
printing/emitting the description.

Reviewers: kcc, eugenis, vitalybuka

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 281093
2016-09-09 21:09:06 +00:00
Filipe Cabecinhas 4aff9e6d71 [asan] Add a new AddressDescription structure, which can describe any type of address.
Summary:
This is useful for inclusion in the Error* structures, to describe an
arbitrary address.

Remove the old struct since it's used only once. This removes one level of
indirection, and moves all *AddressDescription to be one of the recently
introduced structures.

This merges differential revisions: D24131 and D24132

Reviewers: kcc, eugenis, vitalybuka

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 281090
2016-09-09 20:43:20 +00:00
Kostya Serebryany d77e8c0269 [sanitizer] fix a potential buffer overflow due to __sanitizer_symbolize_pc (need to put a zero after strncmp). LOL
llvm-svn: 281015
2016-09-09 02:13:27 +00:00
Evgeniy Stepanov 55f9f18cb2 Fix tsan-go build.
Disable the new abort-in-SIGABRT code under SANITIZER_GO.

llvm-svn: 280980
2016-09-08 19:16:01 +00:00
Bill Seurer ba7c5cfbbb [powerpc] Move #if to appease warnings-as-errors tests
Previous patch added a #if which causes some unused identifier warnings.

llvm-svn: 280976
2016-09-08 18:09:47 +00:00
Renato Golin 6f605133dd Revert "[XRay] ARM 32-bit no-Thumb support in compiler-rt"
This reverts commit r280890, as the related LLVM commit broke the thumb bots.

llvm-svn: 280969
2016-09-08 17:13:15 +00:00
Reid Kleckner 490ccc9cc7 Fix linker warning about sanitizer_common_nolibc functions on Windows
llvm-svn: 280962
2016-09-08 16:46:06 +00:00
Qin Zhao 0ab52b97e8 Revert "[ESan][MIPS] Adds support for MIPS64"
Summary:
This reverts commit 62b3eecdbe72af0255f0639b0446087a47efbf48. (D23799)

The CL cause 13 ESan test failure on x86_64:
Failing Tests (13):
    EfficiencySanitizer-x86_64 :: TestCases/large-stack-linux.c
    EfficiencySanitizer-x86_64 :: TestCases/libc-intercept.c
    EfficiencySanitizer-x86_64 :: TestCases/mmap-shadow-conflict.c
    EfficiencySanitizer-x86_64 :: TestCases/struct-simple.cpp
    EfficiencySanitizer-x86_64 :: TestCases/verbose-simple.c
    EfficiencySanitizer-x86_64 :: TestCases/workingset-early-fault.c
    EfficiencySanitizer-x86_64 :: TestCases/workingset-memset.cpp
    EfficiencySanitizer-x86_64 :: TestCases/workingset-midreport.cpp
    EfficiencySanitizer-x86_64 :: TestCases/workingset-samples.cpp
    EfficiencySanitizer-x86_64 :: TestCases/workingset-signal-posix.cpp
    EfficiencySanitizer-x86_64 :: TestCases/workingset-simple.cpp
    EfficiencySanitizer-x86_64 :: Unit/circular_buffer.cpp
    EfficiencySanitizer-x86_64 :: Unit/hashtable.cpp

  Unexpected Failures: 13

Reviewers: bruening, slthakur

Subscribers: sdardis, kubabrecka, beanz

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

llvm-svn: 280954
2016-09-08 16:09:46 +00:00
Kuba Brecka 8651c04ce0 [asan] Fix handle_abort_on_error.cc test on Darwin
r280885 added a testcase for handle_abort, which is broken on macOS, let’s add this support into sanitizer_mac.cc.

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

llvm-svn: 280945
2016-09-08 14:32:11 +00:00
Filipe Cabecinhas 3e848ea586 [asan] Handle SIGBART signal description. (found by buildbot)
llvm-svn: 280934
2016-09-08 13:28:26 +00:00
Filipe Cabecinhas 1989be7cf0 [asan] Reify ErrorDeadlySignal
Summary: Keep reifying other errors.

Reviewers: kcc, samsonov

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 280930
2016-09-08 12:58:15 +00:00
Kuba Brecka 419ebb2891 [tsan] Support C++11 call_once in TSan on Darwin
This patch adds a wrapper for call_once, which uses an already-compiled helper __call_once with an atomic release which is invisible to TSan. To avoid false positives, the interceptor performs an explicit atomic release in the callback wrapper.

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

llvm-svn: 280920
2016-09-08 10:15:20 +00:00
Nico Weber 81291a0fce Correctly escape %.
Found be an MSVC warning; I filed PR30320 for adding a similar warning to clang.

llvm-svn: 280900
2016-09-08 01:46:52 +00:00
Dean Michael Berris 5332645c6d [XRay] ARM 32-bit no-Thumb support in compiler-rt
This is a port of XRay to ARM 32-bit, without Thumb support yet.
This is one of 3 commits to different repositories of XRay ARM port. The
other 2 are:

1. https://reviews.llvm.org/D23931 (LLVM)
2. https://reviews.llvm.org/D23932 (Clang test)

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

llvm-svn: 280890
2016-09-08 00:28:26 +00:00
Evgeniy Stepanov 337e40f157 [sanitizer] Fix a conflict between abort_on_error and handle_abort.
Reset the SIGABRT signal handler before calling abort().

Also, change the error message when catching SIGABRT to say "ABRT"
instead of "SEGV".

llvm-svn: 280885
2016-09-07 23:40:53 +00:00
Evgeniy Stepanov e29f05d037 [asan] Fix build on Linux.
llvm-svn: 280881
2016-09-07 23:19:16 +00:00
Saleem Abdulrasool d14c2c0139 builtins: make sure that flags is setup properly for __clear_cache
On Linux ARM, the syscall will take 3 arguments (start, end, flags).  Ensure
that we do not pass garbage to the flags, which can cause the cacheflush call to
fail, and therefore cause an abort at runtime.

llvm-svn: 280877
2016-09-07 22:59:54 +00:00
Evgeniy Stepanov 3989c9f96f [asan] Fix a crash in GetCurrentThread() before init.
Android-specific code in GetCurrentThread() does not handle the situation when there is no
ThreadContext for the current thread. This happens if the current thread is requested before the
main thread is added to the registry. 64-bit allocator does that to record map/unmap stats during
initialization.

llvm-svn: 280876
2016-09-07 22:57:06 +00:00
Evgeniy Stepanov 0b2dba1841 [asan] Add openlog() on Android.
Normally, syslog() uses argv[0] for the log tag; bionic, however,
would crash in syslog() before libc constructor unless the log
tag is explicitly set with openlog().

llvm-svn: 280875
2016-09-07 22:56:02 +00:00
Francis Ricci 52fdd22250 [compiler-rt] Allow sanitizers to be compiled for windows with clang
Summary:
A few small changes required to permit building the sanitizers
with Clang instead of only with MSVC.

Reviewers: compnerd, beanz, rnk

Subscribers: beanz, timurrrr, kubabrecka, dberris, llvm-commits

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

llvm-svn: 280863
2016-09-07 21:03:22 +00:00
Bill Seurer 14f382065f [powerpc] Move #if to appease warnings-as-errors tests
Previous patch added a #if which caused a variable and function
to be unused.

llvm-svn: 280846
2016-09-07 19:44:04 +00:00
Bill Seurer f2a02894c7 [powerpc] Disable ManyThreadsWithStatsStressTest test for ppc64
Since r279664 this test causes frequent failures of test runs for ppc64le and
occasional failures for ppc64be which makes buildbot results unreliable.  If
the underlying problem is fixed it can be re-enabled.

llvm-svn: 280823
2016-09-07 16:30:31 +00:00
Filipe Cabecinhas 25ad7b52c3 [asan] Reify ErrorNewDeleteSizeMismatch
Summary: Keep reifying other errors.

Reviewers: kcc, samsonov

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 280812
2016-09-07 14:20:54 +00:00
Sagar Thakur 41f08b4422 [ESan][MIPS] Adds support for MIPS64
With this patch 10 out of 13 tests are passing.

Following is the list of failing tests:

    struct-simple.cpp
    workingset-signal-posix.cpp
    mmap-shadow-conflict.c

Reviewed by bruening
Differential: D23799

llvm-svn: 280795
2016-09-07 09:09:03 +00:00
Krzysztof Parzyszek 6e2e0e8b8f Add #include <cstdio> to unbreak build (missing definition of stderr)
llvm-svn: 280714
2016-09-06 16:26:49 +00:00
Dmitry Vyukov 3c503d1b52 asan: allow __asan_{before,after}_dynamic_init without registered globals
When optimizing, GCC optimizes away aggressively unused static globals.
The __asan_before_dynamic_init/__asan_after_dynamic_init calls are placed
in static constructor earlier while the registration of the globals is done
later in the compilation process.  If all the globals with
dynamic initialization are optimized away from some particular TU in between
those two, libasan can fail on an assertion that dynamic_init_globals is
empty.

While I'm going to commit a GCC change which will remove the
__asan_before_dynamic_init/__asan_after_dynamic_init in many cases when this
happens (basically if the optimizers can prove there are no memory
references in between the two calls), there are still testcases where such
pair of calls is left, e.g. for
struct S { S () { asm volatile ("" : : : "memory"); } };
static S c;

int
main ()
{
  return 0;
}
with -O2 -fsanitize=address and ASAN_OPTIONS=check_initialization_order=true
this still fails the assertion.  Trying to avoid this problem on the
compiler side would decrease code quality I'm afraid, whether it is making
sure for -fsanitize=address we keep around at least one dynamically
initialized global if the
__asan_before_dynamic_init/__asan_after_dynamic_init pair has been emitted,
or adding some artificial global which would be used as the condition for
those calls etc.
So, can the assertion be instead just removed, this really shouldn't slow
down the calls measurably (for __asan_before_dynamic_init it is even
cheaper) and the assertion doesn't check something worthwhile anyway (it is
sufficient if there is a single dynamically initialized global in any other
TU to make it happy).

Details in http://gcc.gnu.org/PR77396

Author: Jakub Jelinek
llvm-svn: 280657
2016-09-05 12:22:56 +00:00
Chris Bieneman 90646fe815 [CMake] Add option (defaulted off) to exclude atomic.c
The atomic builtin source is problematic when cross-compiling builtins because it requires a variable and sometimes large set of system headers. This option allows users to optionally prevent it from being built.

llvm-svn: 280416
2016-09-01 21:05:49 +00:00
Evgeniy Stepanov bc555b7ebe [tsan] Bump stack frame size limit.
llvm-svn: 280411
2016-09-01 20:43:59 +00:00
Reid Kleckner 507ba20907 Fix dll_host.cc test after adding div and gep trace coverage points
llvm-svn: 280387
2016-09-01 18:08:05 +00:00
Filipe Cabecinhas 9512821e22 Remove extra scariness.Clear() call.
llvm-svn: 280372
2016-09-01 14:41:17 +00:00
Filipe Cabecinhas f1fb439d31 Clear scariness score when initializing ErrorDoubleFree
llvm-svn: 280363
2016-09-01 12:51:58 +00:00
Ivan Krasin f3e82f1418 Fix the use of unitialized value while reporting double free in ASAN.
Summary:
This is a follow up to https://reviews.llvm.org/rL280201 where this issue was introduced.

ASAN tests failed:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/25219/steps/run%20asan%20tests/logs/stdio

Reviewers: filcab

Subscribers: kubabrecka

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

llvm-svn: 280325
2016-08-31 23:42:27 +00:00
Kostya Serebryany 2700bd831a [sanitizer] extend SizeClassMap to take more template parameters, add VeryCompactSizeClassMap for testing purposes
llvm-svn: 280266
2016-08-31 17:52:55 +00:00
Filipe Cabecinhas 453b55551f Fix buildbot bug: Wasn't printing scariness for DoubleFree
llvm-svn: 280213
2016-08-31 09:39:47 +00:00
Filipe Cabecinhas b16672d91d Reify ErrorDoubleFree
Summary: Keep reifying other errors.

Reviewers: kcc, samsonov

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 280201
2016-08-31 07:38:09 +00:00
Kostya Serebryany 4fd30769c1 [sanitizer] remove kBatchClassID that is not used any more; NFC
llvm-svn: 280185
2016-08-31 00:37:33 +00:00
Saleem Abdulrasool 000b071b07 stats: define WIN32_LEAN_AND_MEAN when including windows.h
Reduce the amount of the header that we end up including in the build.  The
additional definitions are not necessary.

llvm-svn: 280146
2016-08-30 20:15:46 +00:00
Saleem Abdulrasool 6ca511439d profile: add missing include for Windows
Add a missing Windows.h which is needed for the windows type usage in the TU
(e.g. HANDLE).

llvm-svn: 280145
2016-08-30 20:15:44 +00:00
Filipe Cabecinhas fddfdca030 Start reifying error descriptions (Re-do of D23672 supporting VS2013)
Summary:
@kcc: I know you've accepted the other revision, but since this is a
non-trivial change, I'm updating it to show why D24029 would help.

This commit sets up the infrastructure to use reified error
descriptions, and moves ReportStackOverflow to the new system.

After we convert all the errors, we'll be able to simplify ScopedInErrorReport
and remove the older debugging mechanism which had some errors partly reified
in some way. We'll be able to maintain the external API.

ScopedInErrorReport will be able to track one of the reified errors at a time.
The purpose of this is so we have its destructor actually print the error and
possibly interface with the debugger (will depend on the platform, of course).

Reviewers: kcc, samsonov, timurrrr

Subscribers: kcc, llvm-commits, kubabrecka

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

llvm-svn: 280111
2016-08-30 17:08:55 +00:00
Filipe Cabecinhas e0e18917b3 Split ScarinessScore between its "storage" (POD), and an initializing object.
Summary:
This is needed so we can use it for D23672 on VS2013, since this VS
version doesn't support unrestricted unions, and doesn't allow us to
uses an object without a trivial default constructor inside a union.

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 280110
2016-08-30 17:08:47 +00:00
Kostya Serebryany b3177cea0a [sanitizer-coverage] add two more modes of instrumentation: trace-div and trace-gep, mostly usaful for value-profile-based fuzzing; run-time part
llvm-svn: 280045
2016-08-30 01:27:46 +00:00
Kostya Serebryany 6496de48c7 [scudo] use 32 bits of ASLR entropy instead of just 24 when shuffling allocated chunks
llvm-svn: 279983
2016-08-29 17:45:43 +00:00
Vitaly Buka ac644fa917 [asan] Remove runtime flag detect_stack_use_after_scope
Summary:
We are going to use store instructions to poison some allocas.
Runtime flag will require branching in instrumented code on every lifetime
intrinsic. We'd like to avoid that.

Reviewers: eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 279981
2016-08-29 17:16:59 +00:00
Filipe Cabecinhas c0d14ecea3 Revert "Start reifying error descriptions. Second try: Try to appease Visual Studio."
This reverts r279931. Will try it with the same Visual Studio version
before committing again.

llvm-svn: 279932
2016-08-28 10:42:21 +00:00
Filipe Cabecinhas b477ce015d Start reifying error descriptions. Second try: Try to appease Visual Studio.
Summary:
This commit sets up the infrastructure to use reified error
descriptions, and moves ReportStackOverflow to the new system.

After we convert all the errors, we'll be able to simplify ScopedInErrorReport
and remove the older debugging mechanism which had some errors partly reified
in some way. We'll be able to maintain the external API.

ScopedInErrorReport will be able to track one of the reified errors at a time.
The purpose of this is so we have its destructor actually print the error and
possibly interface with the debugger (will depend on the platform, of course).

Reviewers: kcc, samsonov, timurrrr

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 279931
2016-08-28 10:32:44 +00:00
Kostya Serebryany b72479b84a [asan] first attempt at releasing free-d memory back to the system using madvise. Requires quite some tuning.
llvm-svn: 279887
2016-08-26 23:58:42 +00:00
Filipe Cabecinhas d2cc637793 Revert "Start reifying error descriptions"
This reverts r279862 to investigate VS failures.

llvm-svn: 279865
2016-08-26 20:59:02 +00:00
Chris Bieneman 21395f9839 [CMake] Connect Compiler-RT targets to LLVM Runtimes directory
This patch builds on LLVM r279776.

In this patch I've done some cleanup and abstracted three common steps runtime components have in their CMakeLists files, and added a fourth.

The three steps I abstract are:

(1) Add a top-level target (i.e asan, msan, ...)
(2) Set the target properties for sorting files in IDE generators
(3) Make the compiler-rt target depend on the top-level target

The new step is to check if a command named "runtime_register_component" is defined, and to call it with the component name.

The runtime_register_component command is defined in llvm/runtimes/CMakeLists.txt, and presently just adds the component to a list of sub-components, which later gets used to generate target mappings.

With this patch a new workflow for runtimes builds is supported. The new workflow when building runtimes from the LLVM runtimes directory is:

> cmake [...]
> ninja runtimes-configure
> ninja asan

The "runtimes-configure" target builds all the dependencies for configuring the runtimes projects, and runs CMake on the runtimes projects. Running the runtimes CMake generates a list of targets to bind into the top-level CMake so subsequent build invocations will have access to some of Compiler-RT's targets through the top-level build.

Note: This patch does exclude some top-level targets from compiler-rt libraries because they either don't install files (sanitizer_common), or don't have a cooresponding `check` target (stats).
llvm-svn: 279863
2016-08-26 20:52:22 +00:00
Filipe Cabecinhas 403423cb59 Start reifying error descriptions
Summary:
This commit sets up the infrastructure to use reified error
descriptions, and moves ReportStackOverflow to the new system.

After we convert all the errors, we'll be able to simplify ScopedInErrorReport
and remove the older debugging mechanism which had some errors partly reified
in some way. We'll be able to maintain the external API.

ScopedInErrorReport will be able to track one of the reified errors at a time.
The purpose of this is so we have its destructor actually print the error and
possibly interface with the debugger (will depend on the platform, of course).

Reviewers: kcc, samsonov, timurrrr

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 279862
2016-08-26 20:49:11 +00:00
Dean Michael Berris fdb0f39ae2 [compiler-rt][XRay] Remove unnecessary assertion.
This assert only causes issues with signed/unsigned comparisons.

llvm-svn: 279819
2016-08-26 12:33:33 +00:00
Dean Michael Berris d7bd8fbc0e Revert " [compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration"
This reverts commit 6659b10799b287ad815e49c4f1b01abc4369b03d.

llvm-svn: 279818
2016-08-26 12:31:02 +00:00
Dean Michael Berris f4f687ae5d [compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration
Summary: This will allow for the sanitizers to be used when c++ abi is unavailable.

    Reviewers: samsonov, beanz, pcc, rnk

    Subscribers: llvm-commits, kubabrecka, compnerd, dberris

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

llvm-svn: 279816
2016-08-26 12:23:20 +00:00
Dean Michael Berris f50eb93da7 [compiler-rt][XRay] Initial per-thread inmemory logging implementation
Depends on D21612 which implements the building blocks for the compiler-rt
implementation of the XRay runtime. We use a naive in-memory log of fixed-size
entries that get written out to a log file when the buffers are full, and when
the thread exits.

This implementation lays some foundations on to allowing for more complex XRay
records to be written to the log in subsequent changes. It also defines the format
that the function call accounting tool in D21987 will start building upon.

Once D21987 lands, we should be able to start defining more tests using that tool
once the function call accounting tool becomes part of the llvm distribution.

Reviewers: echristo, kcc, rnk, eugenis, majnemer, rSerge

Subscribers: sdardis, rSerge, dberris, tberghammer, danalbert, srhines, majnemer, llvm-commits, mehdi_amini

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

llvm-svn: 279805
2016-08-26 06:39:33 +00:00
Richard Smith ebd27cc245 Additional update missed by r279793, should hopefully make the PPC sanitizer bots happy again.
llvm-svn: 279798
2016-08-26 00:30:03 +00:00
Kostya Serebryany 7c5ae7cbc6 [sanitizer] enable random shuffling the memory chunks inside the allocator, under a flag. Set this flag for the scudo allocator, add a test.
llvm-svn: 279793
2016-08-26 00:06:03 +00:00
Kostya Serebryany 1fde590663 [asan] remove unused kAsanHeapRightRedzoneMagic (NFC); part 2 (sorry)
llvm-svn: 279790
2016-08-25 22:51:26 +00:00
Kostya Serebryany a02b918f0a [asan] remove unused kAsanHeapRightRedzoneMagic (NFC)
llvm-svn: 279789
2016-08-25 22:49:35 +00:00
Kostya Serebryany 66b2ac0ee4 [asan] fix windows bot
llvm-svn: 279781
2016-08-25 21:45:18 +00:00
Kostya Serebryany 9aab75f697 [sanitizer] add __sanitizer_symbolize_pc. https://github.com/google/sanitizers/issues/322
llvm-svn: 279780
2016-08-25 21:35:29 +00:00
Kostya Serebryany 15647b17f3 [sanitizer] change SizeClassAllocator64 to accept just one template parameter instead of 5. First, this will make the mangled names shorter. Second, this will make adding more parameters simpler.
llvm-svn: 279771
2016-08-25 20:23:08 +00:00
Adhemerval Zanella ebbd8a9ef3 dfsan: Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for msan on aarch64. As current
mappings for aarch64, 48-bit VMA also supports PIE executable.

Tested on 39 and 48-bit VMA kernels on aarch64.

llvm-svn: 279753
2016-08-25 17:07:43 +00:00
Adhemerval Zanella 1005b7d90c msan: Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for msan on aarch64. As current
mappings for aarch64, 48-bit VMA also supports PIE executable. The
48-bits segments only cover the usual PIE/default segments plus some
more segments (262144GB total, 0.39% total VMA). Memory avaliability
can be increase by adding multiple application segments like 39 and
42 mapping (some mappings were added on this patch as well).

Tested on 39 and 48-bit VMA kernels on aarch64.

llvm-svn: 279752
2016-08-25 17:05:56 +00:00
Kostya Serebryany 8e7ea9ddb5 [sanitizer] re-apply r279572 and r279595 reverted in r279643: change the 64-bit allocator to use a single array for free-d chunks instead of a lock-free linked list of tranfer batches. This change simplifies the code, makes the allocator more 'hardened', and will allow simpler code to release RAM to OS. This may also slowdown malloc stress tests due to lock contension, but I did not observe noticeable slowdown on various real multi-threaded benchmarks.
llvm-svn: 279664
2016-08-24 21:20:10 +00:00
Vitaly Buka 769ec705bc Revert r279572 "[sanitizer] change the 64-bit..." because of failures on ubsan
This reverts commit r279572 and r279595.

llvm-svn: 279643
2016-08-24 17:40:29 +00:00
Kostya Serebryany 865a98d2ed [sanitizer] trying to fix the PPC bots
llvm-svn: 279595
2016-08-24 00:10:25 +00:00
Kostya Serebryany f46d50e360 [sanitizer] change the 64-bit allocator to use a single array for free-d chunks instead of a lock-free linked list of tranfer batches. This change simplifies the code, makes the allocator more 'hardened', and will allow simpler code to release RAM to OS. This may also slowdown malloc stress tests due to lock contension, but I did not observe noticeable slowdown on various real multi-threaded benchmarks.
llvm-svn: 279572
2016-08-23 21:19:47 +00:00
Kostya Serebryany 0549a39a17 [sanitizer] adding a threaded performance stress test for malloc (useful for manual analysis of malloc performance)
llvm-svn: 279570
2016-08-23 21:12:04 +00:00
Kostya Serebryany 6e3cda4dfc [asan] minor fix in the asan memory profile
llvm-svn: 279547
2016-08-23 18:13:51 +00:00
Chris Bieneman d470f434ab Delete remaining compiler-rt makefiles
Summary:
Since we can now build the builtins without a full toolchain these files should no longer be needed.

This is the last vestige of autoconf!

Reviewers: compnerd, iains, jroelofs

Subscribers: dberris, llvm-commits

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

llvm-svn: 279539
2016-08-23 17:32:38 +00:00
Sagar Thakur 49280f6c59 [TSan][MIPS] Changes mips memory layout to support pie with address space randomization.
Reviewed by dvyukov
Differential: D23644

llvm-svn: 279505
2016-08-23 08:15:25 +00:00
Vitaly Buka 72ca69e403 [asan] Fix OOB_char on arm 32bit
Summary:
This does not actually fixes the test.
AddressSanitizer::OOB_char behavior is inconsistent but it somehow usually
works. On arm it runs more iterations than expected. And adding a new test with AddressSanitizerInterface prefix, even empty, somehow breaks OOB_char test.
So I will rename my test to make the bot green and will continue to investigate the test.

Reviewers: krasin

Subscribers: aemerson, rengolin, kubabrecka, llvm-commits, samparker

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

llvm-svn: 279501
2016-08-23 02:58:12 +00:00
Francis Ricci f9153eb305 [builtins] Don't always use -ffreestanding when compiling builtins
This can break on some sysroots. Let the user define it if necessary.

llvm-svn: 279496
2016-08-23 00:49:03 +00:00
Kostya Serebryany ce2163459f [sanitizer] allocator: split the local cache class into two, one for 32-bit allocator and one for 64-bit one. NFC. The two imlementations will diverge in the following changes.
llvm-svn: 279495
2016-08-23 00:30:43 +00:00
Francis Ricci 0f488dc215 [compiler-rt] Use flags found when configuring builtins during compilation
Summary: This fixes the omission of -fPIC when building the builtins.

Reviewers: compnerd, beanz

Subscribers: dberris, llvm-commits

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

llvm-svn: 279469
2016-08-22 20:33:47 +00:00
Francis Ricci 2582a11c4d [compiler-rt] Don't build ubsan cxxabi sources when unused
Summary:
On apple targets, when SANITIZER_CAN_USE_CXXABI is false,
the ubsan cxxabi sources aren't built, since they're unused.
Do this on non-apple targets as well.

This fixes errors when linking sanitizers if c++ abi is
unavailable.

Reviewers: pcc, kubabrecka, beanz

Subscribers: rnk, llvm-commits, kubabrecka, compnerd, dberris

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

llvm-svn: 279467
2016-08-22 20:27:21 +00:00
Filipe Cabecinhas e5914d82d2 [cmake] Fix append_rtti_flag macro and bad var name
llvm-svn: 279450
2016-08-22 18:30:37 +00:00
Evgeniy Stepanov c49b00a249 [msan] Disable prlimit test on glibc < 2.13.
llvm-svn: 279352
2016-08-20 00:38:55 +00:00
Saleem Abdulrasool b6ced621e8 build: allow building a specific set of sanitizers
Introduce a new CMake option `COMPILER_RT_SANITIZERS_TO_BUILD` which takes
either a special token `all` (default) which will preserve the current behaviour
or a CMake list of sanitizers to build.  It will still perform the normal checks
if the sanitizer is requested.  It only permits a further means to exclude a
particular sanitizer.  This gives finer grained control than
`COMPILER_RT_BUILD_SANITIZERS` which only gives an all or nothing control.

llvm-svn: 279253
2016-08-19 15:13:21 +00:00
Filipe Cabecinhas 53a45fa4e3 Cleanup: Move the *AddressDescription printing code to Print() members inside those structs.
Summary:
The Print() members might take optional access_size and bug_type
parameters to still be able to provide the same information

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 279237
2016-08-19 13:07:23 +00:00
Jonas Hahnfeld 2f230be0e2 Revert "[CMake] Fix ASM building in llvm/runtimes"
This reverts the TSAN parts of commit r279215.

llvm-svn: 279218
2016-08-19 08:03:26 +00:00
Jonas Hahnfeld ddbab7d982 [CMake] Fix ASM building in llvm/runtimes
When compiler-rt's CMake is not directly invoked, it will currently not call
project() and thus ASM will not be enabled.
We also don't need to put the .S files through the C compiler then.

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

llvm-svn: 279215
2016-08-19 06:46:00 +00:00
Filipe Cabecinhas 391438a08d Add header guards to asan_descriptions.h
llvm-svn: 279062
2016-08-18 13:22:00 +00:00
Filipe Cabecinhas e86f80c45e Convert AsanLocateAddress to Get*AddressInformation functions.
llvm-svn: 279046
2016-08-18 10:31:19 +00:00
Kostya Serebryany 68f8cbd597 [asan] trying to fix the windows bot
llvm-svn: 279030
2016-08-18 02:04:03 +00:00
Kostya Serebryany 385b973ad3 [sanitizer-coverage] add __sanitizer_cov_trace_cmp[1248] to the sanitizer-coverage interface
llvm-svn: 279026
2016-08-18 01:23:27 +00:00
Vitaly Buka 1396b9f072 [asan] Add __asan_set_shadow_*
Summary:
We are poisoning small allocas using store instruction from instrumented code.
For larger allocas we'd like to insert function calls instead of multiple stores.

PR27453

Reviewers: kcc, eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 279019
2016-08-18 00:56:11 +00:00
Vitaly Buka 334ac36e66 [asan] Remove "Stack partial redzone" from report
Summary: This value is never used.

Reviewers: kcc, eugenis

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 279010
2016-08-17 23:38:08 +00:00
Filipe Cabecinhas 41f41635f9 Split DescribeAddressIfGlobal between a function that gets all the information, and one that prints it.
Summary:
Replacement for part of D23518
This deals with global variable addresses.

(This commit is written on top of D23605, but can be applied by itself)

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 278959
2016-08-17 19:52:12 +00:00
Filipe Cabecinhas 2e767d1972 Split DescribeAddressIfStack between a function that gets all the information, and one that prints it.
Summary:
Replacement for part of D23518
This deals with stack addresses.

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 278958
2016-08-17 19:52:06 +00:00
Filipe Cabecinhas 6b3f82dce2 Deal with buildbot fallout from r278917: s/AllocType()/GetAllocType()/ (had the same name as the enum)
llvm-svn: 278919
2016-08-17 09:24:33 +00:00
Filipe Cabecinhas e068de5137 Rename DescribeHeapAddress to DescribeAddressIfHeap and split it into a function to get all the information about the address, and one to print it.
Summary:
Replacement for part of D23518
This deals with heap addresses, and renames DescribeHeapAddress.
Requires D23520, which moves code around to make it accessible in asan_describers.cc (and still accessible in asan_report.cc if needed).

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 278917
2016-08-17 09:16:08 +00:00
Francis Ricci 39bc97a1ec Revert "[compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration"
This reverts commit dbb6e905684e2e9488887b26c02ee8881849f09f.

llvm-svn: 278852
2016-08-16 20:52:22 +00:00
Francis Ricci 6802eb0868 [compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration
Summary: This will allow for the sanitizers to be used when c++ abi is unavailable.

Reviewers: samsonov, beanz, pcc, rnk

Subscribers: llvm-commits, kubabrecka, compnerd, dberris

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

llvm-svn: 278848
2016-08-16 20:39:10 +00:00
Matthias Braun 0761b5253d sanitizer_common: Fix warning
Clang added warning that taking the address of a packed struct member
possibly yields an unaligned pointer. This case is benign because
the pointer gets casted to an uptr and not used for unaligned accesses.
Add an intermediate cast to char* until this warning is improved (see
also https://reviews.llvm.org/D20561)

llvm-svn: 278835
2016-08-16 18:28:55 +00:00
Filipe Cabecinhas a8c730c047 Move the Decorator, ThreadNameWithParenthesis, and DescribeThread to asan_descriptions.{h,cc}
Summary:
Replacement for part of D23518
Code refactoring to allow us to move some more DescribeAddressIf* functions to work by getting the structured information, and then printing it.

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 278820
2016-08-16 16:38:46 +00:00
Francis Ricci 3d6aa8a475 Revert "[compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration"
This reverts commit cd5fa595648378f38cdad8b07e18433639c28a9c.

llvm-svn: 278800
2016-08-16 13:58:56 +00:00
Sagar Thakur 49307c0297 [MSAN][MIPS] Changed memory mapping to support pie executable.
Reviewed by eugenis
Differential: D22993

llvm-svn: 278793
2016-08-16 12:49:54 +00:00
Sagar Thakur 19b84a0224 [TSan][MIPS] Implements setjmp assembly for MIPS64
Reviewed by dvyukov
Differential: https://reviews.llvm.org/D23494

llvm-svn: 278775
2016-08-16 05:06:56 +00:00
Francis Ricci fda072de97 [compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration
Summary: This will allow for the sanitizers to be used when c++ abi is unavailable.

    Reviewers: samsonov, beanz, pcc, rnk

    Subscribers: llvm-commits, kubabrecka, compnerd, dberris

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

llvm-svn: 278772
2016-08-16 02:15:51 +00:00
Francis Ricci 1185b4ae8d Revert "[compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration"
This reverts commit 9528d86531b1289600e18c407b8e992d7fedb94f.

llvm-svn: 278769
2016-08-16 01:11:07 +00:00
Francis Ricci 13a5a9d7f1 [compiler-rt] Allow c++ abi to be explictly disabled in cmake configuration
Summary: This will allow for the sanitizers to be used when c++ abi is unavailable.

Reviewers: samsonov, beanz, pcc, rnk

Subscribers: llvm-commits, kubabrecka, compnerd, dberris

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

llvm-svn: 278764
2016-08-16 00:16:47 +00:00
Chris Bieneman 86412e56fb [CMake] Renaming test variable to be consistent
Based on post-commit review by compnerd.

llvm-svn: 278728
2016-08-15 20:12:43 +00:00
Filipe Cabecinhas f8a15c3b57 Split DescribeAddressIfShadow between a function that gets all the information, and one that prints it.
Summary:
Replacement for part of D23518
This is the first patch to start reifying information about errors. It deals only with reifying shadow address-related information.
It will allow us to generate structures with all the relevant information for a given error so a debugger can get to them or they can be included in a core dump.

Reviewers: kcc, samsonov

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 278718
2016-08-15 19:30:21 +00:00
Evgeniy Stepanov ff8ee02dec [ubsan] Initialize Android logging.
This adds standalone ubsan output to "adb logcat", the same as ASan does.

llvm-svn: 278706
2016-08-15 18:35:40 +00:00
Chris Bieneman 98ee3de514 [CMake] If the compiler supports _Atomic include atomic.c in builtins libraries
This fixes a long-standing TODO by implementing a compiler check for supporting the _Atomic keyword. If the _Atomic keyword is supported by the compiler we should include it in the builtin library sources.

llvm-svn: 278454
2016-08-12 01:29:26 +00:00
Evgeniy Stepanov 851378831e [asan] abort_on_error=1 by default on Android.
With this change, the default behavior on error is to call abort()
instead of _exit(). This should help the OS to capture a tombstone of
the error.

RAM usage of the lit test suite goes up because of all the tombstone
gathering, so I'm limiting the parallelism of the test target.
Previously it was based on the number of the CPUs on the host
machine, which is definitely wrong.

llvm-svn: 278308
2016-08-11 00:26:29 +00:00
Adhemerval Zanella daa3ebce28 tsan: Remove __pointer_chk_guard@GLIBC_PRIVATE requirement for AArch64
Current AArch64 {sig}{set,long}jmp interposing requires accessing glibc
private __pointer_chk_guard to get process xor mask to demangled the
internal {sig}jmp_buf function pointers.

It causes some packing issues, as described in gcc PR#71042 [1], and is
is not a godd practice to rely on a private glibc namespace (since ABI is
not meant to be stable).

This patch fixes it by changing how libtsan obtains the guarded pointer
value: at initialization a specific routine issues a setjmp call and
using the mangled function pointer and the original value derive the
random guarded pointer.

Checked on aarch64 39-bit VMA.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71042

llvm-svn: 278292
2016-08-10 21:39:28 +00:00
Ying Yi 2c614cf26e test commit.
llvm-svn: 278210
2016-08-10 10:48:02 +00:00
Francis Ricci 81378e46bb [compiler-rt] Allow nm program to be over-ridden for global symbol detection
Summary:
While cross-compiling, a custom nm program may be required. This will also allow for the
use of llvm-nm if desired.

Reviewers: samsonov, beanz, compnerd, eugenis

Subscribers: kubabrecka, dberris, llvm-commits

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

llvm-svn: 278187
2016-08-10 00:45:30 +00:00
Kostya Serebryany 1ab649649d [sanitizer] use 32-bit offset instead of 64-bit pointers in the 64-bit allocator's transfer batches. This saves 2x memory for the transfer batches (up to ~1.5% overall in some cases)
llvm-svn: 278179
2016-08-09 23:30:22 +00:00
Kostya Serebryany d4a5749677 [sanitizer] minor refactoring in the allocator, NFC
llvm-svn: 278163
2016-08-09 20:54:50 +00:00
Xinliang David Li 3b2c002c6d [Profile] Implement new API __llvm_profile_dump
The API is intended to be used by user to do fine
grained (per-region) control of profile dumping.

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

llvm-svn: 278092
2016-08-09 04:21:14 +00:00
Derek Bruening 3ee803a895 [esan] Add iterator to esan's generic hashtable
Summary: Adds simple iterator support to the esan hashtable.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 278027
2016-08-08 17:37:19 +00:00
Derek Bruening 84df6be883 [esan] Add generic resizing hashtable
Summary:
Adds a new, generic, resizing hashtable data structure for use by esan
tools.  No existing sanitizer hashtable is suitable for the use case for
most esan tools: we need non-fixed-size tables, parameterized keys and
payloads, and write access to payloads.  The new hashtable uses either
simple internal or external mutex locking and supports custom hash and
comparision operators.  The focus is on functionality, not performance, to
catalyze creation of a variety of tools.  We can optimize the more
successful tools later.

Adds tests of the data structure.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 278024
2016-08-08 17:25:40 +00:00
Dean Michael Berris 26cc6628f7 [compiler-rt][XRay] Fix XRay test build dependencies
llvm-svn: 277974
2016-08-08 03:42:11 +00:00
Dean Michael Berris 68e74847bf [compiler-rt][XRay] Implement __xray_unpatch() and __xray_remove_handler()
Summary:
We also add one test (and the XRay testing infrastructure) to exercise
the patching and unpatching code. This uses the XRay API exported
through the headers as well, installing a custom log handler.

Depends on D23101 for the updated emitted code alignment for the
return/entry sleds.

Reviewers: rSerge, echristo, rnk

Subscribers: tberghammer, danalbert, srhines, mehdi_amini, llvm-commits

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

llvm-svn: 277971
2016-08-08 03:10:22 +00:00
Kostya Serebryany 4cd2845e6a [sanitizer] allocator: move TransferBatch into SizeClassAllocator64/SizeClassAllocator32 because we actually need different iplementations for the 64- and 32-bit case. NFC; the following patches will make the TransferBatch implementations differ
llvm-svn: 277899
2016-08-06 01:24:11 +00:00
Nico Weber 023bb97737 Disable a few more flaky asan64 tests.
llvm-svn: 277886
2016-08-05 22:51:10 +00:00
Nico Weber 0f6aad4ad2 Disable a few win asan64 tests that don't reliably pass, https://reviews.llvm.org/D23230
llvm-svn: 277882
2016-08-05 22:36:30 +00:00
Reid Kleckner 9cba2e2d97 Fix two tests in Win64 ASan
Go back to intercepting kernel32!RaiseException, and only go for
ntdll!RtlRaiseException if that fails. Fixes throw_and_catch.cc test.

Work around an issue in LLVM's win64 epilogues. We end up with an
epilogue that looks like this, and it drives the Win64 unwinder crazy
until stack overflow:
        call    ill_cc!__asan_handle_no_return
        xor     eax,eax
        add     rsp,40h // epilogue starts
        pop     rbp     // CSR
        ud2             // Trap here
        ret             // Ret?
        nop     word ptr [rax+rax]
        sub     rsp,28h // Next function

Will file a PR soon.

llvm-svn: 277874
2016-08-05 21:47:46 +00:00
Mike Aizatsky 04897dcc3d [sanitizers] trace buffer API to use user-allocated buffer.
Subscribers: kubabrecka

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

llvm-svn: 277858
2016-08-05 20:09:42 +00:00
Etienne Bergeron 61ba38c8dd fix random typos [NFC]
llvm-svn: 277850
2016-08-05 18:49:08 +00:00
Reid Kleckner 628d6b5c81 Fix dumping of process module list and test it
I probably broke this a year ago in r243895.

llvm-svn: 277842
2016-08-05 17:55:00 +00:00
Saleem Abdulrasool b4022f9782 builtins: better categorisation of Thumb1 builtins
Adjust the builtins to better annotate the Thumb1 routines and their purpose.
Exclude the remaining thumb1 sources on Windows ARM.

llvm-svn: 277828
2016-08-05 16:24:56 +00:00
Reid Kleckner 2a06f48bb5 Print a more useful BP value from MSVC-built ASan runtimes
MSVC doesn't have an exact equivalent for __builtin_frame_address, but
_AddressOfReturnAddress() + sizeof(void*) should be equivalent for all
frames build with -fno-omit-frame-pointer.

llvm-svn: 277826
2016-08-05 16:01:57 +00:00
Saleem Abdulrasool b44444b3f1 builtins: split out the EABI and VFP ARM sources
These are meant to only be included on certain targets.  This only disables it
for Windows ARM for now.  Ideally these would be conditionally included as
appropriate.

llvm-svn: 277777
2016-08-04 21:58:39 +00:00
Reid Kleckner c696467530 Avoid re-entrancy between __sanitizer::Report, OutputDebugString, and RtlRaiseException
Our Report implementation calls OutputDebugString, which calls
RtlRaiseException, which can re-enter back into the ASan runtime and
cause a hang.

Don't treat this special debugger-only exception code as a noreturn
event, since the stack won't really unwind all the way.

llvm-svn: 277763
2016-08-04 20:05:13 +00:00
Etienne Bergeron d2b37ada4d fix whitespaces from https://reviews.llvm.org/D23170
llvm-svn: 277746
2016-08-04 18:30:41 +00:00
Etienne Bergeron 27eb6d521e [compiler-rt] Fix memory allocator for dynamic address space
Summary:
The sanitizer allocators can works with a dynamic address space
(i.e. specified with ~0ULL).

Unfortunately, the code was broken on GetMetadata and GetChunkIdx.

The current patch is moving the Win64 memory test to a dynamic
address space. There is a migration to move every concept to a
dynamic address space on windows.

To have a better coverage, the unittest are now testing
dynamic address space on other platforms too.

Reviewers: rnk, kcc

Subscribers: kubabrecka, dberris, llvm-commits, chrisha

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

llvm-svn: 277745
2016-08-04 18:15:38 +00:00
Dean Michael Berris 3c86ed7f60 [compiler-rt][XRay] Stash xmm registers in the trampolines
We now stash and restore the xmm registers in the trampolines so that
log handlers don't need to worry about clobbering these registers.

In response to comments in D21612.

Reviewers: rSerge, eugenis, echristo, rnk

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 277683
2016-08-04 00:09:35 +00:00
Reid Kleckner 222610bf10 [ASan] Report illegal instruction exceptions in ASan
Summary:
Respect the handle_sigill common flag and handle_segv flags while we're
at it.

We still handle signals/exceptions differently on Unix and Windows. The
installation process is tricky on Windows, and difficult to push down
into sanitizer_common without concerning it with the different
static/dynamic CRT models on Windows.

Reviewers: kcc, etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 277621
2016-08-03 18:13:14 +00:00
Etienne Bergeron f856c4a4e2 [compiler-rt] Fix CHECK coding style [NFC]
llvm-svn: 277604
2016-08-03 15:47:40 +00:00
Etienne Bergeron 2bb23bfc73 [compilter-rt] Try to fix correctly rL277560
rL277560: [compiler-rt] Fix broken interception unittest
llvm-svn: 277567
2016-08-03 05:03:35 +00:00
Kostya Serebryany dcaec77936 [sanitizer] remove one redundant loop from the allocator
llvm-svn: 277563
2016-08-03 03:42:55 +00:00
Etienne Bergeron 50b98dce2e [compiler-rt] Fix broken interception unittest
Summary:
This patch is fixing a broken unittest which make the win64 bot failing.

The bug was introduce here:
  https://reviews.llvm.org/D23046

The interception code is not the same in 32-bit and in 64-bit.
The added unittest can only be patched on 32-bits.

Reviewers: rnk

Subscribers: llvm-commits, chrisha

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

llvm-svn: 277560
2016-08-03 02:44:30 +00:00
Reid Kleckner 9f0ef01197 Reduce coverage PC buffer size on 32-bit Windows to match 32-bit Linux
In r235779, Timur bumped the buffer size up to 1<<27, or about 134
million coverage points, presumably to handle Chrome. We allocate two
arrays of uptrs with this size, and this reliably exhausts all available
address space on 32-bit Windows (2 allocations of 512MB) when ASan is
also enabled.

Let's reduce the buffer size for now to stabilize the test suite. We can
re-evaluate the approach later when we've brought the Chrome ASan
builders back to life.

Kostya said that Mike reduced the number of instrumented coverage points
that LLVM emits by half since Timur made this change, so reducing this
array size should also be safe.

With this change, the 32-bit ASan tests reliably pass for me on Windows
10.

llvm-svn: 277558
2016-08-03 01:19:46 +00:00
Kostya Serebryany c49e296805 [sanitizer] refactor TransferBatch to hide the implementation. NFC expected. Second attempt after failed r276383 which was reverted.
llvm-svn: 277554
2016-08-03 00:14:10 +00:00
Kostya Serebryany 8b4904f9d7 [scudo] add NORETURN to the declaration of dieWithMessage; this should fix a warning in lib/scudo/scudo_termination.cpp
llvm-svn: 277546
2016-08-02 23:23:13 +00:00
Kostya Serebryany 707894b092 [sanitizer] Implement a __asan_default_options() equivalent for Scudo
Summary:
Currently, the Scudo Hardened Allocator only gets its flags via the SCUDO_OPTIONS environment variable.
With this patch, we offer the opportunity for programs to define their own options via __scudo_default_options() which behaves like __asan_default_options() (weak symbol).
A relevant test has been added as well, and the documentation updated accordingly.
I also used this patch as an opportunity to rename a few variables to comply with the LLVM naming scheme, and replaced a use of Report with dieWithMessage for consistency (and to avoid a callback).

Reviewers: llvm-commits, kcc

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

llvm-svn: 277536
2016-08-02 22:25:38 +00:00
Etienne Bergeron 5d42763779 [compiler-rt] Add more interception patterns.
Summary:
These instructions where not supported on my win7 computer.
They were happening on strstr when building chrome unittests with asan.

Reviewers: rnk

Subscribers: llvm-commits, chrisha

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

llvm-svn: 277519
2016-08-02 20:38:05 +00:00
Reid Kleckner d6371ea52a [asan] Intercept RtlRaiseException instead of kernel32!RaiseException
Summary:
On my install of Windows 10, RaiseException is a tail call to
kernelbase!RaiseException. Obviously, we fail to intercept that.
Instead, try hooking at the ntdll!RtlRaiseException layer. It is
unlikely that this layer will contain control flow.

Intercepting at this level requires adding a decoding for
'LEA ESP, [ESP + 0xXXXXXXXX]', which is a really obscure way to write
'SUB ESP, 0xXXXXXXXX' that avoids clobbering EFLAGS.

Reviewers: etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 277518
2016-08-02 20:36:29 +00:00
Etienne Bergeron eb09609f39 fix comments typos [NFC]
llvm-svn: 277511
2016-08-02 20:07:49 +00:00
Xinliang David Li 14c91c4eca [Profile] track ownership of filename pattern string
Make sure runtime copy and owns the string when passed
in from external users of runtime API.

llvm-svn: 277507
2016-08-02 19:34:00 +00:00
Reid Kleckner b0e4a86e05 [asan] Remove NtWaitForWorkViaWorkerFactory interceptor
Summary:
On Windows 10, this gets called after TLS has been torn down from NTDLL,
and we crash attempting to return fake_tsd. This interceptor isn't
needed after r242948 anyway, so let's remove it. The ASan runtime can
now tolerate unregistered threads calling __asan_handle_no_return.

Reviewers: vitalybuka, etienneb

Subscribers: kubabrecka, llvm-commits

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

llvm-svn: 277478
2016-08-02 16:17:32 +00:00
Kuba Brecka a56c2ad594 Follow-up for r277458: Update the tsan_mman_test.cc unit test.
llvm-svn: 277463
2016-08-02 14:41:03 +00:00
Kuba Brecka 3a748d6067 [tsan] Fix the behavior of OSAtomicTestAndClear
The system implementation of OSAtomicTestAndClear returns the original bit, but the TSan interceptor has a bug which always returns zero from the function. This patch fixes this and adds a test.

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

llvm-svn: 277461
2016-08-02 14:30:52 +00:00
Kuba Brecka b5a60ec7fe [tsan] Fix behavior of realloc(nullptr, 0) on Darwin
On Darwin, there are some apps that rely on realloc(nullptr, 0) returning a valid pointer. TSan currently returns nullptr in this case, let's fix it to avoid breaking binary compatibility.

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

llvm-svn: 277458
2016-08-02 14:22:12 +00:00
Jonas Hahnfeld 9b2c3ab620 [CMake] Load LLVMConfig for standalone build of builtins
Therefore move some code into reusable macros.

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

llvm-svn: 277418
2016-08-02 05:51:05 +00:00
Reid Kleckner 1bd5e3ec56 Use 'unsigned long' to match the APIs of the MS bitscan intrinsics
We were getting warnings about how 'uint32_t*' is different from
'unsigned long*' even though they are effectively the same on Windows.

llvm-svn: 277363
2016-08-01 18:39:27 +00:00
Etienne Bergeron 502df06e21 [compiler-rt] Fix various typos in asan dll [NFC]
llvm-svn: 277345
2016-08-01 15:08:12 +00:00
Dimitry Andric 75534e23d0 XFAIL one sanitizer symbolizer test for FreeBSD
Summary:
Due to a QoI issuse in FreeBSD's libcxxrt-based demangler, one sanitizer
symbolizer test consistently appears to fail:

    Value of: DemangleSwiftAndCXX("foo")
      Actual: "float"
    Expected: "foo"

This is because libcxxrt's __cxa_demangle() incorrectly demangles the "foo"
identifier to "float".  It should return an error instead.

For now, XFAIL this particular test for FreeBSD, until we can fix libcxxrt
properly (which might take some time to coordinate with upstream).

Reviewers: rnk, zaks.anna, emaste

Subscribers: emaste, llvm-commits, kubabrecka

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

llvm-svn: 277297
2016-07-31 19:27:46 +00:00
Etienne Bergeron 0b2d71373b [compiler-rt] Add support for interception redirect exports.
Summary:
On windows, an export can be redirected to an other DLL.
This patch is adding the required support to the internal
GetProcAddress implementation.

This case was encountered by instrumenting chromium (win 64-bits)
using this GN configuration:
```
is_component_build = true
is_debug = false
enable_nacl = false
is_clang = true
is_asan = true
clang_base_path = "d:\src\llvm\ninja64"
clang_use_chrome_plugins = false
clang_version = "4.0.0"
```

The operating system is win7 (x64).
Visual Studio: 2015 Professional



Reviewers: rnk

Subscribers: llvm-commits, chrisha

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

llvm-svn: 277294
2016-07-31 17:56:26 +00:00
Adhemerval Zanella 4f9de1e7bf tsan: Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for tsan on aarch64.  As current
mappings for aarch64, 48-bit VMA also supports PIE executable.  This
limits the mapping mechanism because the PIE address bits
(usually 0aaaaXXXXXXXX) makes it harder to create a mask/xor value
to include all memory regions.  I think it is possible to create a
large application VAM range by either dropping PIE support or tune
current range.

It also changes slight the way addresses are packed in SyncVar structure:
previously it assumes x86_64 as the maximum VMA range.  Since ID is 14 bits
wide, shifting 48 bits should be ok.

Tested on x86_64, ppc64le and aarch64 (39 and 48 bits VMA).

llvm-svn: 277137
2016-07-29 12:45:35 +00:00
Dean Michael Berris 17a586e6de [compiler-rt][XRay] Address follow-up comments to initial interface and initialisation code
This addresses some comments from D21612, which contains the following changes:

- Update __xray_patch() and __xray_unpatch() API documentation to not imply asynchrony.
- Introduce a scope cleanup mechanism to make sure we can roll-back changes to the XRayPatching global atomic.
- Introduce a few more comments for potential extension points for other platforms (for the implementation details of patching and un-patching).

Reviewers: eugenis, rnk, kcc, echristo, majnemer

Subscribers: llvm-commits, mehdi_amini

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

llvm-svn: 277124
2016-07-29 07:11:58 +00:00
Etienne Bergeron 74999eb50f Fix broken build bot
The address resolution is ussing RTLD_NEXT and not RTLD_DEFAULT.
Which means &func may not be equivalent to dlsym("func").

llvm-svn: 276951
2016-07-28 01:35:32 +00:00
Etienne Bergeron 8c6eb1566c [compiler-rt] Fix warnings in interception code
Summary:
This patch is re-introducing the code to fix the
dynamic hooking on windows and to fix a compiler
warning on Apple.

Related patches:

* https://reviews.llvm.org/D22641
* https://reviews.llvm.org/D22610
* https://reviews.llvm.org/rL276311
* https://reviews.llvm.org/rL276490

Both architecture are using different techniques to
hook on library functions (memchr, strcpy,...). 

On Apple, the function is not dynamically hooked and
the symbol always points to a valid function 
(i.e. can't be null). The REAL macro returns the
symbol.

On windows, the function is dynamically patch and the
REAL(...) function may or may not be null. It depend
on whether or not the function was hooked correctly.
Also, on windows memcpy and memmove are the same.

```
#if !defined(__APPLE__)
[...]
# define REAL(x) __interception::PTR_TO_REAL(x)
# define ASSIGN_REAL(dst, src) REAL(dst) = REAL(src)
[...]
#else  // __APPLE__
[...]
# define REAL(x) x
# define ASSIGN_REAL(x, y)
[...]
#endif  // __APPLE__

Reviewers: rnk

Subscribers: kcc, hans, kubabrecka, llvm-commits, bruno, chrisha

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

llvm-svn: 276885
2016-07-27 16:16:54 +00:00
Dmitry Vyukov 246e0283d4 tsan: don't deliver signals when they are blocked
When we delay signals we can deliver them when the signal
is blocked. This can be surprising to the program.
Intercept signal blocking functions merely to process
pending signals. As the result, at worst we will delay
a signal till return from the signal blocking function.

llvm-svn: 276876
2016-07-27 14:34:21 +00:00
Dean Michael Berris 9a0c446d9e Use RAII for ensuring that mprotect calls are undone
Summary: This fixes an mprotect leak identified in D21612.

Reviewers: echristo, rSerge

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 276833
2016-07-27 04:30:25 +00:00
Evgeniy Stepanov d140aec490 [asan] Remove zero FSR check on ARM.
The kernel on Nexus 5X returns error_code in ucontext which has
correct FSR_WRITE flag, but empty (zero) abort type field. Removing
the checks means that we will report all SEGVs as READ on very old
kernels, but will properly distinguish READ vs WRITE on moderately
old ones.

llvm-svn: 276803
2016-07-26 21:02:45 +00:00
Evgeniy Stepanov 08ef0e0175 [asan] Hardcode page size 4096 on Android.
EXEC_PAGESIZE lies.
sysconf() is broken in .preinit_array.

llvm-svn: 276802
2016-07-26 21:02:44 +00:00
Reid Kleckner cb42ea0b4f [sanitizer] Try to fix LargeMmapAllocator test on Windows
This test attempts to allocate 100 512MB aligned pages of memory. This
is implemented in the usual way by allocating size + alignment bytes and
aligning the result. As a result, this test allocates 51.2GB of memory.
Windows allocates swap for all memory allocated, and our bots do not
have this much swap available.

Avoid the failure by using a more reasonable alignment, like 16MB, as we
do on 32-bit.

llvm-svn: 276779
2016-07-26 17:59:09 +00:00
Xinliang David Li c5307c6993 Define compatibility flag if not defined with -std=c++
llvm-svn: 276708
2016-07-25 23:12:53 +00:00
Chris Bieneman 56e3827e92 Revert "Enable cross-compilation across architectures on android"
This reverts commit r276333.

As I commented in the review (https://reviews.llvm.org/D22415), this change isn't needed because CMAKE_C_FLAGS is implicitly added by CMake to the command line for all C source files.

With this patch enabled CMAKE_C_FLAGS is duplicated on all C sources, and applied to ASM sources, which is not ideal.

I sent an email about this to llvm-commits on the commit thread. I suspect the problem the patch author was actually seeing is that CMAKE_C_FLAGS isn't applied to ASM files, and the builtins library has quite a few of those. The correct solution there is to specify CMAKE_ASM_FLAGS with whatever flags need to be passed to the compiler when compiling ASM files.

If there are other problems with flag propagation, please let me know.

llvm-svn: 276683
2016-07-25 20:25:38 +00:00
Bruno Cardoso Lopes 1f849e3b84 Revert r276539 "Silence -Wpointer-bool-conversion warning after r276324"
Some bots are not happy with the change.
This reverts commit d307ca28083065851ad969444f3c063562f2d4bd.

llvm-svn: 276541
2016-07-24 01:27:07 +00:00
Bruno Cardoso Lopes bd36338449 Silence -Wpointer-bool-conversion warning after r276324
sanitizer_common_interceptors.inc:667:12: warning: address of function 'memchr' will always evaluate to 'true' [-Wpointer-bool-conversion]
  if (REAL(memchr)) {
  ~~       ^~~~~~

llvm-svn: 276539
2016-07-24 01:09:03 +00:00
Bruno Cardoso Lopes fb4358d15b Revert "fix https://reviews.llvm.org/D22610" and "[compiler-rt] Fix memmove/memcpy overlap detection on windows"
This currently fails ~500 tests on Darwin:
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/20456/

This reverts commit 4cfee0dff1facb8fa2827d25c5943bfef96d1a8f and
dbd91205d578cb61ab77be06087e9f65ba8a7ec8.

llvm-svn: 276490
2016-07-22 23:02:34 +00:00
Kostya Serebryany d251e94a01 [sanitizer] revert r276383 while investigating failures on bot
llvm-svn: 276456
2016-07-22 19:02:59 +00:00
Reid Kleckner ff3ea5f4f8 Try to fix more Windows portability issues in sanitizer tests
Add a %stdcxx11 lit substitution for -std=c++11. Windows defaults to
-std=c++14 when VS 2015 is used because the STL requires it. Harcoding
-std=c++11 in the ASan tests actually downgrades the C++ standard level,
leading to test failures.

Relax a FileCheck pattern in use-after-scope-types.cc.

Disable the sanitizer_common OOM tests. They fail on bots with low swap,
and cause other concurrently running tests to OOM.

llvm-svn: 276454
2016-07-22 18:41:22 +00:00
Xinliang David Li f0e0a74f87 [Profile] cleanup: do not reference name directly of vars shared between rt and llvm
llvm-svn: 276385
2016-07-22 04:08:16 +00:00
Kostya Serebryany 5bc01c108d [sanitizer] refactor TransferBatch to hide the implementation. NFC
llvm-svn: 276383
2016-07-22 02:21:12 +00:00
Kostya Serebryany bfd69e0580 [sanitizer] allocator: introduce kUseSeparateSizeClassForBatch (false by default). When true, it will cause all TransferBatches to be allocated on a separate dedicated size class, which improves security and may potentially simplify memory reclamation. However in the current state this may cause up to 3% extra memory usage. Subsequent changes should bring this overhead down
llvm-svn: 276377
2016-07-22 01:13:13 +00:00
Xinliang David Li e953933a9f [Profile] deprecate __llvm_profile_override_default_filename (part2)
This eliminates unncessary calls and init functions.

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

llvm-svn: 276355
2016-07-21 23:19:18 +00:00
Kostya Serebryany 88e95bf38c [sanitizer] trying to fix Mac bots
llvm-svn: 276346
2016-07-21 22:18:36 +00:00
Kostya Serebryany 395386f910 [sanitizer] better allocator stats (with rss)
llvm-svn: 276343
2016-07-21 21:38:40 +00:00
Etienne Bergeron 901b0dc96a [compiler-rt] Add support for relative offset adjustment in interception
Summary:
Some instructions can only be copied if the relative offset is adjusted.

This patch adds support for two common instruction.
It's quite common to have a indirect load in the prologue 
(loading the security cookie).

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 276336
2016-07-21 21:08:54 +00:00
Francis Ricci 283d8df277 Enable cross-compilation across architectures on android
Summary:
This patch fixes cross-architecture compilation,
by allowing flags like -target and --sysroot to be set for
architecture testing and compilation.

Reviewers: tberghammer, srhines, danalbert, beanz, compnerd

Subscribers: tberghammer, llvm-commits, danalbert

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

llvm-svn: 276333
2016-07-21 21:05:14 +00:00
Reid Kleckner f6d5475e20 Disable thread safe statics in clang-cl, they call the CRT
Also remove the needless static that was using them.

llvm-svn: 276327
2016-07-21 20:03:37 +00:00
Etienne Bergeron 29539a0b7d [compiler-rt] Fix interception of memcpy/memmove on win64
Summary:
This patch is fixing running interception unittests for memcpy/memmove on
windows 64.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276324
2016-07-21 19:49:11 +00:00
Kostya Serebryany 35eeea707e [sanitizer] allocator: remove kPopulateSize and only use SizeClassMap::MaxCached; ensure that TransferBatch size is a power of two, refactor TransferBatch creation/destruction into separate functions.
llvm-svn: 276318
2016-07-21 18:47:53 +00:00
Reid Kleckner db81b3e0b2 Fix clang-cl warning and crash in sanitizers
Make kStderrFd a macro to avoid dynamic initialization of the
report_file global. This actually causes a crash at runtime, because
ASan initializes before static initializers run.

Remove an unused variable in asan_win.cc.

llvm-svn: 276314
2016-07-21 18:31:01 +00:00
Etienne Bergeron 2c781262b8 fix https://reviews.llvm.org/D22610
AppleClang can't compile the assignment expression.

llvm-svn: 276311
2016-07-21 17:58:04 +00:00
Etienne Bergeron aa76a0cf91 [compiler-rt] Fix memmove/memcpy overlap detection on windows
Summary:
The memcpy and memmove functions are the same on windows.
The overlap detection logic is incorrect.

printf-1 test:
```
stdin>:2:114: note: possible intended match here
==877412==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x0000002bf2a8,0x0000002bf2ad) and [0x0000002bf2a9, 0x0000002bf2ae) overlap
```                                                                                                                 ^

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 276299
2016-07-21 16:06:54 +00:00
Dean Michael Berris 938c5031ab [compiler-rt][XRay] re-submitting r276117, with fixes for build breakage due to extraneous and missing dependencies and attempts to build on unsupported OSes
Summary:
This is a fixed-up version of D21612, to address failure identified post-commit.

Original commit description:

This patch implements the initialisation and patching routines for the XRay runtime, along with the necessary trampolines for function entry/exit handling. For now we only define the basic hooks for allowing an implementation to define a handler that gets run on function entry/exit. We expose a minimal API for controlling the behaviour of the runtime (patching, cleanup, and setting the handler to invoke when instrumenting).

Fixes include:
- Gating XRay build to only Linux x86_64 and with the right dependencies in case it is the only library being built
- Including <cstddef> to fix std::size_t issue

Reviewers: kcc, rnk, echristo

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 276251
2016-07-21 07:39:55 +00:00
Xinliang David Li e3fc4d0fdd [Profile] bug fix: profile dir not recursively created
llvm-svn: 276234
2016-07-21 03:38:07 +00:00
Etienne Bergeron d4528b2ea1 [compiler-rt] Fix broken SymInitialize unittest
Summary:
By adding the initialisation of the symbolisation library (DbgHelp)
we are swapping the order in which both warnings are produced.

We can't use CHECK-NEXT as the dbghelp warning is multiline.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 276228
2016-07-21 02:32:37 +00:00
Xinliang David Li bfc4c24952 Sync up with llvm copy /NFC
llvm-svn: 276198
2016-07-20 22:29:16 +00:00
Kostya Serebryany 9835a81529 [sanitizers] split sanitizer_allocator.h into a number of smaller .h files; NFC
llvm-svn: 276195
2016-07-20 22:06:41 +00:00
Hans Wennborg ae4e6fe990 Revert r276117 "[XRay] Basic initialization and flag definition for XRay runtime"
and also the follow-up "[xray] Only build xray on Linux for now"

Two build errors were reported on the llvm-commits list:

	[ 88%] Building CXX object lib/xray/CMakeFiles/clang_rt.xray-x86_64.dir/xray_flags.cc.o
	/mnt/b/sanitizer-buildbot1/sanitizer-x86_64-linux/build/llvm/projects/compiler-rt/lib/xray/xray_init.cc:23:10: fatal error: 'llvm/Support/ELF.h' file not found
  #include "llvm/Support/ELF.h"
					 ^

and

	In file included from /w/src/llvm.org/projects/compiler-rt/lib/xray/xray_interface.cc:16:
	/w/src/llvm.org/projects/compiler-rt/lib/xray/xray_interface_internal.h:36:8: error:
				no type named 'size_t' in namespace 'std'
		std::size_t Entries;
		~~~~~^

llvm-svn: 276186
2016-07-20 21:37:38 +00:00
Reid Kleckner 8367634c7a [xray] Only build xray on Linux for now
Should fix the Windows buildbots, and maybe some other non-Linux Unix
bots too.

XRay currently depends on sanitizer_common, so associate it with the
"build sanitizers" option and remove the option for separately
controlling the XRay build.

llvm-svn: 276124
2016-07-20 14:58:07 +00:00
Dean Michael Berris e1c81d10d7 [compiler-rt] [XRay] Basic initialization and flag definition for XRay runtime
Summary:
This patch implements the initialisation and patching routines for the XRay runtime, along with the necessary trampolines for function entry/exit handling. For now we only define the basic hooks for allowing an implementation to define a handler that gets run on function entry/exit. We expose a minimal API for controlling the behaviour of the runtime (patching, cleanup, and setting the handler to invoke when instrumenting).

Depends on D19904

Reviewers: echristo, kcc, rnk

Subscribers: rnk, mehdi_amini, llvm-commits

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

llvm-svn: 276117
2016-07-20 14:14:50 +00:00
Dmitry Vyukov 080dcf7aa8 tsan: fix windows build
It's only asan that installs vectored SEH handler to map memory lazily.

llvm-svn: 276112
2016-07-20 12:50:49 +00:00
Dmitry Vyukov bbed03ee9b tsan: fix windows build
Currently fails as:

gotsan.cc: In function 'void* __sanitizer::__libc_memalign(__sanitizer::uptr, __sanitizer::uptr)':
gotsan.cc:6194:50: error: 'posix_memalign' was not declared in this scope
   uptr error = posix_memalign(&p, alignment, size);

Windows does not provide posix_memalign.

llvm-svn: 276107
2016-07-20 11:43:52 +00:00
Dmitry Vyukov dcad913ab6 tsan: fix leak of shadow stacks
llvm-svn: 276103
2016-07-20 10:29:08 +00:00
Xinliang David Li b061cdb0e3 Minor cleanup -- clear name structure before parsing
llvm-svn: 276089
2016-07-20 05:10:56 +00:00
Xinliang David Li eaf238d494 [Profile] implement interface to get profile path prefix
Differential Revision:  http://reviews.llvm.org/D22546

llvm-svn: 276083
2016-07-20 04:26:09 +00:00
Xinliang David Li b6d43b7994 [Profile] introduce reusable internal interfaces to find dir separator \NFC
llvm-svn: 276027
2016-07-19 20:48:00 +00:00
Xinliang David Li d4c5e27a27 [Profile] move utility interfaces to the right header /NFC
llvm-svn: 276021
2016-07-19 20:31:46 +00:00
Xinliang David Li d9689aff32 [Profile] use portable macro /NFC
llvm-svn: 276019
2016-07-19 20:20:20 +00:00
Vitaly Buka 9f9c089fe2 Add detect_stack_use_after_scope runtime flag
Summary: This flag could be used to disable check in runtime.

Subscribers: kubabrecka

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

llvm-svn: 276004
2016-07-19 18:11:08 +00:00
Etienne Bergeron cb35161ba3 fix compiler warnings [NFC]
llvm-svn: 275984
2016-07-19 15:30:22 +00:00
Derek Bruening 0fc992442c [esan|wset] Fix flaky sampling tests
Adds a new esan public interface routine __esan_get_sample_count() and uses
it to ensure that tests of sampling receive the minimum number of samples.

llvm-svn: 275948
2016-07-19 05:06:48 +00:00
Derek Bruening 9419737fa8 [esan] Fix sideline thread flaky assert
Fixes an esan sideline thread CHECK that failed to account for the sideline
thread reaching its code before the internal_clone() return value was
assigned in the parent.

llvm-svn: 275946
2016-07-19 05:03:38 +00:00
Vedant Kumar 55ecc100b0 [interception] Remove extra whitespace to appease linters (NFC)
Attempt to fix:

  http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/7774

llvm-svn: 275901
2016-07-18 20:07:27 +00:00
Etienne Bergeron a81a44ffd4 [compiler-rt] Fix incorrect handling of indirect load.
Summary:
Indirect load are relative offset from RIP.

The current trampoline implementation is incorrectly
copying these instructions which make some unittests
crashing.

This patch is not fixing the unittests but it's fixing
the crashes. The functions are no longer hooked.

Patches will come soon to fix these unittests.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275892
2016-07-18 19:50:55 +00:00
Etienne Bergeron d61042b549 [compiler-rt] Allow trampoline allocation further and 1 gig.
Summary:
The trampoline allocation limits the memory scanning to 1 gig.
There is an unittest that is allocating a large object which make
it impossible to the trampoline allocator to find a free spot.

see shadow_mapping_failures:
```
char bigchunk[1 << 30];
```

This patch is not fixing the unittest but it's fixing it's infinite
loop behavior.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275887
2016-07-18 19:33:05 +00:00
Etienne Bergeron d215a8f37e revert https://reviews.llvm.org/D22393
It is breaking build 32-bit build bots.

llvm-svn: 275816
2016-07-18 17:15:22 +00:00
Xinliang David Li fe9ecc9d9a Code refactoring: extract path prefix handling code
.. into reusable interfaces. No functional change is expected.

llvm-svn: 275807
2016-07-18 16:16:12 +00:00
Adhemerval Zanella ab1b926bb9 [asan] Enable 48-bit VMA support on aarch64
This patch adds 48-bits VMA support for asan on aarch64. The current
47-bit mask is not suffice since on aarch64 kernel with 48-bit vma
(default on ubuntu 16.04) the process may use full VMA range as:

[...]
ffffa39a7000-ffffa39a8000 r--p 00000000 00:00 0 [vvar]
ffffa39a8000-ffffa39a9000 r-xp 00000000 00:00 0 [vdso]
ffffa39a9000-ffffa39aa000 r--p 0001c000 08:02 13631554 /lib/aarch64-linux-gnu/ld-2.23.so
ffffa39aa000-ffffa39ac000 rw-p 0001d000 08:02 13631554 /lib/aarch64-linux-gnu/ld-2.23.so
ffffc2227000-ffffc2248000 rw-p 00000000 00:00 0 [stack]

llvm-svn: 275792
2016-07-18 14:47:18 +00:00
Alina Sbirlea 9b47673e3f [compiler-rt] Change all asm directives to __asm__ in cpu_model.
Summary:
Aiming to resolve failure in sanitizer bot by changning all asm directives to __asm__.
Also, consistency.

Reviewers: llvm-commits, echristo, vitalybuka

Subscribers: mehdi_amini

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

llvm-svn: 275740
2016-07-17 23:45:55 +00:00
Kostya Serebryany 4953a01461 [asan] trying to fix the windows build
llvm-svn: 275644
2016-07-15 23:13:03 +00:00
George Burgess IV 70a65c28a7 Fix a typeo.
(obligatory s/typeo/typo)

llvm-svn: 275632
2016-07-15 22:24:24 +00:00
Kostya Serebryany ad0724692e [sanitizers] add interceptor for memmem; add weak hooks for strncasecmp, strcasecmp, strstr, strcasestr, memmem
llvm-svn: 275621
2016-07-15 21:28:58 +00:00
Xinliang David Li aeff1518e0 [Profile] instroduce portability macro for dir separator(s
llvm-svn: 275597
2016-07-15 18:48:14 +00:00
Etienne Bergeron 9da82d6aca [compiler-rt] Fix 64-bits exception handlers in ASAN 64-bits runtime
Summary:
This is adding the appropriate suport for exception handling for
64-bits ASAN on windows.

Reviewers: rnk

Subscribers: kubabrecka, llvm-commits, wang0109, chrisha

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

llvm-svn: 275585
2016-07-15 17:28:10 +00:00
Etienne Bergeron a566fe341f [compiler-rt] Fix incorrect handling of indirect load.
Summary:
Indirect load are relative offset from RIP.

The current trampoline implementation is incorrectly
copying these instructions which make some unittests
crashing.

This patch is not fixing the unittests but it's fixing
the crashes. The functions are no longer hooked.

Patches will come soon to fix these unittests.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275584
2016-07-15 17:26:33 +00:00
Etienne Bergeron 3d89db445d TestCase null_deref was failing in Win64:
c:\lipo\work\asan\b_llvm>c:\lipo\work\asan\b_llvm\projects\compiler-rt\test\asan\X86_64WindowsConfig\TestCases\Output\null_deref.cc.tmp
=================================================================
==5488==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000028 (pc 0x7ff701f91067 bp 0x000c8cf8fbf0 sp 0x000c8cf8fbb0 T0)
==5488==The signal is caused by a READ memory access.
==5488==Hint: address points to the zero page.
    #0 0x7ff701f91066 in NullDeref(int *) C:\lipo\work\asan\llvm\projects\compiler-rt\test\asan\TestCases\null_deref.cc:15:10
    #1 0x8a0388830a67  (<unknown module>)
The reason was symbols was not initilized. In fact, it was first inited
with a call to stack.Print(), which calls
WinSymbolizerTool::SymbolizePC, then InitializeDbgHelpIfNeeded().

Since the StackWalk was performed before the stack.Print(), stack frames
where not gathered correctly.

There should be a better place to initialize symbols. For now, this
patch makes the test happy.

Patch by Wei Wang
Differential Revision: https://reviews.llvm.org/D22410

llvm-svn: 275580
2016-07-15 17:16:37 +00:00
Etienne Bergeron c52ae0e8d1 [asan] Avoid hooking memchr() on Windows64
There is not enough padding in front of memchr(), and, the first 6 bytes
contains a branch instruction. Basically the current interception will
not work on memchr().

It was disabled before, but was missing the part to disable it for
INTERCEPT_LIBRARY_FUNCTION.

Patch by Wei Wang

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

llvm-svn: 275494
2016-07-14 22:29:22 +00:00
Etienne Bergeron 31795c7576 address comments in: https://reviews.llvm.org/D22363
llvm-svn: 275492
2016-07-14 22:18:21 +00:00
Etienne Bergeron 8fc1dca8f7 [compiler-rt] Add more assembly patterns for interception
Summary:
These patterns are encounter when using instrumented DLL.

Without this patch, asan lit test are crashing when trying to hook
on RaiseException function.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275489
2016-07-14 22:14:33 +00:00
Etienne Bergeron 7903382468 [compiler-rt] Add internal wcslen to avoid crashing on windows 64-bits
Summary:
The function wcslen is incorrectly hooked on windows 64-bits.

The interception library is not able to hook without breaking the code.
The function is too small and the interception must be done with
trampoline-hooking which turned out to be incorrect on a small
loop (first few instructions have a backedge).

Reviewers: rnk

Subscribers: wang0109, chrisha, llvm-commits, kubabrecka

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

llvm-svn: 275488
2016-07-14 22:13:41 +00:00
Etienne Bergeron 85be3afda4 [compiler-rt] Fix missing frame with stackwalking on windows 64-bits
Summary: Fix missing frame with stackwalking on windows 64-bits

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275486
2016-07-14 22:04:28 +00:00
Alina Sbirlea 36f57fbc66 Add runtime support for __cpu_model (__builtin_cpu_supports)
Summary:
    This aims to add support for __cpu_model and address Bug 25510. It uses
    the code from lib/Support/Host.cpp for cpu detection, and creates
    __cpu_model with that info.

    Tested on OSX and built on Linux as well (though libgcc is the default).
    The use of "asm" required -std=gnu99, hence the cmake change. Corrections
    on better addressing this are welcome.

    Previously reverted, up for review again to iron out outstanding issues.

Reviewers: llvm-commits, joerg, echristo, mehdi_amini

Subscribers: mehdi_amini

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

llvm-svn: 275484
2016-07-14 22:02:35 +00:00
Renato Golin 2931b21286 [RT-ARM] Syntax unified for aeabi_mem* functions
Use unified syntax for builtins/arm/aeabi_mem*.S.

This makes these files consistent with the others.

This fixes a problem on the linker, which can fail with the message
"relocation truncated to fit: R_ARM_THM_JUMP11 against symbol"

Patch by Kor Nielsen.

llvm-svn: 275264
2016-07-13 14:01:15 +00:00
Reid Kleckner cd03f6f4f6 [sanitizers] Allocate 12MB for stack instead of 134MB
The thread registry test was failing to allocate 25 threads with stack
size 134MB, which is pretty reasonable.

Also print the error code in our pthread wrappers in case this happens
again.

llvm-svn: 275209
2016-07-12 20:10:28 +00:00
Etienne Bergeron e318b83745 [asan] Fix interception unittest on Windows64.
mov edi,edi is _not_ NOP in 64-bit, use 66,90h instead.
This bug was causing interception unittest to crash on 
Windows64 (windows 8 and windows 10).

Credits to etienneb for finding the root cause.

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D22274

llvm-svn: 275207
2016-07-12 19:39:07 +00:00
Etienne Bergeron c4d57d9c5f [compiler-rt] Disable a test failing on windows.
Summary:
The unittest is not working on windows. The "regexp.h" is not available and
gtest-port won't support regexp with operator '|'.

The test wasn't failing on 32-bits because of this check:
```
  if (SANITIZER_WORDSIZE != 64 || ASAN_AVOID_EXPENSIVE_TESTS) return;
```

```
[ RUN      ] AddressSanitizer.HugeMallocTest
C:/src/llvm/llvm/utils/unittest/googletest\src/gtest-port.cc(272): error: Failed
Syntax error at index 30 in simple regular expression "is located 1 bytes to the left|AddressSanitizer failed to allocate": '|' is unsupported.
C:/src/llvm/llvm/projects/compiler-rt/lib/asan/tests/asan_test.cc(308): error: Death test: Ident((char*)malloc(n_megs << 20))[-1] = 0
    Result: died but not with expected error.
  Expected: is located 1 bytes to the left|AddressSanitizer failed to allocate
```

See gtest-port.h:
```
  #elif GTEST_OS_WINDOWS

// <regex.h> is not available on Windows.  Use our own simple regex
// implementation instead.
# define GTEST_USES_SIMPLE_RE 1
```

Reviewers: rnk

Subscribers: llvm-commits, wang0109, kubabrecka, chrisha

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

llvm-svn: 275181
2016-07-12 15:33:25 +00:00
Etienne Bergeron 9c2a22000e [compiler-rt] Enhance function padding detection for function interception
Summary:
Many CRT (64-bits) functions contains a "hint-nop". The current padding
detection is not able to recognize the 10-bytes padding and the HotPatch
hooking technique cannot be used.

Other patterns may be discover and may be added later.

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275180
2016-07-12 15:33:04 +00:00
Etienne Bergeron ef4b449124 fix incorrect constant (from http://reviews.llvm.org/D22111)
llvm-svn: 275136
2016-07-12 01:30:58 +00:00
Etienne Bergeron c9c5405b52 missing modifications for http://reviews.llvm.org/D21952
llvm-svn: 275124
2016-07-11 23:09:33 +00:00
Etienne Bergeron f5525670ad [compiler-rt] Refactor the interception code on windows.
Summary:
This is a cleanup and refactoring of the interception code on windows

Enhancement:
  * Adding the support for 64-bits code
  * Adding several hooking technique:
    * Detour
    * JumpRedirect
    * HotPatch
    * Trampoline
  * Adding a trampoline memory pool (64-bits) and release the allocated memory in unittests

Cleanup:
  * Adding unittests for 64-bits hooking techniques
  * Enhancing the RoundUpInstruction by sharing common decoder

Reviewers: rnk

Subscribers: llvm-commits, wang0109, chrisha

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

llvm-svn: 275123
2016-07-11 23:02:18 +00:00
Etienne Bergeron 0e6a1b3bd2 remove empty lines
llvm-svn: 275112
2016-07-11 21:57:11 +00:00
Etienne Bergeron ab42f4ddba [compiler-rt] Fix VisualStudio virtual folders layout
Summary:
This patch is a refactoring of the way cmake 'targets' are grouped.
It won't affect non-UI cmake-generators.

Clang/LLVM are using a structured way to group targets which ease
navigation through Visual Studio UI. The Compiler-RT projects
differ from the way Clang/LLVM are grouping targets.

This patch doesn't contain behavior changes.

Reviewers: kubabrecka, rnk

Subscribers: wang0109, llvm-commits, kubabrecka, chrisha

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

llvm-svn: 275111
2016-07-11 21:51:56 +00:00
Etienne Bergeron 1128db8fe1 [asan] Add exception handler to map memory on demand on Win64.
Memory will be committed on demand when exception happens while accessing
shadow memeory region.

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D21942

llvm-svn: 275107
2016-07-11 21:40:59 +00:00
Etienne Bergeron 81c0f32cf2 [compiler-rt] Refactor the interception code on windows.
[asan] Fix unittest Asan-x86_64-inline-Test crashing on Windows64

REAL(memcpy) was used in several places in Asan, while REAL(memmove) was not used.
This CL chooses to patch memcpy() first, solving the crash for unittest.

The crash looks like this:

projects\compiler-rt\lib\asan\tests\default\Asan-x86_64-inline-Test.exe
=================================================================
==22680==ERROR: AddressSanitizer: access-violation on unknown address 0x000000000000 (pc 0x000000000000 bp 0x0029d555f590 sp 0x0029d555f438 T0)
==22680==Hint: pc points to the zero page.

AddressSanitizer can not provide additional info.
 SUMMARY: AddressSanitizer: access-violation (<unknown module>)
==22680==ABORTING

Patch by: Wei Wang
Differential Revision: http://reviews.llvm.org/D22232

llvm-svn: 275098
2016-07-11 20:37:12 +00:00
Kuba Brecka ddc3cc65cb [tsan] Add support for GCD IO channels on Darwin
This patch adds interceptors for dispatch_io_*, dispatch_read and dispatch_write functions. This avoids false positives when using GCD IO. Adding several test cases.

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

llvm-svn: 275071
2016-07-11 15:57:50 +00:00
Etienne Bergeron 07d648fcaf whitespaces + re-indent
llvm-svn: 275023
2016-07-10 21:06:06 +00:00
Derek Bruening dec4bd0838 [esan] Add __esan_report for mid-run data
Summary:
Adds a new public interface routine __esan_report() which can be used to
request profiling results prior to abnormal termination (e.g., for a server
process killed by its parent where the normal exit does not allow for
normal result reporting).

Implements this for the working-set tool.  The cache frag tool is left
unimplemented as it requires missing iteration capabilities.

Adds a new test.

Reviewers: aizatsky

Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka

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

llvm-svn: 274964
2016-07-09 04:13:25 +00:00
Alina Sbirlea 0efdda0956 Revert "Add runtime support for __cpu_model (__builtin_cpu_supports)"
This reverts commit r274873 until additional fixes are resolved.

llvm-svn: 274944
2016-07-08 22:22:43 +00:00
Alina Sbirlea 9ebebce2df Add runtime support for __cpu_model (__builtin_cpu_supports)
Summary:
This aims to add support for __cpu_model and address Bug 25510. It uses
the code from lib/Support/Host.cpp for cpu detection, and creates
__cpu_model with that info.

Tested on OSX, it builts successfully, but the current version does
*not* resolve Bug 25510. The __cpu_model symbol is present in the
library but it only gets loaded with -all_load. This patch will not land
until this issue is clarified.

Built on Linux as well (though libgcc is the default). The use of "asm"
required -std=gnu99, hence the cmake change. Corrections on better
addressing this are welcome.

Note: See additional comments on D20988 (committed as r271921).

Reviewers: llvm-commits, joerg, echristo, mehdi_amini

Subscribers: mehdi_amini

Differential revision: http://reviews.llvm.org/D21033

llvm-svn: 274873
2016-07-08 16:28:54 +00:00
Alina Sbirlea fb11f27253 Revert r274865-r274870
llvm-svn: 274872
2016-07-08 16:28:52 +00:00
Alina Sbirlea d6ce086f32 Added comments identifing code source
llvm-svn: 274870
2016-07-08 16:18:41 +00:00
Alina Sbirlea 13a4583714 Check cpuid supported for i386.
Summary:

Reviewers:

Subscribers:

llvm-svn: 274868
2016-07-08 16:18:39 +00:00
Alina Sbirlea 7847598113 Add default initialization. Add unit test.
llvm-svn: 274867
2016-07-08 16:18:38 +00:00