[asan] Make ASan compatible with linker dead stripping on Windows
authorReid Kleckner <rnk@google.com>
Mon, 21 Nov 2016 20:40:37 +0000 (20:40 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 21 Nov 2016 20:40:37 +0000 (20:40 +0000)
commit01660a3d2ac48db45c56874bea7ea09ff05216dc
tree75733c24a66894334a02761a1f70baaddd182a7d
parent17e3f9b79dd6ffe4200e2cf102f22d90dea99171
[asan] Make ASan compatible with linker dead stripping on Windows

Summary:
This is similar to what was done for Darwin in rL264645 /
http://reviews.llvm.org/D16737, but it uses COFF COMDATs to achive the
same result instead of relying on new custom linker features.

As on MachO, this creates one metadata global per instrumented global.
The metadata global is placed in the custom .ASAN$GL section, which the
ASan runtime will iterate over during initialization. There are no other
references to the metadata, so normal linker dead stripping would
discard it. However, the metadata is put in a COMDAT group with the
instrumented global, so that it will be discarded if and only if the
instrumented global is discarded.

I didn't update the ASan ABI version check since this doesn't affect
non-Windows platforms, and the WinASan ABI isn't really stable yet.

Implementing this for ELF will require extending LLVM IR and MC a bit so
that we can use non-COMDAT section groups.

Reviewers: pcc, kcc, mehdi_amini, kubabrecka

Subscribers: llvm-commits

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

llvm-svn: 287576
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/test/Instrumentation/AddressSanitizer/global_metadata_darwin.ll
llvm/test/Instrumentation/AddressSanitizer/global_metadata_windows.ll [new file with mode: 0644]