Skip to content

Commit 06fc64b

Browse files
BertalanDlinusg
authored andcommitted
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.
1 parent 28c088c commit 06fc64b

File tree

12 files changed

+538
-667
lines changed

12 files changed

+538
-667
lines changed

CMakeLists.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
1616
"Please re-read the BuildInstructions documentation, and use the superbuild configuration\n")
1717
endif()
1818

19-
if(SERENITY_ARCH STREQUAL "i686")
20-
set(SERENITY_CLANG_ARCH "i386")
21-
else()
22-
set(SERENITY_CLANG_ARCH "${SERENITY_ARCH}")
23-
endif()
24-
2519
set(CMAKE_INSTALL_MESSAGE NEVER)
2620

2721
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -176,7 +170,6 @@ add_compile_options(-fdiagnostics-color=always)
176170
add_compile_options(-fno-delete-null-pointer-checks)
177171
add_compile_options(-ffile-prefix-map=${SerenityOS_SOURCE_DIR}=.)
178172
add_compile_options(-fno-exceptions)
179-
add_compile_options(-ftls-model=initial-exec)
180173
add_compile_options(-fno-semantic-interposition)
181174
add_compile_options(-fsized-deallocation)
182175
add_compile_options(-fstack-clash-protection)
@@ -194,26 +187,21 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
194187
add_compile_options(-Wno-c99-designator)
195188
add_compile_options(-Wno-implicit-const-int-float-conversion)
196189
add_compile_options(-Wno-inconsistent-missing-override)
190+
add_compile_options(-Wno-null-pointer-subtraction)
197191
add_compile_options(-Wno-tautological-constant-out-of-range-compare)
198192
add_compile_options(-Wno-unneeded-internal-declaration)
193+
add_compile_options(-Wno-unused-but-set-variable)
199194
add_compile_options(-Wno-unused-function)
200195
add_compile_options(-fno-aligned-allocation)
201196
add_compile_options(-fconstexpr-steps=16777216)
202-
add_compile_options(-gdwarf-4)
203197

204-
# FIXME: Why can't clang find this path for compiler_rt builtins?
205-
link_directories(${TOOLCHAIN_ROOT}/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/serenity)
198+
# Clang doesn't add compiler_rt to the search path when compiling with -nostdlib.
199+
link_directories(${TOOLCHAIN_ROOT}/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/${SERENITY_ARCH}-pc-serenity/)
206200
add_link_options(LINKER:--allow-shlib-undefined)
207201
endif()
208202

209203
add_link_options(LINKER:-z,text)
210204

211-
if("${SERENITY_ARCH}" STREQUAL "i686")
212-
add_compile_options(-march=i686)
213-
elseif("${SERENITY_ARCH}" STREQUAL "x86_64")
214-
add_compile_options(-march=x86-64)
215-
endif()
216-
217205
add_compile_definitions(SANITIZE_PTRS)
218206
set(CMAKE_CXX_FLAGS_STATIC "${CMAKE_CXX_FLAGS} -static")
219207
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie -fpic")

Kernel/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,14 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
400400
endif()
401401
link_directories(${TOOLCHAIN_ROOT}/${SERENITY_ARCH}-pc-serenity/lib)
402402
link_directories(${TOOLCHAIN_ROOT}/lib/gcc/${SERENITY_ARCH}-pc-serenity/${GCC_VERSION}/)
403+
404+
set(TARGET_STRING "")
403405
else() # Assume Clang
404406
add_compile_options(-Waddress-of-packed-member)
405407
add_compile_options(-faligned-allocation)
408+
409+
# We need this in order to pick up the #define __serenity__, otherwise we end up including unistd.h into the linker script
410+
set(TARGET_STRING "--target=${CMAKE_CXX_COMPILER_TARGET}")
406411

407412
add_link_options(LINKER:--build-id=none)
408413
endif()
@@ -476,7 +481,7 @@ add_dependencies(Kernel generate_EscapeSequenceStateMachine.h)
476481

