Commit Graph

96 Commits

Author SHA1 Message Date
Reid Kleckner 389c7f9142 Really fix the Windows sanitizer build
Don't list __sanitizer_print_memory profile as an INTERFACE_FUNCTION. It
is not exported by ASan; it is exported by user code.

Move the weak definition from asan_win.cc to sanitizer_win.cc to fix the
ubsan tests.

llvm-svn: 281619
2016-09-15 15:39:52 +00:00
Reid Kleckner ba0126896c Fix the Windows build after r281546
llvm-svn: 281558
2016-09-14 23:07:05 +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
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
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
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
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
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
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
Etienne Bergeron 502df06e21 [compiler-rt] Fix various typos in asan dll [NFC]
llvm-svn: 277345
2016-08-01 15:08:12 +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
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
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 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 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 00f3f6e296 This patch is activating the build of Asan on Windows 64-bits.
It's fixing compilation errors. The runtime is not yet working.

Missing features:

OverrideFunction for x64
an equiv function for inline asm (atomic_compare_exchange_strong)
shadow memory offset needs to be adjusted
RoundUpToInstrBoundary for x64
They will be implemented by subsequent patches.

Patch by Wei Wang.

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

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

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

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

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

llvm-svn: 264006
2016-03-21 23:51:21 +00:00
Kuba Brecka 65aa45e872 [tsan] Use re-exec method to enable interceptors on older versions of OS X
In AddressSanitizer, we have the MaybeReexec method to detect when we're running without DYLD_INSERT_LIBRARIES (in which case interceptors don't work) and re-execute with the environment variable set. On OS X 10.11+, this is no longer necessary, but to have ThreadSanitizer supported on older versions of OS X, let's use the same method as well. This patch moves the implementation from `asan/` into `sanitizer_common/`.

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

llvm-svn: 254600
2015-12-03 10:39:43 +00:00
Saleem Abdulrasool d006c9368d Sanitizer: define WIN32_LEAN_AND_MEAN
Define WIN32_LEAN_AND_MEAN before including Windows.h.  This is already being
done in some places.  This does it more broadly.  This permits building ASAN on
Linux for Winndows, as well as reduces the amount of included declarations.

llvm-svn: 251649
2015-10-29 20:36:55 +00:00
Reid Kleckner dd7b4406d1 Fix installation of the unhandled exception filter with r244767
Apparently /Zc:inline causes static globals in custom sections to be
discarded if they are unreferenced.

llvm-svn: 244908
2015-08-13 16:37:28 +00:00
Kostya Serebryany cc9fd3cbe9 [sanitizer] 2-nd attempt. Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski. This time the test is enabled only on x86-64 (it broke on ARM)
llvm-svn: 244234
2015-08-06 17:52:54 +00:00
Renato Golin 4ae2e1f575 Revert "[sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski"
This reverts commit r244136, it was breaking the ARM bots for too long. We should investigate it offline.

