llvm-project

Форк
0
/
config-ix.cmake 
922 строки · 37.6 Кб
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)
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.
19
llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
20

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()
36

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 ()
77

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)
107

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()
112

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)
117

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)
122

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 -Wgnu-anonymous-struct" COMPILER_RT_HAS_WGNU_ANONYMOUS_STRUCT_FLAG)
131
check_cxx_compiler_flag("-Werror -Wvariadic-macros"    COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
132
check_cxx_compiler_flag("-Werror -Wunused-parameter"   COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
133
check_cxx_compiler_flag("-Werror -Wcovered-switch-default" COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
134
check_cxx_compiler_flag("-Werror -Wsuggest-override"   COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
135
check_cxx_compiler_flag("-Werror -Wthread-safety" COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG)
136
check_cxx_compiler_flag("-Werror -Wthread-safety-reference" COMPILER_RT_HAS_WTHREAD_SAFETY_REFERENCE_FLAG)
137
check_cxx_compiler_flag("-Werror -Wthread-safety-beta" COMPILER_RT_HAS_WTHREAD_SAFETY_BETA_FLAG)
138
check_cxx_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC)
139
check_cxx_compiler_flag(-Wno-format COMPILER_RT_HAS_WNO_FORMAT)
140
check_cxx_compiler_flag(-Wno-format-pedantic COMPILER_RT_HAS_WNO_FORMAT_PEDANTIC)
141

142
check_cxx_compiler_flag("/experimental:external /external:W0" COMPILER_RT_HAS_EXTERNAL_FLAG)
143

144
check_cxx_compiler_flag(/W4 COMPILER_RT_HAS_W4_FLAG)
145
check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG)
146
check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG)
147
check_cxx_compiler_flag(/wd4206 COMPILER_RT_HAS_WD4206_FLAG)
148
check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG)
149
check_cxx_compiler_flag(/wd4221 COMPILER_RT_HAS_WD4221_FLAG)
150
check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG)
151
check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG)
152
check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG)
153

154
check_cxx_compiler_flag("-Werror -Warray-bounds" COMPILER_RT_HAS_ARRAY_BOUNDS_FLAG)
155
check_cxx_compiler_flag("-Werror -Wuninitialized" COMPILER_RT_HAS_UNINITIALIZED_FLAG)
156
check_cxx_compiler_flag("-Werror -Wshadow" COMPILER_RT_HAS_SHADOW_FLAG)
157
check_cxx_compiler_flag("-Werror -Wempty-body" COMPILER_RT_HAS_EMPTY_BODY_FLAG)
158
check_cxx_compiler_flag("-Werror -Wsizeof-pointer-memaccess" COMPILER_RT_HAS_SIZEOF_POINTER_MEMACCESS_FLAG)
159
check_cxx_compiler_flag("-Werror -Wsizeof-array-argument" COMPILER_RT_HAS_SIZEOF_ARRAY_ARGUMENT_FLAG)
160
check_cxx_compiler_flag("-Werror -Wsuspicious-memaccess" COMPILER_RT_HAS_SUSPICIOUS_MEMACCESS_FLAG)
161
check_cxx_compiler_flag("-Werror -Wbuiltin-memcpy-chk-size" COMPILER_RT_HAS_BUILTIN_MEMCPY_CHK_SIZE_FLAG)
162
check_cxx_compiler_flag("-Werror -Warray-bounds-pointer-arithmetic" COMPILER_RT_HAS_ARRAY_BOUNDS_POINTER_ARITHMETIC_FLAG)
163
check_cxx_compiler_flag("-Werror -Wreturn-stack-address" COMPILER_RT_HAS_RETURN_STACK_ADDRESS_FLAG)
164
check_cxx_compiler_flag("-Werror -Wsizeof-array-decay" COMPILER_RT_HAS_SIZEOF_ARRAY_DECAY_FLAG)
165
check_cxx_compiler_flag("-Werror -Wformat-insufficient-args" COMPILER_RT_HAS_FORMAT_INSUFFICIENT_ARGS_FLAG)
166
check_cxx_compiler_flag("-Werror -Wformat-security" COMPILER_RT_HAS_BUILTIN_FORMAL_SECURITY_FLAG)
167
check_cxx_compiler_flag("-Werror -Wsizeof-array-div" COMPILER_RT_HAS_SIZEOF_ARRAY_DIV_FLAG)
168
check_cxx_compiler_flag("-Werror -Wsizeof-pointer-div" COMPILER_RT_HAS_SIZEOF_POINTER_DIV_FLAG)
169

170
# Symbols.
171
check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
172

173
# Includes.
174
check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG)
175
check_cxx_compiler_flag(-nostdlib++ COMPILER_RT_HAS_NOSTDLIBXX_FLAG)
176
check_include_files("sys/auxv.h"    COMPILER_RT_HAS_AUXV)
177

178
# Libraries.
179
check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
180
check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
181
check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
182
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
183
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
184

