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
This commit is contained in:
Daniel Bertalan 2023-09-10 22:09:22 +02:00
parent 1f747b9132
commit 6fd8f9ea51
2 changed files with 6 additions and 0 deletions

View file

@ -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()

View file

@ -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)