Index: compiler-rt/builtins/CMakeLists.txt =================================================================== --- /dev/null +++ compiler-rt/builtins/CMakeLists.txt @@ -0,0 +1,45 @@ +# CMake build for CompilerRT builtins. +# +# This includes just builtins and crtbegin/crtend. + +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) +cmake_minimum_required(VERSION 3.4.3) +project(CompilerRTBuiltins C ASM) +endif() + +list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_CURRENT_LIST_DIR}/../cmake" + "${CMAKE_CURRENT_LIST_DIR}/../cmake/Modules") + +set(COMPILER_RT_STANDALONE_BUILD TRUE) +set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE) +include(base-config-ix) +include(CompilerRTUtils) + +load_llvm_config() +construct_compiler_rt_default_triple() + +if(APPLE) + include(CompilerRTDarwinUtils) +endif() +if(CMAKE_HOST_APPLE AND APPLE) + include(UseLibtool) +endif() + +include(AddCompilerRT) + +option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) +mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) +option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON) +mark_as_advanced(COMPILER_RT_BUILD_CRT) +option(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY "Use eh_frame in crtbegin.o/crtend.o" ON) +mark_as_advanced(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY) + +include(builtin-config-ix) + +if(COMPILER_RT_BUILD_BUILTINS) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../lib/builtins lib/builtins) +endif() +if(COMPILER_RT_BUILD_CRT AND COMPILER_RT_HAS_CRT) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../lib/crt lib/crt) +endif() Index: compiler-rt/cmake/builtin-config-ix.cmake =================================================================== --- compiler-rt/cmake/builtin-config-ix.cmake +++ compiler-rt/cmake/builtin-config-ix.cmake @@ -13,6 +13,7 @@ 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_flag(-Wno-pedantic COMPILER_RT_HAS_WNO_PEDANTIC) builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD " @@ -46,6 +47,13 @@ set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${HEXAGON} ${MIPS32} ${MIPS64} ${PPC64} ${RISCV32} ${RISCV64} ${SPARC} ${SPARCV9} ${WASM32} ${WASM64}) +set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV32} ${RISCV64}) + +if(ANDROID) + set(OS_NAME "Android") +else() + set(OS_NAME "${CMAKE_SYSTEM_NAME}") +endif() include(CompilerRTUtils) include(CompilerRTDarwinUtils) @@ -164,6 +172,14 @@ # Architectures supported by compiler-rt libraries. filter_available_targets(BUILTIN_SUPPORTED_ARCH ${ALL_BUILTIN_SUPPORTED_ARCH}) + filter_available_targets(CRT_SUPPORTED_ARCH + ${ALL_CRT_SUPPORTED_ARCH}) + + if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") + set(COMPILER_RT_HAS_CRT TRUE) + else() + set(COMPILER_RT_HAS_CRT FALSE) + endif() endif() message(STATUS "Builtin supported architectures: ${BUILTIN_SUPPORTED_ARCH}") Index: compiler-rt/cmake/config-ix.cmake =================================================================== --- compiler-rt/cmake/config-ix.cmake +++ compiler-rt/cmake/config-ix.cmake @@ -261,7 +261,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) @@ -527,7 +526,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}) @@ -611,12 +609,6 @@ # TODO: Add builtins support. -if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") - 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) Index: compiler-rt/lib/builtins/CMakeLists.txt =================================================================== --- compiler-rt/lib/builtins/CMakeLists.txt +++ compiler-rt/lib/builtins/CMakeLists.txt @@ -2,32 +2,18 @@ # generic implementations of the core runtime library along with optimized # architecture-specific code in various subdirectories. -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) cmake_minimum_required(VERSION 3.4.3) - project(CompilerRTBuiltins C ASM) - set(COMPILER_RT_STANDALONE_BUILD TRUE) - set(COMPILER_RT_BUILTINS_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(CMAKE_HOST_APPLE AND APPLE) - include(UseLibtool) + + message(WARNING "Using this directory as top-level for build is deprecated, please use compiler-rt/builtins directory instead") + if(NOT __BUILTINS_PROCESSED__) + set(__BUILTINS_PROCESSED__ TRUE) + include(../../builtins/CMakeLists.txt) + return() endif() - include(AddCompilerRT) endif() -include(builtin-config-ix) - # TODO: Need to add a mechanism for logging errors when builtin source files are # added to a sub-directory and not this CMakeLists file. set(GENERIC_SOURCES Index: llvm/runtimes/CMakeLists.txt =================================================================== --- llvm/runtimes/CMakeLists.txt +++ llvm/runtimes/CMakeLists.txt @@ -235,7 +235,7 @@ cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) llvm_ExternalProject_Add(builtins - ${compiler_rt_path}/lib/builtins + ${compiler_rt_path}/builtins DEPENDS ${ARG_DEPENDS} CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} @@ -271,7 +271,7 @@ endforeach() llvm_ExternalProject_Add(builtins-${target} - ${compiler_rt_path}/lib/builtins + ${compiler_rt_path}/builtins DEPENDS ${ARG_DEPENDS} CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR} -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}