185
if (ANDROID AND COMPILER_RT_HAS_LIBDL)
186
  # Android's libstdc++ has a dependency on libdl.
187
  list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
188
endif()
189
check_library_exists(c++ __cxa_throw "" COMPILER_RT_HAS_LIBCXX)
190
check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX)
191

192
# Linker flags.
193
llvm_check_compiler_linker_flag(C "-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
194
llvm_check_compiler_linker_flag(C "-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
195

196
if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
197
  set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat")
198
  llvm_check_compiler_linker_flag(C "${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
199
endif()
200

201
set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers)
202
file(WRITE ${DUMMY_VERS} "{};")
203
set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}")
204
if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
205
  # Solaris 11.4 ld only supports --version-script with
206
  # -z gnu-version-script-compat.
207
  string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}")
208
endif()
209
llvm_check_compiler_linker_flag(C "${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)
210

211
if(ANDROID)
212
  llvm_check_compiler_linker_flag(C "-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
213
  check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)
214
endif()
215

216
# Architectures.
217

218
# List of all architectures we can target.
219
set(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.
225
set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc)
226
file(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.
231
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND
232
    NOT CMAKE_SIZEOF_VOID_P EQUAL 8 AND
233
    NOT ${arch} MATCHES "avr|msp430")
234
  message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.")
235
endif()
236

237
test_targets()
238

239
# Returns a list of architecture specific target cflags in @out_var list.
240
function(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()
254
endfunction()
255

256
# Returns a list of architecture specific target ldflags in @out_var list.
257
function(get_target_link_flags_for_arch arch out_var)
258
  list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX)
259
  if(ARCH_INDEX EQUAL -1)
260
    message(FATAL_ERROR "Unsupported architecture: ${arch}")
261
  else()
262
    # Workaround for direct calls to __tls_get_addr on Solaris/amd64.
263
    if(OS_NAME MATCHES "SunOS" AND ${arch} MATCHES x86_64)
264
      set(${out_var} "-Wl,-z,relax=transtls" PARENT_SCOPE)
265
    endif()
266
  endif()
267
endfunction()
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.
272
macro(get_test_cc_for_arch arch cc_out cflags_out)
273
  if (NOT ${ARGC} EQUAL 3)
274
    message(FATAL_ERROR "got too many args. expected 3, got ${ARGC} (namely: ${ARGV})")
275
  endif()
276
  if(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.
279
    set(${cc_out} ${COMPILER_RT_TEST_COMPILER})
280
    set(${cflags_out} ${COMPILER_RT_TEST_COMPILER_CFLAGS})
281
  else()
282
    get_target_flags_for_arch(${arch} ${cflags_out})
283
    if(APPLE)
284
      list(APPEND ${cflags_out} ${DARWIN_osx_CFLAGS})
285
    endif()
286
    string(REPLACE ";" " " ${cflags_out} "${${cflags_out}}")
287
  endif()
288
endmacro()
289

290
# Returns CFLAGS that should be used to run tests for the
291
# specific apple platform and architecture.
292
function(get_test_cflags_for_apple_platform platform arch cflags_out)
293
  is_valid_apple_platform("${platform}" is_valid_platform)
294
  if (NOT is_valid_platform)
295
    message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
296
  endif()
297
  set(test_cflags "")
298
  get_target_flags_for_arch(${arch} test_cflags)
299

300
  if (NOT "${arch}" STREQUAL "arm64e")
301
    list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
302
  else()
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.
309
    foreach (flag ${DARWIN_${platform}_CFLAGS})
310
      if ("${flag}" MATCHES "^${DARWIN_${platform}_MIN_VER_FLAG}=.+")
311
        # Find the SDK version
312
        get_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.
315
        if (NOT "${xcrun_platform_name}" STREQUAL "")
316
          find_darwin_sdk_version(platform_sdk_version "${xcrun_platform_name}")
317
          # Patch flag with correct deployment target
318
          set(replacement_flag "${DARWIN_${platform}_MIN_VER_FLAG}=${platform_sdk_version}")
319
          list(APPEND test_cflags "${replacement_flag}")
320
        endif()
321
      else()
322
        # Copy through
323
        list(APPEND test_cflags "${flag}")
324
      endif()
325
    endforeach()
326
  endif()
327

328
  string(REPLACE ";" " " test_cflags_str "${test_cflags}")
329
  string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
330
  set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
331
endfunction()
332

333
function(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.
336
  is_valid_apple_platform("${platform}" is_valid_platform)
337
  if (NOT is_valid_platform)
338
    message(FATAL_ERROR "\"${platform}\" is not a valid apple platform")
339
  endif()
340
  string(TOUPPER "${platform}" platform_upper)
341
  string(REGEX REPLACE "OSSIM$" "OSSim" platform_upper_capitalized "${platform_upper}")
342
  set(${platform_capitalized} "${platform_upper_capitalized}" PARENT_SCOPE)
343
endfunction()
344

345
function(is_valid_apple_platform platform is_valid_out)
346
  set(is_valid FALSE)
347
  if ("${platform}" STREQUAL "")
348
    message(FATAL_ERROR "platform cannot be empty")
349
  endif()
350
  if ("${platform}" MATCHES "^(osx|((ios|watchos|tvos)(sim)?))$")
351
    set(is_valid TRUE)
352
  endif()
353
  set(${is_valid_out} ${is_valid} PARENT_SCOPE)
354
endfunction()
355

356
# Maps the Apple platform name used in Compiler-rt's CMake code
357
# to the name recognised by xcrun's `--sdk` argument
358
function(get_xcrun_platform_from_apple_platform platform out_var)
359
  set(xcrun_platform "")
360
  if ("${platform}" STREQUAL "osx")
361
    set(xcrun_platform "macosx")
362
  elseif ("${platform}" STREQUAL "iossim")
363
    set(xcrun_platform "iphonesimulator")
364
  elseif ("${platform}" STREQUAL "ios")
365
    set(xcrun_platform "iphoneos")
366
  elseif ("${platform}" STREQUAL "watchossim")
367
    set(xcrun_platform "watchsimulator")
368
  elseif ("${platform}" STREQUAL "watchos")
369
    set(xcrun_platform "watchos")
370
  elseif ("${platform}" STREQUAL "tvossim")
371
    set(xcrun_platform "appletvsimulator")
372
  elseif ("${platform}" STREQUAL "tvos")
373
    set(xcrun_platform "appletvos")
374
  else()
375
    # TODO(dliew): Make this an error.
376
    message(WARNING "\"${platform}\" is not a handled apple platform")
377
  endif()
378
  set(${out_var} ${xcrun_platform} PARENT_SCOPE)
379
endfunction()
380

381
include(AllSupportedArchDefs)
382

383
if(APPLE)
384
  include(CompilerRTDarwinUtils)
385

386
  find_darwin_sdk_dir(DARWIN_osx_SYSROOT macosx)
387
  find_darwin_sdk_dir(DARWIN_iossim_SYSROOT iphonesimulator)
388
  find_darwin_sdk_dir(DARWIN_ios_SYSROOT iphoneos)
389
  find_darwin_sdk_dir(DARWIN_watchossim_SYSROOT watchsimulator)
390
  find_darwin_sdk_dir(DARWIN_watchos_SYSROOT watchos)
391
  find_darwin_sdk_dir(DARWIN_tvossim_SYSROOT appletvsimulator)
392
  find_darwin_sdk_dir(DARWIN_tvos_SYSROOT appletvos)
393

394
  if(NOT DARWIN_osx_SYSROOT)
395
    message(WARNING "Could not determine OS X sysroot, trying /usr/include")
396
    if(EXISTS /usr/include)
397
      set(DARWIN_osx_SYSROOT /)
398
    else()
399
      message(ERROR "Could not detect OS X Sysroot. Either install Xcode or the Apple Command Line Tools")
400
    endif()
401
  endif()
402

403
  if(COMPILER_RT_ENABLE_IOS)
404
    list(APPEND DARWIN_EMBEDDED_PLATFORMS ios)
405
    set(DARWIN_ios_MIN_VER 9.0)
406
    set(DARWIN_ios_MIN_VER_FLAG -miphoneos-version-min)
407
    set(DARWIN_ios_SANITIZER_MIN_VER_FLAG
408
      ${DARWIN_ios_MIN_VER_FLAG}=${DARWIN_ios_MIN_VER})
409
    set(DARWIN_iossim_MIN_VER_FLAG -mios-simulator-version-min)
410
    set(DARWIN_iossim_SANITIZER_MIN_VER_FLAG
411
      ${DARWIN_iossim_MIN_VER_FLAG}=${DARWIN_ios_MIN_VER})
412
  endif()
413
  if(COMPILER_RT_ENABLE_WATCHOS)
414
    list(APPEND DARWIN_EMBEDDED_PLATFORMS watchos)
415
    set(DARWIN_watchos_MIN_VER 2.0)
416
    set(DARWIN_watchos_MIN_VER_FLAG -mwatchos-version-min)
417
    set(DARWIN_watchos_SANITIZER_MIN_VER_FLAG
418
      ${DARWIN_watchos_MIN_VER_FLAG}=${DARWIN_watchos_MIN_VER})
419
    set(DARWIN_watchossim_MIN_VER_FLAG -mwatchos-simulator-version-min)
420
    set(DARWIN_watchossim_SANITIZER_MIN_VER_FLAG
421
      ${DARWIN_watchossim_MIN_VER_FLAG}=${DARWIN_watchos_MIN_VER})
422
  endif()
423
  if(COMPILER_RT_ENABLE_TVOS)
424
    list(APPEND DARWIN_EMBEDDED_PLATFORMS tvos)
425
    set(DARWIN_tvos_MIN_VER 9.0)
426
    set(DARWIN_tvos_MIN_VER_FLAG -mtvos-version-min)
427
    set(DARWIN_tvos_SANITIZER_MIN_VER_FLAG
428
      ${DARWIN_tvos_MIN_VER_FLAG}=${DARWIN_tvos_MIN_VER})
429
    set(DARWIN_tvossim_MIN_VER_FLAG -mtvos-simulator-version-min)
430
    set(DARWIN_tvossim_SANITIZER_MIN_VER_FLAG
431
      ${DARWIN_tvossim_MIN_VER_FLAG}=${DARWIN_tvos_MIN_VER})
432
  endif()
433

434
  set(SANITIZER_COMMON_SUPPORTED_OS osx)
435
  set(PROFILE_SUPPORTED_OS osx)
436
  set(TSAN_SUPPORTED_OS osx)
437
  set(XRAY_SUPPORTED_OS osx)
438
  set(FUZZER_SUPPORTED_OS osx)
439
  set(ORC_SUPPORTED_OS)
440
  set(UBSAN_SUPPORTED_OS osx)
441
  set(LSAN_SUPPORTED_OS osx)
442
  set(STATS_SUPPORTED_OS osx)
443

444
  # FIXME: Support a general COMPILER_RT_ENABLE_OSX to match other platforms.
445
  set(ORC_ENABLE_OSX 1 CACHE BOOL "Whether to build the orc runtime library for osx")
446
  if(ORC_ENABLE_OSX)
447
    set(ORC_SUPPORTED_OS osx)
448
  endif()
449

450
  set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.13)
451
  set(DARWIN_osx_MIN_VER_FLAG "-mmacosx-version-min")
452

453
  string(REGEX MATCH "${DARWIN_osx_MIN_VER_FLAG}=([.0-9]+)"
454
         MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}")
455

456
  if(NOT SANITIZER_MIN_OSX_VERSION)
457
    if(MACOSX_VERSION_MIN_FLAG)
458
      set(MIN_OSX_VERSION "${CMAKE_MATCH_1}")
459
    elseif(CMAKE_OSX_DEPLOYMENT_TARGET)
460
      set(MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET})
461
    else()
462
      set(MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION})
