Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / cmake / config-ix.cmake
bloba8e078f1ebc98887438e9444b3f77545a7a9d40b
1 include(CMakePushCheckState)
2 include(AddLLVM)
3 include(LLVMCheckCompilerLinkerFlag)
4 include(CheckCCompilerFlag)
5 include(CheckCXXCompilerFlag)
6 include(CheckIncludeFiles)
7 include(CheckLibraryExists)
8 include(LLVMCheckCompilerLinkerFlag)
9 include(CheckSymbolExists)
10 include(TestBigEndian)
12 # The compiler driver may be implicitly trying to link against libunwind.
13 # This is normally ok (libcxx relies on an unwinder), but if libunwind is
14 # built in the same cmake invocation as compiler-rt and we're using the
15 # in tree version of runtimes, we'd be linking against the just-built
16 # libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
17 # built libunwind isn't installed yet). For those cases, it'd be good to
18 # link with --uwnindlib=none. Check if that option works.
19 llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
21 check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
22 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
23   include(HandleCompilerRT)
24   find_compiler_rt_library(builtins COMPILER_RT_BUILTINS_LIBRARY
25                            FLAGS ${SANITIZER_COMMON_FLAGS})
26   # TODO(PR51389): We should check COMPILER_RT_BUILTINS_LIBRARY and report an
27   # error if the value is NOTFOUND rather than silenty continuing but we first
28   # need to fix find_compiler_rt_library on Darwin.
29 else()
30   if (ANDROID)
31     check_library_exists(gcc __gcc_personality_v0 "" COMPILER_RT_HAS_GCC_LIB)
32   else()
33     check_library_exists(gcc_s __gcc_personality_v0 "" COMPILER_RT_HAS_GCC_S_LIB)
34   endif()
35 endif()
37 check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
38 if (C_SUPPORTS_NODEFAULTLIBS_FLAG)
39   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
40   if (COMPILER_RT_HAS_LIBC)
41     list(APPEND CMAKE_REQUIRED_LIBRARIES c)
42   endif ()
43   if (COMPILER_RT_USE_BUILTINS_LIBRARY)
44     # TODO: remote this check once we address PR51389.
45     if (${COMPILER_RT_BUILTINS_LIBRARY})
46       list(APPEND CMAKE_REQUIRED_LIBRARIES "${COMPILER_RT_BUILTINS_LIBRARY}")
47     endif()
48   elseif (COMPILER_RT_HAS_GCC_S_LIB)
49     list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s)
50   elseif (COMPILER_RT_HAS_GCC_LIB)
51     list(APPEND CMAKE_REQUIRED_LIBRARIES gcc)
52   endif ()
53   if (MINGW)
54     # Mingw64 requires quite a few "C" runtime libraries in order for basic
55     # programs to link successfully with -nodefaultlibs.
56     if (COMPILER_RT_USE_BUILTINS_LIBRARY)
57       set(MINGW_RUNTIME ${COMPILER_RT_BUILTINS_LIBRARY})
58     else ()
59       set(MINGW_RUNTIME gcc_s gcc)
60     endif()
61     set(MINGW_LIBRARIES mingw32 ${MINGW_RUNTIME} moldname mingwex msvcrt advapi32
62                         shell32 user32 kernel32 mingw32 ${MINGW_RUNTIME}
63                         moldname mingwex msvcrt)
64     list(APPEND CMAKE_REQUIRED_LIBRARIES ${MINGW_LIBRARIES})
65   endif()
66   if (NOT TARGET unwind)
67     # Don't check for a library named unwind, if there's a target with that name within
68     # the same build.
69     check_library_exists(unwind _Unwind_GetRegionStart "" COMPILER_RT_HAS_LIBUNWIND)
70     if (COMPILER_RT_HAS_LIBUNWIND)
71       # If we're omitting default libraries, we might need to manually link in libunwind.
72       # This can affect whether we detect a statically linked libc++ correctly.
73       list(APPEND CMAKE_REQUIRED_LIBRARIES unwind)
74     endif()
75   endif()
76 endif ()
78 # CodeGen options.
79 check_c_compiler_flag(-ffreestanding         COMPILER_RT_HAS_FFREESTANDING_FLAG)
80 check_c_compiler_flag(-fomit-frame-pointer   COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG)
81 check_c_compiler_flag(-std=c11               COMPILER_RT_HAS_STD_C11_FLAG)
82 check_c_compiler_flag(-fcf-protection=full   COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
83 check_cxx_compiler_flag(-fPIC                COMPILER_RT_HAS_FPIC_FLAG)
84 check_cxx_compiler_flag(-fPIE                COMPILER_RT_HAS_FPIE_FLAG)
85 check_cxx_compiler_flag(-fno-builtin         COMPILER_RT_HAS_FNO_BUILTIN_FLAG)
86 check_cxx_compiler_flag(-fno-exceptions      COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG)
87 check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)
88 check_cxx_compiler_flag(-funwind-tables      COMPILER_RT_HAS_FUNWIND_TABLES_FLAG)
89 check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG)
90 check_cxx_compiler_flag(-fno-sanitize=safe-stack COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG)
91 check_cxx_compiler_flag(-fvisibility=hidden  COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
92 check_cxx_compiler_flag(-frtti               COMPILER_RT_HAS_FRTTI_FLAG)
93 check_cxx_compiler_flag(-fno-rtti            COMPILER_RT_HAS_FNO_RTTI_FLAG)
94 check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG)
95 check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC)
96 check_cxx_compiler_flag(-fno-lto             COMPILER_RT_HAS_FNO_LTO_FLAG)
97 check_cxx_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
98 check_cxx_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
99 check_cxx_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
100 check_cxx_compiler_flag(-fno-coverage-mapping COMPILER_RT_HAS_FNO_COVERAGE_MAPPING_FLAG)
101 check_cxx_compiler_flag("-Werror -mcrc32"    COMPILER_RT_HAS_MCRC32_FLAG)
102 check_cxx_compiler_flag("-Werror -msse4.2"   COMPILER_RT_HAS_MSSE4_2_FLAG)
103 check_cxx_compiler_flag(--sysroot=.          COMPILER_RT_HAS_SYSROOT_FLAG)
104 check_cxx_compiler_flag("-Werror -mcrc"      COMPILER_RT_HAS_MCRC_FLAG)
105 check_cxx_compiler_flag(-fno-partial-inlining COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG)
106 check_cxx_compiler_flag(-Werror -ftrivial-auto-var-init=pattern COMPILER_RT_HAS_TRIVIAL_AUTO_INIT)
108 if(NOT WIN32 AND NOT CYGWIN)
109   # MinGW warns if -fvisibility-inlines-hidden is used.
110   check_cxx_compiler_flag("-fvisibility-inlines-hidden" COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG)
111 endif()
113 check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG)
114 check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG)
115 check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG)
116 check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG)
118 # Debug info flags.
119 check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG)
120 check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG)
121 check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG)
123 # Warnings.
124 check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG)
125 check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG)
126 check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG)
127 check_cxx_compiler_flag("-Werror -Wglobal-constructors"   COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG)
128 check_cxx_compiler_flag("-Werror -Wc99-extensions"     COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG)
129 check_cxx_compiler_flag("-Werror -Wgnu"                COMPILER_RT_HAS_WGNU_FLAG)
130 check_cxx_compiler_flag("-Werror -Wvariadic-macros"    COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
131 check_cxx_compiler_flag("-Werror -Wunused-parameter"   COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
132 check_cxx_compiler_flag("-Werror -Wcovered-switch-default" COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
133 check_cxx_compiler_flag("-Werror -Wsuggest-override"   COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
134 check_cxx_compiler_flag("-Werror -Wthread-safety" COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG)
135 check_cxx_compiler_flag("-Werror -Wthread-safety-reference" COMPILER_RT_HAS_WTHREAD_SAFETY_REFERENCE_FLAG)
136 check_cxx_compiler_flag("-Werror -Wthread-safety-beta" COMPILER_RT_HAS_WTHREAD_SAFETY_BETA_FLAG)
137 check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
138 check_cxx_compiler_flag(-Wno-format COMPILER_RT_HAS_WNO_FORMAT)
139 check_cxx_compiler_flag(-Wno-format-pedantic COMPILER_RT_HAS_WNO_FORMAT_PEDANTIC)
141 check_cxx_compiler_flag("/experimental:external /external:W0" COMPILER_RT_HAS_EXTERNAL_FLAG)
143 check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG)
144 check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG)
145 check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG)
146 check_cxx_compiler_flag(/wd4206 COMPILER_RT_HAS_WD4206_FLAG)
147 check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG)
148 check_cxx_compiler_flag(/wd4221 COMPILER_RT_HAS_WD4221_FLAG)
149 check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG)
150 check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG)
151 check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
153 check_cxx_compiler_flag(-Werror -Warray-bounds COMPILER_RT_HAS_ARRAY_BOUNDS_FLAG)
154 check_cxx_compiler_flag(-Werror -Wuninitialized COMPILER_RT_HAS_UNINITIALIZED_FLAG)
155 check_cxx_compiler_flag(-Werror -Wshadow COMPILER_RT_HAS_SHADOW_FLAG)
156 check_cxx_compiler_flag(-Werror -Wempty-body COMPILER_RT_HAS_EMPTY_BODY_FLAG)
157 check_cxx_compiler_flag(-Werror -Wsizeof-pointer-memaccess COMPILER_RT_HAS_SIZEOF_POINTER_MEMACCESS_FLAG)
158 check_cxx_compiler_flag(-Werror -Wsizeof-array-argument COMPILER_RT_HAS_SIZEOF_ARRAY_ARGUMENT_FLAG)
159 check_cxx_compiler_flag(-Werror -Wsuspicious-memaccess COMPILER_RT_HAS_SUSPICIOUS_MEMACCESS_FLAG)
160 check_cxx_compiler_flag(-Werror -Wbuiltin-memcpy-chk-size COMPILER_RT_HAS_BUILTIN_MEMCPY_CHK_SIZE_FLAG)
161 check_cxx_compiler_flag(-Werror -Warray-bounds-pointer-arithmetic COMPILER_RT_HAS_ARRAY_BOUNDS_POINTER_ARITHMETIC_FLAG)
162 check_cxx_compiler_flag(-Werror -Wreturn-stack-address COMPILER_RT_HAS_RETURN_STACK_ADDRESS_FLAG)
163 check_cxx_compiler_flag(-Werror -Wsizeof-array-decay COMPILER_RT_HAS_SIZEOF_ARRAY_DECAY_FLAG)
164 check_cxx_compiler_flag(-Werror -Wformat-insufficient-args COMPILER_RT_HAS_FORMAT_INSUFFICIENT_ARGS_FLAG)
165 check_cxx_compiler_flag(-Werror -Wformat-security COMPILER_RT_HAS_BUILTIN_FORMAL_SECURITY_FLAG)
166 check_cxx_compiler_flag(-Werror -Wsizeof-array-div COMPILER_RT_HAS_SIZEOF_ARRAY_DIV_FLAG)
167 check_cxx_compiler_flag(-Werror -Wsizeof-pointer-div COMPILER_RT_HAS_SIZEOF_POINTER_DIV_FLAG)
169 # Symbols.
170 check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
172 # Includes.
173 check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG)
174 check_cxx_compiler_flag(-nostdlib++ COMPILER_RT_HAS_NOSTDLIBXX_FLAG)
175 check_include_files("sys/auxv.h"    COMPILER_RT_HAS_AUXV)
177 # Libraries.
178 check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
179 check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
180 check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
181 check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
182 check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
184 # Look for terminfo library, used in unittests that depend on LLVMSupport.
185 if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
186   set(MAYBE_REQUIRED REQUIRED)
187 else()
188   set(MAYBE_REQUIRED)
189 endif()
190 if(LLVM_ENABLE_TERMINFO)
191   find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
192 endif()
193 if(COMPILER_RT_TERMINFO_LIB)
194   set(LLVM_ENABLE_TERMINFO 1)
195 else()
196   set(LLVM_ENABLE_TERMINFO 0)
197 endif()
199 if (ANDROID AND COMPILER_RT_HAS_LIBDL)
200   # Android's libstdc++ has a dependency on libdl.
201   list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
202 endif()
203 check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX)
204 check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
206 # Linker flags.
207 llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
208 llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
210 if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
211   set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat")
212   llvm_check_compiler_linker_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
213 endif()
215 set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers)
216 file(WRITE ${DUMMY_VERS} "{};")
217 set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}")
218 if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
219   # Solaris 11.4 ld only supports --version-script with
220   # -z gnu-version-script-compat.
221   string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}")
222 endif()
223 llvm_check_compiler_linker_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)
225 if(ANDROID)
226   llvm_check_compiler_linker_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
227   check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
228 endif()
230 # Architectures.
232 # List of all architectures we can target.
233 set(COMPILER_RT_SUPPORTED_ARCH)
235 # Try to compile a very simple source file to ensure we can target the given
236 # platform. We use the results of these tests to build only the various target
237 # runtime libraries supported by our current compilers cross-compiling
238 # abilities.
239 set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
240 file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <stdio.h>\nint main(void) { printf(\"hello, world\"); }\n")
242 # Detect whether the current target platform is 32-bit or 64-bit, and setup
243 # the correct commandline flags needed to attempt to target 32-bit and 64-bit.
244 # AVR and MSP430 are omitted since they have 16-bit pointers.
245 if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
246     NOT CMAKE_SIZEOF_VOID_P EQUAL 8 AND
247     NOT ${arch} MATCHES "avr|msp430")
248   message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
249 endif()
251 test_targets()
253 # Returns a list of architecture specific target cflags in @out_var list.
254 function(get_target_flags_for_arch arch out_var)
255   list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
256   if(ARCH_INDEX EQUAL -1)
257     message(FATAL_ERROR "Unsupported architecture: ${arch}")
258   else()
259     if (NOT APPLE)
260       set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
261     else()
262       # This is only called in constructing cflags for tests executing on the
263       # host. This will need to all be cleaned up to support building tests
264       # for cross-targeted hardware (i.e. iOS).
265       set(${out_var} -arch ${arch} PARENT_SCOPE)
266     endif()
267   endif()
268 endfunction()
270 # Returns a list of architecture specific target ldflags in @out_var list.
271 function(get_target_link_flags_for_arch arch out_var)
272   list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
273   if(ARCH_INDEX EQUAL -1)
274     message(FATAL_ERROR "Unsupported architecture: ${arch}")
275   else()
276     # Workaround for direct calls to __tls_get_addr on Solaris/amd64.
277     if(OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)
278       set(${out_var} "-Wl,-z,relax=transtls" PARENT_SCOPE)
279     endif()
280   endif()
281 endfunction()
283 # Returns a compiler and CFLAGS that should be used to run tests for the
284 # specific architecture.  When cross-compiling, this is controled via
285 # COMPILER_RT_TEST_COMPILER and COMPILER_RT_TEST_COMPILER_CFLAGS.
286 macro(get_test_cc_for_arch arch cc_out cflags_out)
287   if (NOT ${ARGC} EQUAL 3)
288     message(FATAL_ERROR "got too many args. expected 3, got ${ARGC} (namely: ${ARGV})")
289   endif()
290   if(ANDROID OR (NOT APPLE AND ${arch} MATCHES "arm|aarch64|riscv32|riscv64"))
291     # This is only true if we are cross-compiling.
292     # Build all tests with host compiler and use host tools.
293     set(${cc_out} ${COMPILER_RT_TEST_COMPILER})
294     set(${cflags_out} ${COMPILER_RT_TEST_COMPILER_CFLAGS})
295   else()
296     get_target_flags_for_arch(${arch} ${cflags_out})
297     if(APPLE)
298       list(APPEND ${cflags_out} ${DARWIN_osx_CFLAGS})
299     endif()
300     string(REPLACE ";" " " ${cflags_out} "${${cflags_out}}")
301   endif()
302 endmacro()
304 # Returns CFLAGS that should be used to run tests for the
305 # specific apple platform and architecture.
306 function(get_test_cflags_for_apple_platform platform arch cflags_out)
307   is_valid_apple_platform("${platform}" is_valid_platform)
308   if (NOT is_valid_platform)
309     message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
310   endif()
311   set(test_cflags "")
312   get_target_flags_for_arch(${arch} test_cflags)
314   if (NOT "${arch}" STREQUAL "arm64e")
315     list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
316   else()
317     # arm64e is not currently ABI stable so we need to build for the
318     # OS version being tested. Rather than querying the device under test
319     # we use the SDK version which "should" be the same as the
320     # device under test (it is a configuration error for these not to match).
321     # FIXME(dliew): We can remove this if we build the runtimes with the appropriate
322     # deployment target for arm64e.
323     foreach (flag ${DARWIN_${platform}_CFLAGS})
324       if ("${flag}" MATCHES "^${DARWIN_${platform}_MIN_VER_FLAG}=.+")
325         # Find the SDK version
326         get_xcrun_platform_from_apple_platform("${platform}" xcrun_platform_name)
327         # TODO(dliew): Remove this check once get_xcrun_platform_from_apple_platform
328         # emits a fatal error for unrecognised platforms.
329         if (NOT "${xcrun_platform_name}" STREQUAL "")
330           find_darwin_sdk_version(platform_sdk_version "${xcrun_platform_name}")
331           # Patch flag with correct deployment target
332           set(replacement_flag "${DARWIN_${platform}_MIN_VER_FLAG}=${platform_sdk_version}")
333           list(APPEND test_cflags "${replacement_flag}")
334         endif()
335       else()
336         # Copy through
337         list(APPEND test_cflags "${flag}")
338       endif()
339     endforeach()
340   endif()
342   string(REPLACE ";" " " test_cflags_str "${test_cflags}")
343   string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
344   set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
345 endfunction()
347 function(get_capitalized_apple_platform platform platform_capitalized)
348   # TODO(dliew): Remove uses of this function. It exists to preserve needlessly complex
349   # directory naming conventions used by the Sanitizer lit test suites.
350   is_valid_apple_platform("${platform}" is_valid_platform)
351   if (NOT is_valid_platform)
352     message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
353   endif()
354   string(TOUPPER "${platform}" platform_upper)
355   string(REGEX REPLACE "OSSIM$" "OSSim" platform_upper_capitalized "${platform_upper}")
356   set(${platform_capitalized} "${platform_upper_capitalized}" PARENT_SCOPE)
357 endfunction()
359 function(is_valid_apple_platform platform is_valid_out)
360   set(is_valid FALSE)
361   if ("${platform}" STREQUAL "")
362     message(FATAL_ERROR "platform cannot be empty")
363   endif()
364   if ("${platform}" MATCHES "^(osx|((ios|watchos|tvos)(sim)?))$")
365     set(is_valid TRUE)
366   endif()
367   set(${is_valid_out} ${is_valid} PARENT_SCOPE)
368 endfunction()
370 # Maps the Apple platform name used in Compiler-rt's CMake code
371 # to the name recognised by xcrun's `--sdk` argument
372 function(get_xcrun_platform_from_apple_platform platform out_var)
373   set(xcrun_platform "")
374   if ("${platform}" STREQUAL "osx")
375     set(xcrun_platform "macosx")
376   elseif ("${platform}" STREQUAL "iossim")
377     set(xcrun_platform "iphonesimulator")
378   elseif ("${platform}" STREQUAL "ios")
379     set(xcrun_platform "iphoneos")
380   elseif ("${platform}" STREQUAL "watchossim")
381     set(xcrun_platform "watchsimulator")
382   elseif ("${platform}" STREQUAL "watchos")
383     set(xcrun_platform "watchos")
384   elseif ("${platform}" STREQUAL "tvossim")
385     set(xcrun_platform "appletvsimulator")
386   elseif ("${platform}" STREQUAL "tvos")
387     set(xcrun_platform "appletvos")
388   else()
389     # TODO(dliew): Make this an error.
390     message(WARNING "\"${platform}\" is not a handled apple platform")
391   endif()
392   set(${out_var} ${xcrun_platform} PARENT_SCOPE)
393 endfunction()
395 include(AllSupportedArchDefs)
397 if(APPLE)
398   include(CompilerRTDarwinUtils)
400   find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
401   find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
402   find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
403   find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
404   find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
405   find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
406   find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
408   if(NOT DARWIN_osx_SYSROOT)
409     message(WARNING "Could not determine OS X sysroot, trying /usr/include")
410     if(EXISTS /usr/include)
411       set(DARWIN_osx_SYSROOT /)
412     else()
413       message(ERROR "Could not detect OS X Sysroot. Either install Xcode or the Apple Command Line Tools")
414     endif()
415   endif()
417   if(COMPILER_RT_ENABLE_IOS)
418     list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
419     set(DARWIN_ios_MIN_VER 9.0)
420     set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
421     set(DARWIN_ios_SANITIZER_MIN_VER_FLAG
422       ${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_MIN_VER})
423     set(DARWIN_iossim_MIN_VER_FLAG -mios-simulator-version-min)
424     set(DARWIN_iossim_SANITIZER_MIN_VER_FLAG
425       ${DARWIN_iossim_MIN_VER_FLAG}=${DARWIN_ios_MIN_VER})
426   endif()
427   if(COMPILER_RT_ENABLE_WATCHOS)
428     list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
429     set(DARWIN_watchos_MIN_VER 2.0)
430     set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
431     set(DARWIN_watchos_SANITIZER_MIN_VER_FLAG
432       ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_MIN_VER})
433     set(DARWIN_watchossim_MIN_VER_FLAG -mwatchos-simulator-version-min)
434     set(DARWIN_watchossim_SANITIZER_MIN_VER_FLAG
435       ${DARWIN_watchossim_MIN_VER_FLAG}=${DARWIN_watchos_MIN_VER})
436   endif()
437   if(COMPILER_RT_ENABLE_TVOS)
438     list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
439     set(DARWIN_tvos_MIN_VER 9.0)
440     set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
441     set(DARWIN_tvos_SANITIZER_MIN_VER_FLAG
442       ${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_MIN_VER})
443     set(DARWIN_tvossim_MIN_VER_FLAG -mtvos-simulator-version-min)
444     set(DARWIN_tvossim_SANITIZER_MIN_VER_FLAG
445       ${DARWIN_tvossim_MIN_VER_FLAG}=${DARWIN_tvos_MIN_VER})
446   endif()
448   set(SANITIZER_COMMON_SUPPORTED_OS osx)
449   set(PROFILE_SUPPORTED_OS osx)
450   set(TSAN_SUPPORTED_OS osx)
451   set(XRAY_SUPPORTED_OS osx)
452   set(FUZZER_SUPPORTED_OS osx)
453   set(ORC_SUPPORTED_OS osx)
454   set(UBSAN_SUPPORTED_OS osx)
455   set(LSAN_SUPPORTED_OS osx)
456   set(STATS_SUPPORTED_OS osx)
458   # Note: In order to target x86_64h on OS X the minimum deployment target must
459   # be 10.8 or higher.
460   set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.10)
461   set(DARWIN_osx_MIN_VER_FLAG "-mmacosx-version-min")
462   if(NOT SANITIZER_MIN_OSX_VERSION)
463     string(REGEX MATCH "${DARWIN_osx_MIN_VER_FLAG}=([.0-9]+)"
464            MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
465     if(MACOSX_VERSION_MIN_FLAG)
466       set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}")
467     elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
468       set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
469     else()
470       set(SANITIZER_MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION})
471     endif()
472     if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
473       message(FATAL_ERROR "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too old.")
474     endif()
475     if(SANITIZER_MIN_OSX_VERSION VERSION_GREATER ${DEFAULT_SANITIZER_MIN_OSX_VERSION})
476       message(WARNING "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too new, setting to '${DEFAULT_SANITIZER_MIN_OSX_VERSION}' instead.")
477       set(SANITIZER_MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION})
478     endif()
479   endif()
481   # We're setting the flag manually for each target OS
482   set(CMAKE_OSX_DEPLOYMENT_TARGET "")
484   set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
485   set(DARWIN_COMMON_LINK_FLAGS
486     -stdlib=libc++
487     -lc++
488     -lc++abi)
490   llvm_check_compiler_linker_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
491   if(COMPILER_RT_HAS_APP_EXTENSION)
492     list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension")
493   endif()
495   set(DARWIN_osx_CFLAGS
496     ${DARWIN_COMMON_CFLAGS}
497     ${DARWIN_osx_MIN_VER_FLAG}=${SANITIZER_MIN_OSX_VERSION})
498   set(DARWIN_osx_LINK_FLAGS
499     ${DARWIN_COMMON_LINK_FLAGS}
500     ${DARWIN_osx_MIN_VER_FLAG}=${SANITIZER_MIN_OSX_VERSION})
502   if(DARWIN_osx_SYSROOT)
503     list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
504     list(APPEND DARWIN_osx_LINK_FLAGS -isysroot ${DARWIN_osx_SYSROOT})
505   endif()
507   # Figure out which arches to use for each OS
508   darwin_get_toolchain_supported_archs(toolchain_arches)
509   message(STATUS "Toolchain supported arches: ${toolchain_arches}")
511   if(NOT MACOSX_VERSION_MIN_FLAG)
512     darwin_test_archs(osx
513       DARWIN_osx_ARCHS
514       ${toolchain_arches})
515     message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
516     foreach(arch ${DARWIN_osx_ARCHS})
517       list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
518       set(CAN_TARGET_${arch} 1)
519     endforeach()
521     foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
522       if(DARWIN_${platform}sim_SYSROOT)
523         set(DARWIN_${platform}sim_CFLAGS
524           ${DARWIN_COMMON_CFLAGS}
525           ${DARWIN_${platform}sim_SANITIZER_MIN_VER_FLAG}
526           -isysroot ${DARWIN_${platform}sim_SYSROOT})
527         set(DARWIN_${platform}sim_LINK_FLAGS
528           ${DARWIN_COMMON_LINK_FLAGS}
529           ${DARWIN_${platform}sim_SANITIZER_MIN_VER_FLAG}
530           -isysroot ${DARWIN_${platform}sim_SYSROOT})
532         set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
533         darwin_test_archs(${platform}sim
534           DARWIN_${platform}sim_ARCHS
535           ${toolchain_arches})
536         message(STATUS "${platform} Simulator supported arches: ${DARWIN_${platform}sim_ARCHS}")
537         if(DARWIN_${platform}sim_ARCHS)
538           list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform}sim)
539           list(APPEND PROFILE_SUPPORTED_OS ${platform}sim)
540           list(APPEND TSAN_SUPPORTED_OS ${platform}sim)
541           list(APPEND FUZZER_SUPPORTED_OS ${platform}sim)
542           list(APPEND ORC_SUPPORTED_OS ${platform}sim)
543           list(APPEND UBSAN_SUPPORTED_OS ${platform}sim)
544           list(APPEND LSAN_SUPPORTED_OS ${platform}sim)
545           list(APPEND STATS_SUPPORTED_OS ${platform}sim)
546         endif()
547         foreach(arch ${DARWIN_${platform}sim_ARCHS})
548           list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
549           set(CAN_TARGET_${arch} 1)
550         endforeach()
551       endif()
553       if(DARWIN_${platform}_SYSROOT)
554         set(DARWIN_${platform}_CFLAGS
555           ${DARWIN_COMMON_CFLAGS}
556           ${DARWIN_${platform}_SANITIZER_MIN_VER_FLAG}
557           -isysroot ${DARWIN_${platform}_SYSROOT})
558         set(DARWIN_${platform}_LINK_FLAGS
559           ${DARWIN_COMMON_LINK_FLAGS}
560           ${DARWIN_${platform}_SANITIZER_MIN_VER_FLAG}
561           -isysroot ${DARWIN_${platform}_SYSROOT})
563         darwin_test_archs(${platform}
564           DARWIN_${platform}_ARCHS
565           ${toolchain_arches})
566         message(STATUS "${platform} supported arches: ${DARWIN_${platform}_ARCHS}")
567         if(DARWIN_${platform}_ARCHS)
568           list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform})
569           list(APPEND PROFILE_SUPPORTED_OS ${platform})
571           list_intersect(DARWIN_${platform}_TSAN_ARCHS DARWIN_${platform}_ARCHS ALL_TSAN_SUPPORTED_ARCH)
572           if(DARWIN_${platform}_TSAN_ARCHS)
573             list(APPEND TSAN_SUPPORTED_OS ${platform})
574           endif()
575           list(APPEND FUZZER_SUPPORTED_OS ${platform})
576           list(APPEND ORC_SUPPORTED_OS ${platform})
577           list(APPEND UBSAN_SUPPORTED_OS ${platform})
578           list(APPEND LSAN_SUPPORTED_OS ${platform})
579           list(APPEND STATS_SUPPORTED_OS ${platform})
580         endif()
581         foreach(arch ${DARWIN_${platform}_ARCHS})
582           list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
583           set(CAN_TARGET_${arch} 1)
584         endforeach()
585       endif()
586     endforeach()
587   endif()
589   # Explicitly disable unsupported Sanitizer configurations.
590   list(REMOVE_ITEM FUZZER_SUPPORTED_OS "watchos")
591   list(REMOVE_ITEM FUZZER_SUPPORTED_OS "watchossim")
593   # for list_intersect
594   include(CompilerRTUtils)
596   list_intersect(SANITIZER_COMMON_SUPPORTED_ARCH
597     ALL_SANITIZER_COMMON_SUPPORTED_ARCH
598     COMPILER_RT_SUPPORTED_ARCH
599     )
600   set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
601   set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
602   set(ASAN_ABI_SUPPORTED_ARCH ${ALL_ASAN_ABI_SUPPORTED_ARCH})
603   list_intersect(ASAN_SUPPORTED_ARCH
604     ALL_ASAN_SUPPORTED_ARCH
605     SANITIZER_COMMON_SUPPORTED_ARCH)
606   list_intersect(DFSAN_SUPPORTED_ARCH
607     ALL_DFSAN_SUPPORTED_ARCH
608     SANITIZER_COMMON_SUPPORTED_ARCH)
609   list_intersect(GWP_ASAN_SUPPORTED_ARCH
610     ALL_GWP_ASAN_SUPPORTED_ARCH
611     SANITIZER_COMMON_SUPPORTED_ARCH)
612   list_intersect(LSAN_SUPPORTED_ARCH
613     ALL_LSAN_SUPPORTED_ARCH
614     SANITIZER_COMMON_SUPPORTED_ARCH)
615   list_intersect(MSAN_SUPPORTED_ARCH
616     ALL_MSAN_SUPPORTED_ARCH
617     SANITIZER_COMMON_SUPPORTED_ARCH)
618   list_intersect(HWASAN_SUPPORTED_ARCH
619     ALL_HWASAN_SUPPORTED_ARCH
620     SANITIZER_COMMON_SUPPORTED_ARCH)
621   list_intersect(MEMPROF_SUPPORTED_ARCH
622     ALL_MEMPROF_SUPPORTED_ARCH
623     SANITIZER_COMMON_SUPPORTED_ARCH)
624   list_intersect(PROFILE_SUPPORTED_ARCH
625     ALL_PROFILE_SUPPORTED_ARCH
626     SANITIZER_COMMON_SUPPORTED_ARCH)
627   list_intersect(TSAN_SUPPORTED_ARCH
628     ALL_TSAN_SUPPORTED_ARCH
629     SANITIZER_COMMON_SUPPORTED_ARCH)
630   list_intersect(UBSAN_SUPPORTED_ARCH
631     ALL_UBSAN_SUPPORTED_ARCH
632     SANITIZER_COMMON_SUPPORTED_ARCH)
633   list_intersect(SAFESTACK_SUPPORTED_ARCH
634     ALL_SAFESTACK_SUPPORTED_ARCH
635     SANITIZER_COMMON_SUPPORTED_ARCH)
636   list_intersect(CFI_SUPPORTED_ARCH
637     ALL_CFI_SUPPORTED_ARCH
638     SANITIZER_COMMON_SUPPORTED_ARCH)
639   list_intersect(SCUDO_STANDALONE_SUPPORTED_ARCH
640     ALL_SCUDO_STANDALONE_SUPPORTED_ARCH
641     SANITIZER_COMMON_SUPPORTED_ARCH)
642   list_intersect(FUZZER_SUPPORTED_ARCH
643     ALL_FUZZER_SUPPORTED_ARCH
644     SANITIZER_COMMON_SUPPORTED_ARCH)
645   list_intersect(XRAY_SUPPORTED_ARCH
646     ALL_XRAY_SUPPORTED_ARCH
647     SANITIZER_COMMON_SUPPORTED_ARCH)
648   list_intersect(SHADOWCALLSTACK_SUPPORTED_ARCH
649     ALL_SHADOWCALLSTACK_SUPPORTED_ARCH
650     SANITIZER_COMMON_SUPPORTED_ARCH)
651   list_intersect(ORC_SUPPORTED_ARCH
652     ALL_ORC_SUPPORTED_ARCH
653     SANITIZER_COMMON_SUPPORTED_ARCH)
655 else()
656   # Architectures supported by compiler-rt libraries.
657   filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
658     ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH})
659   # LSan and UBSan common files should be available on all architectures
660   # supported by other sanitizers (even if they build into dummy object files).
661   filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
662     ${SANITIZER_COMMON_SUPPORTED_ARCH})
663   filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
664     ${SANITIZER_COMMON_SUPPORTED_ARCH})
665   filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
666   filter_available_targets(FUZZER_SUPPORTED_ARCH ${ALL_FUZZER_SUPPORTED_ARCH})
667   filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
668   filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
669   filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
670   filter_available_targets(HWASAN_SUPPORTED_ARCH ${ALL_HWASAN_SUPPORTED_ARCH})
671   filter_available_targets(MEMPROF_SUPPORTED_ARCH ${ALL_MEMPROF_SUPPORTED_ARCH})
672   filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
673   filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
674   filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
675   filter_available_targets(SAFESTACK_SUPPORTED_ARCH
676     ${ALL_SAFESTACK_SUPPORTED_ARCH})
677   filter_available_targets(CFI_SUPPORTED_ARCH ${ALL_CFI_SUPPORTED_ARCH})
678   filter_available_targets(SCUDO_STANDALONE_SUPPORTED_ARCH ${ALL_SCUDO_STANDALONE_SUPPORTED_ARCH})
679   filter_available_targets(XRAY_SUPPORTED_ARCH ${ALL_XRAY_SUPPORTED_ARCH})
680   filter_available_targets(SHADOWCALLSTACK_SUPPORTED_ARCH
681     ${ALL_SHADOWCALLSTACK_SUPPORTED_ARCH})
682   filter_available_targets(GWP_ASAN_SUPPORTED_ARCH ${ALL_GWP_ASAN_SUPPORTED_ARCH})
683   filter_available_targets(ORC_SUPPORTED_ARCH ${ALL_ORC_SUPPORTED_ARCH})
684 endif()
686 if (MSVC)
687   # Allow setting clang-cl's /winsysroot flag.
688   set(LLVM_WINSYSROOT "" CACHE STRING
689     "If set, argument to clang-cl's /winsysroot")
691   if (LLVM_WINSYSROOT)
692     set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
693         "Path to the DIA SDK")
694   else()
695     set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
696         "Path to the DIA SDK")
697   endif()
699   # See if the DIA SDK is available and usable.
700   if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
701     set(CAN_SYMBOLIZE 1)
702   else()
703     set(CAN_SYMBOLIZE 0)
704   endif()
705 else()
706   set(CAN_SYMBOLIZE 1)
707 endif()
709 find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
710 find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold DOC "GNU gold")
712 if(COMPILER_RT_SUPPORTED_ARCH)
713   list(REMOVE_DUPLICATES COMPILER_RT_SUPPORTED_ARCH)
714 endif()
715 message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
717 set(ALL_SANITIZERS asan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;asan_abi)
718 set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
719     "sanitizers to build if supported on the target (all;${ALL_SANITIZERS})")
720 list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
722 if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
723     (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS" OR
724     (OS_NAME MATCHES "Windows" AND NOT CYGWIN AND
725         (NOT MINGW OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))))
726   set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
727 else()
728   set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
729 endif()
731 if (COMPILER_RT_HAS_SANITIZER_COMMON)
732   set(COMPILER_RT_HAS_INTERCEPTION TRUE)
733 else()
734   set(COMPILER_RT_HAS_INTERCEPTION FALSE)
735 endif()
737 if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND APPLE)
738   set(COMPILER_RT_HAS_ASAN_ABI TRUE)
739 else()
740   set(COMPILER_RT_HAS_ASAN_ABI FALSE)
741 endif()
742 if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
743   set(COMPILER_RT_HAS_ASAN TRUE)
744 else()
745   set(COMPILER_RT_HAS_ASAN FALSE)
746 endif()
748 if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
749   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
750 else()
751   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
752 endif()
754 # TODO: Add builtins support.
756 if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
757     OS_NAME MATCHES "Linux")
758   set(COMPILER_RT_HAS_DFSAN TRUE)
759 else()
760   set(COMPILER_RT_HAS_DFSAN FALSE)
761 endif()
763 if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
764     OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|Fuchsia")
765   set(COMPILER_RT_HAS_LSAN TRUE)
766 else()
767   set(COMPILER_RT_HAS_LSAN FALSE)
768 endif()
770 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
771     OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
772   set(COMPILER_RT_HAS_MSAN TRUE)
773 else()
774   set(COMPILER_RT_HAS_MSAN FALSE)
775 endif()
777 if (COMPILER_RT_HAS_SANITIZER_COMMON AND HWASAN_SUPPORTED_ARCH AND
778     OS_NAME MATCHES "Linux|Android|Fuchsia")
779   set(COMPILER_RT_HAS_HWASAN TRUE)
780 else()
781   set(COMPILER_RT_HAS_HWASAN FALSE)
782 endif()
784 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MEMPROF_SUPPORTED_ARCH AND
785     OS_NAME MATCHES "Linux")
786   set(COMPILER_RT_HAS_MEMPROF TRUE)
787 else()
788   set(COMPILER_RT_HAS_MEMPROF FALSE)
789 endif()
791 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
792     OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
793   set(COMPILER_RT_HAS_PROFILE TRUE)
794 else()
795   set(COMPILER_RT_HAS_PROFILE FALSE)
796 endif()
798 if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH)
799   if (OS_NAME MATCHES "Linux|Darwin|FreeBSD|NetBSD")
800     set(COMPILER_RT_HAS_TSAN TRUE)
801   elseif (OS_NAME MATCHES "Android" AND ANDROID_PLATFORM_LEVEL GREATER 23)
802     set(COMPILER_RT_HAS_TSAN TRUE)
803   else()
804     set(COMPILER_RT_HAS_TSAN FALSE)
805   endif()
806 else()
807   set(COMPILER_RT_HAS_TSAN FALSE)
808 endif()
810 if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
811   set(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME TRUE)
812 else()
813   set(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME FALSE)
814 endif()
816 if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
817     OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS")
818   set(COMPILER_RT_HAS_UBSAN TRUE)
819 else()
820   set(COMPILER_RT_HAS_UBSAN FALSE)
821 endif()
823 if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
824     OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Android|Darwin")
825   set(COMPILER_RT_HAS_UBSAN_MINIMAL TRUE)
826 else()
827   set(COMPILER_RT_HAS_UBSAN_MINIMAL FALSE)
828 endif()
830 if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
831     OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
832   set(COMPILER_RT_HAS_SAFESTACK TRUE)
833 else()
834   set(COMPILER_RT_HAS_SAFESTACK FALSE)
835 endif()
837 if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH)
838   set(COMPILER_RT_HAS_CFI TRUE)
839 else()
840   set(COMPILER_RT_HAS_CFI FALSE)
841 endif()
843 #TODO(kostyak): add back Android & Fuchsia when the code settles a bit.
844 if (SCUDO_STANDALONE_SUPPORTED_ARCH AND
845     COMPILER_RT_BUILD_SANITIZERS AND
846     "scudo_standalone" IN_LIST COMPILER_RT_SANITIZERS_TO_BUILD AND
847     OS_NAME MATCHES "Linux" AND
848     COMPILER_RT_HAS_AUXV)
849   set(COMPILER_RT_HAS_SCUDO_STANDALONE TRUE)
850 else()
851   set(COMPILER_RT_HAS_SCUDO_STANDALONE FALSE)
852 endif()
854 if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND
855     OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Fuchsia")
856   set(COMPILER_RT_HAS_XRAY TRUE)
857 else()
858   set(COMPILER_RT_HAS_XRAY FALSE)
859 endif()
861 if (ORC_SUPPORTED_ARCH)
862   set(COMPILER_RT_HAS_ORC TRUE)
863 else()
864   set(COMPILER_RT_HAS_ORC FALSE)
865 endif()
867 if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
868     OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|Fuchsia|Windows")
869   set(COMPILER_RT_HAS_FUZZER TRUE)
870 else()
871   set(COMPILER_RT_HAS_FUZZER FALSE)
872 endif()
874 if (COMPILER_RT_HAS_SANITIZER_COMMON AND SHADOWCALLSTACK_SUPPORTED_ARCH AND
875     OS_NAME MATCHES "Linux|Android")
876   set(COMPILER_RT_HAS_SHADOWCALLSTACK TRUE)
877 else()
878   set(COMPILER_RT_HAS_SHADOWCALLSTACK FALSE)
879 endif()
881 # Note: Fuchsia and Windows are not currently supported by GWP-ASan. Support
882 # is planned for these platforms. Darwin is also not supported due to TLS
883 # calling malloc on first use.
884 # TODO(hctim): Enable this on Android again. Looks like it's causing a SIGSEGV
885 # for Scudo and GWP-ASan, further testing needed.
886 if (GWP_ASAN_SUPPORTED_ARCH AND
887     COMPILER_RT_BUILD_GWP_ASAN AND
888     COMPILER_RT_BUILD_SANITIZERS AND
889     "gwp_asan" IN_LIST COMPILER_RT_SANITIZERS_TO_BUILD AND
890     OS_NAME MATCHES "Linux")
891   set(COMPILER_RT_HAS_GWP_ASAN TRUE)
892 else()
893   set(COMPILER_RT_HAS_GWP_ASAN FALSE)
894 endif()
895 pythonize_bool(COMPILER_RT_HAS_GWP_ASAN)