• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(CMakePushCheckState)
2include(CheckCXXCompilerFlag)
3include(CheckLibraryExists)
4include(CheckSymbolExists)
5include(TestBigEndian)
6
7function(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()
12endfunction()
13
14# CodeGen options.
15check_cxx_compiler_flag(-fPIC                COMPILER_RT_HAS_FPIC_FLAG)
16check_cxx_compiler_flag(-fPIE                COMPILER_RT_HAS_FPIE_FLAG)
17check_cxx_compiler_flag(-fno-builtin         COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
18check_cxx_compiler_flag(-fno-exceptions      COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
19check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)
20check_cxx_compiler_flag(-funwind-tables      COMPILER_RT_HAS_FUNWIND_TABLES_FLAG)
21check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG)
22check_cxx_compiler_flag(-fno-sanitize=safe-stack COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG)
23check_cxx_compiler_flag(-fvisibility=hidden  COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
24check_cxx_compiler_flag(-fno-rtti            COMPILER_RT_HAS_FNO_RTTI_FLAG)
25check_cxx_compiler_flag(-ffreestanding       COMPILER_RT_HAS_FFREESTANDING_FLAG)
26check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
27check_cxx_compiler_flag(-std=c++11           COMPILER_RT_HAS_STD_CXX11_FLAG)
28check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
29check_cxx_compiler_flag(-fno-lto             COMPILER_RT_HAS_FNO_LTO_FLAG)
30check_cxx_compiler_flag("-Werror -msse3" COMPILER_RT_HAS_MSSE3_FLAG)
31check_cxx_compiler_flag(-std=c99             COMPILER_RT_HAS_STD_C99_FLAG)
32check_cxx_compiler_flag(--sysroot=.          COMPILER_RT_HAS_SYSROOT_FLAG)
33
34if(NOT WIN32 AND NOT CYGWIN)
35  # MinGW warns if -fvisibility-inlines-hidden is used.
36  check_cxx_compiler_flag("-fvisibility-inlines-hidden" COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG)
37endif()
38
39check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG)
40check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG)
41check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG)
42check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG)
43
44# Debug info flags.
45check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG)
46check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG)
47check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG)
48
49# Warnings.
50check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG)
51check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG)
52check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG)
53check_cxx_compiler_flag("-Werror -Wglobal-constructors"   COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG)
54check_cxx_compiler_flag("-Werror -Wc99-extensions"     COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG)
55check_cxx_compiler_flag("-Werror -Wgnu"                COMPILER_RT_HAS_WGNU_FLAG)
56check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor"   COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG)
57check_cxx_compiler_flag("-Werror -Wvariadic-macros"    COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
58
59check_cxx_compiler_flag(/W3 COMPILER_RT_HAS_W3_FLAG)
60check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG)
61check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG)
62check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG)
63check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG)
64check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG)
65check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
66
67# Symbols.
68check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
69
70# Libraries.
71check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
72check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
73check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
74check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
75check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
76check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
77
78# Linker flags.
79if(ANDROID)
80  check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
81  check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
82endif()
83
84# Architectures.
85
86# List of all architectures we can target.
87set(COMPILER_RT_SUPPORTED_ARCH)
88
89# Try to compile a very simple source file to ensure we can target the given
90# platform. We use the results of these tests to build only the various target
91# runtime libraries supported by our current compilers cross-compiling
92# abilities.
93set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
94file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n")
95
96function(check_compile_definition def argstring out_var)
97  if("${def}" STREQUAL "")
98    set(${out_var} TRUE PARENT_SCOPE)
99    return()
100  endif()
101  cmake_push_check_state()
102  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
103  check_symbol_exists(${def} "" ${out_var})
104  cmake_pop_check_state()
105endfunction()
106
107# test_target_arch(<arch> <def> <target flags...>)
108# Checks if architecture is supported: runs host compiler with provided
109# flags to verify that:
110#   1) <def> is defined (if non-empty)
111#   2) simple file can be successfully built.
112# If successful, saves target flags for this architecture.
113macro(test_target_arch arch def)
114  set(TARGET_${arch}_CFLAGS ${ARGN})
115  set(argstring "")
116  foreach(arg ${ARGN})
117    set(argstring "${argstring} ${arg}")
118  endforeach()
119  check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF)
120  if(NOT HAS_${arch}_DEF)
121    set(CAN_TARGET_${arch} FALSE)
122  else()
123    set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}")
124    try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE}
125                COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}"
126                OUTPUT_VARIABLE TARGET_${arch}_OUTPUT
127                CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}")
128  endif()
129  if(${CAN_TARGET_${arch}})
130    list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
131  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "${arch}" AND
132         COMPILER_RT_HAS_EXPLICIT_DEFAULT_TARGET_TRIPLE)
133    # Bail out if we cannot target the architecture we plan to test.
134    message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}")
135  endif()
136endmacro()
137
138# Add $arch as supported with no additional flags.
139macro(add_default_target_arch arch)
140  set(TARGET_${arch}_CFLAGS "")
141  set(CAN_TARGET_${arch} 1)
142  list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
143endmacro()
144
145macro(detect_target_arch)
146  check_symbol_exists(__arm__ "" __ARM)
147  check_symbol_exists(__aarch64__ "" __AARCH64)
148  check_symbol_exists(__x86_64__ "" __X86_64)
149  check_symbol_exists(__i686__ "" __I686)
150  check_symbol_exists(__i386__ "" __I386)
151  check_symbol_exists(__mips__ "" __MIPS)
152  check_symbol_exists(__mips64__ "" __MIPS64)
153  if(__ARM)
154    add_default_target_arch(arm)
155  elseif(__AARCH64)
156    add_default_target_arch(aarch64)
157  elseif(__X86_64)
158    add_default_target_arch(x86_64)
159  elseif(__I686)
160    add_default_target_arch(i686)
161  elseif(__I386)
162    add_default_target_arch(i386)
163  elseif(__MIPS64) # must be checked before __MIPS
164    add_default_target_arch(mips64)
165  elseif(__MIPS)
166    add_default_target_arch(mips)
167  endif()
168endmacro()
169
170# Detect whether the current target platform is 32-bit or 64-bit, and setup
171# the correct commandline flags needed to attempt to target 32-bit and 64-bit.
172if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
173    NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
174  message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
175endif()
176
177# Generate the COMPILER_RT_SUPPORTED_ARCH list.
178if(ANDROID)
179  # Examine compiler output to determine target architecture.
180  detect_target_arch()
181  set(COMPILER_RT_OS_SUFFIX "-android")
182elseif(NOT APPLE) # Supported archs for Apple platforms are generated later
183  if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "i[2-6]86|x86|amd64")
184    if(NOT MSVC)
185      test_target_arch(x86_64 "" "-m64")
186      # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may
187      # target different variant than "$CMAKE_C_COMPILER -m32". This part should
188      # be gone after we resolve PR14109.
189      test_target_arch(i686 __i686__ "-m32")
190      test_target_arch(i386 __i386__ "-m32")
191    else()
192      if (CMAKE_SIZEOF_VOID_P EQUAL 4)
193        test_target_arch(i386 "" "")
194      else()
195        test_target_arch(x86_64 "" "")
196      endif()
197    endif()
198  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "powerpc")
199    TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN)
200    if(HOST_IS_BIG_ENDIAN)
201      test_target_arch(powerpc64 "" "-m64")
202    else()
203      test_target_arch(powerpc64le "" "-m64")
204    endif()
205  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
206    # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
207    # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match
208    # clang's default CPU's. In the 64-bit case, we must also specify the ABI
209    # since the default ABI differs between gcc and clang.
210    # FIXME: Ideally, we would build the N32 library too.
211    test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu")
212    test_target_arch(mips64el "" "-mips64r2" "--target=mips64el-linux-gnu" "-mabi=n64")
213  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips")
214    test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
215    test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=n64")
216  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm")
217    test_target_arch(arm "" "-march=armv7-a" "-mfloat-abi=soft")
218    test_target_arch(armhf "" "-march=armv7-a" "-mfloat-abi=hard")
219  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch32")
220    test_target_arch(aarch32 "" "-march=armv8-a")
221  elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "aarch64")
222    test_target_arch(aarch64 "" "-march=armv8-a")
223  endif()
224  set(COMPILER_RT_OS_SUFFIX "")
225endif()
226
227# Takes ${ARGN} and puts only supported architectures in @out_var list.
228function(filter_available_targets out_var)
229  set(archs ${${out_var}})
230  foreach(arch ${ARGN})
231    list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
232    if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch})
233      list(APPEND archs ${arch})
234    endif()
235  endforeach()
236  set(${out_var} ${archs} PARENT_SCOPE)
237endfunction()
238
239# Returns a list of architecture specific target cflags in @out_var list.
240function(get_target_flags_for_arch arch out_var)
241  list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
242  if(ARCH_INDEX EQUAL -1)
243    message(FATAL_ERROR "Unsupported architecture: ${arch}")
244  else()
245    if (NOT APPLE)
246      set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
247    else()
248      # This is only called in constructing cflags for tests executing on the
249      # host. This will need to all be cleaned up to support building tests
250      # for cross-targeted hardware (i.e. iOS).
251      set(${out_var} -arch ${arch} PARENT_SCOPE)
252    endif()
253  endif()
254endfunction()
255
256set(ARM64 aarch64)
257set(ARM32 arm armhf)
258set(X86 i386 i686)
259set(X86_64 x86_64)
260set(MIPS32 mips mipsel)
261set(MIPS64 mips64 mips64el)
262set(PPC64 powerpc64 powerpc64le)
263
264if(APPLE)
265  set(ARM64 arm64)
266  set(ARM32 armv7 armv7s)
267  set(X86_64 x86_64 x86_64h)
268endif()
269
270set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
271    ${MIPS32} ${MIPS64})
272set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
273    ${ARM32} ${ARM64} ${MIPS32} ${MIPS64})
274set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
275    ${MIPS32} ${MIPS64} ${PPC64})
276set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
277set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
278set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
279set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
280    ${MIPS32} ${MIPS64})
281set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
282set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
283    ${MIPS32} ${MIPS64} ${PPC64})
284set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
285set(ALL_CFI_SUPPORTED_ARCH ${X86} ${X86_64})
286
287if(APPLE)
288  include(CompilerRTDarwinUtils)
289
290  # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not
291  # the command line tools. If this is the case, we need to find the OS X
292  # sysroot to pass to clang.
293  if(NOT EXISTS /usr/include)
294    execute_process(COMMAND xcodebuild -version -sdk macosx Path
295       OUTPUT_VARIABLE OSX_SYSROOT
296       ERROR_QUIET
297       OUTPUT_STRIP_TRAILING_WHITESPACE)
298    set(OSX_SYSROOT_FLAG "-isysroot${OSX_SYSROOT}")
299  endif()
300
301  option(COMPILER_RT_ENABLE_IOS "Enable building for iOS - Experimental" Off)
302
303  find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
304  find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
305  find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
306
307  # Note: In order to target x86_64h on OS X the minimum deployment target must
308  # be 10.8 or higher.
309  set(SANITIZER_COMMON_SUPPORTED_OS osx)
310  set(BUILTIN_SUPPORTED_OS osx)
311  set(PROFILE_SUPPORTED_OS osx)
312  set(TSAN_SUPPORTED_OS osx)
313  if(NOT SANITIZER_MIN_OSX_VERSION)
314    string(REGEX MATCH "-mmacosx-version-min=([.0-9]+)"
315           MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
316    if(MACOSX_VERSION_MIN_FLAG)
317      set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}")
318    elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
319      set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
320    else()
321      set(SANITIZER_MIN_OSX_VERSION 10.9)
322    endif()
323    if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
324      message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}")
325    endif()
326  endif()
327
328  # We're setting the flag manually for each target OS
329  set(CMAKE_OSX_DEPLOYMENT_TARGET "")
330
331  set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
332  set(DARWIN_COMMON_LINKFLAGS
333    -stdlib=libc++
334    -lc++
335    -lc++abi)
336
337  set(DARWIN_osx_CFLAGS
338    ${DARWIN_COMMON_CFLAGS}
339    -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
340  set(DARWIN_osx_LINKFLAGS
341    ${DARWIN_COMMON_LINKFLAGS}
342    -mmacosx-version-min=${SANITIZER_MIN_OSX_VERSION})
343  set(DARWIN_osx_BUILTIN_MIN_VER 10.5)
344  set(DARWIN_osx_BUILTIN_MIN_VER_FLAG
345      -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER})
346
347  if(DARWIN_osx_SYSROOT)
348    list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
349    list(APPEND DARWIN_osx_LINKFLAGS -isysroot ${DARWIN_osx_SYSROOT})
350  endif()
351
352  # Figure out which arches to use for each OS
353  darwin_get_toolchain_supported_archs(toolchain_arches)
354  message(STATUS "Toolchain supported arches: ${toolchain_arches}")
355
356  if(NOT MACOSX_VERSION_MIN_FLAG)
357    darwin_test_archs(osx
358      DARWIN_osx_ARCHS
359      ${toolchain_arches})
360    message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
361    foreach(arch ${DARWIN_osx_ARCHS})
362      list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
363      set(CAN_TARGET_${arch} 1)
364    endforeach()
365
366    # Need to build a 10.4 compatible libclang_rt
367    set(DARWIN_10.4_SYSROOT ${DARWIN_osx_SYSROOT})
368    set(DARWIN_10.4_BUILTIN_MIN_VER 10.4)
369    set(DARWIN_10.4_BUILTIN_MIN_VER_FLAG
370        -mmacosx-version-min=${DARWIN_10.4_BUILTIN_MIN_VER})
371    set(DARWIN_10.4_SKIP_CC_KEXT On)
372    darwin_test_archs(10.4
373      DARWIN_10.4_ARCHS
374      ${toolchain_arches})
375    message(STATUS "OSX 10.4 supported arches: ${DARWIN_10.4_ARCHS}")
376    if(DARWIN_10.4_ARCHS)
377      # don't include the Haswell slice in the 10.4 compatibility library
378      list(REMOVE_ITEM DARWIN_10.4_ARCHS x86_64h)
379      list(APPEND BUILTIN_SUPPORTED_OS 10.4)
380    endif()
381
382    if(DARWIN_iossim_SYSROOT)
383      set(DARWIN_iossim_CFLAGS
384        ${DARWIN_COMMON_CFLAGS}
385        -mios-simulator-version-min=7.0
386        -isysroot ${DARWIN_iossim_SYSROOT})
387      set(DARWIN_iossim_LINKFLAGS
388        ${DARWIN_COMMON_LINKFLAGS}
389        -mios-simulator-version-min=7.0
390        -isysroot ${DARWIN_iossim_SYSROOT})
391      set(DARWIN_iossim_BUILTIN_MIN_VER 6.0)
392      set(DARWIN_iossim_BUILTIN_MIN_VER_FLAG
393        -mios-simulator-version-min=${DARWIN_iossim_BUILTIN_MIN_VER})
394
395      set(DARWIN_iossim_SKIP_CC_KEXT On)
396      darwin_test_archs(iossim
397        DARWIN_iossim_ARCHS
398        ${toolchain_arches})
399      message(STATUS "iOS Simulator supported arches: ${DARWIN_iossim_ARCHS}")
400      if(DARWIN_iossim_ARCHS)
401        list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim)
402        list(APPEND BUILTIN_SUPPORTED_OS iossim)
403        list(APPEND PROFILE_SUPPORTED_OS iossim)
404      endif()
405      foreach(arch ${DARWIN_iossim_ARCHS})
406        list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
407        set(CAN_TARGET_${arch} 1)
408      endforeach()
409    endif()
410
411    if(DARWIN_ios_SYSROOT AND COMPILER_RT_ENABLE_IOS)
412      set(DARWIN_ios_CFLAGS
413        ${DARWIN_COMMON_CFLAGS}
414        -miphoneos-version-min=7.0
415        -isysroot ${DARWIN_ios_SYSROOT})
416      set(DARWIN_ios_LINKFLAGS
417        ${DARWIN_COMMON_LINKFLAGS}
418        -miphoneos-version-min=7.0
419        -isysroot ${DARWIN_ios_SYSROOT})
420      set(DARWIN_ios_BUILTIN_MIN_VER 6.0)
421      set(DARWIN_ios_BUILTIN_MIN_VER_FLAG
422        -miphoneos-version-min=${DARWIN_ios_BUILTIN_MIN_VER})
423
424      darwin_test_archs(ios
425        DARWIN_ios_ARCHS
426        ${toolchain_arches})
427      message(STATUS "iOS supported arches: ${DARWIN_ios_ARCHS}")
428      if(DARWIN_ios_ARCHS)
429        list(APPEND SANITIZER_COMMON_SUPPORTED_OS ios)
430        list(APPEND BUILTIN_SUPPORTED_OS ios)
431        list(APPEND PROFILE_SUPPORTED_OS ios)
432      endif()
433      foreach(arch ${DARWIN_ios_ARCHS})
434        list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
435        set(CAN_TARGET_${arch} 1)
436      endforeach()
437    endif()
438  endif()
439
440  # for list_union
441  include(CompilerRTUtils)
442
443  list_union(BUILTIN_SUPPORTED_ARCH ALL_BUILTIN_SUPPORTED_ARCH toolchain_arches)
444
445  list_union(SANITIZER_COMMON_SUPPORTED_ARCH
446    ALL_SANITIZER_COMMON_SUPPORTED_ARCH
447    COMPILER_RT_SUPPORTED_ARCH
448    )
449  set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
450  set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
451  list_union(ASAN_SUPPORTED_ARCH
452    ALL_ASAN_SUPPORTED_ARCH
453    SANITIZER_COMMON_SUPPORTED_ARCH)
454  list_union(DFSAN_SUPPORTED_ARCH
455    ALL_DFSAN_SUPPORTED_ARCH
456    SANITIZER_COMMON_SUPPORTED_ARCH)
457  list_union(LSAN_SUPPORTED_ARCH
458    ALL_LSAN_SUPPORTED_ARCH
459    SANITIZER_COMMON_SUPPORTED_ARCH)
460  list_union(MSAN_SUPPORTED_ARCH
461    ALL_MSAN_SUPPORTED_ARCH
462    SANITIZER_COMMON_SUPPORTED_ARCH)
463  list_union(PROFILE_SUPPORTED_ARCH
464    ALL_PROFILE_SUPPORTED_ARCH
465    SANITIZER_COMMON_SUPPORTED_ARCH)
466  list_union(TSAN_SUPPORTED_ARCH
467    ALL_TSAN_SUPPORTED_ARCH
468    SANITIZER_COMMON_SUPPORTED_ARCH)
469  list_union(UBSAN_SUPPORTED_ARCH
470    ALL_UBSAN_SUPPORTED_ARCH
471    SANITIZER_COMMON_SUPPORTED_ARCH)
472  list_union(SAFESTACK_SUPPORTED_ARCH
473    ALL_SAFESTACK_SUPPORTED_ARCH
474    SANITIZER_COMMON_SUPPORTED_ARCH)
475  list_union(CFI_SUPPORTED_ARCH
476    ALL_CFI_SUPPORTED_ARCH
477    SANITIZER_COMMON_SUPPORTED_ARCH)
478else()
479  # Architectures supported by compiler-rt libraries.
480  filter_available_targets(BUILTIN_SUPPORTED_ARCH
481    ${ALL_BUILTIN_SUPPORTED_ARCH})
482  filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
483    ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH})
484  # LSan and UBSan common files should be available on all architectures
485  # supported by other sanitizers (even if they build into dummy object files).
486  filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
487    ${SANITIZER_COMMON_SUPPORTED_ARCH})
488  filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
489    ${SANITIZER_COMMON_SUPPORTED_ARCH})
490  filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
491  filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
492  filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
493  filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
494  filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
495  filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
496  filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
497  filter_available_targets(SAFESTACK_SUPPORTED_ARCH
498    ${ALL_SAFESTACK_SUPPORTED_ARCH})
499  filter_available_targets(CFI_SUPPORTED_ARCH ${ALL_CFI_SUPPORTED_ARCH})
500endif()
501
502message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
503
504if(ANDROID)
505  set(OS_NAME "Android")
506else()
507  set(OS_NAME "${CMAKE_SYSTEM_NAME}")
508endif()
509
510if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
511    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR
512    (OS_NAME MATCHES "Windows" AND MSVC)))
513  set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
514else()
515  set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
516endif()
517
518if (COMPILER_RT_HAS_SANITIZER_COMMON AND
519    (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
520  set(COMPILER_RT_HAS_INTERCEPTION TRUE)
521else()
522  set(COMPILER_RT_HAS_INTERCEPTION FALSE)
523endif()
524
525if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND
526    (NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4))
527  set(COMPILER_RT_HAS_ASAN TRUE)
528else()
529  set(COMPILER_RT_HAS_ASAN FALSE)
530endif()
531
532if (OS_NAME MATCHES "Linux|FreeBSD|Windows")
533  set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
534else()
535  set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
536endif()
537
538# TODO: Add builtins support.
539
540if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
541    OS_NAME MATCHES "Linux")
542  set(COMPILER_RT_HAS_DFSAN TRUE)
543else()
544  set(COMPILER_RT_HAS_DFSAN FALSE)
545endif()
546
547if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
548    OS_NAME MATCHES "Linux|FreeBSD")
549  set(COMPILER_RT_HAS_LSAN TRUE)
550else()
551  set(COMPILER_RT_HAS_LSAN FALSE)
552endif()
553
554if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
555    OS_NAME MATCHES "Linux")
556  set(COMPILER_RT_HAS_MSAN TRUE)
557else()
558  set(COMPILER_RT_HAS_MSAN FALSE)
559endif()
560
561if (PROFILE_SUPPORTED_ARCH AND
562    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
563  set(COMPILER_RT_HAS_PROFILE TRUE)
564else()
565  set(COMPILER_RT_HAS_PROFILE FALSE)
566endif()
567
568if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND
569    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
570  set(COMPILER_RT_HAS_TSAN TRUE)
571else()
572  set(COMPILER_RT_HAS_TSAN FALSE)
573endif()
574
575if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
576    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows")
577  set(COMPILER_RT_HAS_UBSAN TRUE)
578else()
579  set(COMPILER_RT_HAS_UBSAN FALSE)
580endif()
581
582if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
583    OS_NAME MATCHES "Darwin|Linux|FreeBSD")
584  set(COMPILER_RT_HAS_SAFESTACK TRUE)
585else()
586  set(COMPILER_RT_HAS_SAFESTACK FALSE)
587endif()
588
589if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH AND
590    OS_NAME MATCHES "Linux")
591  set(COMPILER_RT_HAS_CFI TRUE)
592else()
593  set(COMPILER_RT_HAS_CFI FALSE)
594endif()
595