463
    endif()
464

465
    # Note: In order to target x86_64h on OS X the minimum deployment target must
466
    # be 10.8 or higher.
467
    if(MIN_OSX_VERSION VERSION_LESS "10.7")
468
      message(FATAL_ERROR "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too old.")
469
    endif()
470
  endif()
471

472
  set(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
476
  set(CMAKE_OSX_DEPLOYMENT_TARGET "")
477

478
  set(DARWIN_COMMON_CFLAGS -stdlib=libc++)
479
  set(DARWIN_COMMON_LINK_FLAGS
480
    -stdlib=libc++
481
    -lc++
482
    -lc++abi)
483

484
  llvm_check_compiler_linker_flag(C "-fapplication-extension" COMPILER_RT_HAS_APP_EXTENSION)
485
  if(COMPILER_RT_HAS_APP_EXTENSION)
486
    list(APPEND DARWIN_COMMON_LINK_FLAGS "-fapplication-extension")
487
  endif()
488

489
  set(DARWIN_osx_CFLAGS
490
    ${DARWIN_COMMON_CFLAGS}
491
    ${DARWIN_osx_MIN_VER_FLAG}=${SANITIZER_MIN_OSX_VERSION})
492
  set(DARWIN_osx_LINK_FLAGS
493
    ${DARWIN_COMMON_LINK_FLAGS}
494
    ${DARWIN_osx_MIN_VER_FLAG}=${SANITIZER_MIN_OSX_VERSION})
495

496
  if(DARWIN_osx_SYSROOT)
497
    list(APPEND DARWIN_osx_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
498
    list(APPEND DARWIN_osx_LINK_FLAGS -isysroot ${DARWIN_osx_SYSROOT})
499
  endif()
500

501
  # Figure out which arches to use for each OS
502
  darwin_get_toolchain_supported_archs(toolchain_arches)
503
  message(STATUS "Toolchain supported arches: ${toolchain_arches}")
504

505
  if(NOT MACOSX_VERSION_MIN_FLAG)
506
    darwin_test_archs(osx
507
      DARWIN_osx_ARCHS
508
      ${toolchain_arches})
509
    message(STATUS "OSX supported arches: ${DARWIN_osx_ARCHS}")
510
    foreach(arch ${DARWIN_osx_ARCHS})
511
      list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
512
      set(CAN_TARGET_${arch} 1)
513
    endforeach()
514

515
    foreach(platform ${DARWIN_EMBEDDED_PLATFORMS})
516
      if(DARWIN_${platform}sim_SYSROOT)
517
        set(DARWIN_${platform}sim_CFLAGS
518
          ${DARWIN_COMMON_CFLAGS}
519
          ${DARWIN_${platform}sim_SANITIZER_MIN_VER_FLAG}
520
          -isysroot ${DARWIN_${platform}sim_SYSROOT})
521
        set(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

526
        set(DARWIN_${platform}sim_SKIP_CC_KEXT On)
527
        darwin_test_archs(${platform}sim
528
          DARWIN_${platform}sim_ARCHS
529
          ${toolchain_arches})
530
        message(STATUS "${platform} Simulator supported arches: ${DARWIN_${platform}sim_ARCHS}")
531
        if(DARWIN_${platform}sim_ARCHS)
532
          list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform}sim)
533
          list(APPEND PROFILE_SUPPORTED_OS ${platform}sim)
534
          list(APPEND TSAN_SUPPORTED_OS ${platform}sim)
535
          list(APPEND FUZZER_SUPPORTED_OS ${platform}sim)
536
          list(APPEND ORC_SUPPORTED_OS ${platform}sim)
537
          list(APPEND UBSAN_SUPPORTED_OS ${platform}sim)
538
          list(APPEND LSAN_SUPPORTED_OS ${platform}sim)
539
          list(APPEND STATS_SUPPORTED_OS ${platform}sim)
540
        endif()
541
        foreach(arch ${DARWIN_${platform}sim_ARCHS})
542
          list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
543
          set(CAN_TARGET_${arch} 1)
544
        endforeach()
545
      endif()
546

547
      if(DARWIN_${platform}_SYSROOT)
548
        set(DARWIN_${platform}_CFLAGS
549
          ${DARWIN_COMMON_CFLAGS}
550
          ${DARWIN_${platform}_SANITIZER_MIN_VER_FLAG}
551
          -isysroot ${DARWIN_${platform}_SYSROOT})
552
        set(DARWIN_${platform}_LINK_FLAGS
553
          ${DARWIN_COMMON_LINK_FLAGS}
554
          ${DARWIN_${platform}_SANITIZER_MIN_VER_FLAG}
555
          -isysroot ${DARWIN_${platform}_SYSROOT})
556

557
        darwin_test_archs(${platform}
558
          DARWIN_${platform}_ARCHS
559
          ${toolchain_arches})
560
        message(STATUS "${platform} supported arches: ${DARWIN_${platform}_ARCHS}")
561
        if(DARWIN_${platform}_ARCHS)
562
          list(APPEND SANITIZER_COMMON_SUPPORTED_OS ${platform})
563
          list(APPEND PROFILE_SUPPORTED_OS ${platform})
564

565
          list_intersect(DARWIN_${platform}_TSAN_ARCHS DARWIN_${platform}_ARCHS ALL_TSAN_SUPPORTED_ARCH)
566
          if(DARWIN_${platform}_TSAN_ARCHS)
567
            list(APPEND TSAN_SUPPORTED_OS ${platform})
568
          endif()
569
          list(APPEND FUZZER_SUPPORTED_OS ${platform})
570
          list(APPEND ORC_SUPPORTED_OS ${platform})
571
          list(APPEND UBSAN_SUPPORTED_OS ${platform})
572
          list(APPEND LSAN_SUPPORTED_OS ${platform})
573
          list(APPEND STATS_SUPPORTED_OS ${platform})
574
        endif()
575
        foreach(arch ${DARWIN_${platform}_ARCHS})
576
          list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch})
