1 include(CMakePushCheckState)
2 include(CheckCXXCompilerFlag)
3 include(CheckLibraryExists)
4 include(CheckSymbolExists)
7 function(check_linker_flag flag out_var)
8 cmake_push_check_state()
9 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
10 check_cxx_compiler_flag("" ${out_var})
11 cmake_pop_check_state()
15 check_cxx_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG)
16 check_cxx_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG)
17 check_cxx_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
18 check_cxx_compiler_flag(-fno-exceptions COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
19 check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)
20 check_cxx_compiler_flag(-funwind-tables COMPILER_RT_HAS_FUNWIND_TABLES_FLAG)
21 check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG)
22 check_cxx_compiler_flag(-fno-sanitize=safe-stack COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG)
23 check_cxx_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
24 check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG)
25 check_cxx_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG)
26 check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
27 check_cxx_compiler_flag(-std=c++11 COMPILER_RT_HAS_STD_CXX11_FLAG)
28 check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
29 check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG)
30 check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG)
32 check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG)
33 check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG)
34 check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG)
35 check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG)
38 check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG)
39 check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG)
40 check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG)
43 check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG)
44 check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG)
45 check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG)
46 check_cxx_compiler_flag("-Werror -Wglobal-constructors" COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG)
47 check_cxx_compiler_flag("-Werror -Wc99-extensions" COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG)
48 check_cxx_compiler_flag("-Werror -Wgnu" COMPILER_RT_HAS_WGNU_FLAG)
49 check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG)
50 check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
52 check_cxx_compiler_flag(/W3 COMPILER_RT_HAS_W3_FLAG)
53 check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG)
54 check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG)
55 check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG)
56 check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG)
57 check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG)
58 check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
61 check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
64 check_library_exists(c printf "" COMPILER_RT_HAS_LIBC)
65 check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
66 check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
67 check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
68 check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
69 check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
73 check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
74 check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
79 # List of all architectures we can target.
80 set(COMPILER_RT_SUPPORTED_ARCH)
82 # Try to compile a very simple source file to ensure we can target the given
83 # platform. We use the results of these tests to build only the various target
84 # runtime libraries supported by our current compilers cross-compiling
86 set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
87 file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
89 function(check_compile_definition def argstring out_var)
90 if("${def}" STREQUAL "")
91 set(${out_var} TRUE PARENT_SCOPE)
94 cmake_push_check_state()
95 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
96 check_symbol_exists(${def} "" ${out_var})
97 cmake_pop_check_state()
100 # test_target_arch(<arch> <def> <target flags...>)
101 # Checks if architecture is supported: runs host compiler with provided
102 # flags to verify that:
103 # 1) <def> is defined (if non-empty)
104 # 2) simple file can be successfully built.
105 # If successful, saves target flags for this architecture.
106 macro(test_target_arch arch def)
107 set(TARGET_${arch}_CFLAGS ${ARGN})
110 set(argstring "${argstring} ${arg}")
112 check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
113 if(NOT HAS_${arch}_DEF)
114 set(CAN_TARGET_${arch} FALSE)
116 set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
117 try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
118 COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
119 OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
120 CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
122 if(${CAN_TARGET_${arch}})
123 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
124 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND
125 COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
126 # Bail out if we cannot target the architecture we plan to test.
127 message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
131 # Add $arch as supported with no additional flags.
132 macro(add_default_target_arch arch)
133 set(TARGET_${arch}_CFLAGS "")
134 set(CAN_TARGET_${arch} 1)
135 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
138 macro(detect_target_arch)
139 check_symbol_exists(__arm__ "" __ARM)
140 check_symbol_exists(__aarch64__ "" __AARCH64)
141 check_symbol_exists(__x86_64__ "" __X86_64)
142 check_symbol_exists(__i686__ "" __I686)
143 check_symbol_exists(__i386__ "" __I386)
144 check_symbol_exists(__mips__ "" __MIPS)
145 check_symbol_exists(__mips64__ "" __MIPS64)
147 add_default_target_arch(arm)
149 add_default_target_arch(aarch64)
151 add_default_target_arch(x86_64)
153 add_default_target_arch(i686)
155 add_default_target_arch(i386)
156 elseif(__MIPS64) # must be checked before __MIPS
157 add_default_target_arch(mips64)
159 add_default_target_arch(mips)
163 # Detect whether the current target platform is 32-bit or 64-bit, and setup
164 # the correct commandline flags needed to attempt to target 32-bit and 64-bit.
165 if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
166 NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
167 message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
170 # Generate the COMPILER_RT_SUPPORTED_ARCH list.
172 # Examine compiler output to determine target architecture.
174 set(COMPILER_RT_OS_SUFFIX "-android")
175 elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
176 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
178 test_target_arch(x86_64 "" "-m64")
179 # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may
180 # target different variant than "$CMAKE_C_COMPILER -m32". This part should
181 # be gone after we resolve PR14109.
182 test_target_arch(i686 __i686__ "-m32")
183 test_target_arch(i386 __i386__ "-m32")
185 if (CMAKE_SIZEOF_VOID_P EQUAL 4)
186 test_target_arch(i386 "" "")
188 test_target_arch(x86_64 "" "")
191 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
192 TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
193 if(HOST_IS_BIG_ENDIAN)
194 test_target_arch(powerpc64 "" "-m64")
196 test_target_arch(powerpc64le "" "-m64")
198 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
199 # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
200 # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match
201 # clang's default CPU's. In the 64-bit case, we must also specify the ABI
202 # since the default ABI differs between gcc and clang.
203 # FIXME: Ideally, we would build the N32 library too.
204 test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
205 test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64")
206 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
207 test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
208 test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64")
209 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
210 if("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES "eabihf")
211 test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
213 test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
215 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
216 test_target_arch(aarch32 "" "-march=armv8-a")
217 elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
218 test_target_arch(aarch64 "" "-march=armv8-a")
220 set(COMPILER_RT_OS_SUFFIX "")
223 # Takes ${ARGN} and puts only supported architectures in @out_var list.
224 function(filter_available_targets out_var)
225 set(archs ${${out_var}})
226 foreach(arch ${ARGN})
227 list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
228 if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
229 list(APPEND archs ${arch})
232 set(${out_var} ${archs} PARENT_SCOPE)
235 # Returns a list of architecture specific target cflags in @out_var list.
236 function(get_target_flags_for_arch arch out_var)
237 list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
238 if(ARCH_INDEX EQUAL -1)
239 message(FATAL_ERROR "Unsupported architecture: ${arch}")
242 set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
244 # This is only called in constructing cflags for tests executing on the
245 # host. This will need to all be cleaned up to support building tests
246 # for cross-targeted hardware (i.e. iOS).
247 set(${out_var} -arch ${arch} PARENT_SCOPE)
256 set(MIPS32 mips mipsel)
257 set(MIPS64 mips64 mips64el)
258 set(PPC64 powerpc64 powerpc64le)
262 set(ARM32 armv7 armv7s)
263 set(X86_64 x86_64 x86_64h)
266 set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
268 set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
269 ${ARM32} ${ARM64} ${MIPS32} ${MIPS64})
270 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
271 ${MIPS32} ${MIPS64} ${PPC64})
272 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
273 set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
274 set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
275 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
277 set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
278 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
279 ${MIPS32} ${MIPS64} ${PPC64})
280 set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64})
283 include(CompilerRTDarwinUtils)
285 option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off)
287 find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
288 find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
289 find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
291 # Note: In order to target x86_64h on OS X the minimum deployment target must
293 set(SANITIZER_COMMON_SUPPORTED_OS osx)
294 set(BUILTIN_SUPPORTED_OS osx)
295 set(PROFILE_SUPPORTED_OS osx)
296 set(TSAN_SUPPORTED_OS osx)
297 if(NOT SANITIZER_MIN_OSX_VERSION)
298 string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)"
299 MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
300 if(MACOSX_VERSION_MIN_FLAG)
301 set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}")
302 elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
303 set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
305 set(SANITIZER_MIN_OSX_VERSION 10.9)
307 if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
308 message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}")
312 # We're setting the flag manually for each target OS
313 set(CMAKE_OSX_DEPLOYMENT_TARGET "")
315 set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
316 set(DARWIN_COMMON_LINKFLAGS
321 set(DARWIN_osx_CFLAGS
322 ${DARWIN_COMMON_CFLAGS}
323 -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
324 set(DARWIN_osx_LINKFLAGS
325 ${DARWIN_COMMON_LINKFLAGS}
326 -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
327 set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
328 set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
329 -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
331 if(DARWIN_osx_SYSROOT)
332 list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
333 list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${DARWIN_osx_SYSROOT})
336 # Figure out which arches to use for each OS
337 darwin_get_toolchain_supported_archs(toolchain_arches)
338 message(STATUS "Toolchain supported arches: ${toolchain_arches}")
340 if(NOT MACOSX_VERSION_MIN_FLAG)
341 darwin_test_archs(osx
344 message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
345 foreach(arch ${DARWIN_osx_ARCHS})
346 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
347 set(CAN_TARGET_${arch} 1)
350 # Need to build a 10.4 compatible libclang_rt
351 set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT})
352 set(DARWIN_10.4_BUILTIN_MIN_VER 10.4)
353 set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG
354 -mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER})
355 set(DARWIN_10.4_SKIP_CC_KEXT On)
356 darwin_test_archs(10.4
359 message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}")
360 if(DARWIN_10.4_ARCHS)
361 # don't include the Haswell slice in the 10.4 compatibility library
362 list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h)
363 list(APPEND BUILTIN_SUPPORTED_OS 10.4)
366 if(DARWIN_iossim_SYSROOT)
367 set(DARWIN_iossim_CFLAGS
368 ${DARWIN_COMMON_CFLAGS}
369 -mios-simulator-version-min=7.0
370 -isysroot ${DARWIN_iossim_SYSROOT})
371 set(DARWIN_iossim_LINKFLAGS
372 ${DARWIN_COMMON_LINKFLAGS}
373 -mios-simulator-version-min=7.0
374 -isysroot ${DARWIN_iossim_SYSROOT})
375 set(DARWIN_iossim_BUILTIN_MIN_VER 6.0)
376 set(DARWIN_iossim_BUILTIN_MIN_VER_FLAG
377 -mios-simulator-version-min=${DARWIN_iossim_BUILTIN_MIN_VER})
379 set(DARWIN_iossim_SKIP_CC_KEXT On)
380 darwin_test_archs(iossim
383 message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}")
384 if(DARWIN_iossim_ARCHS)
385 list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim)
387 foreach(arch ${DARWIN_iossim_ARCHS})
388 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
389 set(CAN_TARGET_${arch} 1)
393 if(DARWIN_ios_SYSROOT AND COMPILER_RT_ENABLE_IOS)
394 set(DARWIN_ios_CFLAGS
395 ${DARWIN_COMMON_CFLAGS}
396 -miphoneos-version-min=7.0
397 -isysroot ${DARWIN_ios_SYSROOT})
398 set(DARWIN_ios_LINKFLAGS
399 ${DARWIN_COMMON_LINKFLAGS}
400 -miphoneos-version-min=7.0
401 -isysroot ${DARWIN_ios_SYSROOT})
402 set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
403 set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
404 -miphoneos-version-min=${DARWIN_ios_BUILTIN_MIN_VER})
406 darwin_test_archs(ios
409 message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}")
411 list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios)
412 list(APPEND BUILTIN_SUPPORTED_OS ios)
413 list(APPEND PROFILE_SUPPORTED_OS ios)
414 list(APPEND BUILTIN_SUPPORTED_OS iossim)
416 foreach(arch ${DARWIN_ios_ARCHS})
417 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
418 set(CAN_TARGET_${arch} 1)
424 include(CompilerRTUtils)
426 list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches)
428 list_union(SANITIZER_COMMON_SUPPORTED_ARCH
429 ALL_SANITIZER_COMMON_SUPPORTED_ARCH
430 COMPILER_RT_SUPPORTED_ARCH
432 set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
433 set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
434 list_union(ASAN_SUPPORTED_ARCH
435 ALL_ASAN_SUPPORTED_ARCH
436 SANITIZER_COMMON_SUPPORTED_ARCH)
437 list_union(DFSAN_SUPPORTED_ARCH
438 ALL_DFSAN_SUPPORTED_ARCH
439 SANITIZER_COMMON_SUPPORTED_ARCH)
440 list_union(LSAN_SUPPORTED_ARCH
441 ALL_LSAN_SUPPORTED_ARCH
442 SANITIZER_COMMON_SUPPORTED_ARCH)
443 list_union(MSAN_SUPPORTED_ARCH
444 ALL_MSAN_SUPPORTED_ARCH
445 SANITIZER_COMMON_SUPPORTED_ARCH)
446 list_union(PROFILE_SUPPORTED_ARCH
447 ALL_PROFILE_SUPPORTED_ARCH
448 SANITIZER_COMMON_SUPPORTED_ARCH)
449 list_union(TSAN_SUPPORTED_ARCH
450 ALL_TSAN_SUPPORTED_ARCH
451 SANITIZER_COMMON_SUPPORTED_ARCH)
452 list_union(UBSAN_SUPPORTED_ARCH
453 ALL_UBSAN_SUPPORTED_ARCH
454 SANITIZER_COMMON_SUPPORTED_ARCH)
455 list_union(SAFESTACK_SUPPORTED_ARCH
456 ALL_SAFESTACK_SUPPORTED_ARCH
457 SANITIZER_COMMON_SUPPORTED_ARCH)
459 # Architectures supported by compiler-rt libraries.
460 filter_available_targets(BUILTIN_SUPPORTED_ARCH
461 ${ALL_BUILTIN_SUPPORTED_ARCH})
462 filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
463 ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH})
464 # LSan and UBSan common files should be available on all architectures
465 # supported by other sanitizers (even if they build into dummy object files).
466 filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
467 ${SANITIZER_COMMON_SUPPORTED_ARCH})
468 filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
469 ${SANITIZER_COMMON_SUPPORTED_ARCH})
470 filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
471 filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
472 filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
473 filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
474 filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
475 filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
476 filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
477 filter_available_targets(SAFESTACK_SUPPORTED_ARCH
478 ${ALL_SAFESTACK_SUPPORTED_ARCH})
481 message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
484 set(OS_NAME "Android")
486 set(OS_NAME "${CMAKE_SYSTEM_NAME}")
489 if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
490 (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR
491 (OS_NAME MATCHES "Windows" AND MSVC)))
492 set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
494 set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
497 if (COMPILER_RT_HAS_SANITIZER_COMMON AND
498 (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
499 set(COMPILER_RT_HAS_INTERCEPTION TRUE)
501 set(COMPILER_RT_HAS_INTERCEPTION FALSE)
504 if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND
505 (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
506 set(COMPILER_RT_HAS_ASAN TRUE)
508 set(COMPILER_RT_HAS_ASAN FALSE)
511 if (OS_NAME MATCHES "Linux|FreeBSD|Windows")
512 set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
514 set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
517 # TODO: Add builtins support.
519 if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
520 OS_NAME MATCHES "Linux")
521 set(COMPILER_RT_HAS_DFSAN TRUE)
523 set(COMPILER_RT_HAS_DFSAN FALSE)
526 if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
527 OS_NAME MATCHES "Linux|FreeBSD")
528 set(COMPILER_RT_HAS_LSAN TRUE)
530 set(COMPILER_RT_HAS_LSAN FALSE)
533 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
534 OS_NAME MATCHES "Linux")
535 set(COMPILER_RT_HAS_MSAN TRUE)
537 set(COMPILER_RT_HAS_MSAN FALSE)
540 if (PROFILE_SUPPORTED_ARCH AND
541 OS_NAME MATCHES "Darwin|Linux|FreeBSD")
542 set(COMPILER_RT_HAS_PROFILE TRUE)
544 set(COMPILER_RT_HAS_PROFILE FALSE)
547 if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
548 OS_NAME MATCHES "Linux|FreeBSD")
549 set(COMPILER_RT_HAS_TSAN TRUE)
551 set(COMPILER_RT_HAS_TSAN FALSE)
555 option(COMPILER_RT_ENABLE_TSAN_OSX "Enable building TSan for OS X - Experimental" Off)
556 if(COMPILER_RT_ENABLE_TSAN_OSX)
557 set(COMPILER_RT_HAS_TSAN TRUE)
561 if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
562 OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows")
563 set(COMPILER_RT_HAS_UBSAN TRUE)
565 set(COMPILER_RT_HAS_UBSAN FALSE)
568 # -msse3 flag is not valid for Mips therefore clang gives a warning
569 # message with -msse3. But check_c_compiler_flags() checks only for
570 # compiler error messages. Therefore COMPILER_RT_HAS_MSSE3_FLAG turns out to be
571 # true on Mips, so we make it false here.
572 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
573 set(COMPILER_RT_HAS_MSSE3_FLAG FALSE)
576 if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
577 OS_NAME MATCHES "Darwin|Linux|FreeBSD")
578 set(COMPILER_RT_HAS_SAFESTACK TRUE)
580 set(COMPILER_RT_HAS_SAFESTACK FALSE)