From 6fd8f9ea5197231749c29c566cc0cf0dc8a205d6 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sun, 10 Sep 2023 22:09:22 +0200 Subject: [PATCH] CMake: Link with `-Bsymbolic-non-weak-functions` if supported This flag makes the linker bind default-visibility functions locally, so that calls to them do not have to go through the PLT. This makes it impossible to override them by preloading a DSO. This was already the case partially due to `-fno-semantic-interposition`, however that flag is only able to optimize call sites that are in the same Translation Unit as the function definitions. This removes 80% of the PLT relocations in `libjs.so.serenity`. Obsoletes #20877 --- Meta/CMake/lagom_compile_options.cmake | 4 ++++ Meta/CMake/serenity_compile_options.cmake | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index 3c5d17935f..40f646766c 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -20,3 +20,7 @@ function(add_linker_flag_if_supported flag) endfunction() add_linker_flag_if_supported(LINKER:--gdb-index) + +if (NOT ENABLE_FUZZERS) + add_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions) +endif() diff --git a/Meta/CMake/serenity_compile_options.cmake b/Meta/CMake/serenity_compile_options.cmake index 7cc39f5a25..ecb5ef132f 100644 --- a/Meta/CMake/serenity_compile_options.cmake +++ b/Meta/CMake/serenity_compile_options.cmake @@ -29,6 +29,8 @@ add_compile_options(-g1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +add_link_options(LINKER:-Bsymbolic-non-weak-functions) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options(-Wno-maybe-uninitialized) add_compile_options(-Wcast-align)