Skip to content

Commit

Permalink
fixup! cmake: Add HARDENING option
Browse files Browse the repository at this point in the history
1. Do not apply hardening flags for C compiler. It mirrors behavior from
the master branch.

2. Do not pass `-mbranch-protection=bti` during link stage.
  • Loading branch information
hebasto committed May 23, 2024
1 parent f5f951d commit 8b1f8ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ try_append_cxx_flags("-fstack-reuse=none" TARGET core_base_interface)

if(ENABLE_HARDENING)
add_library(hardening_interface INTERFACE)
target_link_libraries(core_base_interface INTERFACE hardening_interface)
target_link_libraries(core_base_interface INTERFACE
$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:hardening_interface>
)
if(MSVC)
try_append_linker_flag("/DYNAMICBASE" TARGET hardening_interface)
try_append_linker_flag("/HIGHENTROPYVA" TARGET hardening_interface)
Expand All @@ -519,7 +521,7 @@ if(ENABLE_HARDENING)
endif()

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
try_append_cxx_flags("-mbranch-protection=bti" TARGET hardening_interface)
try_append_cxx_flags("-mbranch-protection=bti" TARGET hardening_interface SKIP_LINK)
endif()

try_append_linker_flag("-Wl,--enable-reloc-section" TARGET hardening_interface)
Expand Down

0 comments on commit 8b1f8ad

Please sign in to comment.