mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
Toolchain: Add support for building the userland with the mold linker
This commit adds support for building the SerenityOS userland with the new [mold linker]. This is not enabled by default yet; to link using mold, run the `Toolchain/BuildMold.sh` script to build the latest release of mold, and set the `ENABLE_MOLD_LINKER` CMake variable to ON. This option relies on toolchain support that has been added just recently, so you might need to rebuild your toolchain for mold to work. [mold linker]: https://github.com/rui314/mold
This commit is contained in:
parent
ad649c48da
commit
4055c393fc
Notes:
sideshowbarker
2024-07-17 20:19:01 +09:00
Author: https://github.com/BertalanD Commit: https://github.com/SerenityOS/serenity/commit/4055c393fc9 Pull-request: https://github.com/SerenityOS/serenity/pull/12049 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/bgianfo ✅ Reviewed-by: https://github.com/linusg ✅
7 changed files with 60 additions and 1 deletions
|
@ -267,6 +267,9 @@ endif()
|
|||
add_subdirectory(AK)
|
||||
add_subdirectory(Kernel)
|
||||
if(NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
|
||||
if (ENABLE_MOLD_LINKER)
|
||||
add_link_options(-fuse-ld=mold)
|
||||
endif()
|
||||
add_subdirectory(Userland)
|
||||
add_subdirectory(Tests)
|
||||
endif()
|
||||
|
|
|
@ -53,6 +53,7 @@ There are some optional features that can be enabled during compilation that are
|
|||
- `ENABLE_PCI_IDS_DOWNLOAD`: downloads the [`pci.ids` database](https://pci-ids.ucw.cz/) that contains information about PCI devices at build time, if not already present. Enabled by default.
|
||||
- `BUILD_LAGOM`: builds [Lagom](../Meta/Lagom/ReadMe.md), which makes various SerenityOS libraries and programs available on the host system.
|
||||
- `ENABLE_KERNEL_LTO`: builds the kernel with link-time optimization.
|
||||
- `ENABLE_MOLD_LINKER`: builds the userland with the [`mold` linker](https://github.com/rui314/mold). `mold` can be built by running `Toolchain/BuildMold.sh`.
|
||||
- `INCLUDE_WASM_SPEC_TESTS`: downloads and includes the WebAssembly spec testsuite tests. In order to use this option, you will need to install `prettier` and `wabt`. wabt version 1.0.23 or higher is required to pre-process the WebAssembly spec testsuite.
|
||||
- `SERENITY_TOOLCHAIN`: Specifies whether to use the established GNU toolchain, or the experimental Clang-based toolchain for building SerenityOS. See the [Clang-based toolchain](#clang-based-toolchain) section below.
|
||||
- `SERENITY_ARCH`: Specifies which architecture to build for. Currently supported options are `i686` and `x86_64`. `x86_64` requires a separate toolchain build from `i686`.
|
||||
|
|
|
@ -11,3 +11,4 @@ serenity_option(ENABLE_KERNEL_ADDRESS_SANITIZER OFF CACHE BOOL "Enable kernel ad
|
|||
serenity_option(ENABLE_KERNEL_COVERAGE_COLLECTION OFF CACHE BOOL "Enable KCOV and kernel coverage instrumentation in gcc/clang")
|
||||
serenity_option(ENABLE_KERNEL_LTO OFF CACHE BOOL "Build the kernel with link-time optimization")
|
||||
serenity_option(ENABLE_EXTRA_KERNEL_DEBUG_SYMBOLS OFF CACHE BOOL "Enable -Og and -ggdb3 options for Kernel code for easier debugging")
|
||||
serenity_option(ENABLE_MOLD_LINKER OFF CACHE BOOL "Link the SerenityOS userland with the mold linker")
|
||||
|
|
|
@ -57,7 +57,9 @@ function(serenity_libc target_name fs_name)
|
|||
target_link_libraries(${target_name} clang_rt.builtins)
|
||||
# FIXME: Implement -static-libstdc++ in the next toolchain update.
|
||||
target_link_options(${target_name} PRIVATE -nostdlib++ -Wl,-Bstatic -lc++ -Wl,-Bdynamic)
|
||||
target_link_options(${target_name} PRIVATE -Wl,--no-dependent-libraries)
|
||||
if (NOT ENABLE_MOLD_LINKER)
|
||||
target_link_options(${target_name} PRIVATE -Wl,--no-dependent-libraries)
|
||||
endif()
|
||||
endif()
|
||||
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
serenity_generated_sources(${target_name})
|
||||
|
|
|
@ -294,6 +294,10 @@ pushd "$DIR/Build/clang"
|
|||
done
|
||||
popd
|
||||
|
||||
pushd "$DIR/Local/clang/bin/"
|
||||
buildstep "mold_symlink" ln -s ../../mold/bin/mold ld.mold
|
||||
popd
|
||||
|
||||
# === SAVE TO CACHE ===
|
||||
|
||||
pushd "$DIR"
|
||||
|
|
|
@ -399,6 +399,10 @@ pushd "$DIR/Build/$ARCH"
|
|||
|
||||
popd
|
||||
|
||||
pushd "$DIR/Local/$ARCH/$ARCH-pc-serenity/bin"
|
||||
buildstep "mold_symlink" ln -s ../../../mold/bin/mold ld.mold
|
||||
popd
|
||||
|
||||
|
||||
# == SAVE TO CACHE ==
|
||||
|
||||
|
|
44
Toolchain/BuildMold.sh
Executable file
44
Toolchain/BuildMold.sh
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script builds the mold linker that can optionally be used for linking
|
||||
# the SerenityOS userland.
|
||||
set -e
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
NPROC="nproc"
|
||||
SYSTEM_NAME="$(uname -s)"
|
||||
|
||||
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
||||
NPROC="sysctl -n hw.ncpuonline"
|
||||
elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
|
||||
NPROC="sysctl -n hw.ncpu"
|
||||
elif [ "$SYSTEM_NAME" = "Darwin" ]; then
|
||||
NPROC="sysctl -n hw.ncpu"
|
||||
fi
|
||||
|
||||
[ -z "$MAKEJOBS" ] && MAKEJOBS=$($NPROC)
|
||||
|
||||
mkdir -p "$DIR"/Tarballs
|
||||
pushd "$DIR"/Tarballs
|
||||
|
||||
if [ "$1" = "--git" ]; then
|
||||
[ ! -d mold ] && git clone https://github.com/rui314/mold.git
|
||||
|
||||
cd mold
|
||||
|
||||
git pull
|
||||
else
|
||||
VERSION=1.0.2
|
||||
[ ! -e mold-$VERSION.tar.gz ] && curl -L "https://github.com/rui314/mold/archive/refs/tags/v$VERSION.tar.gz" -o mold-$VERSION.tar.gz
|
||||
[ ! -e mold-$VERSION ] && tar -xzf mold-$VERSION.tar.gz
|
||||
cd mold-$VERSION
|
||||
fi
|
||||
|
||||
make clean
|
||||
export DESTDIR="$DIR"/Local/mold
|
||||
export PREFIX=
|
||||
make -j "$MAKEJOBS"
|
||||
make install
|
||||
|
||||
popd
|
Loading…
Reference in a new issue