[compiler-rt] r214861 - [ASan/Win] Handle SEH exceptions even with -GS
Timur Iskhodzhanov
timurrrr at google.com
Tue Aug 5 06:26:26 PDT 2014
Author: timurrrr
Date: Tue Aug 5 08:26:26 2014
New Revision: 214861
URL: http://llvm.org/viewvc/llvm-project?rev=214861&view=rev
Log:
[ASan/Win] Handle SEH exceptions even with -GS
This is a follow-up to r213654, r213656, r213667 and r213668.
Modified:
compiler-rt/trunk/lib/asan/asan_dll_thunk.cc
compiler-rt/trunk/lib/asan/asan_interceptors.cc
compiler-rt/trunk/test/asan/TestCases/Windows/dll_seh.cc
compiler-rt/trunk/test/asan/TestCases/Windows/seh.cc
Modified: compiler-rt/trunk/lib/asan/asan_dll_thunk.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_dll_thunk.cc?rev=214861&r1=214860&r2=214861&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_dll_thunk.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_dll_thunk.cc Tue Aug 5 08:26:26 2014
@@ -75,7 +75,7 @@ struct FunctionInterceptor<0> {
// Special case of hooks -- ASan own interface functions. Those are only called
// after __asan_init, thus an empty implementation is sufficient.
#define INTERFACE_FUNCTION(name) \
- extern "C" void name() { \
+ extern "C" __declspec(noinline) void name() { \
volatile int prevent_icf = (__LINE__ << 8); (void)prevent_icf; \
__debugbreak(); \
} \
@@ -325,6 +325,14 @@ WRAP_W_W(_expand_dbg)
INTERCEPT_LIBRARY_FUNCTION(atoi);
INTERCEPT_LIBRARY_FUNCTION(atol);
INTERCEPT_LIBRARY_FUNCTION(_except_handler3);
+
+// _except_handler4 checks -GS cookie which is different for each module, so we
+// can't use INTERCEPT_LIBRARY_FUNCTION(_except_handler4).
+INTERCEPTOR(int, _except_handler4, void *a, void *b, void *c, void *d) {
+ __asan_handle_no_return();
+ return REAL(_except_handler4)(a, b, c, d);
+}
+
INTERCEPT_LIBRARY_FUNCTION(frexp);
INTERCEPT_LIBRARY_FUNCTION(longjmp);
INTERCEPT_LIBRARY_FUNCTION(memchr);
@@ -348,6 +356,7 @@ INTERCEPT_LIBRARY_FUNCTION(wcslen);
// is defined.
void InterceptHooks() {
INTERCEPT_HOOKS();
+ INTERCEPT_FUNCTION(_except_handler4);
}
// We want to call __asan_init before C/C++ initializers/constructors are
Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=214861&r1=214860&r2=214861&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Tue Aug 5 08:26:26 2014
@@ -308,6 +308,12 @@ INTERCEPTOR(int, _except_handler3, void
__asan_handle_no_return();
return REAL(_except_handler3)(a, b, c, d);
}
+
+INTERCEPTOR(int, _except_handler4, void *a, void *b, void *c, void *d) {
+ CHECK(REAL(_except_handler4));
+ __asan_handle_no_return();
+ return REAL(_except_handler4)(a, b, c, d);
+}
#endif
#if ASAN_INTERCEPT_MLOCKX
@@ -745,6 +751,7 @@ void InitializeWindowsInterceptors() {
ASAN_INTERCEPT_FUNC(CreateThread);
ASAN_INTERCEPT_FUNC(RaiseException);
ASAN_INTERCEPT_FUNC(_except_handler3);
+ ASAN_INTERCEPT_FUNC(_except_handler4);
}
} // namespace __asan
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/dll_seh.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_seh.cc?rev=214861&r1=214860&r2=214861&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/dll_seh.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/dll_seh.cc Tue Aug 5 08:26:26 2014
@@ -4,6 +4,12 @@
// build a large project using "clang-cl -fallback -fsanitize=address".
//
// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+//
+// Check both -GS and -GS- builds:
+// RUN: cl -LD -c %s -Fo%t.obj
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll %t.obj
+// RUN: %run %t %t.dll
+//
// RUN: cl -LD -GS- -c %s -Fo%t.obj
// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll %t.obj
// RUN: %run %t %t.dll
Modified: compiler-rt/trunk/test/asan/TestCases/Windows/seh.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/seh.cc?rev=214861&r1=214860&r2=214861&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/seh.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/seh.cc Tue Aug 5 08:26:26 2014
@@ -3,7 +3,11 @@
// the rest is built with Clang. This represents the typical scenario when we
// build a large project using "clang-cl -fallback -fsanitize=address".
//
-// FIXME: Investigate why -GS- is required.
+// Check both -GS and -GS- builds:
+// RUN: cl -c %s -Fo%t.obj
+// RUN: %clangxx_asan -o %t.exe %s %t.obj
+// RUN: %run %t.exe
+//
// RUN: cl -GS- -c %s -Fo%t.obj
// RUN: %clangxx_asan -o %t.exe %s %t.obj
// RUN: %run %t.exe
More information about the llvm-commits
mailing list