577
          set(CAN_TARGET_${arch} 1)
578
        endforeach()
579
      endif()
580
    endforeach()
581
  endif()
582

583
  # Explicitly disable unsupported Sanitizer configurations.
584
  list(REMOVE_ITEM FUZZER_SUPPORTED_OS "watchos")
585
  list(REMOVE_ITEM FUZZER_SUPPORTED_OS "watchossim")
586

587
  # for list_intersect
588
  include(CompilerRTUtils)
589

590
  list_intersect(SANITIZER_COMMON_SUPPORTED_ARCH
591
    ALL_SANITIZER_COMMON_SUPPORTED_ARCH
592
    COMPILER_RT_SUPPORTED_ARCH
593
    )
594
  set(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
595
  set(UBSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH})
596
  set(ASAN_ABI_SUPPORTED_ARCH ${ALL_ASAN_ABI_SUPPORTED_ARCH})
597
  list_intersect(ASAN_SUPPORTED_ARCH
598
    ALL_ASAN_SUPPORTED_ARCH
599
    SANITIZER_COMMON_SUPPORTED_ARCH)
600
  list_intersect(RTSAN_SUPPORTED_ARCH
601
    ALL_RTSAN_SUPPORTED_ARCH
602
    SANITIZER_COMMON_SUPPORTED_ARCH)
