[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
This commit is contained in:
Petr Hosek 2022-02-28 12:21:11 -08:00
parent 3297758901
commit ed28461e27
5 changed files with 84 additions and 9 deletions

View File

@ -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)

View File

@ -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`

View File

@ -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)

View File

@ -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}")

View File

@ -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)