mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes with better C++20 support and improved handling of new features by clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our Clang binaries will only be 2-4% slower than if we dynamically linked them, but we save hundreds of megabytes of disk space. The `BuildClang.sh` script has been reworked to build the entire toolchain in just three steps: one for the compiler, one for GNU binutils, and one for the runtime libraries. This reduces the complexity of the build script, and will allow us to modify the CI configuration to only rebuild the libraries when our libc headers change. Most of the compile flags have been moved out to a separate CMake cache file, similarly to how the Android and Fuchsia toolchains are implemented within the LLVM repo. This provides a nicer interface than the heaps of command-line arguments. We no longer build separate toolchains for each architecture, as the same Clang binary can compile code for multiple targets. The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in this commit. Clang happily accepts an `i686-pc-serenity` target triple, which matches what our GCC toolchain accepts.
This commit is contained in:
parent
28c088cd91
commit
06fc64be13
Notes:
sideshowbarker
2024-07-18 22:57:59 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/06fc64be13d Pull-request: https://github.com/SerenityOS/serenity/pull/9378 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/itamar8910 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/nico Reviewed-by: https://github.com/timschumi
@ -16,12 +16,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
|
||||
"Please re-read the BuildInstructions documentation, and use the superbuild configuration\n")
|
||||
endif()
|
||||
|
||||
if(SERENITY_ARCH STREQUAL "i686")
|
||||
set(SERENITY_CLANG_ARCH "i386")
|
||||
else()
|
||||
set(SERENITY_CLANG_ARCH "${SERENITY_ARCH}")
|
||||
endif()
|
||||
|
||||
set(CMAKE_INSTALL_MESSAGE NEVER)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
@ -176,7 +170,6 @@ add_compile_options(-fdiagnostics-color=always)
|
||||
add_compile_options(-fno-delete-null-pointer-checks)
|
||||
add_compile_options(-ffile-prefix-map=${SerenityOS_SOURCE_DIR}=.)
|
||||
add_compile_options(-fno-exceptions)
|
||||
add_compile_options(-ftls-model=initial-exec)
|
||||
add_compile_options(-fno-semantic-interposition)
|
||||
add_compile_options(-fsized-deallocation)
|
||||
add_compile_options(-fstack-clash-protection)
|
||||
@ -194,26 +187,21 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
add_compile_options(-Wno-c99-designator)
|
||||
add_compile_options(-Wno-implicit-const-int-float-conversion)
|
||||
add_compile_options(-Wno-inconsistent-missing-override)
|
||||
add_compile_options(-Wno-null-pointer-subtraction)
|
||||
add_compile_options(-Wno-tautological-constant-out-of-range-compare)
|
||||
add_compile_options(-Wno-unneeded-internal-declaration)
|
||||
add_compile_options(-Wno-unused-but-set-variable)
|
||||
add_compile_options(-Wno-unused-function)
|
||||
add_compile_options(-fno-aligned-allocation)
|
||||
add_compile_options(-fconstexpr-steps=16777216)
|
||||
add_compile_options(-gdwarf-4)
|
||||
|
||||
# FIXME: Why can't clang find this path for compiler_rt builtins?
|
||||
link_directories(${TOOLCHAIN_ROOT}/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/serenity)
|
||||
# Clang doesn't add compiler_rt to the search path when compiling with -nostdlib.
|
||||
link_directories(${TOOLCHAIN_ROOT}/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/${SERENITY_ARCH}-pc-serenity/)
|
||||
add_link_options(LINKER:--allow-shlib-undefined)
|
||||
endif()
|
||||
|
||||
add_link_options(LINKER:-z,text)
|
||||
|
||||
if("${SERENITY_ARCH}" STREQUAL "i686")
|
||||
add_compile_options(-march=i686)
|
||||
elseif("${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||
add_compile_options(-march=x86-64)
|
||||
endif()
|
||||
|
||||
add_compile_definitions(SANITIZE_PTRS)
|
||||
set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fpic")
|
||||
|
@ -400,9 +400,14 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
endif()
|
||||
link_directories(${TOOLCHAIN_ROOT}/${SERENITY_ARCH}-pc-serenity/lib)
|
||||
link_directories(${TOOLCHAIN_ROOT}/lib/gcc/${SERENITY_ARCH}-pc-serenity/${GCC_VERSION}/)
|
||||
|
||||
set(TARGET_STRING "")
|
||||
else() # Assume Clang
|
||||
add_compile_options(-Waddress-of-packed-member)
|
||||
add_compile_options(-faligned-allocation)
|
||||
|
||||
# We need this in order to pick up the #define __serenity__, otherwise we end up including unistd.h into the linker script
|
||||
set(TARGET_STRING "--target=${CMAKE_CXX_COMPILER_TARGET}")
|
||||
|
||||
add_link_options(LINKER:--build-id=none)
|
||||
endif()
|
||||
@ -476,7 +481,7 @@ add_dependencies(Kernel generate_EscapeSequenceStateMachine.h)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT linker.ld
|
||||
COMMAND "${CMAKE_CXX_COMPILER}" -E -P -x c -I${CMAKE_CURRENT_SOURCE_DIR}/.. "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld" -o "${CMAKE_CURRENT_BINARY_DIR}/linker.ld"
|
||||
COMMAND "${CMAKE_CXX_COMPILER}" ${TARGET_STRING} -E -P -x c -I${CMAKE_CURRENT_SOURCE_DIR}/.. "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld" -o "${CMAKE_CURRENT_BINARY_DIR}/linker.ld"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld"
|
||||
COMMENT "Preprocessing linker.ld"
|
||||
VERBATIM
|
||||
@ -497,7 +502,7 @@ if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(Kernel PRIVATE kernel_heap gcc)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
target_link_libraries(Kernel PRIVATE kernel_heap "clang_rt.builtins-${SERENITY_CLANG_ARCH}")
|
||||
target_link_libraries(Kernel PRIVATE kernel_heap clang_rt.builtins)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -51,7 +51,7 @@ set_target_properties(${PREKERNEL_TARGET} PROPERTIES LINK_DEPENDS ${PREKERNEL_LI
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(${PREKERNEL_TARGET} PRIVATE gcc)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
target_link_libraries(${PREKERNEL_TARGET} PRIVATE "clang_rt.builtins-${SERENITY_CLANG_ARCH}" c++abi)
|
||||
target_link_libraries(${PREKERNEL_TARGET} PRIVATE clang_rt.builtins)
|
||||
endif()
|
||||
|
||||
if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")
|
||||
|
@ -57,7 +57,7 @@ function(serenity_libc target_name fs_name)
|
||||
install(TARGETS ${target_name} DESTINATION usr/lib)
|
||||
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
target_link_libraries(${target_name} "clang_rt.builtins-${SERENITY_CLANG_ARCH}")
|
||||
target_link_libraries(${target_name} clang_rt.builtins)
|
||||
endif()
|
||||
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
serenity_generated_sources(${target_name})
|
||||
|
@ -46,14 +46,13 @@ else
|
||||
fi
|
||||
|
||||
SERENITY_ARCH="${SERENITY_ARCH:-i686}"
|
||||
LLVM_VERSION="${LLVM_VERSION:-12.0.1}"
|
||||
LLVM_VERSION="${LLVM_VERSION:-13.0.0}"
|
||||
|
||||
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
|
||||
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR"/Toolchain/Local/clang/"$SERENITY_ARCH"
|
||||
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR"/Toolchain/Local/clang/
|
||||
mkdir -p mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
|
||||
$CP "$TOOLCHAIN_DIR"/lib/clang/"$LLVM_VERSION"/lib/serenity/* mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
|
||||
$CP "$TOOLCHAIN_DIR"/lib/libunwind* mnt/usr/lib
|
||||
$CP "$TOOLCHAIN_DIR"/lib/libc++* mnt/usr/lib
|
||||
$CP "$TOOLCHAIN_DIR"/lib/clang/"$LLVM_VERSION"/lib/"$SERENITY_ARCH"-pc-serenity/* mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
|
||||
$CP "$TOOLCHAIN_DIR"/lib/"$SERENITY_ARCH"-pc-serenity/* mnt/usr/lib
|
||||
elif [ "$SERENITY_ARCH" != "aarch64" ]; then
|
||||
$CP "$SERENITY_SOURCE_DIR"/Toolchain/Local/"$SERENITY_ARCH"/"$SERENITY_ARCH"-pc-serenity/lib/libgcc_s.so mnt/usr/lib
|
||||
fi
|
||||
|
@ -180,7 +180,11 @@ cmd_with_target() {
|
||||
BUILD_DIR="$SERENITY_SOURCE_DIR/Build/$TARGET$TARGET_TOOLCHAIN"
|
||||
if [ "$TARGET" != "lagom" ]; then
|
||||
export SERENITY_ARCH="$TARGET"
|
||||
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/$TARGET_TOOLCHAIN/$TARGET"
|
||||
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
||||
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/clang"
|
||||
else
|
||||
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/$TARGET_TOOLCHAIN/$TARGET"
|
||||
fi
|
||||
SUPER_BUILD_DIR="$SERENITY_SOURCE_DIR/Build/superbuild-$TARGET$TARGET_TOOLCHAIN"
|
||||
else
|
||||
SUPER_BUILD_DIR="$BUILD_DIR"
|
||||
@ -225,7 +229,7 @@ delete_target() {
|
||||
build_toolchain() {
|
||||
echo "build_toolchain: $TOOLCHAIN_DIR"
|
||||
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
|
||||
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ARCH="$TARGET" ./BuildClang.sh )
|
||||
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ./BuildClang.sh )
|
||||
else
|
||||
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ARCH="$TARGET" ./BuildIt.sh )
|
||||
fi
|
||||
|
@ -7,13 +7,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
echo "$DIR"
|
||||
|
||||
ARCH=${ARCH:-"i686"}
|
||||
LLVM_ARCH=
|
||||
[ "$ARCH" = "i686" ] && LLVM_ARCH="i386" || LLVM_ARCH="$ARCH"
|
||||
LLVM_TARGET="$LLVM_ARCH-pc-serenity"
|
||||
PREFIX="$DIR/Local/clang/$ARCH"
|
||||
BUILD="$DIR/../Build/clang/$ARCH"
|
||||
SYSROOT="$BUILD/Root"
|
||||
PREFIX="$DIR/Local/clang/"
|
||||
BUILD="$DIR/../Build/"
|
||||
USERLAND_ARCHS="i686 x86_64"
|
||||
ARCHS="$USERLAND_ARCHS aarch64"
|
||||
|
||||
MD5SUM="md5sum"
|
||||
REALPATH="realpath"
|
||||
@ -65,12 +62,11 @@ if [ "$dev" = "1" ] && [ "$ci" = "1" ]; then
|
||||
fi
|
||||
|
||||
echo PREFIX is "$PREFIX"
|
||||
echo SYSROOT is "$SYSROOT"
|
||||
|
||||
mkdir -p "$DIR/Tarballs"
|
||||
|
||||
LLVM_VERSION="12.0.1"
|
||||
LLVM_MD5SUM="c28061313a4f1b7d74cd491a19f569b4"
|
||||
LLVM_VERSION="13.0.0"
|
||||
LLVM_MD5SUM="bfc5191cbe87954952d25c6884596ccb"
|
||||
LLVM_NAME="llvm-project-$LLVM_VERSION.src"
|
||||
LLVM_PKG="$LLVM_NAME.tar.xz"
|
||||
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$LLVM_PKG"
|
||||
@ -92,7 +88,7 @@ buildstep_ninja() {
|
||||
# When ninja writes to a pipe, it strips ANSI escape codes and prints one line per buildstep.
|
||||
# Instead, use NINJA_STATUS so that we get colored output from LLVM's build and fewer lines of output when running in a tty.
|
||||
# ANSI escape codes in NINJA_STATUS are slightly janky (ninja thinks that "\e[34m" needs 5 output characters instead of 5, so
|
||||
# it's middle elision is slightly off; also it would happily elide the "\e39m" which messes up the output if the terminal is too
|
||||
# its middle elision is slightly off; also it would happily elide the "\e39m" which messes up the output if the terminal is too
|
||||
# narrow), but it's still working better than the alternative.
|
||||
NAME=$1
|
||||
shift
|
||||
@ -100,6 +96,7 @@ buildstep_ninja() {
|
||||
}
|
||||
|
||||
# === DEPENDENCIES ===
|
||||
|
||||
buildstep dependencies echo "Checking whether 'make' is available..."
|
||||
if ! command -v ${MAKE:-make} >/dev/null; then
|
||||
buildstep dependencies echo "Please make sure to install GNU Make (for the '${MAKE:-make}' tool)."
|
||||
@ -192,7 +189,7 @@ pushd "$DIR/Tarballs"
|
||||
# Drop the previously patched extracted dir
|
||||
rm -rf "${LLVM_NAME}"
|
||||
# Also drop the build dir
|
||||
rm -rf "$DIR/Build/clang/$ARCH"
|
||||
rm -rf "$DIR/Build/clang"
|
||||
fi
|
||||
echo "Extracting LLVM..."
|
||||
tar -xJf "$LLVM_PKG"
|
||||
@ -224,7 +221,7 @@ pushd "$DIR/Tarballs"
|
||||
|
||||
if [ -d "$BINUTILS_NAME" ]; then
|
||||
rm -rf "$BINUTILS_NAME"
|
||||
rm -rf "$DIR/Build/clang/$ARCH/binutils"
|
||||
rm -rf "$DIR/Build/clang/binutils"
|
||||
fi
|
||||
echo "Extracting GNU binutils"
|
||||
|
||||
@ -243,182 +240,95 @@ pushd "$DIR/Tarballs"
|
||||
popd
|
||||
popd
|
||||
|
||||
# === COPY SERENITYOS HEADERS ===
|
||||
# === COPY HEADERS ===
|
||||
|
||||
mkdir -p "$BUILD"
|
||||
pushd "$BUILD"
|
||||
mkdir -p Root/usr/include/
|
||||
SRC_ROOT=$($REALPATH "$DIR"/..)
|
||||
FILES=$(find "$SRC_ROOT"/Kernel/API "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM "$SRC_ROOT"/Userland/Libraries/LibPthread "$SRC_ROOT"/Userland/Libraries/LibDl -name '*.h' -print)
|
||||
for header in $FILES; do
|
||||
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@" -e "s@$SRC_ROOT/Userland/Libraries/LibPthread@@" -e "s@$SRC_ROOT/Userland/Libraries/LibDl@@" -e "s@$SRC_ROOT/Kernel/@Kernel/@")
|
||||
buildstep "system_headers" install -D "$header" "Root/usr/include/$target"
|
||||
done
|
||||
unset SRC_ROOT
|
||||
popd
|
||||
SRC_ROOT=$($REALPATH "$DIR"/..)
|
||||
FILES=$(find "$SRC_ROOT"/Kernel/API "$SRC_ROOT"/Userland/Libraries/LibC "$SRC_ROOT"/Userland/Libraries/LibM "$SRC_ROOT"/Userland/Libraries/LibPthread "$SRC_ROOT"/Userland/Libraries/LibDl -name '*.h' -print)
|
||||
|
||||
for arch in $ARCHS; do
|
||||
mkdir -p "$BUILD/${arch}clang"
|
||||
pushd "$BUILD/${arch}clang"
|
||||
mkdir -p Root/usr/include/
|
||||
for header in $FILES; do
|
||||
target=$(echo "$header" | sed -e "s@$SRC_ROOT/Userland/Libraries/LibC@@" -e "s@$SRC_ROOT/Userland/Libraries/LibM@@" -e "s@$SRC_ROOT/Userland/Libraries/LibPthread@@" -e "s@$SRC_ROOT/Userland/Libraries/LibDl@@" -e "s@$SRC_ROOT/Kernel/@Kernel/@")
|
||||
buildstep "system_headers" install -D "$header" "Root/usr/include/$target"
|
||||
done
|
||||
popd
|
||||
done
|
||||
unset SRC_ROOT
|
||||
|
||||
# === COPY LIBRARY STUBS ===
|
||||
|
||||
for arch in $USERLAND_ARCHS; do
|
||||
pushd "$BUILD/${arch}clang"
|
||||
mkdir -p Root/usr/lib/
|
||||
for lib in "$DIR/Stubs/${arch}clang/"*".so"; do
|
||||
lib_name=$(basename "$lib")
|
||||
[ ! -f "Root/usr/lib/${lib_name}.so" ] && cp "$lib" "Root/usr/lib/${lib_name}"
|
||||
done
|
||||
popd
|
||||
done
|
||||
|
||||
# === COMPILE AND INSTALL ===
|
||||
|
||||
rm -rf "$PREFIX"
|
||||
mkdir -p "$PREFIX"
|
||||
|
||||
mkdir -p "$DIR/Build/clang/$ARCH"
|
||||
|
||||
pushd "$DIR/Build/clang/$ARCH"
|
||||
mkdir -p "$DIR/Build/clang"
|
||||
|
||||
pushd "$DIR/Build/clang"
|
||||
mkdir -p llvm
|
||||
pushd llvm
|
||||
buildstep "llvm+clang/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/llvm" \
|
||||
buildstep "llvm/configure" cmake "$DIR/Tarballs/$LLVM_NAME/llvm" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="MinSizeRel" \
|
||||
-DSERENITY_i686-pc-serenity_SYSROOT="$BUILD/i686clang/Root" \
|
||||
-DSERENITY_x86_64-pc-serenity_SYSROOT="$BUILD/x86_64clang/Root" \
|
||||
-DSERENITY_aarch64-pc-serenity_SYSROOT="$BUILD/aarch64clang/Root" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_DEFAULT_TARGET_TRIPLE="$LLVM_TARGET" \
|
||||
'-DLLVM_TARGETS_TO_BUILD=X86;AArch64' \
|
||||
-DLLVM_ENABLE_BINDINGS=OFF \
|
||||
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
|
||||
-DLLVM_ENABLE_PROJECTS="clang;lld" \
|
||||
-DLLVM_INCLUDE_BENCHMARKS=OFF \
|
||||
-DLLVM_INCLUDE_TESTS=OFF \
|
||||
-DLLVM_LINK_LLVM_DYLIB=ON \
|
||||
-DLLVM_INSTALL_UTILS=OFF \
|
||||
-C "$DIR/CMake/LLVMConfig.cmake" \
|
||||
${dev:+"-DLLVM_CCACHE_BUILD=ON"} \
|
||||
${ci:+"-DLLVM_CCACHE_BUILD=ON"} \
|
||||
${ci:+"-DLLVM_CCACHE_DIR=$LLVM_CCACHE_DIR"} \
|
||||
${ci:+"-DLLVM_CCACHE_MAXSIZE=$LLVM_CCACHE_MAXSIZE"} \
|
||||
|| exit 1
|
||||
${ci:+"-DLLVM_CCACHE_MAXSIZE=$LLVM_CCACHE_MAXSIZE"}
|
||||
|
||||
buildstep_ninja "llvm+clang/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "llvm+clang/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
LLVM_COMPILER_FLAGS="-target $LLVM_TARGET --sysroot $SYSROOT -ftls-model=initial-exec -ffreestanding -nostdlib -nostdlib++"
|
||||
|
||||
mkdir -p "compiler-rt"
|
||||
pushd compiler-rt
|
||||
buildstep "compiler-rt/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/compiler-rt" \
|
||||
-GNinja \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX/lib/clang/${LLVM_VERSION}" \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_AR="$PREFIX/bin/llvm-ar" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_ASM_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_ASM_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_ASM_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
|
||||
-DCOMPILER_RT_OS_DIR="serenity" \
|
||||
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
|
||||
-DCOMPILER_RT_BUILD_BUILTINS=ON \
|
||||
-DCOMPILER_RT_BUILD_CRT=ON \
|
||||
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
|
||||
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
|
||||
-DCOMPILER_RT_BUILD_PROFILE=OFF \
|
||||
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
|
||||
-DCOMPILER_RT_BUILD_XRAY=OFF || exit 1
|
||||
|
||||
buildstep_ninja "compiler-rt/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "compiler-rt/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libunwind
|
||||
pushd libunwind
|
||||
buildstep "libunwind/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libunwind" \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLIBUNWIND_TARGET_TRIPLE="$LLVM_TARGET" \
|
||||
-DLIBUNWIND_SYSROOT="$SYSROOT" || exit 1
|
||||
|
||||
buildstep_ninja "libunwind/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libunwind/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libcxxabi
|
||||
pushd libcxxabi
|
||||
buildstep "libcxxabi/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libcxxabi" \
|
||||
-GNinja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_COMPILER_TARGET="$LLVM_TARGET" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLIBCXXABI_STANDALONE_BUILD=ON \
|
||||
-DLIBCXXABI_ENABLE_EXCEPTIONS=ON \
|
||||
-DLIBCXXABI_STANDALONE_BUILD=ON \
|
||||
-DLIBCXXABI_ENABLE_ASSERTIONS=OFF \
|
||||
-DLIBCXXABI_BAREMETAL=ON || exit 1
|
||||
|
||||
buildstep_ninja "libcxxabi/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libcxxabi/install" ninja install || exit 1
|
||||
popd
|
||||
|
||||
mkdir -p libcxx
|
||||
pushd libcxx
|
||||
buildstep "libcxx/configure" cmake "$DIR/Tarballs/llvm-project-$LLVM_VERSION.src/libcxx" \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="Release" \
|
||||
-DCMAKE_BINARY_DIR="$PREFIX/usr" \
|
||||
-DCMAKE_SYSROOT="$SYSROOT" \
|
||||
-DCMAKE_C_COMPILER="$PREFIX/bin/clang" \
|
||||
-DCMAKE_C_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_CXX_COMPILER="$PREFIX/bin/clang++" \
|
||||
-DCMAKE_CXX_FLAGS="$LLVM_COMPILER_FLAGS" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-DLLVM_CONFIG_PATH="$PREFIX/bin/llvm-config" \
|
||||
-DLLVM_BINARY_DIR="$PREFIX/usr" \
|
||||
-DLIBCXX_INSTALL_LIBRARY=ON \
|
||||
-DLIBCXX_ENABLE_LOCALIZATION=OFF \
|
||||
-DLIBCXX_ENABLE_FILESYSTEM=OFF \
|
||||
-DLIBCXX_INSTALL_HEADERS=ON \
|
||||
-DLIBCXX_ENABLE_SHARED=ON \
|
||||
-DLIBCXX_ENABLE_LOCALIZATION=OFF \
|
||||
-DLIBCXX_ENABLE_STATIC=ON \
|
||||
-DLIBCXX_CXX_ABI="libcxxabi" \
|
||||
-DLIBCXX_INCLUDE_BENCHMARKS=OFF || exit 1
|
||||
|
||||
buildstep "libcxx/build" ninja -j "$MAKEJOBS" || exit 1
|
||||
buildstep "libcxx/install" ninja install || exit 1
|
||||
buildstep "libcxx/install-headers" ninja install-cxx-headers || exit 1
|
||||
buildstep_ninja "llvm/build" ninja -j "$MAKEJOBS"
|
||||
buildstep "llvm/install" ninja install/strip
|
||||
popd
|
||||
|
||||
mkdir -p binutils
|
||||
pushd binutils
|
||||
buildstep "binutils/configure" "$DIR/Tarballs/$BINUTILS_NAME/configure" --prefix="$PREFIX/binutils" \
|
||||
--target="$ARCH-pc-serenity" \
|
||||
buildstep "binutils/configure" "$DIR/Tarballs/$BINUTILS_NAME/configure" --prefix="$PREFIX" \
|
||||
--enable-targets="$(echo "$ARCHS" | sed -E "s@(\S)(\s|$)@\1-pc-serenity,@g")" \
|
||||
--program-prefix="gnu-" \
|
||||
--disable-nls \
|
||||
--disable-gas \
|
||||
--disable-gold \
|
||||
--disable-ld \
|
||||
--disable-gprof \
|
||||
--enable-shared || exit 1
|
||||
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS" || exit 1
|
||||
buildstep "binutils/install" "$MAKE" install || exit 1
|
||||
--enable-shared
|
||||
buildstep "binutils/build" "$MAKE" -j "$MAKEJOBS"
|
||||
buildstep "binutils/install" "$MAKE" install
|
||||
popd
|
||||
|
||||
for arch in $ARCHS; do
|
||||
mkdir -p runtimes/"$arch"
|
||||
pushd runtimes/"$arch"
|
||||
buildstep "runtimes/$arch/configure" cmake "$DIR/Tarballs/$LLVM_NAME/runtimes" \
|
||||
-G Ninja \
|
||||
-DSERENITY_TOOLCHAIN_ARCH="$arch" \
|
||||
-DSERENITY_TOOLCHAIN_ROOT="$PREFIX" \
|
||||
-DSERENITY_BUILD_DIR="$BUILD/${arch}clang/" \
|
||||
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
|
||||
-C "$DIR/CMake/LLVMRuntimesConfig.cmake"
|
||||
|
||||
buildstep "runtimes/$arch/build" ninja -j "$MAKEJOBS"
|
||||
buildstep "runtimes/$arch/install" ninja install
|
||||
popd
|
||||
done
|
||||
popd
|
||||
|
||||
# === REMOVE UNNECESSARY BUILD ARTIFACTS ===
|
||||
rm -r "$PREFIX"/lib/libclang*.a "$PREFIX"/lib/libLLVM*.a "$PREFIX"/lib/liblld*.a
|
||||
|
||||
# === SAVE TO CACHE ===
|
||||
|
||||
pushd "$DIR"
|
||||
if [ "$TRY_USE_LOCAL_TOOLCHAIN" = "y" ]; then
|
||||
echo "::endgroup::"
|
||||
|
@ -5,7 +5,7 @@ set(CMAKE_SYSTEM_PROCESSOR "@SERENITY_ARCH@")
|
||||
|
||||
set(SERENITYOS 1)
|
||||
set(triple @SERENITY_ARCH@-pc-serenity)
|
||||
set(TOOLCHAIN_ROOT @SERENITY_SOURCE_DIR@/Toolchain/Local/clang/@SERENITY_ARCH@)
|
||||
set(TOOLCHAIN_ROOT @SERENITY_SOURCE_DIR@/Toolchain/Local/clang/)
|
||||
set(TOOLCHAIN_PATH ${TOOLCHAIN_ROOT}/bin)
|
||||
|
||||
# where to read from/write to
|
||||
@ -26,7 +26,7 @@ set(CMAKE_STRIP ${TOOLCHAIN_PATH}/llvm-strip)
|
||||
set(CMAKE_AR ${TOOLCHAIN_PATH}/llvm-ar)
|
||||
set(SERENITY_CXXFILT ${TOOLCHAIN_PATH}/llvm-cxxfilt)
|
||||
# FIXME: Persuade LLVM maintainers to add `--update-section` to llvm-objcopy, as it's required for the kernel symbol map.
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_ROOT}/binutils/bin/@SERENITY_ARCH@-pc-serenity-objcopy)
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH}/gnu-objcopy)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--hash-style=gnu,-z,relro,-z,now,-z,noexecstack,-z,max-page-size=0x1000,-z,separate-code")
|
||||
|
||||
|
67
Toolchain/CMake/LLVMConfig.cmake
Normal file
67
Toolchain/CMake/LLVMConfig.cmake
Normal file
@ -0,0 +1,67 @@
|
||||
# This file specifies the options used for building the Clang compiler, LLD linker and the compiler builtins library
|
||||
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
|
||||
|
||||
set(LLVM_TARGETS_TO_BUILD "X86;AArch64" CACHE STRING "")
|
||||
|
||||
set(LLVM_ENABLE_PROJECTS "llvm;clang;lld" CACHE STRING "")
|
||||
set(LLVM_ENABLE_RUNTIMES "compiler-rt" CACHE STRING "")
|
||||
|
||||
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
|
||||
set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "")
|
||||
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
|
||||
set(LLVM_BUILD_UTILS OFF CACHE BOOL "")
|
||||
set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
|
||||
set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
|
||||
set(LLVM_LINK_LLVM_DYLIB ON CACHE BOOL "")
|
||||
set(LLVM_INSTALL_UTILS OFF CACHE BOOL "")
|
||||
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
|
||||
set(LLVM_INSTALL_BINUTILS_SYMLINKS OFF CACHE BOOL "")
|
||||
|
||||
set(CLANG_ENABLE_CLANGD OFF CACHE BOOL "")
|
||||
|
||||
set(compiler_flags "-nostdlib -nostdlib++")
|
||||
foreach(target i686-pc-serenity;x86_64-pc-serenity;aarch64-pc-serenity)
|
||||
list(APPEND targets "${target}")
|
||||
|
||||
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
|
||||
set(RUNTIMES_${target}_CMAKE_SYSROOT ${SERENITY_${target}_SYSROOT} CACHE PATH "")
|
||||
set(RUNTIMES_${target}_CMAKE_C_FLAGS ${compiler_flags} CACHE STRING "")
|
||||
set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${compiler_flags} CACHE STRING "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_CRT ON CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
|
||||
|
||||
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
|
||||
set(BUILTINS_${target}_CMAKE_SYSROOT ${SERENITY_${target}_SYSROOT} CACHE PATH "")
|
||||
set(BUILTINS_${target}_COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN OFF CACHE BOOL "")
|
||||
endforeach()
|
||||
|
||||
set(LLVM_TOOLCHAIN_TOOLS
|
||||
llvm-addr2line
|
||||
llvm-ar
|
||||
llvm-cov
|
||||
llvm-cxxfilt
|
||||
llvm-dwarfdump
|
||||
llvm-ifs
|
||||
llvm-lib
|
||||
llvm-nm
|
||||
llvm-objcopy
|
||||
llvm-objdump
|
||||
llvm-profdata
|
||||
llvm-rc
|
||||
llvm-ranlib
|
||||
llvm-readelf
|
||||
llvm-readobj
|
||||
llvm-size
|
||||
llvm-strings
|
||||
llvm-strip
|
||||
llvm-symbolizer
|
||||
CACHE STRING "")
|
||||
|
||||
set(LLVM_RUNTIME_TARGETS ${targets} CACHE STRING "")
|
||||
set(LLVM_BUILTIN_TARGETS ${targets} CACHE STRING "")
|
52
Toolchain/CMake/LLVMRuntimesConfig.cmake
Normal file
52
Toolchain/CMake/LLVMRuntimesConfig.cmake
Normal file
@ -0,0 +1,52 @@
|
||||
# This file specifies the options used for building the various LLVM runtime libraries
|
||||
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "")
|
||||
|
||||
set(LLVM_ENABLE_RUNTIMES "libcxx;libcxxabi;libunwind" CACHE STRING "")
|
||||
|
||||
set(target_triple ${SERENITY_TOOLCHAIN_ARCH}-pc-serenity)
|
||||
|
||||
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
|
||||
set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "")
|
||||
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
|
||||
set(LLVM_BUILD_UTILS OFF CACHE BOOL "")
|
||||
set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
|
||||
set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
|
||||
set(LLVM_LINK_LLVM_DYLIB ON CACHE BOOL "")
|
||||
set(LLVM_INSTALL_UTILS OFF CACHE BOOL "")
|
||||
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
|
||||
set(LLVM_INSTALL_BINUTILS_SYMLINKS OFF CACHE BOOL "")
|
||||
set(LLVM_DEFAULT_TARGET_TRIPLE ${target_triple} CACHE STRING "")
|
||||
set(LLVM_BINARY_DIR "${SERENITY_TOOLCHAIN_ROOT}" CACHE PATH "")
|
||||
|
||||
set(CMAKE_SYSROOT "${SERENITY_BUILD_DIR}/Root" CACHE PATH "")
|
||||
set(compiler_flags "-nostdlib -nostdlib++")
|
||||
|
||||
set(CMAKE_C_COMPILER "${SERENITY_TOOLCHAIN_ROOT}/bin/clang" CACHE PATH "")
|
||||
set(CMAKE_C_COMPILER_WORKS ON CACHE BOOL "")
|
||||
set(CMAKE_CXX_COMPILER "${SERENITY_TOOLCHAIN_ROOT}/bin/clang++" CACHE PATH "")
|
||||
set(CMAKE_CXX_COMPILER_WORKS ON CACHE BOOL "")
|
||||
set(CMAKE_ASM_COMPILER "${SERENITY_TOOLCHAIN_ROOT}/bin/clang" CACHE PATH "")
|
||||
set(CMAKE_ASM_COMPILER_WORKS ON CACHE BOOL "")
|
||||
set(CMAKE_LINKER "${SERENITY_TOOLCHAIN_ROOT}/bin/ld.lld" CACHE PATH "")
|
||||
foreach(tool ranlib;nm;objdump;objcopy;strip)
|
||||
string(TOUPPER tool Tool)
|
||||
set(CMAKE_${Tool} "${SERENITY_TOOLCHAIN_ROOT}/bin/llvm-${tool}" CACHE PATH "")
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_C_COMPILER_TARGET ${target_triple} CACHE STRING "")
|
||||
set(CMAKE_CXX_COMPILER_TARGET ${target_triple} CACHE STRING "")
|
||||
set(CMAKE_ASM_COMPILER_TARGET ${target_triple} CACHE STRING "")
|
||||
|
||||
set(CMAKE_C_FLAGS ${compiler_flags} CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS ${compiler_flags} CACHE STRING "")
|
||||
|
||||
set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
|
||||
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
|
||||
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
|
||||
set(LIBCXX_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
|
||||
if (NOT "${SERENITY_TOOLCHAIN_ARCH}" STREQUAL "aarch64")
|
||||
set(LIBCXX_HAS_M_LIB ON CACHE BOOL "")
|
||||
endif()
|
||||
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
|
||||
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
|
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,8 @@ add_executable(Loader.so ${SOURCES})
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_link_libraries(Loader.so PRIVATE gcc)
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
target_link_libraries(Loader.so PRIVATE "clang_rt.builtins-${SERENITY_CLANG_ARCH}")
|
||||
target_link_libraries(Loader.so PRIVATE clang_rt.builtins)
|
||||
endif ()
|
||||
|
||||
target_link_options(Loader.so PRIVATE LINKER:--no-dynamic-linker)
|
||||
install(TARGETS Loader.so RUNTIME DESTINATION usr/lib/)
|
||||
|
Loading…
Reference in New Issue
Block a user