annotate compiler-rt/CMakeLists.txt @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1f2b6ac9f198
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 # CMake build for CompilerRT.
anatofuz
parents:
diff changeset
2 #
anatofuz
parents:
diff changeset
3 # An important constraint of the build is that it only produces libraries
anatofuz
parents:
diff changeset
4 # based on the ability of the host toolchain to target various platforms.
anatofuz
parents:
diff changeset
5
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
6 cmake_minimum_required(VERSION 3.20.0)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
7
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
8 set(LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake")
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
9 include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
10 NO_POLICY_SCOPE)
150
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 # Check if compiler-rt is built as a standalone project.
anatofuz
parents:
diff changeset
13 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
anatofuz
parents:
diff changeset
14 project(CompilerRT C CXX ASM)
anatofuz
parents:
diff changeset
15 set(COMPILER_RT_STANDALONE_BUILD TRUE)
anatofuz
parents:
diff changeset
16 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
anatofuz
parents:
diff changeset
17 endif()
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 # Add path for custom compiler-rt modules.
anatofuz
parents:
diff changeset
20 list(INSERT CMAKE_MODULE_PATH 0
anatofuz
parents:
diff changeset
21 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
anatofuz
parents:
diff changeset
22 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
23 "${LLVM_COMMON_CMAKE_UTILS}"
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
24 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
150
anatofuz
parents:
diff changeset
25 )
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 if(CMAKE_CONFIGURATION_TYPES)
anatofuz
parents:
diff changeset
28 set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
anatofuz
parents:
diff changeset
29 else()
anatofuz
parents:
diff changeset
30 set(CMAKE_CFG_RESOLVED_INTDIR "")
anatofuz
parents:
diff changeset
31 endif()
anatofuz
parents:
diff changeset
32
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
33 include(SetPlatformToolchainTools)
150
anatofuz
parents:
diff changeset
34 include(base-config-ix)
anatofuz
parents:
diff changeset
35 include(CompilerRTUtils)
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
36 include(CMakeDependentOption)
150
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
anatofuz
parents:
diff changeset
39 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
40 option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
41 mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
150
anatofuz
parents:
diff changeset
42 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
anatofuz
parents:
diff changeset
43 mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
anatofuz
parents:
diff changeset
44 option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
anatofuz
parents:
diff changeset
45 mark_as_advanced(COMPILER_RT_BUILD_XRAY)
anatofuz
parents:
diff changeset
46 option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
anatofuz
parents:
diff changeset
47 mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
anatofuz
parents:
diff changeset
48 option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
anatofuz
parents:
diff changeset
49 mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
50 option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
51 mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
150
anatofuz
parents:
diff changeset
52 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
anatofuz
parents:
diff changeset
53 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
54 option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
55 mark_as_advanced(COMPILER_RT_BUILD_ORC)
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
56 option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
57 mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
58 option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
150
anatofuz
parents:
diff changeset
59
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
60 option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
61 mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
62 option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
63 mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
64 option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
65 mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
150
anatofuz
parents:
diff changeset
66
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
67 if(FUCHSIA)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
68 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
69 else()
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
70 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
71 endif()
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
72 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
150
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
anatofuz
parents:
diff changeset
75 "Build for a bare-metal target.")
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 if (COMPILER_RT_STANDALONE_BUILD)
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
78 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
79 set(CMAKE_CXX_STANDARD_REQUIRED YES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
80 set(CMAKE_CXX_EXTENSIONS NO)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
81
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
82 if (NOT LLVM_RUNTIMES_BUILD)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
83 load_llvm_config()
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
84 endif()
150
anatofuz
parents:
diff changeset
85 if (TARGET intrinsics_gen)
anatofuz
parents:
diff changeset
86 # Loading the llvm config causes this target to be imported so place it
anatofuz
parents:
diff changeset
87 # under the appropriate folder in an IDE.
anatofuz
parents:
diff changeset
88 set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
anatofuz
parents:
diff changeset
89 endif()
anatofuz
parents:
diff changeset
90
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
91 find_package(Python3 COMPONENTS Interpreter)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
92 if(NOT Python3_Interpreter_FOUND)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
93 message(WARNING "Python3 not found, using python2 as a fallback")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
94 find_package(Python2 COMPONENTS Interpreter REQUIRED)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
95 if(Python2_VERSION VERSION_LESS 2.7)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
96 message(SEND_ERROR "Python 2.7 or newer is required")
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
97 endif()
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
98
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
99 # Treat python2 as python3
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
100 add_executable(Python3::Interpreter IMPORTED)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
101 set_target_properties(Python3::Interpreter PROPERTIES
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
102 IMPORTED_LOCATION ${Python2_EXECUTABLE})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
103 set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
150
anatofuz
parents:
diff changeset
104 endif()
anatofuz
parents:
diff changeset
105
anatofuz
parents:
diff changeset
106 # Ensure that fat libraries are built correctly on Darwin
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
107 if(APPLE)
150
anatofuz
parents:
diff changeset
108 include(UseLibtool)
anatofuz
parents:
diff changeset
109 endif()
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 # Define default arguments to lit.
anatofuz
parents:
diff changeset
112 set(LIT_ARGS_DEFAULT "-sv")
anatofuz
parents:
diff changeset
113 if (MSVC OR XCODE)
anatofuz
parents:
diff changeset
114 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
anatofuz
parents:
diff changeset
115 endif()
anatofuz
parents:
diff changeset
116 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
anatofuz
parents:
diff changeset
117 set(LLVM_LIT_OUTPUT_DIR "${COMPILER_RT_EXEC_OUTPUT_DIR}")
anatofuz
parents:
diff changeset
118 endif()
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 construct_compiler_rt_default_triple()
anatofuz
parents:
diff changeset
121 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
anatofuz
parents:
diff changeset
122 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
anatofuz
parents:
diff changeset
123 set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
124 CHECK_SYMBOL_EXISTS (__thumb__ "" COMPILER_RT_ARM_THUMB)
150
anatofuz
parents:
diff changeset
125 endif()
anatofuz
parents:
diff changeset
126 endif()
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
127 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^mips")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
128 CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS32R6 "" COMPILER_RT_MIPS32R6)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
129 CHECK_SYMBOL_EXISTS (_MIPS_ARCH_MIPS64R6 "" COMPILER_RT_MIPS64R6)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
130 CHECK_SYMBOL_EXISTS (__mips64 "" COMPILER_RT_MIPS_64)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
131 CHECK_SYMBOL_EXISTS (__MIPSEL__ "" COMPILER_RT_MIPS_EL)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
132 if ("${COMPILER_RT_MIPS_64}")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
133 set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips64")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
134 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
135 set(COMPILER_RT_DEFAULT_TARGET_ARCH "mips")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
136 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
137 if ("${COMPILER_RT_MIPS_EL}")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
138 set(COMPILER_RT_DEFAULT_TARGET_ARCH "${COMPILER_RT_DEFAULT_TARGET_ARCH}el")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
139 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
140 endif()
150
anatofuz
parents:
diff changeset
141 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
anatofuz
parents:
diff changeset
142 set(ANDROID 1)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
143 string(REGEX MATCH "-target(=| +)[^ ]+android[a-z]*([0-9]+)" ANDROID_API_LEVEL "${CMAKE_C_FLAGS}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
144 set(ANDROID_API_LEVEL ${CMAKE_MATCH_2})
150
anatofuz
parents:
diff changeset
145 endif()
anatofuz
parents:
diff changeset
146 pythonize_bool(ANDROID)
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
anatofuz
parents:
diff changeset
149 set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
anatofuz
parents:
diff changeset
150
anatofuz
parents:
diff changeset
151 pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
anatofuz
parents:
diff changeset
152
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
153 # We support running instrumented tests when we're not cross-compiling
150
anatofuz
parents:
diff changeset
154 # and target a UNIX-like system or Windows.
anatofuz
parents:
diff changeset
155 # We can run tests on Android even when we are cross-compiling.
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
156 if((NOT "${CMAKE_CROSSCOMPILING}" AND (UNIX OR WIN32))
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
157 OR ANDROID OR COMPILER_RT_EMULATOR)
150
anatofuz
parents:
diff changeset
158 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
anatofuz
parents:
diff changeset
159 else()
anatofuz
parents:
diff changeset
160 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
anatofuz
parents:
diff changeset
161 endif()
anatofuz
parents:
diff changeset
162
anatofuz
parents:
diff changeset
163 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
anatofuz
parents:
diff changeset
164 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
anatofuz
parents:
diff changeset
165 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
anatofuz
parents:
diff changeset
166 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
anatofuz
parents:
diff changeset
167 pythonize_bool(COMPILER_RT_DEBUG)
anatofuz
parents:
diff changeset
168
anatofuz
parents:
diff changeset
169 option(COMPILER_RT_INTERCEPT_LIBDISPATCH
anatofuz
parents:
diff changeset
170 "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
anatofuz
parents:
diff changeset
171 option(COMPILER_RT_LIBDISPATCH_INSTALL_PATH
anatofuz
parents:
diff changeset
172 "Specify if libdispatch is installed in a custom location" "")
anatofuz
parents:
diff changeset
173 if (COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE)
anatofuz
parents:
diff changeset
174 set(COMPILER_RT_LIBDISPATCH_CFLAGS -fblocks)
anatofuz
parents:
diff changeset
175 set(COMPILER_RT_TEST_LIBDISPATCH_CFLAGS)
anatofuz
parents:
diff changeset
176 if (COMPILER_RT_LIBDISPATCH_INSTALL_PATH)
anatofuz
parents:
diff changeset
177 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS
anatofuz
parents:
diff changeset
178 -I${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/include
anatofuz
parents:
diff changeset
179 -L${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib
anatofuz
parents:
diff changeset
180 -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib)
anatofuz
parents:
diff changeset
181 endif()
anatofuz
parents:
diff changeset
182 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS -lBlocksRuntime -ldispatch)
anatofuz
parents:
diff changeset
183 endif()
anatofuz
parents:
diff changeset
184 if (APPLE) # Always enable on Apple platforms.
anatofuz
parents:
diff changeset
185 set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON)
anatofuz
parents:
diff changeset
186 endif()
anatofuz
parents:
diff changeset
187 pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH)
anatofuz
parents:
diff changeset
188
anatofuz
parents:
diff changeset
189 if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
anatofuz
parents:
diff changeset
190 # Mac OS X prior to 10.9 had problems with exporting symbols from
anatofuz
parents:
diff changeset
191 # libc++/libc++abi.
anatofuz
parents:
diff changeset
192 set(cxxabi_supported OFF)
anatofuz
parents:
diff changeset
193 else()
anatofuz
parents:
diff changeset
194 set(cxxabi_supported ON)
anatofuz
parents:
diff changeset
195 endif()
anatofuz
parents:
diff changeset
196
anatofuz
parents:
diff changeset
197 option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
anatofuz
parents:
diff changeset
198
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
199 set(SANITIZER_CAN_USE_CXXABI OFF)
150
anatofuz
parents:
diff changeset
200 if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
anatofuz
parents:
diff changeset
201 set(SANITIZER_CAN_USE_CXXABI ON)
anatofuz
parents:
diff changeset
202 endif()
anatofuz
parents:
diff changeset
203 pythonize_bool(SANITIZER_CAN_USE_CXXABI)
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205 macro(handle_default_cxx_lib var)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
206 # Specifying -stdlib= in CMAKE_CXX_FLAGS overrides the defaults.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
207 if (CMAKE_CXX_FLAGS MATCHES "-stdlib=([a-zA-Z+]*)")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
208 set(${var}_LIBNAME "${CMAKE_MATCH_1}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
209 set(${var}_SYSTEM 1)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
210 elseif (${var} STREQUAL "default")
150
anatofuz
parents:
diff changeset
211 if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
anatofuz
parents:
diff changeset
212 set(${var}_LIBNAME "libc++")
anatofuz
parents:
diff changeset
213 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
214 elseif (FUCHSIA)
anatofuz
parents:
diff changeset
215 set(${var}_LIBNAME "libc++")
anatofuz
parents:
diff changeset
216 set(${var}_INTREE 1)
anatofuz
parents:
diff changeset
217 else()
anatofuz
parents:
diff changeset
218 set(${var}_LIBNAME "libstdc++")
anatofuz
parents:
diff changeset
219 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
220 endif()
anatofuz
parents:
diff changeset
221 else()
anatofuz
parents:
diff changeset
222 set(${var}_LIBNAME "${${var}}")
anatofuz
parents:
diff changeset
223 set(${var}_SYSTEM 1)
anatofuz
parents:
diff changeset
224 endif()
anatofuz
parents:
diff changeset
225 endmacro()
anatofuz
parents:
diff changeset
226
anatofuz
parents:
diff changeset
227 # This is either directly the C++ ABI library or the full C++ library
anatofuz
parents:
diff changeset
228 # which pulls in the ABI transitively.
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
229 # TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY.
150
anatofuz
parents:
diff changeset
230 set(SANITIZER_CXX_ABI "default" CACHE STRING
anatofuz
parents:
diff changeset
231 "Specify C++ ABI library to use.")
anatofuz
parents:
diff changeset
232 set(CXXABIS none default libstdc++ libc++ libcxxabi)
anatofuz
parents:
diff changeset
233 set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
anatofuz
parents:
diff changeset
234 handle_default_cxx_lib(SANITIZER_CXX_ABI)
anatofuz
parents:
diff changeset
235
anatofuz
parents:
diff changeset
236 # This needs to be a full C++ library for linking gtest and unit tests.
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
237 # TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY.
150
anatofuz
parents:
diff changeset
238 set(SANITIZER_TEST_CXX "default" CACHE STRING
anatofuz
parents:
diff changeset
239 "Specify C++ library to use for tests.")
anatofuz
parents:
diff changeset
240 set(CXXLIBS none default libstdc++ libc++)
anatofuz
parents:
diff changeset
241 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
anatofuz
parents:
diff changeset
242 handle_default_cxx_lib(SANITIZER_TEST_CXX)
anatofuz
parents:
diff changeset
243
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
244 option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." OFF)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
245 cmake_dependent_option(COMPILER_RT_ENABLE_STATIC_UNWINDER
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
246 "Statically link the LLVM unwinder." OFF
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
247 "COMPILER_RT_USE_LLVM_UNWINDER" OFF)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
248
150
anatofuz
parents:
diff changeset
249 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
anatofuz
parents:
diff changeset
250 if (FUCHSIA)
anatofuz
parents:
diff changeset
251 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
anatofuz
parents:
diff changeset
252 elseif (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED)
anatofuz
parents:
diff changeset
253 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
anatofuz
parents:
diff changeset
254 endif()
anatofuz
parents:
diff changeset
255
anatofuz
parents:
diff changeset
256 option(SANITIZER_USE_STATIC_LLVM_UNWINDER
anatofuz
parents:
diff changeset
257 "Use static LLVM unwinder." ${DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER})
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
258 pythonize_bool(SANITIZER_USE_STATIC_LLVM_UNWINDER)
150
anatofuz
parents:
diff changeset
259
anatofuz
parents:
diff changeset
260 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI OFF)
anatofuz
parents:
diff changeset
261 if (DEFINED LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_SHARED)
anatofuz
parents:
diff changeset
262 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI ON)
anatofuz
parents:
diff changeset
263 endif()
anatofuz
parents:
diff changeset
264
anatofuz
parents:
diff changeset
265 option(SANITIZER_USE_STATIC_CXX_ABI
anatofuz
parents:
diff changeset
266 "Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI})
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
267 pythonize_bool(SANITIZER_USE_STATIC_CXX_ABI)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
268
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
269 set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX OFF)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
270 if (DEFINED LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_SHARED)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
271 set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX ON)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
272 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
273
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
274 option(SANITIZER_USE_STATIC_TEST_CXX
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
275 "Use static libc++ for tests." ${DEFAULT_SANITIZER_USE_STATIC_TEST_CXX})
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
276 pythonize_bool(SANITIZER_USE_STATIC_TEST_CXX)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
277
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
278 set(COMPILER_RT_SUPPORTED_CXX_LIBRARIES none default libcxx)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
279 set(COMPILER_RT_CXX_LIBRARY "default" CACHE STRING "Specify C++ library to use. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
280 if (NOT "${COMPILER_RT_CXX_LIBRARY}" IN_LIST COMPILER_RT_SUPPORTED_CXX_LIBRARIES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
281 message(FATAL_ERROR "Unsupported C++ library: '${COMPILER_RT_CXX_LIBRARY}'. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
282 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
283 cmake_dependent_option(COMPILER_RT_STATIC_CXX_LIBRARY
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
284 "Statically link the C++ library." OFF
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
285 "COMPILER_RT_CXX_LIBRARY" OFF)
150
anatofuz
parents:
diff changeset
286
anatofuz
parents:
diff changeset
287 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF)
anatofuz
parents:
diff changeset
288 if (FUCHSIA)
anatofuz
parents:
diff changeset
289 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON)
anatofuz
parents:
diff changeset
290 endif()
anatofuz
parents:
diff changeset
291
anatofuz
parents:
diff changeset
292 option(COMPILER_RT_USE_BUILTINS_LIBRARY
anatofuz
parents:
diff changeset
293 "Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
anatofuz
parents:
diff changeset
294
anatofuz
parents:
diff changeset
295 include(config-ix)
anatofuz
parents:
diff changeset
296
anatofuz
parents:
diff changeset
297 #================================
anatofuz
parents:
diff changeset
298 # Setup Compiler Flags
anatofuz
parents:
diff changeset
299 #================================
anatofuz
parents:
diff changeset
300
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
301 # fcf-protection is a gcc/clang option for CET support on Linux platforms.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
302 # We need to handle MSVC CET option on Windows platforms.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
303 if (NOT MSVC)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
304 if (COMPILER_RT_ENABLE_CET AND NOT COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
305 message(FATAL_ERROR "Compiler used to build compiler-rt doesn't support CET!")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
306 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
307 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
308
150
anatofuz
parents:
diff changeset
309 if(MSVC)
anatofuz
parents:
diff changeset
310 # Override any existing /W flags with /W4. This is what LLVM does. Failing to
anatofuz
parents:
diff changeset
311 # remove other /W[0-4] flags will result in a warning about overriding a
anatofuz
parents:
diff changeset
312 # previous flag.
anatofuz
parents:
diff changeset
313 if (COMPILER_RT_HAS_W4_FLAG)
anatofuz
parents:
diff changeset
314 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
anatofuz
parents:
diff changeset
315 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
anatofuz
parents:
diff changeset
316 append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
317 endif()
anatofuz
parents:
diff changeset
318 else()
anatofuz
parents:
diff changeset
319 append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
320 endif()
anatofuz
parents:
diff changeset
321 if(COMPILER_RT_ENABLE_WERROR)
anatofuz
parents:
diff changeset
322 append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
323 append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
324 endif()
anatofuz
parents:
diff changeset
325
anatofuz
parents:
diff changeset
326 # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
anatofuz
parents:
diff changeset
327 if(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
anatofuz
parents:
diff changeset
328 add_definitions(-D__func__=__FUNCTION__)
anatofuz
parents:
diff changeset
329 endif()
anatofuz
parents:
diff changeset
330
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
331 # Provide some common commandline flags for Sanitizer runtimes.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
332 if("${ANDROID_API_LEVEL}" GREATER_EQUAL 29)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
333 list(APPEND SANITIZER_COMMON_CFLAGS -fno-emulated-tls)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
334 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " -fno-emulated-tls")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
335 endif()
150
anatofuz
parents:
diff changeset
336 if(NOT WIN32)
anatofuz
parents:
diff changeset
337 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
338 endif()
anatofuz
parents:
diff changeset
339 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
340 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
341 if(NOT COMPILER_RT_DEBUG AND NOT APPLE)
anatofuz
parents:
diff changeset
342 append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
343 endif()
anatofuz
parents:
diff changeset
344 append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
345 append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
346 append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
347 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
348 if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
anatofuz
parents:
diff changeset
349 append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
350 endif()
anatofuz
parents:
diff changeset
351 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
352
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
353 # By default do not instrument or use profdata for compiler-rt.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
354 if(NOT COMPILER_RT_ENABLE_PGO)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
355 if(LLVM_PROFDATA_FILE AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
356 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-use")
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
357 endif()
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
358 if(LLVM_BUILD_INSTRUMENTED MATCHES IR AND COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
359 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-generate")
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
360 elseif((LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE) AND COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG)
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
361 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-generate")
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
362 if(LLVM_BUILD_INSTRUMENTED_COVERAGE AND COMPILER_RT_HAS_FNO_COVERAGE_MAPPING_FLAG)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
363 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-coverage-mapping")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
364 endif()
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
365 endif()
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
366 endif()
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
367
150
anatofuz
parents:
diff changeset
368 # The following is a workaround for powerpc64le. This is the only architecture
anatofuz
parents:
diff changeset
369 # that requires -fno-function-sections to work properly. If lacking, the ASan
anatofuz
parents:
diff changeset
370 # Linux test function-sections-are-bad.cpp fails with the following error:
anatofuz
parents:
diff changeset
371 # 'undefined symbol: __sanitizer_unaligned_load32'.
anatofuz
parents:
diff changeset
372 if(DEFINED TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
373 if(CMAKE_CXX_COMPILER_ID MATCHES "XL")
anatofuz
parents:
diff changeset
374 append("-qnofuncsect" TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
375 else()
anatofuz
parents:
diff changeset
376 append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
anatofuz
parents:
diff changeset
377 endif()
anatofuz
parents:
diff changeset
378 endif()
anatofuz
parents:
diff changeset
379
anatofuz
parents:
diff changeset
380 # The following is a workaround for s390x. This avoids creation of "partial
anatofuz
parents:
diff changeset
381 # inline" function fragments when building the asan libraries with certain
anatofuz
parents:
diff changeset
382 # GCC versions. The presence of those fragments, in particular for the
anatofuz
parents:
diff changeset
383 # interceptors, changes backtraces seen in asan error cases, which causes
anatofuz
parents:
diff changeset
384 # testsuite failures.
anatofuz
parents:
diff changeset
385 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
anatofuz
parents:
diff changeset
386 append_list_if(COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG -fno-partial-inlining SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
387 endif()
anatofuz
parents:
diff changeset
388
anatofuz
parents:
diff changeset
389 if(MSVC)
anatofuz
parents:
diff changeset
390 # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
391 set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
150
anatofuz
parents:
diff changeset
392 append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
393 append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
394
anatofuz
parents:
diff changeset
395 # Disable thread safe initialization for static locals. ASan shouldn't need
anatofuz
parents:
diff changeset
396 # it. Thread safe initialization assumes that the CRT has already been
anatofuz
parents:
diff changeset
397 # initialized, but ASan initializes before the CRT.
anatofuz
parents:
diff changeset
398 list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
anatofuz
parents:
diff changeset
399 endif()
anatofuz
parents:
diff changeset
400
anatofuz
parents:
diff changeset
401 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
402
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
403 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Wthread-safety THREAD_SAFETY_FLAGS)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
404 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_REFERENCE_FLAG -Wthread-safety-reference THREAD_SAFETY_FLAGS)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
405 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_BETA_FLAG -Wthread-safety-beta THREAD_SAFETY_FLAGS)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
406 list(APPEND SANITIZER_COMMON_CFLAGS ${THREAD_SAFETY_FLAGS})
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
407 string(REPLACE ";" " " thread_safety_flags_space_sep "${THREAD_SAFETY_FLAGS}")
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
408 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${thread_safety_flags_space_sep}")
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
409
150
anatofuz
parents:
diff changeset
410 # If we're using MSVC,
anatofuz
parents:
diff changeset
411 # always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
anatofuz
parents:
diff changeset
412 if (NOT MSVC)
anatofuz
parents:
diff changeset
413
anatofuz
parents:
diff changeset
414 # Build with optimization, unless we're in debug mode.
anatofuz
parents:
diff changeset
415 if(COMPILER_RT_DEBUG)
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
416 list(APPEND SANITIZER_COMMON_CFLAGS -O1)
150
anatofuz
parents:
diff changeset
417 else()
anatofuz
parents:
diff changeset
418 list(APPEND SANITIZER_COMMON_CFLAGS -O3)
anatofuz
parents:
diff changeset
419 endif()
anatofuz
parents:
diff changeset
420 endif()
anatofuz
parents:
diff changeset
421
anatofuz
parents:
diff changeset
422 # Determine if we should restrict stack frame sizes.
anatofuz
parents:
diff changeset
423 # Stack frames on PowerPC, Mips, SystemZ and in debug build can be much larger than
anatofuz
parents:
diff changeset
424 # anticipated.
anatofuz
parents:
diff changeset
425 # FIXME: Fix all sanitizers and add -Wframe-larger-than to
anatofuz
parents:
diff changeset
426 # SANITIZER_COMMON_FLAGS
anatofuz
parents:
diff changeset
427 if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
anatofuz
parents:
diff changeset
428 AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips|s390x")
anatofuz
parents:
diff changeset
429 set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
anatofuz
parents:
diff changeset
430 else()
anatofuz
parents:
diff changeset
431 set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
anatofuz
parents:
diff changeset
432 endif()
anatofuz
parents:
diff changeset
433
anatofuz
parents:
diff changeset
434 if(FUCHSIA OR UNIX)
anatofuz
parents:
diff changeset
435 set(SANITIZER_USE_SYMBOLS TRUE)
anatofuz
parents:
diff changeset
436 else()
anatofuz
parents:
diff changeset
437 set(SANITIZER_USE_SYMBOLS FALSE)
anatofuz
parents:
diff changeset
438 endif()
anatofuz
parents:
diff changeset
439
anatofuz
parents:
diff changeset
440 # Build sanitizer runtimes with debug info.
anatofuz
parents:
diff changeset
441 if(MSVC)
anatofuz
parents:
diff changeset
442 # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
anatofuz
parents:
diff changeset
443 # warning from the MS linker complaining that it can't find the 'vc140.pdb'
anatofuz
parents:
diff changeset
444 # file used by our object library compilations.
anatofuz
parents:
diff changeset
445 list(APPEND SANITIZER_COMMON_CFLAGS /Z7)
anatofuz
parents:
diff changeset
446 foreach(var_to_update
anatofuz
parents:
diff changeset
447 CMAKE_CXX_FLAGS
anatofuz
parents:
diff changeset
448 CMAKE_CXX_FLAGS_DEBUG
anatofuz
parents:
diff changeset
449 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
anatofuz
parents:
diff changeset
450 string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
anatofuz
parents:
diff changeset
451 "${var_to_update}" "${${var_to_update}}")
anatofuz
parents:
diff changeset
452 endforeach()
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
453 elseif(APPLE)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
454 # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
455 # for all build types so that the runtime can be debugged.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
456 if(NOT COMPILER_RT_HAS_G_FLAG)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
457 message(FATAL_ERROR "-g is not supported by host compiler")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
458 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
459 list(APPEND SANITIZER_COMMON_CFLAGS -g)
150
anatofuz
parents:
diff changeset
460 elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
anatofuz
parents:
diff changeset
461 list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
anatofuz
parents:
diff changeset
462 elseif(COMPILER_RT_HAS_G_FLAG)
anatofuz
parents:
diff changeset
463 list(APPEND SANITIZER_COMMON_CFLAGS -g)
anatofuz
parents:
diff changeset
464 endif()
anatofuz
parents:
diff changeset
465
anatofuz
parents:
diff changeset
466 if(LLVM_ENABLE_MODULES)
anatofuz
parents:
diff changeset
467 # Sanitizers cannot be built with -fmodules. The interceptors intentionally
anatofuz
parents:
diff changeset
468 # don't include system headers, which is incompatible with modules.
anatofuz
parents:
diff changeset
469 list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
anatofuz
parents:
diff changeset
470 endif()
anatofuz
parents:
diff changeset
471
anatofuz
parents:
diff changeset
472 # Turn off several warnings.
anatofuz
parents:
diff changeset
473 append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
474 append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
475 append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
476 # format-pedantic warns about passing T* for %p, which is not useful.
150
anatofuz
parents:
diff changeset
477 append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
478 append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
479 append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
480 append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
481 append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
482
anatofuz
parents:
diff changeset
483 append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
anatofuz
parents:
diff changeset
484
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
485 # When lsan scans the stack for detecting reachable pointers, it's possible for
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
486 # a leaked pointer, which was pushed to the stack on an earlier function call,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
487 # to still exist on the stack when doing a leak check if that part of the stack
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
488 # was not overwritten. In particular, if there's any uninitialized data in the
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
489 # lsan runtime, and the SP we start from is sufficiently deep into the runtime,
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
490 # then a leaked pointer could be marked as reachable. Such instances could be
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
491 # mitigated by clobbering any uninitialized data. Note that this won't cover
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
492 # all possible uninitialized stack contents, such as those used for register
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
493 # spill slots, unused portions for alignment, or even local variables not
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
494 # yet in scope at a certain point in the function.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
495 #
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
496 # Note that this type of issue was discovered with lsan, but can apply to other
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
497 # sanitizers.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
498 append_list_if(COMPILER_RT_HAS_TRIVIAL_AUTO_INIT -ftrivial-auto-var-init=pattern SANITIZER_COMMON_CFLAGS)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
499
150
anatofuz
parents:
diff changeset
500 # Set common link flags.
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
501 # TODO: We should consider using the same model as libc++, that is use either
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
502 # -nostdlib++ and --unwindlib=none if supported, or -nodefaultlibs otherwise.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
503 append_list_if(C_SUPPORTS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
150
anatofuz
parents:
diff changeset
504 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
anatofuz
parents:
diff changeset
505
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
506 # Only necessary for 32-bit SPARC. Solaris 11.2+ ld uses -z ignore/-z record
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
507 # natively, but supports --as-needed/--no-as-needed for GNU ld compatibility.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
508 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
509 list(APPEND SANITIZER_COMMON_LINK_LIBS -Wl,--as-needed atomic -Wl,--no-as-needed)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
510 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
511
150
anatofuz
parents:
diff changeset
512 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
anatofuz
parents:
diff changeset
513 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
anatofuz
parents:
diff changeset
514 else()
anatofuz
parents:
diff changeset
515 if (ANDROID)
anatofuz
parents:
diff changeset
516 append_list_if(COMPILER_RT_HAS_GCC_LIB gcc SANITIZER_COMMON_LINK_LIBS)
anatofuz
parents:
diff changeset
517 else()
anatofuz
parents:
diff changeset
518 append_list_if(COMPILER_RT_HAS_GCC_S_LIB gcc_s SANITIZER_COMMON_LINK_LIBS)
anatofuz
parents:
diff changeset
519 endif()
anatofuz
parents:
diff changeset
520 endif()
anatofuz
parents:
diff changeset
521
anatofuz
parents:
diff changeset
522 append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
523 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
524 list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
525 endif()
150
anatofuz
parents:
diff changeset
526
anatofuz
parents:
diff changeset
527 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
528 set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT ON)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
529 else()
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
530 set(SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT OFF)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
531 endif()
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
532 option(SANITIZER_NO_UNDEFINED_SYMBOLS "Report error on unresolved symbol references" ${SANITIZER_NO_UNDEFINED_SYMBOLS_DEFAULT})
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
533 if (SANITIZER_NO_UNDEFINED_SYMBOLS)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
534 list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs)
150
anatofuz
parents:
diff changeset
535 endif()
anatofuz
parents:
diff changeset
536
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
537 # TODO: COMPILER_RT_COMMON_CFLAGS and COMPILER_RT_COMMON_LINK_FLAGS are
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
538 # intended for use in non-sanitizer runtimes such as libFuzzer, profile or XRay,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
539 # move these higher to include common flags, then derive SANITIZER_COMMON_CFLAGS
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
540 # and SANITIZER_COMMON_LINK_FLAGS from those and append sanitizer-specific flags.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
541 set(COMPILER_RT_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
542 set(COMPILER_RT_COMMON_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
543
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
544 # We don't use the C++ standard library, so avoid including it by mistake.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
545 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
546 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
547
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
548 # Remove -stdlib= which is unused when passing -nostdinc++...
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
549 string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
550 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
551
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
552 # ...we need it to build some runtimes and tests so readd it where appropriate.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
553 list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
554 list(APPEND COMPILER_RT_COMMON_LINK_FLAGS ${stdlib_flag})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
555
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
556 # TODO: There's a lot of duplication across lib/*/tests/CMakeLists.txt files,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
557 # move some of the common flags to COMPILER_RT_UNITTEST_CFLAGS.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
558
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
559 # Unittests need access to C++ standard library.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
560 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " ${stdlib_flag}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
561
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
562 # When cross-compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help in compilation
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
563 # and linking of unittests.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
564 string(REPLACE " " ";" COMPILER_RT_UNITTEST_CFLAGS "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
565 set(COMPILER_RT_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_CFLAGS})
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
566
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
567 if(COMPILER_RT_USE_LLVM_UNWINDER)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
568 # We're linking directly against the libunwind that we're building so don't
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
569 # try to link in the toolchain's default libunwind which may be missing.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
570 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_COMMON_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
571 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_UNITTEST_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
572 if (COMPILER_RT_ENABLE_STATIC_UNWINDER)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
573 list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:unwind_static>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
574 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
575 list(APPEND COMPILER_RT_UNWINDER_LINK_LIBS "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:unwind_shared>,unwind_shared,unwind_static>>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
576 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
577 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
578
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
579 if (COMPILER_RT_CXX_LIBRARY STREQUAL "libcxx")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
580 # We are using the in-tree libc++ so avoid including the default one.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
581 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
582 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
583 # Use the in-tree libc++ through explicit include and library paths.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
584 set(COMPILER_RT_CXX_CFLAGS "$<$<TARGET_EXISTS:cxx-headers>:$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>$<JOIN:$<TARGET_PROPERTY:cxx-headers,INTERFACE_INCLUDE_DIRECTORIES>,$<SEMICOLON>$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>>>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
585 if (COMPILER_RT_STATIC_CXX_LIBRARY)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
586 set(COMPILER_RT_CXX_LINK_LIBS "$<TARGET_LINKER_FILE:cxx_static>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
587 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
588 set(COMPILER_RT_CXX_LINK_LIBS "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:cxx_shared>,cxx_shared,cxx_static>>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
589 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
590 elseif (COMPILER_RT_CXX_LIBRARY STREQUAL "none")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
591 # We aren't using any C++ standard library so avoid including the default one.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
592 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
593 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
594 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
595 # Nothing to be done for `default`.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
596 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
597
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
598 if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
599 if (SANITIZER_CXX_ABI_INTREE)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
600 # TODO: We don't need to add --unwindlib=none to SANITIZER_COMMON_LINK_FLAGS
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
601 # because we added -nodefaultlibs there earlier, and adding would result in
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
602 # a warning, but if we switch to -nostdlib++, we would need to add it here.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
603 # append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SANITIZER_COMMON_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
604 if(SANITIZER_USE_STATIC_CXX_ABI)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
605 if(TARGET libcxx-abi-static)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
606 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
607 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
608 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
609 if(TARGET libcxx-abi-shared)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
610 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-shared)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
611 elseif(TARGET libcxx-abi-static)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
612 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
613 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
614 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
615 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
616 append_list_if(COMPILER_RT_HAS_LIBCXX c++ SANITIZER_CXX_ABI_LIBRARIES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
617 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
618 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
619 list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
620 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
621 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
622 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
623
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
624 if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
625 if (SANITIZER_TEST_CXX_INTREE)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
626 list(APPEND SANITIZER_TEST_CXX_CFLAGS "$<$<TARGET_EXISTS:cxx-headers>:$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>$<JOIN:$<TARGET_PROPERTY:cxx-headers,INTERFACE_INCLUDE_DIRECTORIES>,$<SEMICOLON>$<IF:$<BOOL:${MSVC}>,/imsvc,-isystem>>>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
627 if (SANITIZER_USE_STATIC_TEST_CXX)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
628 list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:cxx_static>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
629 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
630 list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<TARGET_LINKER_FILE:$<IF:$<TARGET_EXISTS:cxx_shared>,cxx_shared,cxx_static>>")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
631 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
632 # We are using the in tree libc++ so avoid including the default one.
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
633 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_UNITTEST_CFLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
634 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_UNITTEST_LINK_FLAGS)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
635 else()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
636 append_list_if(COMPILER_RT_HAS_LIBCXX -lc++ SANITIZER_TEST_CXX_LIBRARIES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
637 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
638 elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++")
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
639 append_list_if(COMPILER_RT_HAS_LIBSTDCXX -lstdc++ SANITIZER_TEST_CXX_LIBRARIES)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
640 endif()
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
641
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
642 # Unittests support.
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
643 # FIXME: When compiler-rt is build using -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON, then
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
644 # The LLVM_THIRD_PARTY_DIR variable is not set.
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
645 if (NOT LLVM_THIRD_PARTY_DIR)
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
646 set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
647 endif()
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
648
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
649 set(COMPILER_RT_GTEST_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googletest)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
650 set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
651 set(COMPILER_RT_GTEST_CFLAGS
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
652 -DGTEST_NO_LLVM_SUPPORT=1
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
653 -DGTEST_HAS_RTTI=0
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
654 -I${COMPILER_RT_GTEST_PATH}/include
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
655 -I${COMPILER_RT_GTEST_PATH}
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
656 )
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
657
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
658 # Mocking support.
252
1f2b6ac9f198 LLVM16-1
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 236
diff changeset
659 set(COMPILER_RT_GMOCK_PATH ${LLVM_THIRD_PARTY_DIR}/unittest/googlemock)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
660 set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
661 set(COMPILER_RT_GMOCK_CFLAGS
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
662 -DGTEST_NO_LLVM_SUPPORT=1
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
663 -DGTEST_HAS_RTTI=0
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
664 -I${COMPILER_RT_GMOCK_PATH}/include
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
665 -I${COMPILER_RT_GMOCK_PATH}
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
666 )
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
667
236
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
668 if(COMPILER_RT_HAS_G_FLAG)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
669 list(APPEND COMPILER_RT_UNITTEST_CFLAGS -g)
c4bab56944e8 LLVM 16
kono
parents: 223
diff changeset
670 endif()
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
671 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
672 append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
673 append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
674
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
675 if(MSVC)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
676 # gtest use a lot of stuff marked as deprecated on Windows.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
677 list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
678 endif()
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
679
150
anatofuz
parents:
diff changeset
680 # Warnings to turn off for all libraries, not just sanitizers.
anatofuz
parents:
diff changeset
681 append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
anatofuz
parents:
diff changeset
682
anatofuz
parents:
diff changeset
683 if (CMAKE_LINKER MATCHES "link.exe$")
anatofuz
parents:
diff changeset
684 # Silence MSVC linker warnings caused by empty object files. The
anatofuz
parents:
diff changeset
685 # sanitizer libraries intentionally use ifdefs that result in empty
anatofuz
parents:
diff changeset
686 # files, rather than skipping these files in the build system.
anatofuz
parents:
diff changeset
687 # Ideally, we would pass this flag only for the libraries that need
anatofuz
parents:
diff changeset
688 # it, but CMake doesn't seem to have a way to set linker flags for
anatofuz
parents:
diff changeset
689 # individual static libraries, so we enable the suppression flag for
anatofuz
parents:
diff changeset
690 # the whole compiler-rt project.
anatofuz
parents:
diff changeset
691 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
anatofuz
parents:
diff changeset
692 endif()
anatofuz
parents:
diff changeset
693
anatofuz
parents:
diff changeset
694 add_subdirectory(include)
anatofuz
parents:
diff changeset
695
anatofuz
parents:
diff changeset
696 option(COMPILER_RT_USE_LIBCXX
anatofuz
parents:
diff changeset
697 "Enable compiler-rt to use libc++ from the source tree" ON)
anatofuz
parents:
diff changeset
698 if(COMPILER_RT_USE_LIBCXX)
anatofuz
parents:
diff changeset
699 if(LLVM_ENABLE_PROJECTS_USED)
anatofuz
parents:
diff changeset
700 # Don't use libcxx if LLVM_ENABLE_PROJECTS does not enable it.
anatofuz
parents:
diff changeset
701 set(COMPILER_RT_LIBCXX_PATH ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
anatofuz
parents:
diff changeset
702 set(COMPILER_RT_LIBCXXABI_PATH ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
anatofuz
parents:
diff changeset
703 else()
anatofuz
parents:
diff changeset
704 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
anatofuz
parents:
diff changeset
705 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
anatofuz
parents:
diff changeset
706 ${LLVM_MAIN_SRC_DIR}/../libcxx
anatofuz
parents:
diff changeset
707 ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
anatofuz
parents:
diff changeset
708 if(IS_DIRECTORY ${path})
anatofuz
parents:
diff changeset
709 set(COMPILER_RT_LIBCXX_PATH ${path})
anatofuz
parents:
diff changeset
710 break()
anatofuz
parents:
diff changeset
711 endif()
anatofuz
parents:
diff changeset
712 endforeach()
anatofuz
parents:
diff changeset
713 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi
anatofuz
parents:
diff changeset
714 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi
anatofuz
parents:
diff changeset
715 ${LLVM_MAIN_SRC_DIR}/../libcxxabi
anatofuz
parents:
diff changeset
716 ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
anatofuz
parents:
diff changeset
717 if(IS_DIRECTORY ${path})
anatofuz
parents:
diff changeset
718 set(COMPILER_RT_LIBCXXABI_PATH ${path})
anatofuz
parents:
diff changeset
719 break()
anatofuz
parents:
diff changeset
720 endif()
anatofuz
parents:
diff changeset
721 endforeach()
anatofuz
parents:
diff changeset
722 endif()
anatofuz
parents:
diff changeset
723 endif()
anatofuz
parents:
diff changeset
724
anatofuz
parents:
diff changeset
725 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
anatofuz
parents:
diff changeset
726 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
anatofuz
parents:
diff changeset
727 set(COMPILER_RT_HAS_LLD TRUE)
anatofuz
parents:
diff changeset
728 else()
anatofuz
parents:
diff changeset
729 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
anatofuz
parents:
diff changeset
730 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
anatofuz
parents:
diff changeset
731 set(COMPILER_RT_HAS_LLD TRUE)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
732 endif()
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
733 endif()
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
734
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
735 if(ANDROID)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
736 set(COMPILER_RT_HAS_LLD TRUE)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
737 set(COMPILER_RT_TEST_USE_LLD TRUE)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
738 append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
739 append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld COMPILER_RT_UNITTEST_LINK_FLAGS)
150
anatofuz
parents:
diff changeset
740 endif()
anatofuz
parents:
diff changeset
741 pythonize_bool(COMPILER_RT_HAS_LLD)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
742 pythonize_bool(COMPILER_RT_TEST_USE_LLD)
150
anatofuz
parents:
diff changeset
743
anatofuz
parents:
diff changeset
744 add_subdirectory(lib)
anatofuz
parents:
diff changeset
745
anatofuz
parents:
diff changeset
746 if(COMPILER_RT_INCLUDE_TESTS)
anatofuz
parents:
diff changeset
747 add_subdirectory(unittests)
anatofuz
parents:
diff changeset
748 add_subdirectory(test)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
749 # Don't build llvm-lit for runtimes-build, it will clean up map_config.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
750 if (COMPILER_RT_STANDALONE_BUILD AND NOT LLVM_RUNTIMES_BUILD)
150
anatofuz
parents:
diff changeset
751 # If we have a valid source tree, generate llvm-lit into the bin directory.
anatofuz
parents:
diff changeset
752 # The user can still choose to have the check targets *use* a different lit
anatofuz
parents:
diff changeset
753 # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
anatofuz
parents:
diff changeset
754 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
755 # Needed for lit support in standalone builds.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
756 include(AddLLVM)
150
anatofuz
parents:
diff changeset
757 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
anatofuz
parents:
diff changeset
758 elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
anatofuz
parents:
diff changeset
759 message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
anatofuz
parents:
diff changeset
760 "point to a valid file. You will not be able to run tests.")
anatofuz
parents:
diff changeset
761 endif()
anatofuz
parents:
diff changeset
762 endif()
anatofuz
parents:
diff changeset
763 endif()
anatofuz
parents:
diff changeset
764
anatofuz
parents:
diff changeset
765 add_subdirectory(tools)