@@ -32,6 +32,20 @@ set(ASAN_SOURCES
32
32
asan_win.cpp
33
33
)
34
34
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
+
35
49
if (NOT WIN32 AND NOT APPLE )
36
50
list (APPEND ASAN_SOURCES
37
51
asan_interceptors_vfork.S
@@ -83,7 +97,13 @@ SET(ASAN_HEADERS
83
97
)
84
98
85
99
include_directories (..)
86
-
100
+ if (MSVC )
101
+ # asan on windows only supports the release dll version of the runtimes, in the interest of
102
+ # only having one asan dll to support/test. Having asan statically linked
103
+ # with the runtime might be possible, but it multiplies the number of scenerios to test.
104
+ # the program USING sanitizers can use whatever version of the runtime it wants to.
105
+ set (CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
106
+ endif ()
87
107
set (ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS} )
88
108
89
109
append_list_if(MSVC /Zl ASAN_CFLAGS)
@@ -117,7 +137,11 @@ append_list_if(WIN32 INTERCEPTION_DYNAMIC_CRT ASAN_DYNAMIC_DEFINITIONS)
117
137
set (ASAN_DYNAMIC_CFLAGS ${ASAN_CFLAGS} )
118
138
append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
119
139
-ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS)
120
- append_list_if(MSVC /DEBUG ASAN_DYNAMIC_LINK_FLAGS)
140
+
141
+ # LLVM turns /OPT:ICF back on when LLVM_ENABLE_PDBs is set
142
+ # we _REALLY_ need to turn it back off for ASAN, because the way
143
+ # asan emulates weak functions from DLLs requires NOICF
144
+ append_list_if(MSVC "/DEBUG;/OPT:NOICF" ASAN_DYNAMIC_LINK_FLAGS)
121
145
122
146
set (ASAN_DYNAMIC_LIBS
123
147
${COMPILER_RT_UNWINDER_LINK_LIBS}
@@ -136,7 +160,7 @@ append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
136
160
add_compiler_rt_object_libraries(RTAsan_dynamic
137
161
OS ${SANITIZER_COMMON_SUPPORTED_OS}
138
162
ARCHS ${ASAN_SUPPORTED_ARCH}
139
- SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
163
+ SOURCES ${ASAN_SOURCES}
140
164
ADDITIONAL_HEADERS ${ASAN_HEADERS}
141
165
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
142
166
DEFS ${ASAN_DYNAMIC_DEFINITIONS} )
@@ -221,46 +245,52 @@ else()
221
245
RTSanitizerCommonSymbolizerInternal
222
246
RTLSanCommon
223
247
RTUbsan)
248
+ if (NOT WIN32 )
249
+ add_compiler_rt_runtime(clang_rt.asan
250
+ STATIC
251
+ ARCHS ${ASAN_SUPPORTED_ARCH}
252
+ OBJECT_LIBS RTAsan_preinit
253
+ RTAsan
254
+ ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
255
+ CFLAGS ${ASAN_CFLAGS}
256
+ DEFS ${ASAN_COMMON_DEFINITIONS}
257
+ PARENT_TARGET asan)
224
258
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)
234
-
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)
259
+ add_compiler_rt_runtime(clang_rt.asan_cxx
260
+ STATIC
261
+ ARCHS ${ASAN_SUPPORTED_ARCH}
262
+ OBJECT_LIBS RTAsan_cxx
263
+ RTUbsan_cxx
264
+ CFLAGS ${ASAN_CFLAGS}
265
+ DEFS ${ASAN_COMMON_DEFINITIONS}
266
+ PARENT_TARGET asan)
243
267
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)
268
+ add_compiler_rt_runtime(clang_rt.asan_static
269
+ STATIC
270
+ ARCHS ${ASAN_SUPPORTED_ARCH}
271
+ OBJECT_LIBS RTAsan_static
272
+ CFLAGS ${ASAN_CFLAGS}
273
+ DEFS ${ASAN_COMMON_DEFINITIONS}
274
+ PARENT_TARGET asan)
251
275
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)
276
+ add_compiler_rt_runtime(clang_rt.asan-preinit
277
+ STATIC
278
+ ARCHS ${ASAN_SUPPORTED_ARCH}
279
+ OBJECT_LIBS RTAsan_preinit
280
+ CFLAGS ${ASAN_CFLAGS}
281
+ DEFS ${ASAN_COMMON_DEFINITIONS}
282
+ PARENT_TARGET asan)
283
+ endif ()
259
284
260
285
foreach (arch ${ASAN_SUPPORTED_ARCH} )
261
286
if (COMPILER_RT_HAS_VERSION_SCRIPT)
287
+ if (WIN32 )
288
+ set (SANITIZER_RT_VERSION_LIST_LIBS clang_rt.asan-${arch} )
289
+ else ()
290
+ set (SANITIZER_RT_VERSION_LIST_LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch} )
291
+ endif ()
262
292
add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch}
263
- LIBS clang_rt.asan- ${arch} clang_rt.asan_cxx- ${arch }
293
+ LIBS ${SANITIZER_RT_VERSION_LIST_LIBS }
264
294
EXTRA asan.syms.extra)
265
295
set (VERSION_SCRIPT_FLAG
266
296
-Wl,--version -script,${CMAKE_CURRENT_BINARY_DIR} /clang_rt.asan-dynamic-${arch} .vers)
@@ -278,25 +308,11 @@ else()
278
308
endif ()
279
309
280
310
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
-
296
311
add_compiler_rt_runtime(clang_rt.asan
297
312
SHARED
298
313
ARCHS ${arch}
299
314
OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
315
+ RTAsan_cxx
300
316
RTAsan_dynamic
301
317
# The only purpose of RTAsan_dynamic_version_script_dummy is to
302
318
# carry a dependency of the shared runtime on the version script.
@@ -324,49 +340,48 @@ else()
324
340
endif ()
325
341
326
342
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
-
345
343
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 ()
351
344
352
345
add_compiler_rt_object_libraries(AsanDynamicRuntimeThunk
353
346
${SANITIZER_COMMON_SUPPORTED_OS}
354
347
ARCHS ${arch}
355
- SOURCES asan_globals_win.cpp
356
- asan_win_dynamic_runtime_thunk.cpp
348
+ SOURCES ${ASAN_DYNAMIC_RUNTIME_THUNK_SOURCES}
357
349
CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
358
350
DEFS ${ASAN_COMMON_DEFINITIONS} )
359
351
360
352
add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk
361
353
STATIC
362
354
ARCHS ${arch}
363
355
OBJECT_LIBS AsanDynamicRuntimeThunk
364
- UbsanDynamicRuntimeThunk
365
- SancovDynamicRuntimeThunk
366
- SanitizerCommonDynamicRuntimeThunk
356
+ UbsanRuntimeThunk
357
+ SancovRuntimeThunk
358
+ SanitizerRuntimeThunk
367
359
CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
368
360
DEFS ${ASAN_COMMON_DEFINITIONS}
369
361
PARENT_TARGET asan)
362
+
363
+ # mingw does not support static linkage of the CRT
364
+ if (NOT MINGW)
365
+ set (STATIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_STATIC_RUNTIME_THUNK" )
366
+
367
+ add_compiler_rt_object_libraries(AsanStaticRuntimeThunk
368
+ ${SANITIZER_COMMON_SUPPORTED_OS}
369
+ ARCHS ${arch}
370
+ SOURCES ${ASAN_STATIC_RUNTIME_THUNK_SOURCES}
371
+ CFLAGS ${ASAN_DYNAMIC_CFLAGS} ${STATIC_RUNTIME_THUNK_CFLAGS}
372
+ DEFS ${ASAN_DYNAMIC_DEFINITIONS} )
373
+
374
+ add_compiler_rt_runtime(clang_rt.asan_static_runtime_thunk
375
+ STATIC
376
+ ARCHS ${arch}
377
+ OBJECT_LIBS AsanStaticRuntimeThunk
378
+ UbsanRuntimeThunk
379
+ SancovRuntimeThunk
380
+ SanitizerRuntimeThunk
381
+ CFLAGS ${ASAN_DYNAMIC_CFLAGS} ${STATIC_RUNTIME_THUNK_CFLAGS}
382
+ DEFS ${ASAN_DYNAMIC_DEFINITIONS}
383
+ PARENT_TARGET asan)
384
+ endif ()
370
385
endif ()
371
386
endforeach ()
372
387
endif ()
0 commit comments