[asan/win] Add init hooks to .CRT$XLAB
authorReid Kleckner <rnk@google.com>
Tue, 8 Nov 2016 20:45:45 +0000 (20:45 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 8 Nov 2016 20:45:45 +0000 (20:45 +0000)
commitd092107b0e07b1861e541e5f21b342a74218ccb9
tree38d1e30cf5c82002f9bcbd9d99d326a340828e04
parent6cddfc14f9d0ada23ba5a22902e0140260788058
[asan/win] Add init hooks to .CRT$XLAB

Summary:
User applications may register hooks in the .CRT$XL* callback list,
which is called very early by the loader. This is very common in
Chromium:
https://cs.chromium.org/search/?q=CRT.XL&sq=package:chromium&type=cs

This has flown under the radar for a long time because the loader
appears to catch exceptions originating from these callbacks. It's a
real problem when you're debugging an asan application, though, since it
makes the program crash early.

The solution is to add our own callback to this list, and sort it very
early in the list like we do elsewhere. Also add a test with such an
instrumented callback, and test that it gets called with asan.

Reviewers: etienneb

Subscribers: llvm-commits, kubabrecka

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

llvm-svn: 286290
compiler-rt/lib/asan/asan_win.cc
compiler-rt/lib/asan/asan_win_dll_thunk.cc
compiler-rt/lib/asan/asan_win_dynamic_runtime_thunk.cc
compiler-rt/test/asan/TestCases/Windows/tls_init.cc [new file with mode: 0644]