603
  list_intersect(DFSAN_SUPPORTED_ARCH
604
    ALL_DFSAN_SUPPORTED_ARCH
605
    SANITIZER_COMMON_SUPPORTED_ARCH)
606
  list_intersect(GWP_ASAN_SUPPORTED_ARCH
607
    ALL_GWP_ASAN_SUPPORTED_ARCH
608
    SANITIZER_COMMON_SUPPORTED_ARCH)
609
  list_intersect(LSAN_SUPPORTED_ARCH
610
    ALL_LSAN_SUPPORTED_ARCH
611
    SANITIZER_COMMON_SUPPORTED_ARCH)
612
  list_intersect(MSAN_SUPPORTED_ARCH
613
    ALL_MSAN_SUPPORTED_ARCH
614
    SANITIZER_COMMON_SUPPORTED_ARCH)
615
  list_intersect(NSAN_SUPPORTED_ARCH
616
    ALL_NSAN_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(CTX_PROFILE_SUPPORTED_ARCH
628
    ALL_CTX_PROFILE_SUPPORTED_ARCH
629
    SANITIZER_COMMON_SUPPORTED_ARCH)
630
  list_intersect(TSAN_SUPPORTED_ARCH
631
    ALL_TSAN_SUPPORTED_ARCH
632
    SANITIZER_COMMON_SUPPORTED_ARCH)
633
  list_intersect(UBSAN_SUPPORTED_ARCH
634
    ALL_UBSAN_SUPPORTED_ARCH
635
    SANITIZER_COMMON_SUPPORTED_ARCH)
636
  list_intersect(SAFESTACK_SUPPORTED_ARCH
637
    ALL_SAFESTACK_SUPPORTED_ARCH
638
    SANITIZER_COMMON_SUPPORTED_ARCH)
639
  list_intersect(CFI_SUPPORTED_ARCH
640
    ALL_CFI_SUPPORTED_ARCH
641
    SANITIZER_COMMON_SUPPORTED_ARCH)
642
  list_intersect(SCUDO_STANDALONE_SUPPORTED_ARCH
643
    ALL_SCUDO_STANDALONE_SUPPORTED_ARCH
644
    SANITIZER_COMMON_SUPPORTED_ARCH)
645
  list_intersect(FUZZER_SUPPORTED_ARCH
646
    ALL_FUZZER_SUPPORTED_ARCH
647
    SANITIZER_COMMON_SUPPORTED_ARCH)
648
  list_intersect(XRAY_SUPPORTED_ARCH
649
    ALL_XRAY_SUPPORTED_ARCH
650
    SANITIZER_COMMON_SUPPORTED_ARCH)
651
  list_intersect(SHADOWCALLSTACK_SUPPORTED_ARCH
652
    ALL_SHADOWCALLSTACK_SUPPORTED_ARCH
653
    SANITIZER_COMMON_SUPPORTED_ARCH)
654
  list_intersect(ORC_SUPPORTED_ARCH
655
    ALL_ORC_SUPPORTED_ARCH
656
    SANITIZER_COMMON_SUPPORTED_ARCH)
657

658
else()
659
  # Architectures supported by compiler-rt libraries.
660
  filter_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).
