Commit Graph

28 Commits

Author SHA1 Message Date
Dimitry Andric f2ac1d1df2 Recommit: Stop intercepting some malloc-related functions on FreeBSD and
macOS

Summary:
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.

FreeBSD and macOS do not have the `mallinfo` and `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions.  This also applies to some other malloc-related
functions, such as `memalign`, `pvalloc` and `cfree`.

Fix this by not intercepting `mallinfo`, `mallopt`, `memalign`,
`pvalloc` and `cfree` for FreeBSD and macOS, in all sanitizers.

Also delete the non-functional `cfree` wrapper for Windows, to fix the
test cases on that platform.

Reviewers: emaste, kcc, rnk

Subscribers: timurrrr, eugenis, hans, joerg, llvm-commits, kubamracek

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

llvm-svn: 293536
2017-01-30 19:06:13 +00:00
Reid Kleckner a335055643 Fix _recalloc redefinition link error in ASan RTL
Fixes PR30329

Patch by Hans-Bernhard Broeker!

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

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

Reviewers: samsonov

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

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

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

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

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

llvm-svn: 264005
2016-03-21 23:51:17 +00:00
Evgeniy Stepanov 7555f5ed1f [msan] Remove MSanDR and supporting code.
MSanDR is a dynamic instrumentation tool that can instrument the code
(prebuilt libraries and such) that could not be instrumented at compile time.

This code is unused (to the best of our knowledge) and unmaintained, and
starting to bit-rot.

llvm-svn: 222232
2014-11-18 10:33:15 +00:00
Timur Iskhodzhanov 0a88b25c43 [ASan/Win] Intercept memory allocation functions in the MD CRT
llvm-svn: 216382
2014-08-25 13:19:05 +00:00
Timur Iskhodzhanov 48e21c07c1 Follow-up to r215724: fix a lint warning
llvm-svn: 215725
2014-08-15 16:10:02 +00:00
Timur Iskhodzhanov 5c84264194 [ASan/Win] Introduce a new macro for malloc-like function attributes; also, clang-format the definitions of these functions
llvm-svn: 215724
2014-08-15 16:08:53 +00:00
Timur Iskhodzhanov 750f1cf9e4 [ASan/Win] Remove old, unused and non-functional code that will be re-written soon
llvm-svn: 215707
2014-08-15 12:56:52 +00:00
Timur Iskhodzhanov e6303d1224 Add support for _expand[_dbg] so we don't crash when _aligned_* allocation functions are used
llvm-svn: 204925
2014-03-27 14:01:11 +00:00
Evgeniy Stepanov 42cebb00da [sanitizer] Use the new sanitizer_interception.h header in all interceptors.
llvm-svn: 197808
2013-12-20 13:17:31 +00:00
Alexey Samsonov 9ff4598225 [ASan] Do not rely on malloc context in allocator reports.
Invoke a fatal stack trace unwinder when ASan prints allocator-relevant
error reports (double-free, alloc-dealloc-mismatch, invalid-free).
Thus we'll be able to print complete stack trace even if allocation/free
stacks are not stored (malloc_context_size=0).

Based on the patch by Yuri Gribov!

llvm-svn: 194579
2013-11-13 14:46:58 +00:00
Timur Iskhodzhanov 9dc34adf36 [ASan/Win] Oops, forgot to add the attributes to the memory allocations functions
llvm-svn: 188290
2013-08-13 16:48:18 +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
Kostya Serebryany 3674c6b13b [asan] add a flag alloc_dealloc_mismatch (off by default for now) which finds malloc/delete, new/free, new/delete[], etc mismatches
llvm-svn: 170869
2012-12-21 08:53:59 +00:00
Kostya Serebryany baf583c443 [asan] add two asan flags: fast_unwind_on_fatal and fast_unwind_on_malloc to allow using the slow CFI-based unwinder
llvm-svn: 170117
2012-12-13 09:34:23 +00:00
Alexey Samsonov a555b3faf4 [ASan] Apply some ASan-relevant pieces of patch by Ruben Van Boxem. In the same time, remove ASan from CMake build on Windows after conversation with Timur. We don't want to support building ASan on Windows until it is in a working state.
llvm-svn: 164486
2012-09-24 11:43:40 +00:00
Alexey Samsonov 485d3dc363 Remove file-type tags for .cc files in ASan run-time library
llvm-svn: 157927
2012-06-04 13:50:10 +00:00
Kostya Serebryany 8d03204204 [asan] more renaming
llvm-svn: 157746
2012-05-31 14:35:53 +00:00
Timur Iskhodzhanov 72859836ab [ASan] Add a few more malloc-related interceptors for Windows
llvm-svn: 153327
2012-03-23 11:33:02 +00:00
Timur Iskhodzhanov 2f48b870f3 [ASan] Add back the support for /MT; intercept statically-linked functions
llvm-svn: 152557
2012-03-12 11:45:09 +00:00
Timur Iskhodzhanov bc08fed082 [ASan] Fix lint warning
llvm-svn: 152226
2012-03-07 11:33:15 +00:00
Timur Iskhodzhanov d8dd07f2ff [ASan/Win] Intercept _msize, required for running SQLite
llvm-svn: 152224
2012-03-07 11:19:26 +00:00
Timur Iskhodzhanov 972720e564 [ASan] Replace CRT .dll malloc with our implementation at asan_init() time
llvm-svn: 151715
2012-02-29 11:43:03 +00:00
Timur Iskhodzhanov 36d297d27f [ASan] Intercept functions on Windows - first version
llvm-svn: 151161
2012-02-22 13:59:49 +00:00
Kostya Serebryany 9ff28d661d [asan] The first version of Windows malloc interceptors, patch by timurrrr@google.com
llvm-svn: 149875
2012-02-06 17:56:38 +00:00