Initial stub of a Makefile and patches for LLVM

Nothing much, but getting some patches from chimera linux that should
work.
This commit is contained in:
cowmonk 2025-10-25 16:23:17 -07:00
parent 636c6f0163
commit 6110995cfb
33 changed files with 1813 additions and 0 deletions

View file

@ -0,0 +1,299 @@
From ddba64ea50bc85499ccfae3f79ce7148eb3252bf Mon Sep 17 00:00:00 2001
From: q66 <q66@chimera-linux.org>
Date: Fri, 29 Nov 2024 19:40:34 +0100
Subject: [PATCH 07/29] compiler-rt: build crt in runtimes build
We need this because otherwise the in-tree clang binaries will
not work, as we don't supply external gcc-style runtime.
---
compiler-rt/CMakeLists.txt | 117 +++++++++++++-----------
compiler-rt/lib/builtins/CMakeLists.txt | 55 ++---------
llvm/runtimes/CMakeLists.txt | 12 ++-
runtimes/CMakeLists.txt | 2 +-
4 files changed, 80 insertions(+), 106 deletions(-)
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index bad897a12..3ea1aac04 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -60,47 +60,6 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --no-default-config")
check_cxx_compiler_flag("" COMPILER_RT_HAS_NO_DEFAULT_CONFIG_FLAG)
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
-option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
-mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
-option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
-mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
-option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
-mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
-option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
-mark_as_advanced(COMPILER_RT_BUILD_XRAY)
-option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
-mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
-option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
-mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
-option(COMPILER_RT_BUILD_CTX_PROFILE "Build ctx profile runtime" ON)
-mark_as_advanced(COMPILER_RT_BUILD_CTX_PROFILE)
-option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
-mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
-option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
-mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
-option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
-mark_as_advanced(COMPILER_RT_BUILD_ORC)
-option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
-mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
-option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
-
-option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
-mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
-option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
-mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
-option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
-mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
-
-if(FUCHSIA)
- set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
-else()
- set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
-endif()
-set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
-
-set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
- "Build for a bare-metal target.")
-
if (COMPILER_RT_STANDALONE_BUILD)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
@@ -115,20 +74,7 @@ if (COMPILER_RT_STANDALONE_BUILD)
set_target_properties(intrinsics_gen PROPERTIES FOLDER "LLVM/Tablegenning")
endif()
- find_package(Python3 COMPONENTS Interpreter)
- if(NOT Python3_Interpreter_FOUND)
- message(WARNING "Python3 not found, using python2 as a fallback")
- find_package(Python2 COMPONENTS Interpreter REQUIRED)
- if(Python2_VERSION VERSION_LESS 2.7)
- message(SEND_ERROR "Python 2.7 or newer is required")
- endif()
-
- # Treat python2 as python3
- add_executable(Python3::Interpreter IMPORTED)
- set_target_properties(Python3::Interpreter PROPERTIES
- IMPORTED_LOCATION ${Python2_EXECUTABLE})
- set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
- endif()
+ set(Python3_EXECUTABLE "/usr/bin/python3")
# Ensure that fat libraries are built correctly on Darwin
if(APPLE)
@@ -158,6 +104,67 @@ if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")
endif()
pythonize_bool(ANDROID)
+option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
+mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
+option(COMPILER_RT_DISABLE_AARCH64_FMV "Disable AArch64 Function Multi Versioning support" OFF)
+mark_as_advanced(COMPILER_RT_DISABLE_AARCH64_FMV)
+
+option(COMPILER_RT_BOOTSTRAP "Build just builtins and crt" OFF)
+mark_as_advanced(COMPILER_RT_BOOTSTRAP)
+
+if(COMPILER_RT_BOOTSTRAP)
+ include(AddCompilerRT)
+
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
+ if(COMPILER_RT_BUILD_BUILTINS)
+ set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
+ add_subdirectory(lib/builtins)
+ endif()
+ if(COMPILER_RT_BUILD_CRT)
+ set(COMPILER_RT_CRT_STANDALONE_BUILD TRUE)
+ endif()
+
+ return()
+endif()
+
+option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON)
+mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
+option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
+mark_as_advanced(COMPILER_RT_BUILD_XRAY)
+option(COMPILER_RT_BUILD_LIBFUZZER "Build libFuzzer" ON)
+mark_as_advanced(COMPILER_RT_BUILD_LIBFUZZER)
+option(COMPILER_RT_BUILD_PROFILE "Build profile runtime" ON)
+mark_as_advanced(COMPILER_RT_BUILD_PROFILE)
+option(COMPILER_RT_BUILD_CTX_PROFILE "Build ctx profile runtime" ON)
+mark_as_advanced(COMPILER_RT_BUILD_CTX_PROFILE)
+option(COMPILER_RT_BUILD_MEMPROF "Build memory profiling runtime" ON)
+mark_as_advanced(COMPILER_RT_BUILD_MEMPROF)
+option(COMPILER_RT_BUILD_XRAY_NO_PREINIT "Build xray with no preinit patching" OFF)
+mark_as_advanced(COMPILER_RT_BUILD_XRAY_NO_PREINIT)
+option(COMPILER_RT_BUILD_ORC "Build ORC runtime" ON)
+mark_as_advanced(COMPILER_RT_BUILD_ORC)
+option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
+mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
+option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)
+
+option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
+mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
+option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
+mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
+option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
+mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
+
+if(FUCHSIA)
+ set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
+else()
+ set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
+endif()
+set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")
+
+set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
+ "Build for a bare-metal target.")
+
set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 19316c52d..f89cf87c7 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -7,54 +7,15 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
project(CompilerRTBuiltins C ASM)
- set(COMPILER_RT_STANDALONE_BUILD TRUE)
- set(COMPILER_RT_BUILTINS_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)
-
- if (NOT LLVM_RUNTIMES_BUILD)
- load_llvm_config()
+ if(NOT _BUILTINS_PROCESSED)
+ set(COMPILER_RT_BUILD_BUILTINS TRUE)
+ set(COMPILER_RT_BUILD_CRT FALSE)
+ set(COMPILER_RT_BOOTSTRAP TRUE)
+ set(COMPILER_RT_STANDALONE_BUILD TRUE)
+ include(../../CMakeLists.txt)
+ set(_BUILTINS_PROCESSED TRUE)
+ return()
endif()
- construct_compiler_rt_default_triple()
-
- include(SetPlatformToolchainTools)
- if(APPLE)
- include(CompilerRTDarwinUtils)
- endif()
- if(APPLE)
- include(UseLibtool)
- endif()
- include(AddCompilerRT)
-
- if(MINGW)
- # Simplified version of what's set in cmake/config-ix.cmake; not including
- # builtins, which are linked separately.
- set(MINGW_LIBRARIES mingw32 moldname mingwex msvcrt advapi32 shell32
- user32 kernel32 mingw32 moldname mingwex msvcrt)
- endif()
-endif()
-
-if (COMPILER_RT_STANDALONE_BUILD)
- # When compiler-rt is being built standalone, possibly as a cross-compilation
- # target, the target may or may not want position independent code. This
- # option provides an avenue through which the flag may be controlled when an
- # LLVM configuration is not being utilized.
- option(COMPILER_RT_BUILTINS_ENABLE_PIC
- "Turns on or off -fPIC for the builtin library source"
- ON)
endif()
include(builtin-config-ix)
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 70e85c123..7374074ac 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -88,7 +88,7 @@ function(builtin_default_target compiler_rt_path)
set_enable_per_target_runtime_dir()
llvm_ExternalProject_Add(builtins
- ${compiler_rt_path}/lib/builtins
+ ${compiler_rt_path}
DEPENDS ${ARG_DEPENDS}
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
@@ -96,7 +96,9 @@ function(builtin_default_target compiler_rt_path)
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
-DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
-DCMAKE_C_COMPILER_WORKS=ON
+ -DCMAKE_CXX_COMPILER_WORKS=ON
-DCMAKE_ASM_COMPILER_WORKS=ON
+ -DCOMPILER_RT_BOOTSTRAP=ON
${COMMON_CMAKE_ARGS}
${BUILTINS_CMAKE_ARGS}
PASSTHROUGH_PREFIXES COMPILER_RT
@@ -129,15 +131,17 @@ function(builtin_register_target compiler_rt_path name)
endforeach()
llvm_ExternalProject_Add(builtins-${name}
- ${compiler_rt_path}/lib/builtins
+ ${compiler_rt_path}
DEPENDS ${ARG_DEPENDS}
CMAKE_ARGS -DLLVM_LIBRARY_OUTPUT_INTDIR=${LLVM_LIBRARY_DIR}
-DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR}
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON
-DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR}
-DCMAKE_C_COMPILER_WORKS=ON
+ -DCMAKE_CXX_COMPILER_WORKS=ON
-DCMAKE_ASM_COMPILER_WORKS=ON
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
+ -DCOMPILER_RT_BOOTSTRAP=ON
${COMMON_CMAKE_ARGS}
${${name}_extra_args}
USE_TOOLCHAIN
@@ -262,7 +266,8 @@ function(runtime_default_target)
${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
DEPENDS ${ARG_DEPENDS}
# Builtins were built separately above
- CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
+ CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
+ -DCOMPILER_RT_BUILD_CRT=OFF
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DLLVM_DEFAULT_TARGET_TRIPLE=${LLVM_TARGET_TRIPLE}
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
@@ -399,6 +404,7 @@ function(runtime_register_target name)
DEPENDS ${ARG_DEPENDS}
# Builtins were built separately above
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=OFF
+ -DCOMPILER_RT_BUILD_CRT=OFF
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DLLVM_ENABLE_PROJECTS_USED=${LLVM_ENABLE_PROJECTS_USED}
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR}
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 4a6b317a0..cfbad056d 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -177,7 +177,7 @@ include(HandleLLVMOptions)
# Loot at the PATH first to avoid a version mismatch between the command-line
# python and the CMake-found version
set(Python3_FIND_REGISTRY LAST)
-find_package(Python3 REQUIRED COMPONENTS Interpreter)
+set(Python3_EXECUTABLE "/usr/bin/python3")
# Host triple is used by tests to check if they are running natively.
include(GetHostTriple)
--
2.49.0