]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/cmake/config-ix.cmake
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / compiler-rt / cmake / config-ix.cmake
1 include(CMakePushCheckState)
2 include(CheckCXXCompilerFlag)
3 include(CheckLibraryExists)
4 include(CheckSymbolExists)
5 include(TestBigEndian)
6
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()
12 endfunction()
13
14 # CodeGen options.
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)
31
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)
36
37 # Debug info flags.
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)
41
42 # Warnings.
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)
51
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)
59
60 # Symbols.
61 check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
62
63 # Libraries.
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)
70
71 # Linker flags.
72 if(ANDROID)
73 check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
74 check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
75 endif()
76
77 # Architectures.
78
79 # List of all architectures we can target.
80 set(COMPILER_RT_SUPPORTED_ARCH)
81
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
85 # abilities.
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")
88
89 function(check_compile_definition def argstring out_var)
90 if("${def}" STREQUAL "")
91 set(${out_var} TRUE PARENT_SCOPE)
92 return()
93 endif()
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()
98 endfunction()
99
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})
108 set(argstring "")
109 foreach(arg ${ARGN})
110 set(argstring "${argstring} ${arg}")
111 endforeach()
112 check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
113 if(NOT HAS_${arch}_DEF)
114 set(CAN_TARGET_${arch} FALSE)
115 else()
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}")
121 endif()
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}")
128 endif()
129 endmacro()
130
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})
136 endmacro()
137
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)
146 if(__ARM)
147 add_default_target_arch(arm)
148 elseif(__AARCH64)
149 add_default_target_arch(aarch64)
150 elseif(__X86_64)
151 add_default_target_arch(x86_64)
152 elseif(__I686)
153 add_default_target_arch(i686)
154 elseif(__I386)
155 add_default_target_arch(i386)
156 elseif(__MIPS64) # must be checked before __MIPS
157 add_default_target_arch(mips64)
158 elseif(__MIPS)
159 add_default_target_arch(mips)
160 endif()
161 endmacro()
162
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.")
168 endif()
169
170 # Generate the COMPILER_RT_SUPPORTED_ARCH list.
171 if(ANDROID)
172 # Examine compiler output to determine target architecture.
173 detect_target_arch()
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")
177 if(NOT MSVC)
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")
184 else()
185 if (CMAKE_SIZEOF_VOID_P EQUAL 4)
186 test_target_arch(i386 "" "")
187 else()
188 test_target_arch(x86_64 "" "")
189 endif()
190 endif()
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")
195 else()
196 test_target_arch(powerpc64le "" "-m64")
197 endif()
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")
212 else()
213 test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
214 endif()
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")
219 endif()
220 set(COMPILER_RT_OS_SUFFIX "")
221 endif()
222
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})
230 endif()
231 endforeach()
232 set(${out_var} ${archs} PARENT_SCOPE)
233 endfunction()
234
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}")
240 else()
241 if (NOT APPLE)
242 set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
243 else()
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)
248 endif()
249 endif()
250 endfunction()
251
252 set(ARM64 aarch64)
253 set(ARM32 arm armhf)
254 set(X86 i386 i686)
255 set(X86_64 x86_64)
256 set(MIPS32 mips mipsel)
257 set(MIPS64 mips64 mips64el)
258 set(PPC64 powerpc64 powerpc64le)
259
260 if(APPLE)
261 set(ARM64 arm64)
262 set(ARM32 armv7 armv7s)
263 set(X86_64 x86_64 x86_64h)
264 endif()
265
266 set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
267 ${MIPS32} ${MIPS64})
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}
276 ${MIPS32} ${MIPS64})
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})
281
282 if(APPLE)
283 include(CompilerRTDarwinUtils)
284
285 option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off)
286
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)
290
291 # Note: In order to target x86_64h on OS X the minimum deployment target must
292 # be 10.8 or higher.
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})
304 else()
305 set(SANITIZER_MIN_OSX_VERSION 10.9)
306 endif()
307 if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
308 message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}")
309 endif()
310 endif()
311
312 # We're setting the flag manually for each target OS
313 set(CMAKE_OSX_DEPLOYMENT_TARGET "")
314
315 set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
316 set(DARWIN_COMMON_LINKFLAGS
317 -stdlib=libc++
318 -lc++
319 -lc++abi)
320
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})
330
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})
334 endif()
335
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}")
339
340 if(NOT MACOSX_VERSION_MIN_FLAG)
341 darwin_test_archs(osx
342 DARWIN_osx_ARCHS
343 ${toolchain_arches})
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)
348 endforeach()
349
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
357 DARWIN_10.4_ARCHS
358 ${toolchain_arches})
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)
364 endif()
365
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})
378
379 set(DARWIN_iossim_SKIP_CC_KEXT On)
380 darwin_test_archs(iossim
381 DARWIN_iossim_ARCHS
382 ${toolchain_arches})
383 message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}")
384 if(DARWIN_iossim_ARCHS)
385 list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim)
386 endif()
387 foreach(arch ${DARWIN_iossim_ARCHS})
388 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
389 set(CAN_TARGET_${arch} 1)
390 endforeach()
391 endif()
392
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})
405
406 darwin_test_archs(ios
407 DARWIN_ios_ARCHS
408 ${toolchain_arches})
409 message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}")
410 if(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)
415 endif()
416 foreach(arch ${DARWIN_ios_ARCHS})
417 list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
418 set(CAN_TARGET_${arch} 1)
419 endforeach()
420 endif()
421 endif()
422
423 # for list_union
424 include(CompilerRTUtils)
425
426 list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches)
427
428 list_union(SANITIZER_COMMON_SUPPORTED_ARCH
429 ALL_SANITIZER_COMMON_SUPPORTED_ARCH
430 COMPILER_RT_SUPPORTED_ARCH
431 )
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)
458 else()
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})
479 endif()
480
481 message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
482
483 if(ANDROID)
484 set(OS_NAME "Android")
485 else()
486 set(OS_NAME "${CMAKE_SYSTEM_NAME}")
487 endif()
488
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)
493 else()
494 set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
495 endif()
496
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)
500 else()
501 set(COMPILER_RT_HAS_INTERCEPTION FALSE)
502 endif()
503
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)
507 else()
508 set(COMPILER_RT_HAS_ASAN FALSE)
509 endif()
510
511 if (OS_NAME MATCHES "Linux|FreeBSD|Windows")
512 set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
513 else()
514 set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
515 endif()
516
517 # TODO: Add builtins support.
518
519 if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
520 OS_NAME MATCHES "Linux")
521 set(COMPILER_RT_HAS_DFSAN TRUE)
522 else()
523 set(COMPILER_RT_HAS_DFSAN FALSE)
524 endif()
525
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)
529 else()
530 set(COMPILER_RT_HAS_LSAN FALSE)
531 endif()
532
533 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
534 OS_NAME MATCHES "Linux")
535 set(COMPILER_RT_HAS_MSAN TRUE)
536 else()
537 set(COMPILER_RT_HAS_MSAN FALSE)
538 endif()
539
540 if (PROFILE_SUPPORTED_ARCH AND
541 OS_NAME MATCHES "Darwin|Linux|FreeBSD")
542 set(COMPILER_RT_HAS_PROFILE TRUE)
543 else()
544 set(COMPILER_RT_HAS_PROFILE FALSE)
545 endif()
546
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)
550 else()
551 set(COMPILER_RT_HAS_TSAN FALSE)
552 endif()
553
554 if(APPLE)
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)
558 endif()
559 endif()
560
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)
564 else()
565 set(COMPILER_RT_HAS_UBSAN FALSE)
566 endif()
567
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)
574 endif()
575
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)
579 else()
580 set(COMPILER_RT_HAS_SAFESTACK FALSE)
581 endif()