Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 1 | include(CMakePushCheckState) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 2 | include(CheckCXXCompilerFlag) |
| 3 | include(CheckLibraryExists) |
| 4 | include(CheckSymbolExists) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | include(TestBigEndian) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 7 | function(check_linker_flag flag out_var) |
| 8 | cmake_push_check_state() |
| 9 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}") |
| 10 | check_cxx_compiler_flag("" ${out_var}) |
| 11 | cmake_pop_check_state() |
| 12 | endfunction() |
| 13 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | # CodeGen options. |
| 15 | check_cxx_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) |
| 16 | check_cxx_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) |
| 17 | check_cxx_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_BUILTIN_FLAG) |
| 18 | check_cxx_compiler_flag(-fno-exceptions COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG) |
| 19 | check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG) |
| 20 | check_cxx_compiler_flag(-funwind-tables COMPILER_RT_HAS_FUNWIND_TABLES_FLAG) |
| 21 | check_cxx_compiler_flag(-fno-stack-protector COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 22 | check_cxx_compiler_flag(-fno-sanitize=safe-stack COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 23 | check_cxx_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG) |
| 24 | check_cxx_compiler_flag(-fno-rtti COMPILER_RT_HAS_FNO_RTTI_FLAG) |
| 25 | check_cxx_compiler_flag(-ffreestanding COMPILER_RT_HAS_FFREESTANDING_FLAG) |
| 26 | check_cxx_compiler_flag("-Werror -fno-function-sections" COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG) |
| 27 | check_cxx_compiler_flag(-std=c++11 COMPILER_RT_HAS_STD_CXX11_FLAG) |
| 28 | check_cxx_compiler_flag(-ftls-model=initial-exec COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 29 | check_cxx_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) |
| 30 | check_cxx_compiler_flag(-msse3 COMPILER_RT_HAS_MSSE3_FLAG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | |
| 32 | check_cxx_compiler_flag(/GR COMPILER_RT_HAS_GR_FLAG) |
| 33 | check_cxx_compiler_flag(/GS COMPILER_RT_HAS_GS_FLAG) |
| 34 | check_cxx_compiler_flag(/MT COMPILER_RT_HAS_MT_FLAG) |
| 35 | check_cxx_compiler_flag(/Oy COMPILER_RT_HAS_Oy_FLAG) |
| 36 | |
| 37 | # Debug info flags. |
| 38 | check_cxx_compiler_flag(-gline-tables-only COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG) |
| 39 | check_cxx_compiler_flag(-g COMPILER_RT_HAS_G_FLAG) |
| 40 | check_cxx_compiler_flag(/Zi COMPILER_RT_HAS_Zi_FLAG) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 41 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 42 | # Warnings. |
| 43 | check_cxx_compiler_flag(-Wall COMPILER_RT_HAS_WALL_FLAG) |
| 44 | check_cxx_compiler_flag(-Werror COMPILER_RT_HAS_WERROR_FLAG) |
| 45 | check_cxx_compiler_flag("-Werror -Wframe-larger-than=512" COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG) |
| 46 | check_cxx_compiler_flag("-Werror -Wglobal-constructors" COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 47 | check_cxx_compiler_flag("-Werror -Wc99-extensions" COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG) |
| 48 | check_cxx_compiler_flag("-Werror -Wgnu" COMPILER_RT_HAS_WGNU_FLAG) |
| 49 | check_cxx_compiler_flag("-Werror -Wnon-virtual-dtor" COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG) |
| 50 | check_cxx_compiler_flag("-Werror -Wvariadic-macros" COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 51 | |
| 52 | check_cxx_compiler_flag(/W3 COMPILER_RT_HAS_W3_FLAG) |
| 53 | check_cxx_compiler_flag(/WX COMPILER_RT_HAS_WX_FLAG) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 54 | check_cxx_compiler_flag(/wd4146 COMPILER_RT_HAS_WD4146_FLAG) |
| 55 | check_cxx_compiler_flag(/wd4291 COMPILER_RT_HAS_WD4291_FLAG) |
| 56 | check_cxx_compiler_flag(/wd4391 COMPILER_RT_HAS_WD4391_FLAG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 57 | check_cxx_compiler_flag(/wd4722 COMPILER_RT_HAS_WD4722_FLAG) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 58 | check_cxx_compiler_flag(/wd4800 COMPILER_RT_HAS_WD4800_FLAG) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 59 | |
| 60 | # Symbols. |
| 61 | check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL) |
| 62 | |
| 63 | # Libraries. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 64 | check_library_exists(c printf "" COMPILER_RT_HAS_LIBC) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 65 | check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 66 | check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 67 | check_library_exists(m pow "" COMPILER_RT_HAS_LIBM) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 68 | check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 69 | check_library_exists(stdc++ __cxa_throw "" COMPILER_RT_HAS_LIBSTDCXX) |
| 70 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 71 | # Linker flags. |
| 72 | if(ANDROID) |
| 73 | check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) |
| 74 | endif() |
| 75 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 76 | # Architectures. |
| 77 | |
| 78 | # List of all architectures we can target. |
| 79 | set(COMPILER_RT_SUPPORTED_ARCH) |
| 80 | |
| 81 | # Try to compile a very simple source file to ensure we can target the given |
| 82 | # platform. We use the results of these tests to build only the various target |
| 83 | # runtime libraries supported by our current compilers cross-compiling |
| 84 | # abilities. |
| 85 | set(SIMPLE_SOURCE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/simple.cc) |
| 86 | file(WRITE ${SIMPLE_SOURCE} "#include <stdlib.h>\n#include <limits>\nint main() {}\n") |
| 87 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 88 | function(check_compile_definition def argstring out_var) |
| 89 | if("${def}" STREQUAL "") |
| 90 | set(${out_var} TRUE PARENT_SCOPE) |
| 91 | return() |
| 92 | endif() |
| 93 | cmake_push_check_state() |
| 94 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}") |
| 95 | check_symbol_exists(${def} "" ${out_var}) |
| 96 | cmake_pop_check_state() |
| 97 | endfunction() |
| 98 | |
| 99 | # test_target_arch(<arch> <def> <target flags...>) |
| 100 | # Checks if architecture is supported: runs host compiler with provided |
| 101 | # flags to verify that: |
| 102 | # 1) <def> is defined (if non-empty) |
| 103 | # 2) simple file can be successfully built. |
| 104 | # If successful, saves target flags for this architecture. |
| 105 | macro(test_target_arch arch def) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 106 | set(TARGET_${arch}_CFLAGS ${ARGN}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 107 | set(argstring "") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 108 | foreach(arg ${ARGN}) |
| 109 | set(argstring "${argstring} ${arg}") |
| 110 | endforeach() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 111 | check_compile_definition("${def}" "${argstring}" HAS_${arch}_DEF) |
| 112 | if(NOT HAS_${arch}_DEF) |
| 113 | set(CAN_TARGET_${arch} FALSE) |
| 114 | else() |
| 115 | set(argstring "${CMAKE_EXE_LINKER_FLAGS} ${argstring}") |
| 116 | try_compile(CAN_TARGET_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_SOURCE} |
| 117 | COMPILE_DEFINITIONS "${TARGET_${arch}_CFLAGS}" |
| 118 | OUTPUT_VARIABLE TARGET_${arch}_OUTPUT |
| 119 | CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS:STRING=${argstring}") |
| 120 | endif() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 121 | if(${CAN_TARGET_${arch}}) |
| 122 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 123 | elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "${arch}") |
| 124 | # Bail out if we cannot target the architecture we plan to test. |
| 125 | message(FATAL_ERROR "Cannot compile for ${arch}:\n${TARGET_${arch}_OUTPUT}") |
| 126 | endif() |
| 127 | endmacro() |
| 128 | |
| 129 | # Add $arch as supported with no additional flags. |
| 130 | macro(add_default_target_arch arch) |
| 131 | set(TARGET_${arch}_CFLAGS "") |
| 132 | set(CAN_TARGET_${arch} 1) |
| 133 | list(APPEND COMPILER_RT_SUPPORTED_ARCH ${arch}) |
| 134 | endmacro() |
| 135 | |
| 136 | macro(detect_target_arch) |
| 137 | check_symbol_exists(__arm__ "" __ARM) |
| 138 | check_symbol_exists(__aarch64__ "" __AARCH64) |
| 139 | check_symbol_exists(__x86_64__ "" __X86_64) |
| 140 | check_symbol_exists(__i686__ "" __I686) |
| 141 | check_symbol_exists(__i386__ "" __I386) |
| 142 | check_symbol_exists(__mips__ "" __MIPS) |
| 143 | check_symbol_exists(__mips64__ "" __MIPS64) |
| 144 | if(__ARM) |
| 145 | add_default_target_arch(arm) |
| 146 | elseif(__AARCH64) |
| 147 | add_default_target_arch(aarch64) |
| 148 | elseif(__X86_64) |
| 149 | add_default_target_arch(x86_64) |
| 150 | elseif(__I686) |
| 151 | add_default_target_arch(i686) |
| 152 | elseif(__I386) |
| 153 | add_default_target_arch(i386) |
| 154 | elseif(__MIPS64) # must be checked before __MIPS |
| 155 | add_default_target_arch(mips64) |
| 156 | elseif(__MIPS) |
| 157 | add_default_target_arch(mips) |
| 158 | endif() |
| 159 | endmacro() |
| 160 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 161 | # Detect whether the current target platform is 32-bit or 64-bit, and setup |
| 162 | # the correct commandline flags needed to attempt to target 32-bit and 64-bit. |
| 163 | if (NOT CMAKE_SIZEOF_VOID_P EQUAL 4 AND |
| 164 | NOT CMAKE_SIZEOF_VOID_P EQUAL 8) |
| 165 | message(FATAL_ERROR "Please use architecture with 4 or 8 byte pointers.") |
| 166 | endif() |
| 167 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 168 | # Generate the COMPILER_RT_SUPPORTED_ARCH list. |
| 169 | if(ANDROID) |
| 170 | # Can't rely on LLVM_NATIVE_ARCH in cross-compilation. |
| 171 | # Examine compiler output instead. |
| 172 | detect_target_arch() |
| 173 | set(COMPILER_RT_OS_SUFFIX "-android") |
| 174 | else() |
| 175 | if("${LLVM_NATIVE_ARCH}" STREQUAL "X86") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 176 | if(NOT MSVC) |
| 177 | test_target_arch(x86_64 "" "-m64") |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 178 | # FIXME: We build runtimes for both i686 and i386, as "clang -m32" may |
| 179 | # target different variant than "$CMAKE_C_COMPILER -m32". This part should |
| 180 | # be gone after we resolve PR14109. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 181 | test_target_arch(i686 __i686__ "-m32") |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 182 | test_target_arch(i386 __i386__ "-m32") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 183 | else() |
| 184 | test_target_arch(i386 "" "") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 185 | endif() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 186 | elseif("${LLVM_NATIVE_ARCH}" STREQUAL "PowerPC") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 187 | TEST_BIG_ENDIAN(HOST_IS_BIG_ENDIAN) |
| 188 | if(HOST_IS_BIG_ENDIAN) |
| 189 | test_target_arch(powerpc64 "" "-m64") |
| 190 | else() |
| 191 | test_target_arch(powerpc64le "" "-m64") |
| 192 | endif() |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 193 | elseif("${LLVM_NATIVE_ARCH}" STREQUAL "Mips") |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 194 | # Gcc doesn't accept -m32/-m64 so we do the next best thing and use |
| 195 | # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match |
| 196 | # clang's default CPU's. In the 64-bit case, we must also specify the ABI |
| 197 | # since the default ABI differs between gcc and clang. |
| 198 | # FIXME: Ideally, we would build the N32 library too. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 199 | if("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "mipsel|mips64el") |
| 200 | # regex for mipsel, mips64el |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 201 | test_target_arch(mipsel "" "-mips32r2" "--target=mipsel-linux-gnu") |
| 202 | test_target_arch(mips64el "" "-mips64r2" "-mabi=n64") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 203 | else() |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 204 | test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu") |
| 205 | test_target_arch(mips64 "" "-mips64r2" "-mabi=n64") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 206 | endif() |
| 207 | elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 208 | test_target_arch(arm "" "-march=armv7-a") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 209 | elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch32") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 210 | test_target_arch(aarch32 "" "-march=armv8-a") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 211 | elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64") |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 212 | test_target_arch(aarch64 "" "-march=armv8-a") |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 213 | endif() |
| 214 | set(COMPILER_RT_OS_SUFFIX "") |
| 215 | endif() |
| 216 | |
| 217 | message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}") |
| 218 | |
| 219 | # Takes ${ARGN} and puts only supported architectures in @out_var list. |
| 220 | function(filter_available_targets out_var) |
| 221 | set(archs) |
| 222 | foreach(arch ${ARGN}) |
| 223 | list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) |
| 224 | if(NOT (ARCH_INDEX EQUAL -1) AND CAN_TARGET_${arch}) |
| 225 | list(APPEND archs ${arch}) |
| 226 | endif() |
| 227 | endforeach() |
| 228 | set(${out_var} ${archs} PARENT_SCOPE) |
| 229 | endfunction() |
| 230 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 231 | # Returns a list of architecture specific target cflags in @out_var list. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 232 | function(get_target_flags_for_arch arch out_var) |
| 233 | list(FIND COMPILER_RT_SUPPORTED_ARCH ${arch} ARCH_INDEX) |
| 234 | if(ARCH_INDEX EQUAL -1) |
| 235 | message(FATAL_ERROR "Unsupported architecture: ${arch}") |
| 236 | else() |
| 237 | set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE) |
| 238 | endif() |
| 239 | endfunction() |
| 240 | |
| 241 | # Architectures supported by compiler-rt libraries. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 242 | filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH |
| 243 | x86_64 i386 i686 powerpc64 powerpc64le arm aarch64 mips mips64 mipsel mips64el) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 244 | # LSan and UBSan common files should be available on all architectures supported |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 245 | # by other sanitizers (even if they build into dummy object files). |
| 246 | filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH |
| 247 | ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 248 | filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH |
| 249 | ${SANITIZER_COMMON_SUPPORTED_ARCH}) |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 250 | filter_available_targets(ASAN_SUPPORTED_ARCH |
| 251 | x86_64 i386 i686 powerpc64 powerpc64le arm mips mipsel mips64 mips64el) |
| 252 | filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) |
| 253 | filter_available_targets(LSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 254 | filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) |
| 255 | filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64 |
| 256 | mipsel mips64el aarch64 powerpc64 powerpc64le) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 257 | filter_available_targets(TSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 258 | filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips |
| 259 | mipsel mips64 mips64el powerpc64 powerpc64le) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 260 | filter_available_targets(SAFESTACK_SUPPORTED_ARCH x86_64 i386 i686) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 261 | |
| 262 | if(ANDROID) |
| 263 | set(OS_NAME "Android") |
| 264 | else() |
| 265 | set(OS_NAME "${CMAKE_SYSTEM_NAME}") |
| 266 | endif() |
| 267 | |
| 268 | if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND |
| 269 | (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD" OR |
| 270 | (OS_NAME MATCHES "Windows" AND MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 4))) |
| 271 | set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE) |
| 272 | else() |
| 273 | set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE) |
| 274 | endif() |
| 275 | |
| 276 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH) |
| 277 | set(COMPILER_RT_HAS_ASAN TRUE) |
| 278 | else() |
| 279 | set(COMPILER_RT_HAS_ASAN FALSE) |
| 280 | endif() |
| 281 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 282 | if (OS_NAME MATCHES "Linux|FreeBSD|Windows") |
| 283 | set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE) |
| 284 | else() |
| 285 | set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE) |
| 286 | endif() |
| 287 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 288 | # TODO: Add builtins support. |
| 289 | |
| 290 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND |
| 291 | OS_NAME MATCHES "Linux") |
| 292 | set(COMPILER_RT_HAS_DFSAN TRUE) |
| 293 | else() |
| 294 | set(COMPILER_RT_HAS_DFSAN FALSE) |
| 295 | endif() |
| 296 | |
| 297 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND |
| 298 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 299 | set(COMPILER_RT_HAS_LSAN TRUE) |
| 300 | else() |
| 301 | set(COMPILER_RT_HAS_LSAN FALSE) |
| 302 | endif() |
| 303 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 304 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND |
| 305 | OS_NAME MATCHES "Linux") |
| 306 | set(COMPILER_RT_HAS_MSAN TRUE) |
| 307 | else() |
| 308 | set(COMPILER_RT_HAS_MSAN FALSE) |
| 309 | endif() |
| 310 | |
| 311 | if (PROFILE_SUPPORTED_ARCH AND |
| 312 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 313 | set(COMPILER_RT_HAS_PROFILE TRUE) |
| 314 | else() |
| 315 | set(COMPILER_RT_HAS_PROFILE FALSE) |
| 316 | endif() |
| 317 | |
| 318 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH AND |
| 319 | OS_NAME MATCHES "Linux|FreeBSD") |
| 320 | set(COMPILER_RT_HAS_TSAN TRUE) |
| 321 | else() |
| 322 | set(COMPILER_RT_HAS_TSAN FALSE) |
| 323 | endif() |
| 324 | |
| 325 | if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND |
| 326 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 327 | set(COMPILER_RT_HAS_UBSAN TRUE) |
| 328 | else() |
| 329 | set(COMPILER_RT_HAS_UBSAN FALSE) |
| 330 | endif() |
| 331 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 332 | # -msse3 flag is not valid for Mips therefore clang gives a warning |
| 333 | # message with -msse3. But check_c_compiler_flags() checks only for |
| 334 | # compiler error messages. Therefore COMPILER_RT_HAS_MSSE3_FLAG turns out to be |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 335 | # true on Mips, so we make it false here. |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 336 | if("${LLVM_NATIVE_ARCH}" STREQUAL "Mips") |
| 337 | set(COMPILER_RT_HAS_MSSE3_FLAG FALSE) |
| 338 | endif() |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 339 | |
| 340 | if (SAFESTACK_SUPPORTED_ARCH AND |
| 341 | OS_NAME MATCHES "Darwin|Linux|FreeBSD") |
| 342 | set(COMPILER_RT_HAS_SAFESTACK TRUE) |
| 343 | else() |
| 344 | set(COMPILER_RT_HAS_SAFESTACK FALSE) |
| 345 | endif() |