llvm-svn: 244210
2015-08-06 12:42:46 +00:00
Kostya Serebryany ce1799a83f [sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski
llvm-svn: 244136
2015-08-05 21:19:11 +00:00
Reid Kleckner e30c0d25e6 Delete unused <dbghelp.h> include
llvm-svn: 243529
2015-07-29 16:19:40 +00:00
Reid Kleckner 12f6b9c8c0 [asan] Remove AsanPlatformThreadInit
Since the CoreFoundation allocator replacement was moved in r173134, all
implementations of this function have been empty.

Reviewers: samsonov

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

llvm-svn: 242811
2015-07-21 17:42:37 +00:00
Timur Iskhodzhanov d58230b9dc [ASan/Win] Fix a CHECK failure when an exception is thrown from a callback passed to BindIoCompletionCallback
This also simplifies how we handle QueueUserWorkItem

llvm-svn: 232499
2015-03-17 16:50:59 +00:00
Timur Iskhodzhanov 817ac724e2 [ASan] NFC: Factor out platform-specific interceptors
Reviewed at http://reviews.llvm.org/D8321

llvm-svn: 232377
2015-03-16 14:22:53 +00:00
Dmitry Vyukov df01bdca70 asan: fix windows build after commit 230978
llvm-svn: 230980
2015-03-02 17:45:18 +00:00
Timur Iskhodzhanov 5c62af5bb1 Reland r230419 - add __asan_default_suppressions() hook with a fix for Windows
llvm-svn: 230501
2015-02-25 16:00:26 +00:00
Nico Weber d70bb8d8cb Revert 230419, 230425, 230432.
They don't build on Windows.
http://lab.llvm.org:8011/builders/sanitizer-windows/ went red for example.

llvm-svn: 230461
2015-02-25 04:39:21 +00:00
Kostya Serebryany 63419712f8 [asan] one more attempt to fix windows build
llvm-svn: 230432
2015-02-25 02:00:26 +00:00
Timur Iskhodzhanov 6ba66b95d1 [ASan/Win] Add support for sanitizer allocator hooks, __asan_default_options and __asan_on_error
llvm-svn: 230344
2015-02-24 17:07:22 +00:00
Kuba Brecka 9a18c3016c Fix ASan's Noinst unit tests
We currently skip all "Noinst" unit tests on OS X, which was probably caused when we removed the "allow_reexec" flag. The MaybeReexec function fails to re-execute when the runtime is linked statically, because there is no dylib to use. This patch adds an explicit DisableReexec function that is used from asan_noinst_test.cc and the runtime then doesn't try to re-execute.

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

llvm-svn: 228740
2015-02-10 20:37:57 +00:00
Viktor Kutuzov 9b75b757de [Asan] Pack signal context into a structure
Differential Revision: http://reviews.llvm.org/D6148

llvm-svn: 222756
2014-11-25 13:00:21 +00:00
Timur Iskhodzhanov 651725e191 [ASan/Win] Fix PR20918 -- SEH handler doesn't work with the MD runtime
llvm-svn: 217679
2014-09-12 14:01:30 +00:00
Timur Iskhodzhanov 220ddacf8d [ASan/Win] Land the trivial bits of -MD RTL support (PR20214)
llvm-svn: 216265
2014-08-22 12:38:07 +00:00
Timur Iskhodzhanov 19853dd28c [ASan/Win] Catch NULL derefs and page faults
Reviewed at http://reviews.llvm.org/D4471

llvm-svn: 212807
2014-07-11 11:57:41 +00:00
Alexey Samsonov 56b6ee9833 [ASan] Optional support for dynamic ASan runtime on Linux.
Based on http://llvm-reviews.chandlerc.com/D3042 by Yuri Gribov!

llvm-svn: 205308
2014-04-01 13:16:30 +00:00
Alexander Potapenko ea4a0dbb8d [ASan] Implement __sanitizer::InstallDeadlySignalHandlers() and __asan::AsanOnSIGSEGV() on Windows.
llvm-svn: 200554
2014-01-31 15:11:11 +00:00
Alexander Potapenko 789e3e1b7c [ASan] Move the SIGSEGV/SIGBUS handling to sanitizer_common
This change is a part of refactoring intended to have common signal handling behavior in all tools.
This particular CL moves InstallSignalHandlers() into sanitizer_common (making it InstallDeadlySignalHandlers()), but doesn't enable default signal handlers for any tool other than ASan.

llvm-svn: 200542
2014-01-31 13:10:07 +00:00
Alexander Potapenko d8d490ed50 [ASan] Move the sigaltstack() bits to sanitizer_common.
This change is a part of refactoring intended to have common signal handling behavior in all tools.
Note that this particular change doesn't enable use_sigaltstack support in every tool.

llvm-svn: 200310
2014-01-28 11:12:29 +00:00
Timur Iskhodzhanov 1c84bd64db [Sanitizer] Implement Symbolizer class on Windows
llvm-svn: 197571
2013-12-18 14:29:16 +00:00
Sergey Matveev da9f5e7e7f [asan] Improve thread lifetime tracking on POSIX systems.
Call AsanThread::Destroy() from a late-running TSD destructor.
Previously we called it before any user-registered TSD destructors, which caused
false positives in LeakSanitizer.

llvm-svn: 192585
2013-10-14 12:01:05 +00:00
Timur Iskhodzhanov e2b207cfd2 [ASan] Fix a compile-time warning
llvm-svn: 191189
2013-09-23 11:19:43 +00:00
Timur Iskhodzhanov d6c93c7b4d [ASan] Add DLL thunks for the new stack UAR interface
llvm-svn: 191188
2013-09-23 11:05:41 +00:00
Sergey Matveev af179b8d63 [sanitizer] Move GetStackTrace from ASan to sanitizer_common.
llvm-svn: 181424
2013-05-08 12:45:55 +00:00
Evgeniy Stepanov 95eaa21637 [sanitizer] More renamed macros.
llvm-svn: 177401
2013-03-19 14:54:17 +00:00
Evgeniy Stepanov 0af672326a [sanitizer] Replace more platform checks with SANITIZER_ constants.
llvm-svn: 177400
2013-03-19 14:33:38 +00:00
Alexey Samsonov 4f1885a109 [ASan] minor changes to swapcontext handling: don't clear shadow memory if context stack is too large
llvm-svn: 172727
2013-01-17 15:45:28 +00:00