@@ -32,20 +32,6 @@ set(ASAN_SOURCES
3232 asan_win.cpp
3333 )
3434
35- if (WIN32 )
36- set (ASAN_DYNAMIC_RUNTIME_THUNK_SOURCES
37- asan_globals_win.cpp
38- asan_win_common_runtime_thunk.cpp
39- asan_win_dynamic_runtime_thunk.cpp
40- )
41- set (ASAN_STATIC_RUNTIME_THUNK_SOURCES
42- asan_globals_win.cpp
43- asan_malloc_win_thunk.cpp
44- asan_win_common_runtime_thunk.cpp
45- asan_win_static_runtime_thunk.cpp
46- )
47- endif ()
48-
4935if (NOT WIN32 AND NOT APPLE )
5036 list (APPEND ASAN_SOURCES
5137 asan_interceptors_vfork.S
@@ -150,7 +136,7 @@ append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
150136add_compiler_rt_object_libraries(RTAsan_dynamic
151137 OS ${SANITIZER_COMMON_SUPPORTED_OS}
152138 ARCHS ${ASAN_SUPPORTED_ARCH}
153- SOURCES ${ASAN_SOURCES}
139+ SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
154140 ADDITIONAL_HEADERS ${ASAN_HEADERS}
155141 CFLAGS ${ASAN_DYNAMIC_CFLAGS}
156142 DEFS ${ASAN_DYNAMIC_DEFINITIONS} )
@@ -235,52 +221,46 @@ else()
235221 RTSanitizerCommonSymbolizerInternal
236222 RTLSanCommon
237223 RTUbsan)
238- if (NOT WIN32 )
239- add_compiler_rt_runtime(clang_rt.asan
240- STATIC
241- ARCHS ${ASAN_SUPPORTED_ARCH}
242- OBJECT_LIBS RTAsan_preinit
243- RTAsan
244- ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
245- CFLAGS ${ASAN_CFLAGS}
246- DEFS ${ASAN_COMMON_DEFINITIONS}
247- PARENT_TARGET asan)
248224
249- add_compiler_rt_runtime(clang_rt.asan_cxx
250- STATIC
251- ARCHS ${ASAN_SUPPORTED_ARCH}
252- OBJECT_LIBS RTAsan_cxx
253- RTUbsan_cxx
254- CFLAGS ${ASAN_CFLAGS}
255- DEFS ${ASAN_COMMON_DEFINITIONS}
256- PARENT_TARGET asan)
225+ add_compiler_rt_runtime(clang_rt.asan
226+ STATIC
227+ ARCHS ${ASAN_SUPPORTED_ARCH}
228+ OBJECT_LIBS RTAsan_preinit
229+ RTAsan
230+ ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
231+ CFLAGS ${ASAN_CFLAGS}
232+ DEFS ${ASAN_COMMON_DEFINITIONS}
233+ PARENT_TARGET asan)
257234
258- add_compiler_rt_runtime(clang_rt.asan_static
259- STATIC
260- ARCHS ${ASAN_SUPPORTED_ARCH}
261- OBJECT_LIBS RTAsan_static
262- CFLAGS ${ASAN_CFLAGS}
263- DEFS ${ASAN_COMMON_DEFINITIONS}
264- PARENT_TARGET asan)
235+ add_compiler_rt_runtime(clang_rt.asan_cxx
236+ STATIC
237+ ARCHS ${ASAN_SUPPORTED_ARCH}
238+ OBJECT_LIBS RTAsan_cxx
239+ RTUbsan_cxx
240+ CFLAGS ${ASAN_CFLAGS}
241+ DEFS ${ASAN_COMMON_DEFINITIONS}
242+ PARENT_TARGET asan)
265243
266- add_compiler_rt_runtime(clang_rt.asan-preinit
267- STATIC
268- ARCHS ${ASAN_SUPPORTED_ARCH}
269- OBJECT_LIBS RTAsan_preinit
270- CFLAGS ${ASAN_CFLAGS}
271- DEFS ${ASAN_COMMON_DEFINITIONS}
272- PARENT_TARGET asan)
273- endif ()
244+ add_compiler_rt_runtime(clang_rt.asan_static
245+ STATIC
246+ ARCHS ${ASAN_SUPPORTED_ARCH}
247+ OBJECT_LIBS RTAsan_static
248+ CFLAGS ${ASAN_CFLAGS}
249+ DEFS ${ASAN_COMMON_DEFINITIONS}
250+ PARENT_TARGET asan)
251+
252+ add_compiler_rt_runtime(clang_rt.asan-preinit
253+ STATIC
254+ ARCHS ${ASAN_SUPPORTED_ARCH}
255+ OBJECT_LIBS RTAsan_preinit
256+ CFLAGS ${ASAN_CFLAGS}
257+ DEFS ${ASAN_COMMON_DEFINITIONS}
258+ PARENT_TARGET asan)
274259
275260 foreach (arch ${ASAN_SUPPORTED_ARCH} )
276261 if (COMPILER_RT_HAS_VERSION_SCRIPT)
277- if (WIN32 )
278- set (SANITIZER_RT_VERSION_LIST_LIBS clang_rt.asan-${arch} )
279- else ()
280- set (SANITIZER_RT_VERSION_LIST_LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch} )
281- endif ()
282262 add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch}
283- LIBS ${SANITIZER_RT_VERSION_LIST_LIBS }
263+ LIBS clang_rt.asan- ${arch} clang_rt.asan_cxx- ${arch }
284264 EXTRA asan.syms.extra)
285265 set (VERSION_SCRIPT_FLAG
286266 -Wl,--version -script,${CMAKE_CURRENT_BINARY_DIR} /clang_rt.asan-dynamic-${arch} .vers)
@@ -298,11 +278,25 @@ else()
298278 endif ()
299279
300280 set (ASAN_DYNAMIC_WEAK_INTERCEPTION)
281+ if (WIN32 )
282+ add_compiler_rt_object_libraries(AsanWeakInterception
283+ ${SANITIZER_COMMON_SUPPORTED_OS}
284+ ARCHS ${arch}
285+ SOURCES
286+ asan_win_weak_interception.cpp
287+ CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DYNAMIC
288+ DEFS ${ASAN_COMMON_DEFINITIONS} )
289+ set (ASAN_DYNAMIC_WEAK_INTERCEPTION
290+ AsanWeakInterception
291+ UbsanWeakInterception
292+ SancovWeakInterception
293+ SanitizerCommonWeakInterception)
294+ endif ()
295+
301296 add_compiler_rt_runtime(clang_rt.asan
302297 SHARED
303298 ARCHS ${arch}
304299 OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
305- RTAsan_cxx
306300 RTAsan_dynamic
307301 # The only purpose of RTAsan_dynamic_version_script_dummy is to
308302 # carry a dependency of the shared runtime on the version script.
@@ -330,48 +324,49 @@ else()
330324 endif ()
331325
332326 if (WIN32 )
327+ add_compiler_rt_object_libraries(AsanDllThunk
328+ ${SANITIZER_COMMON_SUPPORTED_OS}
329+ ARCHS ${arch}
330+ SOURCES asan_globals_win.cpp
331+ asan_win_dll_thunk.cpp
332+ CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DLL_THUNK
333+ DEFS ${ASAN_COMMON_DEFINITIONS} )
334+
335+ add_compiler_rt_runtime(clang_rt.asan_dll_thunk
336+ STATIC
337+ ARCHS ${arch}
338+ OBJECT_LIBS AsanDllThunk
339+ UbsanDllThunk
340+ SancovDllThunk
341+ SanitizerCommonDllThunk
342+ SOURCES $<TARGET_OBJECTS:RTInterception.${arch} >
343+ PARENT_TARGET asan)
344+
333345 set (DYNAMIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_DYNAMIC_RUNTIME_THUNK" )
346+ if (MSVC )
347+ list (APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-Zl" )
348+ elseif (CMAKE_C_COMPILER_ID MATCHES Clang)
349+ list (APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-nodefaultlibs" )
350+ endif ()
334351
335352 add_compiler_rt_object_libraries(AsanDynamicRuntimeThunk
336353 ${SANITIZER_COMMON_SUPPORTED_OS}
337354 ARCHS ${arch}
338- SOURCES ${ASAN_DYNAMIC_RUNTIME_THUNK_SOURCES}
355+ SOURCES asan_globals_win.cpp
356+ asan_win_dynamic_runtime_thunk.cpp
339357 CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
340358 DEFS ${ASAN_COMMON_DEFINITIONS} )
341359
342360 add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk
343361 STATIC
344362 ARCHS ${arch}
345363 OBJECT_LIBS AsanDynamicRuntimeThunk
346- UbsanRuntimeThunk
347- SancovRuntimeThunk
348- SanitizerRuntimeThunk
364+ UbsanDynamicRuntimeThunk
365+ SancovDynamicRuntimeThunk
366+ SanitizerCommonDynamicRuntimeThunk
349367 CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
350368 DEFS ${ASAN_COMMON_DEFINITIONS}
351369 PARENT_TARGET asan)
352-
353- # mingw does not support static linkage of the CRT
354- if (NOT MINGW)
355- set (STATIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_STATIC_RUNTIME_THUNK" )
356-
357- add_compiler_rt_object_libraries(AsanStaticRuntimeThunk
358- ${SANITIZER_COMMON_SUPPORTED_OS}
359- ARCHS ${arch}
360- SOURCES ${ASAN_STATIC_RUNTIME_THUNK_SOURCES}
361- CFLAGS ${ASAN_DYNAMIC_CFLAGS} ${STATIC_RUNTIME_THUNK_CFLAGS}
362- DEFS ${ASAN_DYNAMIC_DEFINITIONS} )
363-
364- add_compiler_rt_runtime(clang_rt.asan_static_runtime_thunk
365- STATIC
366- ARCHS ${arch}
367- OBJECT_LIBS AsanStaticRuntimeThunk
368- UbsanRuntimeThunk
369- SancovRuntimeThunk
370- SanitizerRuntimeThunk
371- CFLAGS ${ASAN_DYNAMIC_CFLAGS} ${STATIC_RUNTIME_THUNK_CFLAGS}
372- DEFS ${ASAN_DYNAMIC_DEFINITIONS}
373- PARENT_TARGET asan)
374- endif ()
375370 endif ()
376371 endforeach ()
377372endif ()
0 commit comments