477482
add_custom_command(
478483
OUTPUT linker.ld
479-
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"
484+
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"
480485
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/linker.ld"
481486
COMMENT "Preprocessing linker.ld"
482487
VERBATIM
@@ -497,7 +502,7 @@ if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
497502
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
498503
target_link_libraries(Kernel PRIVATE kernel_heap gcc)
499504
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
500-
target_link_libraries(Kernel PRIVATE kernel_heap "clang_rt.builtins-${SERENITY_CLANG_ARCH}")
505+
target_link_libraries(Kernel PRIVATE kernel_heap clang_rt.builtins)
501506
endif()
502507
endif()
503508

Kernel/Prekernel/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ set_target_properties(${PREKERNEL_TARGET} PROPERTIES LINK_DEPENDS ${PREKERNEL_LI
5151
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5252
target_link_libraries(${PREKERNEL_TARGET} PRIVATE gcc)
5353
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
54-
target_link_libraries(${PREKERNEL_TARGET} PRIVATE "clang_rt.builtins-${SERENITY_CLANG_ARCH}" c++abi)
54+
target_link_libraries(${PREKERNEL_TARGET} PRIVATE clang_rt.builtins)
5555
endif()
5656

5757
if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64")

Meta/CMake/utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function(serenity_libc target_name fs_name)
5757
install(TARGETS ${target_name} DESTINATION usr/lib)
5858
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
5959
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
60-
target_link_libraries(${target_name} "clang_rt.builtins-${SERENITY_CLANG_ARCH}")
60+
target_link_libraries(${target_name} clang_rt.builtins)
6161
endif()
6262
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
6363
serenity_generated_sources(${target_name})

Meta/build-root-filesystem.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ else
4646
fi
4747

4848
SERENITY_ARCH="${SERENITY_ARCH:-i686}"
49-
LLVM_VERSION="${LLVM_VERSION:-12.0.1}"
49+
LLVM_VERSION="${LLVM_VERSION:-13.0.0}"
5050

5151
if [ "$SERENITY_TOOLCHAIN" = "Clang" ]; then
52-
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR"/Toolchain/Local/clang/"$SERENITY_ARCH"
52+
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR"/Toolchain/Local/clang/
5353
mkdir -p mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
54-
$CP "$TOOLCHAIN_DIR"/lib/clang/"$LLVM_VERSION"/lib/serenity/* mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
55-
$CP "$TOOLCHAIN_DIR"/lib/libunwind* mnt/usr/lib
56-
$CP "$TOOLCHAIN_DIR"/lib/libc++* mnt/usr/lib
54+
$CP "$TOOLCHAIN_DIR"/lib/clang/"$LLVM_VERSION"/lib/"$SERENITY_ARCH"-pc-serenity/* mnt/usr/lib/clang/"$LLVM_VERSION"/lib/serenity
55+
$CP "$TOOLCHAIN_DIR"/lib/"$SERENITY_ARCH"-pc-serenity/* mnt/usr/lib
5756
elif [ "$SERENITY_ARCH" != "aarch64" ]; then
5857
$CP "$SERENITY_SOURCE_DIR"/Toolchain/Local/"$SERENITY_ARCH"/"$SERENITY_ARCH"-pc-serenity/lib/libgcc_s.so mnt/usr/lib
5958
fi

Meta/serenity.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ cmd_with_target() {
180180
BUILD_DIR="$SERENITY_SOURCE_DIR/Build/$TARGET$TARGET_TOOLCHAIN"
181181
if [ "$TARGET" != "lagom" ]; then
182182
export SERENITY_ARCH="$TARGET"
183-
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/$TARGET_TOOLCHAIN/$TARGET"
183+
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
184+
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/clang"
185+
else
186+
TOOLCHAIN_DIR="$SERENITY_SOURCE_DIR/Toolchain/Local/$TARGET_TOOLCHAIN/$TARGET"
187+
fi
184188
SUPER_BUILD_DIR="$SERENITY_SOURCE_DIR/Build/superbuild-$TARGET$TARGET_TOOLCHAIN"
185189
else
186190
SUPER_BUILD_DIR="$BUILD_DIR"
@@ -225,7 +229,7 @@ delete_target() {
225229
build_toolchain() {
226230
echo "build_toolchain: $TOOLCHAIN_DIR"
227231
if [ "$TOOLCHAIN_TYPE" = "Clang" ]; then
228-
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ARCH="$TARGET" ./BuildClang.sh )
232+
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ./BuildClang.sh )
229233
else
230234
( cd "$SERENITY_SOURCE_DIR/Toolchain" && ARCH="$TARGET" ./BuildIt.sh )
231235
fi

0 commit comments

Comments
 (0)