Skip to content

Commit

Permalink
Merge #211: cmake: Fix hardening flags
Browse files Browse the repository at this point in the history
e2f2f23 fixup! cmake: Add `HARDENING` option (Hennadii Stepanov)

Pull request description:

  During testing #93, a few issues were [noticed](#93 (comment)):
  - > `-mbranch-protection=bti` shouldn't be in C flags

  The other change simplifies the summary code in #93.

ACKs for top commit:
  m3dwards:
    ACK e2f2f23

Tree-SHA512: 386e3c180dbe68d76602bea12737651bbec398bfd5d75c32e3b235d418e60322e1c82ce08c4fb719e205705c5af2895d78d17d6907d8b370b5225dd8d4f0604b
  • Loading branch information
hebasto committed Jun 3, 2024
2 parents 6230d47 + e2f2f23 commit efc356b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ if(ENABLE_HARDENING)
try_append_linker_flag("/NXCOMPAT" TARGET hardening_interface)
else()
target_compile_options(hardening_interface INTERFACE
$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3>
$<$<NOT:$<CONFIG:Debug>>:-U_FORTIFY_SOURCE>
$<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=3>
)

try_append_cxx_flags("-Wstack-protector" TARGET hardening_interface SKIP_LINK)
Expand All @@ -520,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 efc356b

Please sign in to comment.