summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/CMakeLists.txt
diff options
context:
space:
mode:
authorMarcos Pividori <mpividori@google.com>2017-02-02 23:02:11 +0000
committerMarcos Pividori <mpividori@google.com>2017-02-02 23:02:11 +0000
commit753739845908eef985f4b0b5c2c15a46646a8018 (patch)
treead8584c163c8ba12f469c42458bba82b005a7344 /lib/sanitizer_common/CMakeLists.txt
parentbf032f8dc3bff9938162a43d1dbfc31a5eea9615 (diff)
[sanitizer] Use interception to access to strong definitions in the executable.
In Windows, when sanitizers are implemented as a shared library (DLL), users can redefine and export a new definition for weak functions, in the main executable, for example: extern "C" __declspec(dllexport) void __sanitizer_cov_trace_pc_guard(u32* guard) { // Different implementation provided by the client. } However, other dlls, will continue using the default implementation imported from the sanitizer dll. This is different in linux, where all the shared libraries will consider the strong definition. With the implementation in this diff, when the dll is initialized, it will check if the main executable exports the definition for some weak function (for example __sanitizer_cov_trace_pc_guard). If it finds that function, then it will override the function in the dll with that pointer. So, all the dlls with instrumentation that import __sanitizer_cov_trace_pc_guard__dll() from asan dll, will be using the function provided by the main executable. In other words, when the main executable exports a strong definition for a weak function, we ensure all the dlls use that implementation instead of the default weak implementation. The behavior is similar to linux. Now, every user that want to override a weak function, only has to define and export it. The same for Linux and Windows, and it will work fine. So, there is no difference on the user's side. All the sanitizers will include a file sanitizer_win_weak_interception.cc that register sanitizer's weak functions to be intercepted in the binary section WEAK When the sanitizer dll is initialized, it will execute weak_intercept_init() which will consider all the CB registered in the section WEAK. So, for all the weak functions registered, we will check if a strong definition is provided in the main executable. All the files sanitizer_win_weak_interception.cc are independent, so we do not need to include a specific list of sanitizers. Now, we include [asan|ubsan|sanitizer_coverage]_win_weak_interception.cc and sanitizer_win_weak_interception.cc in asan dll, so when it is initialized, it will consider all the weak functions from asan, ubsan and sanitizer coverage. After this diff, sanitizer coverage is fixed for MD on Windows. In particular libFuzzer can provide custom implementation for all sanitizer coverage's weak functions, and they will be considered by asan dll. Differential Revision: https://reviews.llvm.org/D29168 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293958 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/CMakeLists.txt')
-rw-r--r--lib/sanitizer_common/CMakeLists.txt13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sanitizer_common/CMakeLists.txt b/lib/sanitizer_common/CMakeLists.txt
index fe0632866..c01caadd9 100644
--- a/lib/sanitizer_common/CMakeLists.txt
+++ b/lib/sanitizer_common/CMakeLists.txt
@@ -188,6 +188,19 @@ add_compiler_rt_object_libraries(RTSanitizerCommonLibc
DEFS ${SANITIZER_COMMON_DEFINITIONS})
if(MSVC)
+ add_compiler_rt_object_libraries(SanitizerCommonWeakInterception
+ ${SANITIZER_COMMON_SUPPORTED_OS}
+ ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES sanitizer_win_weak_interception.cc
+ CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DYNAMIC
+ DEFS ${SANITIZER_COMMON_DEFINITIONS})
+ add_compiler_rt_object_libraries(SancovWeakInterception
+ ${SANITIZER_COMMON_SUPPORTED_OS}
+ ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+ SOURCES sanitizer_coverage_win_weak_interception.cc
+ CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DYNAMIC
+ DEFS ${SANITIZER_COMMON_DEFINITIONS})
+
add_compiler_rt_object_libraries(SanitizerCommonDllThunk
${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}