From 055d2b6c8adbef749889334b0dd6adbf2662e3a2 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Fri, 11 Aug 2023 12:55:45 +0200 Subject: [PATCH] CMake: Enable RELR relocations for Clang OR x86-64 While LLD and mold support RELR "packed" relocations on all architectures, the BFD linker currently only implements them on x86-64 and POWER. This fixes two issues: - The Kernel had it enabled even for AArch64 + GCC, which led to the following being printed: `warning: -z pack-relative-relocs ignored`. - The userland always had it disabled, even in the supported AArch64 + Clang/mold scenarios. --- CMakeLists.txt | 11 +++++------ Kernel/CMakeLists.txt | 5 ++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2a0f361634..81da07aeb1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,12 +223,11 @@ if (ENABLE_MOLD_LINKER) add_link_options(-fuse-ld=mold) endif() -if(NOT "${SERENITY_ARCH}" STREQUAL "aarch64") - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" OR ENABLE_MOLD_LINKER) - add_link_options(LINKER:--pack-dyn-relocs=relr) - else() - add_link_options(LINKER:-z,pack-relative-relocs) - endif() +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" OR ENABLE_MOLD_LINKER) + add_link_options(LINKER:--pack-dyn-relocs=relr) +elseif("${SERENITY_ARCH}" STREQUAL "x86_64") + # The BFD linker only supports RELR relocations on x86 and POWER. + add_link_options(LINKER:-z,pack-relative-relocs) endif() add_subdirectory(Userland) diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index d62768a568e..a72a9a8d002 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -611,7 +611,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set_source_files_properties(Library/MiniStdLib.cpp PROPERTIES COMPILE_FLAGS "-fno-tree-loop-distribution -fno-tree-loop-distribute-patterns") - add_link_options(LINKER:-z,pack-relative-relocs) + if ("${SERENITY_ARCH}" STREQUAL "x86_64") + # The BFD linker only supports RELR relocations on x86 and POWER. + add_link_options(LINKER:-z,pack-relative-relocs) + endif() else() # Assume Clang add_compile_options(-Waddress-of-packed-member) add_compile_options(-faligned-allocation)