[ASan Win] DLL thunk: make each INTERFACE_FUNCTION unique to prevent ICF linker optim...
authorTimur Iskhodzhanov <timurrrr@google.com>
Fri, 30 May 2014 09:01:17 +0000 (09:01 +0000)
committerTimur Iskhodzhanov <timurrrr@google.com>
Fri, 30 May 2014 09:01:17 +0000 (09:01 +0000)
llvm-svn: 209881

compiler-rt/lib/asan/asan_dll_thunk.cc
compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc

index 2dc4144..15482ba 100644 (file)
@@ -74,7 +74,10 @@ 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() { __debugbreak(); }                                   \
+  extern "C" void name() {                                                     \
+    volatile int prevent_icf = (__LINE__ << 8); (void)prevent_icf;             \
+    __debugbreak();                                                            \
+  }                                                                            \
   INTERCEPT_WHEN_POSSIBLE(#name, name)
 
 // INTERCEPT_HOOKS must be used after the last INTERCEPT_WHEN_POSSIBLE.
index cb22098..befeca6 100644 (file)
@@ -2,6 +2,10 @@
 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
+// Test that it works correctly even with ICF enabled.
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
 #include <stdio.h>
 #include <string.h>
 
index 01ffbce..b5bc1e7 100644 (file)
@@ -2,6 +2,10 @@
 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
+// Test that it works correctly even with ICF enabled.
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
 #include <stdio.h>
 #include <string.h>