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
|
|
6 cmake_minimum_required(VERSION 3.4.3)
|
|
7
|
|
8 if(POLICY CMP0075)
|
|
9 cmake_policy(SET CMP0075 NEW)
|
|
10 endif()
|
|
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"
|
|
23 )
|
|
24
|
|
25 if(CMAKE_CONFIGURATION_TYPES)
|
|
26 set(CMAKE_CFG_RESOLVED_INTDIR "${CMAKE_CFG_INTDIR}/")
|
|
27 else()
|
|
28 set(CMAKE_CFG_RESOLVED_INTDIR "")
|
|
29 endif()
|
|
30
|
|
31 include(base-config-ix)
|
|
32 include(CompilerRTUtils)
|
|
33
|
|
34 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
|
|
35 mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
|
|
36 option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON)
|
|
37 mark_as_advanced(COMPILER_RT_BUILD_CRT)
|
|
38 option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON)
|
|
39 mark_as_advanced(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY)
|
|
40 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
|
|
41 mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
|
|
42 option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
|
|
43 mark_as_advanced(COMPILER_RT_BUILD_XRAY)
|
|
44 option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
|
|
45 mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
|
|
46 option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
|
|
47 mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
|
|
48 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
|
|
49 mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
|
|
50
|
|
51 set(COMPILER_RT_ASAN_SHADOW_SCALE ""
|
|
52 CACHE STRING "Override the shadow scale to be used in ASan runtime")
|
|
53
|
|
54 if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
|
|
55 # Check that the shadow scale value is valid.
|
|
56 if (NOT (COMPILER_RT_ASAN_SHADOW_SCALE GREATER -1 AND
|
|
57 COMPILER_RT_ASAN_SHADOW_SCALE LESS 8))
|
|
58 message(FATAL_ERROR "
|
|
59 Invalid ASan Shadow Scale '${COMPILER_RT_ASAN_SHADOW_SCALE}'.")
|
|
60 endif()
|
|
61
|
|
62 set(COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG
|
|
63 -mllvm -asan-mapping-scale=${COMPILER_RT_ASAN_SHADOW_SCALE})
|
|
64 set(COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION
|
|
65 ASAN_SHADOW_SCALE=${COMPILER_RT_ASAN_SHADOW_SCALE})
|
|
66 set(COMPILER_RT_ASAN_SHADOW_SCALE_FLAG
|
|
67 -D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
|
|
68 endif()
|
|
69
|
|
70 set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOL
|
|
71 "Enable libc interceptors in HWASan (testing mode)")
|
|
72
|
|
73 set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
|
|
74 "Build for a bare-metal target.")
|
|
75
|
|
76 if (COMPILER_RT_STANDALONE_BUILD)
|
|
77 load_llvm_config()
|
|
78 if (TARGET intrinsics_gen)
|
|
79 # Loading the llvm config causes this target to be imported so place it
|
|
80 # under the appropriate folder in an IDE.
|
|
81 set_target_properties(intrinsics_gen PROPERTIES FOLDER "Compiler-RT Misc")
|
|
82 endif()
|
|
83
|
|
84 # Find Python interpreter.
|
|
85 include(FindPythonInterp)
|
|
86 if(NOT PYTHONINTERP_FOUND)
|
|
87 message(FATAL_ERROR "
|
|
88 Unable to find Python interpreter required testing. Please install Python
|
|
89 or specify the PYTHON_EXECUTABLE CMake variable.")
|
|
90 endif()
|
|
91
|
|
92 # Ensure that fat libraries are built correctly on Darwin
|
|
93 if(CMAKE_HOST_APPLE AND APPLE)
|
|
94 include(UseLibtool)
|
|
95 endif()
|
|
96
|
|
97 # Define default arguments to lit.
|
|
98 set(LIT_ARGS_DEFAULT "-sv")
|
|
99 if (MSVC OR XCODE)
|
|
100 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
|
101 endif()
|
|
102 set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
103 set(LLVM_LIT_OUTPUT_DIR "${COMPILER_RT_EXEC_OUTPUT_DIR}")
|
|
104 endif()
|
|
105
|
|
106 construct_compiler_rt_default_triple()
|
|
107 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
|
|
108 if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
|
|
109 set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
|
|
110 endif()
|
|
111 endif()
|
|
112 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
|
|
113 set(ANDROID 1)
|
|
114 endif()
|
|
115 pythonize_bool(ANDROID)
|
|
116
|
|
117 set(ANDROID_NDK_VERSION 18
|
|
118 CACHE STRING "Set this to the Android NDK version that you are using")
|
|
119
|
|
120 set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
121 set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
122
|
|
123 pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
|
|
124
|
|
125 # We support running instrumented tests when we're not cross compiling
|
|
126 # and target a UNIX-like system or Windows.
|
|
127 # We can run tests on Android even when we are cross-compiling.
|
|
128 if(("${CMAKE_HOST_SYSTEM}" STREQUAL "${CMAKE_SYSTEM}" AND (UNIX OR WIN32)) OR ANDROID
|
|
129 OR COMPILER_RT_EMULATOR)
|
|
130 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" ON)
|
|
131 else()
|
|
132 option(COMPILER_RT_CAN_EXECUTE_TESTS "Can we execute instrumented tests" OFF)
|
|
133 endif()
|
|
134
|
|
135 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
|
|
136 option(COMPILER_RT_EXTERNALIZE_DEBUGINFO
|
|
137 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
|
|
138 # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in.
|
|
139 pythonize_bool(COMPILER_RT_DEBUG)
|
|
140
|
|
141 option(COMPILER_RT_INTERCEPT_LIBDISPATCH
|
|
142 "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
|
|
143 option(COMPILER_RT_LIBDISPATCH_INSTALL_PATH
|
|
144 "Specify if libdispatch is installed in a custom location" "")
|
|
145 if (COMPILER_RT_INTERCEPT_LIBDISPATCH AND NOT APPLE)
|
|
146 set(COMPILER_RT_LIBDISPATCH_CFLAGS -fblocks)
|
|
147 set(COMPILER_RT_TEST_LIBDISPATCH_CFLAGS)
|
|
148 if (COMPILER_RT_LIBDISPATCH_INSTALL_PATH)
|
|
149 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS
|
|
150 -I${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/include
|
|
151 -L${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib
|
|
152 -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib)
|
|
153 endif()
|
|
154 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS -lBlocksRuntime -ldispatch)
|
|
155 endif()
|
|
156 if (APPLE) # Always enable on Apple platforms.
|
|
157 set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON)
|
|
158 endif()
|
|
159 pythonize_bool(COMPILER_RT_INTERCEPT_LIBDISPATCH)
|
|
160
|
|
161 if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9")
|
|
162 # Mac OS X prior to 10.9 had problems with exporting symbols from
|
|
163 # libc++/libc++abi.
|
|
164 set(cxxabi_supported OFF)
|
|
165 else()
|
|
166 set(cxxabi_supported ON)
|
|
167 endif()
|
|
168
|
|
169 option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON)
|
|
170
|
|
171 set(SANITIZE_CAN_USE_CXXABI OFF)
|
|
172 if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI)
|
|
173 set(SANITIZER_CAN_USE_CXXABI ON)
|
|
174 endif()
|
|
175 pythonize_bool(SANITIZER_CAN_USE_CXXABI)
|
|
176
|
|
177 macro(handle_default_cxx_lib var)
|
|
178 if (${var} STREQUAL "default")
|
|
179 if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
|
180 set(${var}_LIBNAME "libc++")
|
|
181 set(${var}_SYSTEM 1)
|
|
182 elseif (FUCHSIA)
|
|
183 set(${var}_LIBNAME "libc++")
|
|
184 set(${var}_INTREE 1)
|
|
185 else()
|
|
186 set(${var}_LIBNAME "libstdc++")
|
|
187 set(${var}_SYSTEM 1)
|
|
188 endif()
|
|
189 else()
|
|
190 set(${var}_LIBNAME "${${var}}")
|
|
191 set(${var}_SYSTEM 1)
|
|
192 endif()
|
|
193 endmacro()
|
|
194
|
|
195 # This is either directly the C++ ABI library or the full C++ library
|
|
196 # which pulls in the ABI transitively.
|
|
197 set(SANITIZER_CXX_ABI "default" CACHE STRING
|
|
198 "Specify C++ ABI library to use.")
|
|
199 set(CXXABIS none default libstdc++ libc++ libcxxabi)
|
|
200 set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS})
|
|
201 handle_default_cxx_lib(SANITIZER_CXX_ABI)
|
|
202
|
|
203 # This needs to be a full C++ library for linking gtest and unit tests.
|
|
204 set(SANITIZER_TEST_CXX "default" CACHE STRING
|
|
205 "Specify C++ library to use for tests.")
|
|
206 set(CXXLIBS none default libstdc++ libc++)
|
|
207 set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
|
|
208 handle_default_cxx_lib(SANITIZER_TEST_CXX)
|
|
209
|
|
210 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
|
|
211 if (FUCHSIA)
|
|
212 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
|
|
213 elseif (DEFINED LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_SHARED)
|
|
214 set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
|
|
215 endif()
|
|
216
|
|
217 option(SANITIZER_USE_STATIC_LLVM_UNWINDER
|
|
218 "Use static LLVM unwinder." ${DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER})
|
|
219
|
|
220 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI OFF)
|
|
221 if (DEFINED LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_SHARED)
|
|
222 set(DEFAULT_SANITIZER_USE_STATIC_CXX_ABI ON)
|
|
223 endif()
|
|
224
|
|
225 option(SANITIZER_USE_STATIC_CXX_ABI
|
|
226 "Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI})
|
|
227
|
|
228 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF)
|
|
229 if (FUCHSIA)
|
|
230 set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON)
|
|
231 endif()
|
|
232
|
|
233 option(COMPILER_RT_USE_BUILTINS_LIBRARY
|
|
234 "Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
|
|
235
|
|
236 include(config-ix)
|
|
237
|
|
238 #================================
|
|
239 # Setup Compiler Flags
|
|
240 #================================
|
|
241
|
|
242 if(MSVC)
|
|
243 # Override any existing /W flags with /W4. This is what LLVM does. Failing to
|
|
244 # remove other /W[0-4] flags will result in a warning about overriding a
|
|
245 # previous flag.
|
|
246 if (COMPILER_RT_HAS_W4_FLAG)
|
|
247 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
|
248 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
249 append_string_if(COMPILER_RT_HAS_W4_FLAG /W4 CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
250 endif()
|
|
251 else()
|
|
252 append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
253 endif()
|
|
254 if(COMPILER_RT_ENABLE_WERROR)
|
|
255 append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
256 append_string_if(COMPILER_RT_HAS_WX_FLAG /WX CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
257 endif()
|
|
258
|
|
259 append_string_if(COMPILER_RT_HAS_STD_CXX14_FLAG -std=c++14 CMAKE_CXX_FLAGS)
|
|
260
|
|
261 # Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP.
|
|
262 if(NOT COMPILER_RT_HAS_FUNC_SYMBOL)
|
|
263 add_definitions(-D__func__=__FUNCTION__)
|
|
264 endif()
|
|
265
|
|
266 # Provide some common commmandline flags for Sanitizer runtimes.
|
|
267 if(NOT WIN32)
|
|
268 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
|
|
269 endif()
|
|
270 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
|
|
271 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
|
|
272 if(NOT COMPILER_RT_DEBUG AND NOT APPLE)
|
|
273 append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
|
|
274 endif()
|
|
275 append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
|
|
276 append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
|
|
277 append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
|
|
278 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
|
|
279 if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
|
|
280 append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
|
|
281 endif()
|
|
282 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
|
|
283
|
|
284 # The following is a workaround for powerpc64le. This is the only architecture
|
|
285 # that requires -fno-function-sections to work properly. If lacking, the ASan
|
|
286 # Linux test function-sections-are-bad.cpp fails with the following error:
|
|
287 # 'undefined symbol: __sanitizer_unaligned_load32'.
|
|
288 if(DEFINED TARGET_powerpc64le_CFLAGS)
|
|
289 if(CMAKE_CXX_COMPILER_ID MATCHES "XL")
|
|
290 append("-qnofuncsect" TARGET_powerpc64le_CFLAGS)
|
|
291 else()
|
|
292 append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
|
|
293 endif()
|
|
294 endif()
|
|
295
|
|
296 # The following is a workaround for s390x. This avoids creation of "partial
|
|
297 # inline" function fragments when building the asan libraries with certain
|
|
298 # GCC versions. The presence of those fragments, in particular for the
|
|
299 # interceptors, changes backtraces seen in asan error cases, which causes
|
|
300 # testsuite failures.
|
|
301 if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
|
|
302 append_list_if(COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG -fno-partial-inlining SANITIZER_COMMON_CFLAGS)
|
|
303 endif()
|
|
304
|
|
305 if(MSVC)
|
|
306 # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
|
|
307 # which cause definition mismatches at link time.
|
|
308 # FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
|
|
309 if(COMPILER_RT_HAS_MT_FLAG)
|
|
310 foreach(flag_var
|
|
311 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
312 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
313 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
314 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
315 string(REGEX REPLACE "/M[DT]d" "/MT" ${flag_var} "${${flag_var}}")
|
|
316 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
|
317 string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
|
|
318 endforeach()
|
|
319 endif()
|
|
320 append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
|
|
321 append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
|
|
322
|
|
323 # Disable thread safe initialization for static locals. ASan shouldn't need
|
|
324 # it. Thread safe initialization assumes that the CRT has already been
|
|
325 # initialized, but ASan initializes before the CRT.
|
|
326 list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
|
|
327 endif()
|
|
328
|
|
329 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
|
|
330
|
|
331 # If we're using MSVC,
|
|
332 # always respect the optimization flags set by CMAKE_BUILD_TYPE instead.
|
|
333 if (NOT MSVC)
|
|
334
|
|
335 # Build with optimization, unless we're in debug mode.
|
|
336 if(COMPILER_RT_DEBUG)
|
|
337 list(APPEND SANITIZER_COMMON_CFLAGS -O0)
|
|
338 else()
|
|
339 list(APPEND SANITIZER_COMMON_CFLAGS -O3)
|
|
340 endif()
|
|
341 endif()
|
|
342
|
|
343 # Determine if we should restrict stack frame sizes.
|
|
344 # Stack frames on PowerPC, Mips, SystemZ and in debug build can be much larger than
|
|
345 # anticipated.
|
|
346 # FIXME: Fix all sanitizers and add -Wframe-larger-than to
|
|
347 # SANITIZER_COMMON_FLAGS
|
|
348 if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG AND NOT COMPILER_RT_DEBUG
|
|
349 AND NOT ${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "powerpc|mips|s390x")
|
|
350 set(SANITIZER_LIMIT_FRAME_SIZE TRUE)
|
|
351 else()
|
|
352 set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
|
|
353 endif()
|
|
354
|
|
355 if(FUCHSIA OR UNIX)
|
|
356 set(SANITIZER_USE_SYMBOLS TRUE)
|
|
357 else()
|
|
358 set(SANITIZER_USE_SYMBOLS FALSE)
|
|
359 endif()
|
|
360
|
|
361 # Build sanitizer runtimes with debug info.
|
|
362 if(MSVC)
|
|
363 # Use /Z7 instead of /Zi for the asan runtime. This avoids the LNK4099
|
|
364 # warning from the MS linker complaining that it can't find the 'vc140.pdb'
|
|
365 # file used by our object library compilations.
|
|
366 list(APPEND SANITIZER_COMMON_CFLAGS /Z7)
|
|
367 foreach(var_to_update
|
|
368 CMAKE_CXX_FLAGS
|
|
369 CMAKE_CXX_FLAGS_DEBUG
|
|
370 CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
371 string(REGEX REPLACE "(^| )/Z[i7I]($| )" " /Z7 "
|
|
372 "${var_to_update}" "${${var_to_update}}")
|
|
373 endforeach()
|
|
374 elseif(COMPILER_RT_HAS_GLINE_TABLES_ONLY_FLAG AND NOT COMPILER_RT_DEBUG)
|
|
375 list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
|
|
376 elseif(COMPILER_RT_HAS_G_FLAG)
|
|
377 list(APPEND SANITIZER_COMMON_CFLAGS -g)
|
|
378 endif()
|
|
379
|
|
380 if(LLVM_ENABLE_MODULES)
|
|
381 # Sanitizers cannot be built with -fmodules. The interceptors intentionally
|
|
382 # don't include system headers, which is incompatible with modules.
|
|
383 list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
|
|
384 endif()
|
|
385
|
|
386 # Turn off several warnings.
|
|
387 append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
|
|
388 append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
|
|
389 append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
|
|
390 append_list_if(COMPILER_RT_HAS_WNON_VIRTUAL_DTOR_FLAG -Wno-non-virtual-dtor SANITIZER_COMMON_CFLAGS)
|
|
391 append_list_if(COMPILER_RT_HAS_WD4146_FLAG /wd4146 SANITIZER_COMMON_CFLAGS)
|
|
392 append_list_if(COMPILER_RT_HAS_WD4291_FLAG /wd4291 SANITIZER_COMMON_CFLAGS)
|
|
393 append_list_if(COMPILER_RT_HAS_WD4391_FLAG /wd4391 SANITIZER_COMMON_CFLAGS)
|
|
394 append_list_if(COMPILER_RT_HAS_WD4722_FLAG /wd4722 SANITIZER_COMMON_CFLAGS)
|
|
395 append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS)
|
|
396
|
|
397 append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
|
|
398
|
|
399 # Set common link flags.
|
|
400 append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
|
|
401 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
|
|
402
|
|
403 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
|
|
404 list(APPEND SANITIZER_COMMON_LINK_LIBS ${COMPILER_RT_BUILTINS_LIBRARY})
|
|
405 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
|
|
406 else()
|
|
407 if (ANDROID)
|
|
408 append_list_if(COMPILER_RT_HAS_GCC_LIB gcc SANITIZER_COMMON_LINK_LIBS)
|
|
409 else()
|
|
410 append_list_if(COMPILER_RT_HAS_GCC_S_LIB gcc_s SANITIZER_COMMON_LINK_LIBS)
|
|
411 endif()
|
|
412 endif()
|
|
413
|
|
414 append_list_if(COMPILER_RT_HAS_LIBC c SANITIZER_COMMON_LINK_LIBS)
|
|
415
|
|
416 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
|
|
417 list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
|
|
418 list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
|
|
419 endif()
|
|
420
|
|
421 macro(append_libcxx_libs var)
|
|
422 if (${var}_INTREE)
|
|
423 if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
|
|
424 list(APPEND ${var}_LIBRARIES unwind_static)
|
|
425 elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
|
|
426 list(APPEND ${var}_LIBRARIES unwind_shared)
|
|
427 endif()
|
|
428
|
|
429 if (SANITIZER_USE_STATIC_CXX_ABI AND (TARGET cxxabi_static OR HAVE_LIBCXXABI))
|
|
430 list(APPEND ${var}_LIBRARIES cxxabi_static)
|
|
431 elseif (TARGET cxxabi_shared OR HAVE_LIBCXXABI)
|
|
432 list(APPEND ${var}_LIBRARIES cxxabi_shared)
|
|
433 endif()
|
|
434 else()
|
|
435 append_list_if(COMPILER_RT_HAS_LIBCXX c++ ${var}_LIBRARIES)
|
|
436 endif()
|
|
437 endmacro()
|
|
438
|
|
439 if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++")
|
|
440 append_libcxx_libs(SANITIZER_CXX_ABI)
|
|
441 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi")
|
|
442 list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi")
|
|
443 elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++")
|
|
444 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES)
|
|
445 endif()
|
|
446
|
|
447 if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++")
|
|
448 append_libcxx_libs(SANITIZER_TEST_CXX)
|
|
449 elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++")
|
|
450 append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES)
|
|
451 endif()
|
|
452
|
|
453 # Warnings to turn off for all libraries, not just sanitizers.
|
|
454 append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
|
|
455
|
|
456 if (CMAKE_LINKER MATCHES "link.exe$")
|
|
457 # Silence MSVC linker warnings caused by empty object files. The
|
|
458 # sanitizer libraries intentionally use ifdefs that result in empty
|
|
459 # files, rather than skipping these files in the build system.
|
|
460 # Ideally, we would pass this flag only for the libraries that need
|
|
461 # it, but CMake doesn't seem to have a way to set linker flags for
|
|
462 # individual static libraries, so we enable the suppression flag for
|
|
463 # the whole compiler-rt project.
|
|
464 set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
|
|
465 endif()
|
|
466
|
|
467 add_subdirectory(include)
|
|
468
|
|
469 option(COMPILER_RT_USE_LIBCXX
|
|
470 "Enable compiler-rt to use libc++ from the source tree" ON)
|
|
471 if(COMPILER_RT_USE_LIBCXX)
|
|
472 if(LLVM_ENABLE_PROJECTS_USED)
|
|
473 # Don't use libcxx if LLVM_ENABLE_PROJECTS does not enable it.
|
|
474 set(COMPILER_RT_LIBCXX_PATH ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
|
|
475 set(COMPILER_RT_LIBCXXABI_PATH ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
|
|
476 else()
|
|
477 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
|
|
478 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
|
|
479 ${LLVM_MAIN_SRC_DIR}/../libcxx
|
|
480 ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
|
|
481 if(IS_DIRECTORY ${path})
|
|
482 set(COMPILER_RT_LIBCXX_PATH ${path})
|
|
483 break()
|
|
484 endif()
|
|
485 endforeach()
|
|
486 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxxabi
|
|
487 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxxabi
|
|
488 ${LLVM_MAIN_SRC_DIR}/../libcxxabi
|
|
489 ${LLVM_EXTERNAL_LIBCXXABI_SOURCE_DIR})
|
|
490 if(IS_DIRECTORY ${path})
|
|
491 set(COMPILER_RT_LIBCXXABI_PATH ${path})
|
|
492 break()
|
|
493 endif()
|
|
494 endforeach()
|
|
495 endif()
|
|
496 endif()
|
|
497
|
|
498 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
|
|
499 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
|
|
500 set(COMPILER_RT_HAS_LLD TRUE)
|
|
501 else()
|
|
502 set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
|
|
503 if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
|
|
504 set(COMPILER_RT_HAS_LLD TRUE)
|
|
505 else()
|
|
506 set(COMPILER_RT_HAS_LLD ${COMPILER_RT_HAS_FUSE_LD_LLD_FLAG})
|
|
507 endif()
|
|
508 endif()
|
|
509 pythonize_bool(COMPILER_RT_HAS_LLD)
|
|
510
|
|
511 add_subdirectory(lib)
|
|
512
|
|
513 if(COMPILER_RT_INCLUDE_TESTS)
|
|
514 add_subdirectory(unittests)
|
|
515 add_subdirectory(test)
|
|
516 if (COMPILER_RT_STANDALONE_BUILD)
|
|
517 # If we have a valid source tree, generate llvm-lit into the bin directory.
|
|
518 # The user can still choose to have the check targets *use* a different lit
|
|
519 # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
|
|
520 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
|
|
521 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
|
|
522 elseif(NOT EXISTS ${LLVM_EXTERNAL_LIT})
|
|
523 message(WARNING "Could not find LLVM source directory and LLVM_EXTERNAL_LIT does not"
|
|
524 "point to a valid file. You will not be able to run tests.")
|
|
525 endif()
|
|
526 endif()
|
|
527 endif()
|
|
528
|
|
529 add_subdirectory(tools)
|