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