664
  filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
665
    ${SANITIZER_COMMON_SUPPORTED_ARCH})
666
  filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
667
    ${SANITIZER_COMMON_SUPPORTED_ARCH})
668
  filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
669
  filter_available_targets(RTSAN_SUPPORTED_ARCH ${ALL_RTSAN_SUPPORTED_ARCH})
670
  filter_available_targets(FUZZER_SUPPORTED_ARCH ${ALL_FUZZER_SUPPORTED_ARCH})
671
  filter_available_targets(DFSAN_SUPPORTED_ARCH ${ALL_DFSAN_SUPPORTED_ARCH})
672
  filter_available_targets(LSAN_SUPPORTED_ARCH ${ALL_LSAN_SUPPORTED_ARCH})
673
  filter_available_targets(MSAN_SUPPORTED_ARCH ${ALL_MSAN_SUPPORTED_ARCH})
674
  filter_available_targets(HWASAN_SUPPORTED_ARCH ${ALL_HWASAN_SUPPORTED_ARCH})
675
  filter_available_targets(MEMPROF_SUPPORTED_ARCH ${ALL_MEMPROF_SUPPORTED_ARCH})
676
  filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
677
  filter_available_targets(CTX_PROFILE_SUPPORTED_ARCH ${ALL_CTX_PROFILE_SUPPORTED_ARCH})
678
  filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
679
  filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
680
  filter_available_targets(SAFESTACK_SUPPORTED_ARCH
681
    ${ALL_SAFESTACK_SUPPORTED_ARCH})
682
  filter_available_targets(CFI_SUPPORTED_ARCH ${ALL_CFI_SUPPORTED_ARCH})
683
  filter_available_targets(SCUDO_STANDALONE_SUPPORTED_ARCH ${ALL_SCUDO_STANDALONE_SUPPORTED_ARCH})
684
  filter_available_targets(XRAY_SUPPORTED_ARCH ${ALL_XRAY_SUPPORTED_ARCH})
685
  filter_available_targets(SHADOWCALLSTACK_SUPPORTED_ARCH
686
    ${ALL_SHADOWCALLSTACK_SUPPORTED_ARCH})
