ladybird/Meta/CMake/lagom_compile_options.cmake
Daniel Bertalan 6fd8f9ea51 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
2023-09-18 10:26:42 +02:00

27 lines
725 B
CMake

include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
add_compile_options(-Wno-maybe-uninitialized)
add_compile_options(-Wno-shorten-64-to-32)
add_compile_options(-fsigned-char)
add_compile_options(-g1)
add_compile_options(-ggnu-pubnames)
add_compile_options(-O2)
if (NOT WIN32)
add_compile_options(-fPIC)
endif()
function(add_linker_flag_if_supported flag)
include(CheckLinkerFlag)
check_linker_flag(CXX ${flag} LAGOM_LINKER_SUPPORTS_${flag})
if (${LAGOM_LINKER_SUPPORTS_${flag}})
add_link_options(${flag})
endif()
endfunction()
add_linker_flag_if_supported(LINKER:--gdb-index)
if (NOT ENABLE_FUZZERS)
add_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions)
endif()