Lines Matching +full:libcxx +full:- +full:build

1 # CMake build for CompilerRT.
3 # An important constraint of the build is that it only produces libraries
7 set(LLVM_SUBPROJECT_TITLE "Compiler-RT")
20 # Check if compiler-rt is built as a standalone project.
27 # Add path for custom compiler-rt modules.
42 include(base-config-ix)
49 # Check if we can compile with --no-default-config, or if that omits a config
56 # out of the box. Later on, we end up adding -nostdlib and similar flags
59 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --no-default-config")
63 option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
67 option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
69 option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
71 option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
73 option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
75 option(COMPILER_RT_BUILD_CTX_PROFILE "Build ctx profile runtime" ON)
77 option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
79 option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
81 option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
83 option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
85 option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
89 option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
91 option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
102 "Build for a bare-metal target.")
139 set(LIT_ARGS_DEFAULT "-sv")
141 set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
156 string(REGEX MATCH "-target(=| +)[^ ]+android[a-z]*([0-9]+)" ANDROID_API_LEVEL "${CMAKE_C_FLAGS}")
166 # We support running instrumented tests when we're not cross-compiling
167 # and target a UNIX-like system or Windows.
168 # We can run tests on Android even when we are cross-compiling.
176 option(COMPILER_RT_DEBUG "Build runtimes with full debug info" OFF)
183 "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF)
187 set(COMPILER_RT_LIBDISPATCH_CFLAGS -fblocks)
191 -I${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/include
192 -L${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib
193 -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_INSTALL_PATH}/lib)
195 list(APPEND COMPILER_RT_TEST_LIBDISPATCH_CFLAGS -lBlocksRuntime -ldispatch)
219 # Specifying -stdlib= in CMAKE_CXX_FLAGS overrides the defaults.
220 if (CMAKE_CXX_FLAGS MATCHES "-stdlib=([a-zA-Z+]*)")
291 set(COMPILER_RT_SUPPORTED_CXX_LIBRARIES none default libcxx)
306 "Use compiler-rt builtins instead of libgcc" ${DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY})
308 option(COMPILER_RT_USE_ATOMIC_LIBRARY "Use compiler-rt atomic instead of libatomic" OFF)
310 include(config-ix)
316 # fcf-protection is a gcc/clang option for CET support on Linux platforms.
320 message(FATAL_ERROR "Compiler used to build compiler-rt doesn't support CET!")
326 # remove other /W[0-4] flags will result in a warning about overriding a
329 string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
330 string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
334 append_string_if(COMPILER_RT_HAS_WALL_FLAG -Wall CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
337 append_string_if(COMPILER_RT_HAS_WERROR_FLAG -Werror CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
343 add_definitions(-D__func__=__FUNCTION__)
348 list(APPEND SANITIZER_COMMON_CFLAGS -fno-emulated-tls)
349 string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " -fno-emulated-tls")
352 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
354 append_list_if(COMPILER_RT_HAS_FNO_BUILTIN_FLAG -fno-builtin SANITIZER_COMMON_CFLAGS)
355 append_list_if(COMPILER_RT_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions SANITIZER_COMMON_CFLAGS)
357 append_list_if(COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG -fomit-frame-pointer SANITIZER_COMMON_CFLAGS)
359 append_list_if(COMPILER_RT_HAS_FUNWIND_TABLES_FLAG -funwind-tables SANITIZER_COMMON_CFLAGS)
360 append_list_if(COMPILER_RT_HAS_FNO_STACK_PROTECTOR_FLAG -fno-stack-protector SANITIZER_COMMON_CFLAGS)
361 append_list_if(COMPILER_RT_HAS_FNO_SANITIZE_SAFE_STACK_FLAG -fno-sanitize=safe-stack SANITIZER_COMMON_CFLAGS)
362 append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANITIZER_COMMON_CFLAGS)
364 append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
366 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
368 # By default do not instrument or use profdata for compiler-rt.
371 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-use")
374 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-generate")
376 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-profile-instr-generate")
378 list(APPEND SANITIZER_COMMON_CFLAGS "-fno-coverage-mapping")
384 # that requires -fno-function-sections to work properly. If lacking, the ASan
385 # Linux test function-sections-are-bad.cpp fails with the following error:
389 append("-qnofuncsect" TARGET_powerpc64le_CFLAGS)
391 append_list_if(COMPILER_RT_HAS_FNO_FUNCTION_SECTIONS_FLAG -fno-function-sections TARGET_powerpc64le_CFLAGS)
401 append_list_if(COMPILER_RT_HAS_FNO_PARTIAL_INLINING_FLAG -fno-partial-inlining SANITIZER_COMMON_CFLAGS)
412 # CRT choice flags might be passing them both ways - which leads to
421 string(REGEX REPLACE "[/-]M[DT]d" "" ${flag_var} "${${flag_var}}")
422 string(REGEX REPLACE "[/-]MD" "" ${flag_var} "${${flag_var}}")
423 string(REGEX REPLACE "[/-]D_DEBUG" "" ${flag_var} "${${flag_var}}")
426 append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
427 append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
432 list(APPEND SANITIZER_COMMON_CFLAGS /Zc:threadSafeInit-)
435 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 SANITIZER_COMMON_CFLAGS)
437 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Wthread-safety THREAD_SAFETY_FLAGS)
438 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_REFERENCE_FLAG -Wthread-safety-reference THREAD_SAFETY_FLAGS)
439 append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_BETA_FLAG -Wthread-safety-beta THREAD_SAFETY_FLAGS)
448 # Build with optimization, unless we're in debug mode.
450 list(APPEND SANITIZER_COMMON_CFLAGS -O1)
452 list(APPEND SANITIZER_COMMON_CFLAGS -O3)
457 # Stack frames on PowerPC, Mips, SystemZ and in debug build can be much larger than
459 # FIXME: Fix all sanitizers and add -Wframe-larger-than to
474 # Get the linker version while configuring compiler-rt and explicitly pass it
483 # Build sanitizer runtimes with debug info.
497 # On Apple platforms use full debug info (i.e. not `-gline-tables-only`)
498 # for all build types so that the runtime can be debugged.
500 message(FATAL_ERROR "-g is not supported by host compiler")
502 list(APPEND SANITIZER_COMMON_CFLAGS -g)
504 list(APPEND SANITIZER_COMMON_CFLAGS -gline-tables-only)
506 list(APPEND SANITIZER_COMMON_CFLAGS -g)
510 # Sanitizers cannot be built with -fmodules. The interceptors intentionally
512 list(APPEND SANITIZER_COMMON_CFLAGS -fno-modules)
516 append_list_if(COMPILER_RT_HAS_WGNU_FLAG -Wno-gnu SANITIZER_COMMON_CFLAGS)
517 append_list_if(COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG -Wno-variadic-macros SANITIZER_COMMON_CFLAGS)
518 append_list_if(COMPILER_RT_HAS_WC99_EXTENSIONS_FLAG -Wno-c99-extensions SANITIZER_COMMON_CFLAGS)
519 # format-pedantic warns about passing T* for %p, which is not useful.
526 append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
541 # Disable PowerPC because of https://github.com/llvm/llvm-project/issues/84654.
543 append_list_if(COMPILER_RT_HAS_TRIVIAL_AUTO_INIT -ftrivial-auto-var-init=pattern SANITIZER_COMMON_CFLAGS)
548 # -nostdlib++ and --unwindlib=none if supported, or -nodefaultlibs otherwise.
549 append_list_if(C_SUPPORTS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
550 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
552 # Only necessary for 32-bit SPARC. Solaris 11.2+ ld uses -z ignore/-z record
553 # natively, but supports --as-needed/--no-as-needed for GNU ld compatibility.
555 list(APPEND SANITIZER_COMMON_LINK_LIBS -Wl,--as-needed atomic -Wl,--no-as-needed)
559 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
580 list(APPEND SANITIZER_COMMON_LINK_FLAGS -Wl,-z,defs)
584 # intended for use in non-sanitizer runtimes such as libFuzzer, profile or XRay,
586 # and SANITIZER_COMMON_LINK_FLAGS from those and append sanitizer-specific flags.
591 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS)
592 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS)
594 # Remove -stdlib= which is unused when passing -nostdinc++...
595 string(REGEX MATCHALL "-stdlib=[a-zA-Z+]*" stdlib_flag "${CMAKE_CXX_FLAGS}")
596 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
598 # ...we need it to build some runtimes and tests so readd it where appropriate.
608 # When cross-compiling, COMPILER_RT_TEST_COMPILER_CFLAGS help in compilation
614 "When set to ON and testing in a standalone build, test the runtime \
615 libraries built by this standalone build rather than the runtime libraries \
617 in a standalone build, test the runtime libraries shipped with the compiler \
619 build are configured to use the same runtime library path."
623 list(APPEND COMPILER_RT_UNITTEST_CFLAGS "-I${CMAKE_CURRENT_LIST_DIR}/include")
624 # Ensure that unit tests link against the just-built runtime libraries instead
628 list(APPEND COMPILER_RT_UNITTEST_LINK_FLAGS "-resource-dir=${COMPILER_RT_OUTPUT_DIR}")
635 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_COMMON_LINK_FLAGS)
636 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none COMPILER_RT_UNITTEST_LINK_FLAGS)
644 if (COMPILER_RT_CXX_LIBRARY STREQUAL "libcxx")
645 # We are using the in-tree libc++ so avoid including the default one.
646 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
647 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
648 # Use the in-tree libc++ through explicit include and library paths.
649 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>>>")
657 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS)
658 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS)
665 # TODO: We don't need to add --unwindlib=none to SANITIZER_COMMON_LINK_FLAGS
666 # because we added -nodefaultlibs there earlier, and adding would result in
667 # a warning, but if we switch to -nostdlib++, we would need to add it here.
668 # append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SANITIZER_COMMON_LINK_FLAGS)
670 if(TARGET libcxx-abi-static)
671 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
674 if(TARGET libcxx-abi-shared)
675 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-shared)
676 elseif(TARGET libcxx-abi-static)
677 set(SANITIZER_CXX_ABI_LIBRARIES libcxx-abi-static)
691 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>>>")
698 append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_UNITTEST_CFLAGS)
699 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_UNITTEST_LINK_FLAGS)
701 append_list_if(COMPILER_RT_HAS_LIBCXX -lc++ SANITIZER_TEST_CXX_LIBRARIES)
704 append_list_if(COMPILER_RT_HAS_LIBSTDCXX -lstdc++ SANITIZER_TEST_CXX_LIBRARIES)
708 # FIXME: When compiler-rt is build using -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON, then
711 set(LLVM_THIRD_PARTY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../third-party")
715 set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
717 -DGTEST_NO_LLVM_SUPPORT=1
718 -DGTEST_HAS_RTTI=0
719 -I${COMPILER_RT_GTEST_PATH}/include
720 -I${COMPILER_RT_GTEST_PATH}
725 set(COMPILER_RT_GMOCK_SOURCE ${COMPILER_RT_GMOCK_PATH}/src/gmock-all.cc)
727 -DGTEST_NO_LLVM_SUPPORT=1
728 -DGTEST_HAS_RTTI=0
729 -I${COMPILER_RT_GMOCK_PATH}/include
730 -I${COMPILER_RT_GMOCK_PATH}
734 list(APPEND COMPILER_RT_UNITTEST_CFLAGS -g)
736 append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_UNITTEST_CFLAGS)
737 append_list_if(COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG -Wno-covered-switch-default COMPILER_RT_UNITTEST_CFLAGS)
738 append_list_if(COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG -Wno-suggest-override COMPILER_RT_UNITTEST_CFLAGS)
739 # Detect if the compiler toolchain includes gcc-toolset-12.
742 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v
746 if(compiler_info MATCHES ".*gcc-toolset-12.*")
753 # gcc-toolset-12 in the compiler toolchain on Linux; all of the
754 # deprecated declarations in gcc-toolset-12 used in Google Tests have been
757 list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
761 append_string_if(COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG -Wno-unused-parameter CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
766 # files, rather than skipping these files in the build system.
770 # the whole compiler-rt project.
777 "Enable compiler-rt to use libc++ from the source tree" ON)
780 # Don't use libcxx if LLVM_ENABLE_PROJECTS does not enable it.
784 foreach(path IN ITEMS ${LLVM_MAIN_SRC_DIR}/projects/libcxx
785 ${LLVM_MAIN_SRC_DIR}/runtimes/libcxx
786 ${LLVM_MAIN_SRC_DIR}/../libcxx
820 append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld SANITIZER_COMMON_LINK_FLAGS)
821 append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld COMPILER_RT_UNITTEST_LINK_FLAGS)
830 option(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER "Build Compiler RT linked with in LLVM symbolizer" OFF)
836 # Don't build llvm-lit for runtimes-build, it will clean up map_config.
838 # If we have a valid source tree, generate llvm-lit into the bin directory.
840 # by specifying -DLLVM_EXTERNAL_LIT, but we generate it regardless.
841 if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
844 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit ${CMAKE_CURRENT_BINARY_DIR}/llvm-lit)
846 # LLVM_INSTALL_DIR/bin/llvm-lit (which probably does not exist).