From: Petr Hosek Date: Mon, 28 Feb 2022 20:21:11 +0000 (-0800) Subject: [CMake][compiler-rt] Make CRT separately buildable X-Git-Tag: upstream/15.0.7~14307 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed28461e2716fda004f4f55654ef33bc8c78f203;p=platform%2Fupstream%2Fllvm.git [CMake][compiler-rt] Make CRT separately buildable This is useful when building a complete toolchain to ensure that CRT is built after builtins but before the rest of the compiler-rt. Differential Revision: https://reviews.llvm.org/D120682 --- diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake index 3e86cf6..bc4789d 100644 --- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake +++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake @@ -27,8 +27,6 @@ set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64} ${HEXAGON}) set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}) -set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} - ${PPC64} ${RISCV32} ${RISCV64} ${VE} ${HEXAGON}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) if(ANDROID) diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index 0520958..829aa92 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -238,6 +238,10 @@ function(get_compiler_rt_root_source_dir ROOT_DIR_VAR) # Compiler-RT Builtins standalone build. # `llvm-project/compiler-rt/lib/builtins` set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRTBuiltins_SOURCE_DIR}/../../") + elseif (DEFINED CompilerRTCRT_SOURCE_DIR) + # Compiler-RT CRT standalone build. + # `llvm-project/compiler-rt/lib/crt` + set(PATH_TO_COMPILER_RT_SOURCE_ROOT "${CompilerRTCRT_SOURCE_DIR}/../../") elseif(DEFINED CompilerRT_SOURCE_DIR) # Compiler-RT standalone build. # `llvm-project/compiler-rt` diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 3ad2d6a..2e965df 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -611,7 +611,6 @@ if(APPLE) SANITIZER_COMMON_SUPPORTED_ARCH) else() - filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) # Architectures supported by compiler-rt libraries. filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) @@ -708,12 +707,6 @@ endif() # TODO: Add builtins support. -if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER) - set(COMPILER_RT_HAS_CRT TRUE) -else() - set(COMPILER_RT_HAS_CRT FALSE) -endif() - if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") set(COMPILER_RT_HAS_DFSAN TRUE) diff --git a/compiler-rt/cmake/crt-config-ix.cmake b/compiler-rt/cmake/crt-config-ix.cmake new file mode 100644 index 0000000..2ac2558 --- /dev/null +++ b/compiler-rt/cmake/crt-config-ix.cmake @@ -0,0 +1,48 @@ +include(BuiltinTests) +include(CheckCSourceCompiles) + +# Make all the tests only check the compiler +set(TEST_COMPILE_ONLY On) + +builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) +builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG) +builtin_check_c_compiler_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC) +builtin_check_c_compiler_flag(-fno-lto COMPILER_RT_HAS_FNO_LTO_FLAG) +builtin_check_c_compiler_flag(-fno-profile-generate COMPILER_RT_HAS_FNO_PROFILE_GENERATE_FLAG) +builtin_check_c_compiler_flag(-fno-profile-instr-generate COMPILER_RT_HAS_FNO_PROFILE_INSTR_GENERATE_FLAG) +builtin_check_c_compiler_flag(-fno-profile-instr-use COMPILER_RT_HAS_FNO_PROFILE_INSTR_USE_FLAG) + +if(ANDROID) + set(OS_NAME "Android") +else() + set(OS_NAME "${CMAKE_SYSTEM_NAME}") +endif() + +set(ARM64 aarch64) +set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) +set(X86 i386) +set(X86_64 x86_64) +set(RISCV32 riscv32) +set(RISCV64 riscv64) +set(VE ve) + +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64} ${VE}) + +include(CompilerRTUtils) + +if(NOT APPLE) + if(COMPILER_RT_CRT_STANDALONE_BUILD) + test_targets() + endif() + # Architectures supported by compiler-rt crt library. + filter_available_targets(CRT_SUPPORTED_ARCH + ${ALL_CRT_SUPPORTED_ARCH}) + + if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER) + set(COMPILER_RT_HAS_CRT TRUE) + else() + set(COMPILER_RT_HAS_CRT FALSE) + endif() +endif() + +message(STATUS "Supported architectures for crt: ${CRT_SUPPORTED_ARCH}") diff --git a/compiler-rt/lib/crt/CMakeLists.txt b/compiler-rt/lib/crt/CMakeLists.txt index dc7dd17..b1b0671 100644 --- a/compiler-rt/lib/crt/CMakeLists.txt +++ b/compiler-rt/lib/crt/CMakeLists.txt @@ -1,3 +1,35 @@ +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + cmake_minimum_required(VERSION 3.13.4) + + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + project(CompilerRTCRT C) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set(COMPILER_RT_CRT_STANDALONE_BUILD TRUE) + + set(COMPILER_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..") + + set(LLVM_COMMON_CMAKE_UTILS "${COMPILER_RT_SOURCE_DIR}/../cmake") + + # Add path for custom modules + list(INSERT CMAKE_MODULE_PATH 0 + "${COMPILER_RT_SOURCE_DIR}/cmake" + "${COMPILER_RT_SOURCE_DIR}/cmake/Modules" + "${LLVM_COMMON_CMAKE_UTILS}" + "${LLVM_COMMON_CMAKE_UTILS}/Modules" + ) + + include(base-config-ix) + include(CompilerRTUtils) + + load_llvm_config() + construct_compiler_rt_default_triple() + + include(SetPlatformToolchainTools) + include(AddCompilerRT) +endif() + +include(crt-config-ix) + add_compiler_rt_component(crt) function(check_cxx_section_exists section output)