687
  filter_available_targets(GWP_ASAN_SUPPORTED_ARCH ${ALL_GWP_ASAN_SUPPORTED_ARCH})
688
  filter_available_targets(NSAN_SUPPORTED_ARCH ${ALL_NSAN_SUPPORTED_ARCH})
689
  filter_available_targets(ORC_SUPPORTED_ARCH ${ALL_ORC_SUPPORTED_ARCH})
690
endif()
691

692
if (MSVC)
693
  # Allow setting clang-cl's /winsysroot flag.
694
  set(LLVM_WINSYSROOT "" CACHE STRING
695
    "If set, argument to clang-cl's /winsysroot")
696

697
  if (LLVM_WINSYSROOT)
698
    set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
699
        "Path to the DIA SDK")
700
  else()
701
    set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
702
        "Path to the DIA SDK")
703
  endif()
704

705
  # See if the DIA SDK is available and usable.
706
  if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
707
    set(CAN_SYMBOLIZE 1)
708
  else()
709
    set(CAN_SYMBOLIZE 0)
710
  endif()
711
else()
712
  set(CAN_SYMBOLIZE 1)
713
endif()
714

715
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
716
find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold DOC "GNU gold")
717

718
if(COMPILER_RT_SUPPORTED_ARCH)
719
  list(REMOVE_DUPLICATES COMPILER_RT_SUPPORTED_ARCH)
720
endif()
721
message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")
722

723
set(ALL_SANITIZERS asan;rtsan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;nsan;asan_abi)
724
set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
725
    "sanitizers to build if supported on the target (all;${ALL_SANITIZERS})")
726
list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
727

728
if (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"))))
732
  set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
733
else()
734
  set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)
735
endif()
736

737
if (COMPILER_RT_HAS_SANITIZER_COMMON)
738
  set(COMPILER_RT_HAS_INTERCEPTION TRUE)
739
else()
740
  set(COMPILER_RT_HAS_INTERCEPTION FALSE)
741
endif()
742

743
if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND APPLE)
744
  set(COMPILER_RT_HAS_ASAN_ABI TRUE)
745
else()
746
  set(COMPILER_RT_HAS_ASAN_ABI FALSE)
747
endif()
748
if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
749
  set(COMPILER_RT_HAS_ASAN TRUE)
750
else()
751
  set(COMPILER_RT_HAS_ASAN FALSE)
752
endif()
753

754
if (COMPILER_RT_HAS_SANITIZER_COMMON AND RTSAN_SUPPORTED_ARCH AND
755
    OS_NAME MATCHES "Android|Darwin|Linux")
756
  set(COMPILER_RT_HAS_RTSAN TRUE)
757
else()
758
  set(COMPILER_RT_HAS_RTSAN FALSE)
759
endif()
760

761
if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
762
  set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
763
else()
764
  set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
765
endif()
766

767
# TODO: Add builtins support.
768

769
if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND
770
    OS_NAME MATCHES "Linux")
771
  set(COMPILER_RT_HAS_DFSAN TRUE)
772
else()
773
  set(COMPILER_RT_HAS_DFSAN FALSE)
774
endif()
775

776
if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
777
    OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|Fuchsia")
778
  set(COMPILER_RT_HAS_LSAN TRUE)
779
else()
780
  set(COMPILER_RT_HAS_LSAN FALSE)
781
endif()
782

783
if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
784
    OS_NAME MATCHES "Linux|FreeBSD|NetBSD")
785
  set(COMPILER_RT_HAS_MSAN TRUE)
786
else()
787
  set(COMPILER_RT_HAS_MSAN FALSE)
788
endif()
789

790
if (COMPILER_RT_HAS_SANITIZER_COMMON AND HWASAN_SUPPORTED_ARCH AND
791
    OS_NAME MATCHES "Linux|Android|Fuchsia")
792
  set(COMPILER_RT_HAS_HWASAN TRUE)
793
else()
794
  set(COMPILER_RT_HAS_HWASAN FALSE)
795
endif()
796

797
if (COMPILER_RT_HAS_SANITIZER_COMMON AND MEMPROF_SUPPORTED_ARCH AND
798
    OS_NAME MATCHES "Linux")
799
  set(COMPILER_RT_HAS_MEMPROF TRUE)
800
else()
801
  set(COMPILER_RT_HAS_MEMPROF FALSE)
802
endif()
803

804
if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
805
    OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
806
  set(COMPILER_RT_HAS_PROFILE TRUE)
807
else()
808
  set(COMPILER_RT_HAS_PROFILE FALSE)
809
endif()
810

811
if (COMPILER_RT_HAS_SANITIZER_COMMON AND CTX_PROFILE_SUPPORTED_ARCH AND
812
    OS_NAME MATCHES "Linux")
813
  set(COMPILER_RT_HAS_CTX_PROFILE TRUE)
814
else()
815
  set(COMPILER_RT_HAS_CTX_PROFILE FALSE)
816
endif()
817

