[asan] Export new and delete operators on Windows
authorReid Kleckner <rnk@google.com>
Wed, 23 Mar 2016 20:45:52 +0000 (20:45 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 23 Mar 2016 20:45:52 +0000 (20:45 +0000)
commit03d703bb62e2babcec4dc9d9addbfa39cdaef704
tree4ccb8538a154c8b7370f3144bdf7850c3480da8e
parentfd55fc86edc952ef2b6ac61996425d06af9dd2d2
[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
compiler-rt/lib/asan/asan_malloc_win.cc
compiler-rt/lib/asan/asan_new_delete.cc