musllvm

A pure LLVM/Clang cross compiler toolchain targeting musl C
git clone git://git.daat.foo/musllvm.git
Log | Files | Refs | README | LICENSE

0007-compiler-rt-build-crt-in-runtimes-build.patch (13840B)


      1 From ddba64ea50bc85499ccfae3f79ce7148eb3252bf Mon Sep 17 00:00:00 2001
      2 From: q66 <q66@chimera-linux.org>
      3 Date: Fri, 29 Nov 2024 19:40:34 +0100
      4 Subject: [PATCH 07/29] compiler-rt: build crt in runtimes build
      5 
      6 We need this because otherwise the in-tree clang binaries will
      7 not work, as we don't supply external gcc-style runtime.
      8 ---
      9  compiler-rt/CMakeLists.txt              | 117 +++++++++++++-----------
     10  compiler-rt/lib/builtins/CMakeLists.txt |  55 ++---------
     11  llvm/runtimes/CMakeLists.txt            |  12 ++-
     12  runtimes/CMakeLists.txt                 |   2 +-
     13  4 files changed, 80 insertions(+), 106 deletions(-)
     14 
     15 diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
     16 index bad897a12..3ea1aac04 100644
     17 --- a/compiler-rt/CMakeLists.txt
     18 +++ b/compiler-rt/CMakeLists.txt
     19 @@ -60,47 +60,6 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --no-default-config")
     20  check_cxx_compiler_flag("" COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
     21  set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
     22  
     23 -option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
     24 -mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
     25 -option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
     26 -mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
     27 -option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
     28 -mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
     29 -option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
     30 -mark_as_advanced(COMPILER_RT_BUILD_XRAY)
     31 -option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
     32 -mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
     33 -option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
     34 -mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
     35 -option(COMPILER_RT_BUILD_CTX_PROFILE "Build ctx profile runtime" ON)
     36 -mark_as_advanced(COMPILER_RT_BUILD_CTX_PROFILE)
     37 -option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
     38 -mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
     39 -option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
     40 -mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
     41 -option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
     42 -mark_as_advanced(COMPILER_RT_BUILD_ORC)
     43 -option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
     44 -mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
     45 -option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
     46 -
     47 -option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
     48 -mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
     49 -option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
     50 -mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
     51 -option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
     52 -mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
     53 -
     54 -if(FUCHSIA)
     55 -  set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
     56 -else()
     57 -  set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
     58 -endif()
     59 -set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
     60 -
     61 -set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
     62 -  "Build for a bare-metal target.")
     63 -
     64  if (COMPILER_RT_STANDALONE_BUILD)
     65    set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
     66    set(CMAKE_CXX_STANDARD_REQUIRED YES)
     67 @@ -115,20 +74,7 @@ if (COMPILER_RT_STANDALONE_BUILD)
     68      set_target_properties(intrinsics_gen PROPERTIES FOLDER "LLVM/Tablegenning")
     69    endif()
     70  
     71 -  find_package(Python3 COMPONENTS Interpreter)
     72 -  if(NOT Python3_Interpreter_FOUND)
     73 -    message(WARNING "Python3 not found, using python2 as a fallback")
     74 -    find_package(Python2 COMPONENTS Interpreter REQUIRED)
     75 -    if(Python2_VERSION VERSION_LESS 2.7)
     76 -      message(SEND_ERROR "Python 2.7 or newer is required")
     77 -    endif()
     78 -
     79 -    # Treat python2 as python3
     80 -    add_executable(Python3::Interpreter IMPORTED)
     81 -    set_target_properties(Python3::Interpreter PROPERTIES
     82 -      IMPORTED_LOCATION ${Python2_EXECUTABLE})
     83 -    set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
     84 -  endif()
     85 +  set(Python3_EXECUTABLE "/usr/bin/python3")
     86  
     87    # Ensure that fat libraries are built correctly on Darwin
     88    if(APPLE)
     89 @@ -158,6 +104,67 @@ if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
     90  endif()
     91  pythonize_bool(ANDROID)
     92  
     93 +option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
     94 +mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
     95 +option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
     96 +mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
     97 +
     98 +option(COMPILER_RT_BOOTSTRAP "Build just builtins and crt" OFF)
     99 +mark_as_advanced(COMPILER_RT_BOOTSTRAP)
    100 +
    101 +if(COMPILER_RT_BOOTSTRAP)
    102 +  include(AddCompilerRT)
    103 +
    104 +  set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
    105 +
    106 +  if(COMPILER_RT_BUILD_BUILTINS)
    107 +    set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
    108 +    add_subdirectory(lib/builtins)
    109 +  endif()
    110 +  if(COMPILER_RT_BUILD_CRT)
    111 +    set(COMPILER_RT_CRT_STANDALONE_BUILD TRUE)
    112 +  endif()
    113 +
    114 +  return()
    115 +endif()
    116 +
    117 +option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
    118 +mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
    119 +option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
    120 +mark_as_advanced(COMPILER_RT_BUILD_XRAY)
    121 +option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
    122 +mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
    123 +option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
    124 +mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
    125 +option(COMPILER_RT_BUILD_CTX_PROFILE "Build ctx profile runtime" ON)
    126 +mark_as_advanced(COMPILER_RT_BUILD_CTX_PROFILE)
    127 +option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
    128 +mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
    129 +option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
    130 +mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
    131 +option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
    132 +mark_as_advanced(COMPILER_RT_BUILD_ORC)
    133 +option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
    134 +mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
    135 +option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
    136 +
    137 +option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
    138 +mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
    139 +option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
    140 +mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
    141 +option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
    142 +mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
    143 +
    144 +if(FUCHSIA)
    145 +  set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
    146 +else()
    147 +  set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
    148 +endif()
    149 +set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
    150 +
    151 +set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
    152 +  "Build for a bare-metal target.")
    153 +
    154  set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
    155  set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
    156  
    157 diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
    158 index 19316c52d..f89cf87c7 100644
    159 --- a/compiler-rt/lib/builtins/CMakeLists.txt
    160 +++ b/compiler-rt/lib/builtins/CMakeLists.txt
    161 @@ -7,54 +7,15 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
    162  
    163    set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
    164    project(CompilerRTBuiltins C ASM)
    165 -  set(COMPILER_RT_STANDALONE_BUILD TRUE)
    166 -  set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
    167 -
    168 -  set(COMPILER_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
    169 -
    170 -  set(LLVM_COMMON_CMAKE_UTILS "${COMPILER_RT_SOURCE_DIR}/../cmake")
    171 -
    172 -  # Add path for custom modules
    173 -  list(INSERT CMAKE_MODULE_PATH 0
    174 -    "${COMPILER_RT_SOURCE_DIR}/cmake"
    175 -    "${COMPILER_RT_SOURCE_DIR}/cmake/Modules"
    176 -    "${LLVM_COMMON_CMAKE_UTILS}"
    177 -    "${LLVM_COMMON_CMAKE_UTILS}/Modules"
    178 -    )
    179 -
    180 -  include(base-config-ix)
    181 -  include(CompilerRTUtils)
    182 -
    183 -  if (NOT LLVM_RUNTIMES_BUILD)
    184 -    load_llvm_config()
    185 +  if(NOT _BUILTINS_PROCESSED)
    186 +    set(COMPILER_RT_BUILD_BUILTINS TRUE)
    187 +    set(COMPILER_RT_BUILD_CRT FALSE)
    188 +    set(COMPILER_RT_BOOTSTRAP TRUE)
    189 +    set(COMPILER_RT_STANDALONE_BUILD TRUE)
    190 +    include(../../CMakeLists.txt)
    191 +    set(_BUILTINS_PROCESSED TRUE)
    192 +    return()
    193    endif()
    194 -  construct_compiler_rt_default_triple()
    195 -
    196 -  include(SetPlatformToolchainTools)
    197 -  if(APPLE)
    198 -    include(CompilerRTDarwinUtils)
    199 -  endif()
    200 -  if(APPLE)
    201 -    include(UseLibtool)
    202 -  endif()
    203 -  include(AddCompilerRT)
    204 -
    205 -  if(MINGW)
    206 -    # Simplified version of what's set in cmake/config-ix.cmake; not including
    207 -    # builtins, which are linked separately.
    208 -    set(MINGW_LIBRARIES mingw32 moldname mingwex msvcrt advapi32 shell32
    209 -                        user32 kernel32 mingw32 moldname mingwex msvcrt)
    210 -   endif()
    211 -endif()
    212 -
    213 -if (COMPILER_RT_STANDALONE_BUILD)
    214 -  # When compiler-rt is being built standalone, possibly as a cross-compilation
    215 -  # target, the target may or may not want position independent code. This
    216 -  # option provides an avenue through which the flag may be controlled when an
    217 -  # LLVM configuration is not being utilized.
    218 -  option(COMPILER_RT_BUILTINS_ENABLE_PIC
    219 -    "Turns on or off -fPIC for the builtin library source"
    220 -    ON)
    221  endif()
    222  
    223  include(builtin-config-ix)
    224 diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
    225 index 70e85c123..7374074ac 100644
    226 --- a/llvm/runtimes/CMakeLists.txt
    227 +++ b/llvm/runtimes/CMakeLists.txt
    228 @@ -88,7 +88,7 @@ function(builtin_default_target compiler_rt_path)
    229    set_enable_per_target_runtime_dir()
    230  
    231    llvm_ExternalProject_Add(builtins
    232 -                           ${compiler_rt_path}/lib/builtins
    233 +                           ${compiler_rt_path}
    234                             DEPENDS ${ARG_DEPENDS}
    235                             CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
    236                                        -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
    237 @@ -96,7 +96,9 @@ function(builtin_default_target compiler_rt_path)
    238                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
    239                                        -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
    240                                        -DCMAKE_C_COMPILER_WORKS=ON
    241 +                                      -DCMAKE_CXX_COMPILER_WORKS=ON
    242                                        -DCMAKE_ASM_COMPILER_WORKS=ON
    243 +                                      -DCOMPILER_RT_BOOTSTRAP=ON
    244                                        ${COMMON_CMAKE_ARGS}
    245                                        ${BUILTINS_CMAKE_ARGS}
    246                             PASSTHROUGH_PREFIXES COMPILER_RT
    247 @@ -129,15 +131,17 @@ function(builtin_register_target compiler_rt_path name)
    248    endforeach()
    249  
    250    llvm_ExternalProject_Add(builtins-${name}
    251 -                           ${compiler_rt_path}/lib/builtins
    252 +                           ${compiler_rt_path}
    253                             DEPENDS ${ARG_DEPENDS}
    254                             CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
    255                                        -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
    256                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
    257                                        -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
    258                                        -DCMAKE_C_COMPILER_WORKS=ON
    259 +                                      -DCMAKE_CXX_COMPILER_WORKS=ON
    260                                        -DCMAKE_ASM_COMPILER_WORKS=ON
    261                                        -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
    262 +                                      -DCOMPILER_RT_BOOTSTRAP=ON
    263                                        ${COMMON_CMAKE_ARGS}
    264                                        ${${name}_extra_args}
    265                             USE_TOOLCHAIN
    266 @@ -262,7 +266,8 @@ function(runtime_default_target)
    267                             ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
    268                             DEPENDS ${ARG_DEPENDS}
    269                             # Builtins were built separately above
    270 -                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
    271 +                           CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
    272 +                                      -DCOMPILER_RT_BUILD_CRT=OFF
    273                                        -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
    274                                        -DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
    275                                        -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
    276 @@ -399,6 +404,7 @@ function(runtime_register_target name)
    277                             DEPENDS ${ARG_DEPENDS}
    278                             # Builtins were built separately above
    279                             CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
    280 +                                      -DCOMPILER_RT_BUILD_CRT=OFF
    281                                        -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
    282                                        -DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
    283                                        -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
    284 diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
    285 index 4a6b317a0..cfbad056d 100644
    286 --- a/runtimes/CMakeLists.txt
    287 +++ b/runtimes/CMakeLists.txt
    288 @@ -177,7 +177,7 @@ include(HandleLLVMOptions)
    289  # Loot at the PATH first to avoid a version mismatch between the command-line
    290  # python and the CMake-found version
    291  set(Python3_FIND_REGISTRY LAST)
    292 -find_package(Python3 REQUIRED COMPONENTS Interpreter)
    293 +set(Python3_EXECUTABLE "/usr/bin/python3")
    294  
    295  # Host triple is used by tests to check if they are running natively.
    296  include(GetHostTriple)
    297 -- 
    298 2.49.0
    299