818
if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH)
819
  if (OS_NAME MATCHES "Linux|Darwin|FreeBSD|NetBSD")
820
    set(COMPILER_RT_HAS_TSAN TRUE)
821
  elseif (OS_NAME MATCHES "Android" AND ANDROID_PLATFORM_LEVEL GREATER 23)
822
    set(COMPILER_RT_HAS_TSAN TRUE)
823
  else()
824
    set(COMPILER_RT_HAS_TSAN FALSE)
825
  endif()
826
else()
827
  set(COMPILER_RT_HAS_TSAN FALSE)
828
endif()
829

830
if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
831
  set(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME TRUE)
832
else()
833
  set(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME FALSE)
834
endif()
835

836
if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
837
    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS")
838
  set(COMPILER_RT_HAS_UBSAN TRUE)
839
else()
840
  set(COMPILER_RT_HAS_UBSAN FALSE)
841
endif()
842

843
if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
844
    OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Android|Darwin")
845
  set(COMPILER_RT_HAS_UBSAN_MINIMAL TRUE)
846
else()
847
  set(COMPILER_RT_HAS_UBSAN_MINIMAL FALSE)
848
endif()
849

850
if (COMPILER_RT_HAS_SANITIZER_COMMON AND SAFESTACK_SUPPORTED_ARCH AND
851
    OS_NAME MATCHES "Linux|FreeBSD|NetBSD|SunOS")
852
  set(COMPILER_RT_HAS_SAFESTACK TRUE)
853
else()
854
  set(COMPILER_RT_HAS_SAFESTACK FALSE)
855
endif()
856

857
if (COMPILER_RT_HAS_SANITIZER_COMMON AND CFI_SUPPORTED_ARCH)
858
  set(COMPILER_RT_HAS_CFI TRUE)
859
else()
860
  set(COMPILER_RT_HAS_CFI FALSE)
861
endif()
862

863
#TODO(kostyak): add back Android & Fuchsia when the code settles a bit.
864
if (SCUDO_STANDALONE_SUPPORTED_ARCH AND
865
    COMPILER_RT_BUILD_SANITIZERS AND
866
    "scudo_standalone" IN_LIST COMPILER_RT_SANITIZERS_TO_BUILD AND
867
    OS_NAME MATCHES "Linux" AND
868
    COMPILER_RT_HAS_AUXV)
869
  set(COMPILER_RT_HAS_SCUDO_STANDALONE TRUE)
870
else()
871
  set(COMPILER_RT_HAS_SCUDO_STANDALONE FALSE)
872
endif()
873

874
if (COMPILER_RT_HAS_SANITIZER_COMMON AND XRAY_SUPPORTED_ARCH AND
875
    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Fuchsia")
876
  set(COMPILER_RT_HAS_XRAY TRUE)
877
else()
878
  set(COMPILER_RT_HAS_XRAY FALSE)
879
endif()
880

881
if (ORC_SUPPORTED_ARCH)
882
  set(COMPILER_RT_HAS_ORC TRUE)
883
else()
884
  set(COMPILER_RT_HAS_ORC FALSE)
885
endif()
886

887
if (COMPILER_RT_HAS_SANITIZER_COMMON AND FUZZER_SUPPORTED_ARCH AND
888
    OS_NAME MATCHES "Android|Darwin|Linux|NetBSD|FreeBSD|Fuchsia|Windows")
889
  set(COMPILER_RT_HAS_FUZZER TRUE)
890
else()
891
  set(COMPILER_RT_HAS_FUZZER FALSE)
892
endif()
893

894
if (COMPILER_RT_HAS_SANITIZER_COMMON AND SHADOWCALLSTACK_SUPPORTED_ARCH AND
895
    OS_NAME MATCHES "Linux|Android")
896
  set(COMPILER_RT_HAS_SHADOWCALLSTACK TRUE)
897
else()
898
  set(COMPILER_RT_HAS_SHADOWCALLSTACK FALSE)
899
endif()
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.
906
if (GWP_ASAN_SUPPORTED_ARCH AND
907
    COMPILER_RT_BUILD_GWP_ASAN AND
908
    COMPILER_RT_BUILD_SANITIZERS AND
909
    "gwp_asan" IN_LIST COMPILER_RT_SANITIZERS_TO_BUILD AND
910
    OS_NAME MATCHES "Linux")
911
  set(COMPILER_RT_HAS_GWP_ASAN TRUE)
912
else()
913
  set(COMPILER_RT_HAS_GWP_ASAN FALSE)
914
endif()
915

916
if (COMPILER_RT_HAS_SANITIZER_COMMON AND NSAN_SUPPORTED_ARCH AND
917
    OS_NAME MATCHES "Linux")
918
  set(COMPILER_RT_HAS_NSAN TRUE)
919
else()
920
  set(COMPILER_RT_HAS_NSAN FALSE)
921
endif()
922
pythonize_bool(COMPILER_RT_HAS_GWP_ASAN)
923

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.