From 5bed4206c8bf6604aef3146e9613194f6b6bf2ee Mon Sep 17 00:00:00 2001 From: Timur Iskhodzhanov Date: Fri, 30 May 2014 09:01:17 +0000 Subject: [PATCH] [ASan Win] DLL thunk: make each INTERFACE_FUNCTION unique to prevent ICF linker optimizations llvm-svn: 209881 --- compiler-rt/lib/asan/asan_dll_thunk.cc | 5 ++++- compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc | 4 ++++ compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/asan_dll_thunk.cc b/compiler-rt/lib/asan/asan_dll_thunk.cc index 2dc4144..15482ba 100644 --- a/compiler-rt/lib/asan/asan_dll_thunk.cc +++ b/compiler-rt/lib/asan/asan_dll_thunk.cc @@ -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. diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc index cb22098..befeca6 100644 --- a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc +++ b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cc @@ -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 #include diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc index 01ffbce..b5bc1e7 100644 --- a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc +++ b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cc @@ -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 #include -- 2.7.4