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