diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -296,7 +296,6 @@ ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}) set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9}) -set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64}) set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) if(ANDROID) @@ -582,7 +581,6 @@ 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}) @@ -667,7 +665,7 @@ # TODO: Add builtins support. -if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER) +if (OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER) set(COMPILER_RT_HAS_CRT TRUE) else() set(COMPILER_RT_HAS_CRT FALSE) diff --git a/compiler-rt/cmake/crt-config-ix.cmake b/compiler-rt/cmake/crt-config-ix.cmake new file mode 100644 --- /dev/null +++ b/compiler-rt/cmake/crt-config-ix.cmake @@ -0,0 +1,57 @@ +include(BuiltinTests) +include(CheckCSourceCompiles) + +# Make all the tests only check the compiler +set(TEST_COMPILE_ONLY On) + +# Check host compiler support for certain flags +builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) +builtin_check_c_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) +builtin_check_c_compiler_flag(-fno-builtin COMPILER_RT_HAS_FNO_CRT_FLAG) +builtin_check_c_compiler_flag(-std=c11 COMPILER_RT_HAS_STD_C11_FLAG) +builtin_check_c_compiler_flag(-fvisibility=hidden COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG) +builtin_check_c_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG) +builtin_check_c_compiler_flag(-ffreestanding COMPILER_RT_HAS_FREESTANDING_FLAG) +builtin_check_c_compiler_flag(-fxray-instrument COMPILER_RT_HAS_XRAY_COMPILER_FLAG) + +builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD +" +int foo(int x, int y) { + _Atomic int result = x * y; + return result; +} +") + +set(ARM64 aarch64) +set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) +set(HEXAGON hexagon) +set(X86 i386) +set(X86_64 x86_64) +set(MIPS32 mips mipsel) +set(MIPS64 mips64 mips64el) +set(PPC32 powerpc) +set(PPC64 powerpc64 powerpc64le) +set(RISCV32 riscv32) +set(RISCV64 riscv64) +set(SPARC sparc) +set(SPARCV9 sparcv9) +set(WASM32 wasm32) +set(WASM64 wasm64) +set(S390X s390x) +set(VE ve) + +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64}) + +include(CompilerRTUtils) + +# If we're not building the crt standalone, just rely on the tests in +# config-ix.cmake to tell us what to build. Otherwise we need to do some leg +# work here... +if(COMPILER_RT_CRT_STANDALONE_BUILD) + test_targets() +endif() +# Architectures supported by compiler-rt libraries. +filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) + + +message(STATUS "CRT supported architectures: ${CRT_SUPPORTED_ARCH}") diff --git a/compiler-rt/lib/crt/CMakeLists.txt b/compiler-rt/lib/crt/CMakeLists.txt --- a/compiler-rt/lib/crt/CMakeLists.txt +++ b/compiler-rt/lib/crt/CMakeLists.txt @@ -1,3 +1,29 @@ +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + cmake_minimum_required(VERSION 3.13.4) + + project(CompilerRTCRT C ASM) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set(COMPILER_RT_CRT_STANDALONE_BUILD TRUE) + list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_SOURCE_DIR}/../../cmake" + "${CMAKE_SOURCE_DIR}/../../cmake/Modules") + include(base-config-ix) + include(CompilerRTUtils) + + load_llvm_config() + construct_compiler_rt_default_triple() + + if(APPLE) + include(CompilerRTDarwinUtils) + endif() + if(APPLE) + include(UseLibtool) + endif() + include(AddCompilerRT) +endif() + +include(crt-config-ix) + add_compiler_rt_component(crt) function(check_cxx_section_exists section output) diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -311,6 +311,26 @@ ${EXTRA_ARGS}) endfunction() + function(crt_default_target compiler_rt_path) + cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) + + llvm_ExternalProject_Add(crt + ${compiler_rt_path}/lib/crt + DEPENDS ${ARG_DEPENDS} + CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} + -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} + -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_TRIPLE} + -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON + -DCMAKE_C_COMPILER_TARGET=${TARGET_TRIPLE} + -DCMAKE_ASM_COMPILER_TARGET=${TARGET_TRIPLE} + -DCMAKE_C_COMPILER_WORKS=ON + -DCMAKE_ASM_COMPILER_WORKS=ON + ${BUILTINS_CMAKE_ARGS} + PASSTHROUGH_PREFIXES COMPILER_RT + USE_TOOLCHAIN + ${EXTRA_ARGS}) + endfunction() + # If compiler-rt is present we need to build the builtin libraries first. This # is required because the other runtimes need the builtin libraries present # before the just-built compiler can pass the configuration tests. @@ -319,6 +339,10 @@ if(NOT LLVM_BUILTIN_TARGETS) builtin_default_target(${compiler_rt_path} DEPENDS clang-resource-headers) + if (LLVM_RUNTIMES_CRT_STANDALONE_BUILD) + crt_default_target(${compiler_rt_path} + DEPENDS clang-resource-headers) + endif() else() if("default" IN_LIST LLVM_BUILTIN_TARGETS) builtin_default_target(${compiler_rt_path} @@ -408,6 +432,10 @@ set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF) endif() + if(LLVM_RUNTIMES_CRT_STANDALONE_BUILD) + set(RUNTIMES_EXTRA_CMAKE_ARGS -DCOMPILER_RT_BUILD_CRT=OFF) + endif() + llvm_ExternalProject_Add(runtimes ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${ARG_DEPENDS} @@ -423,6 +451,7 @@ -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_CXX_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON + ${RUNTIMES_EXTRA_CMAKE_ARGS} ${RUNTIMES_CMAKE_ARGS} PASSTHROUGH_PREFIXES LLVM_ENABLE_RUNTIMES ${ARG_PREFIXES}