Commit Graph

5958 Commits

Author SHA1 Message Date
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