Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Hardening.cmake #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cmake/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ macro(
set(NEW_LINK_OPTIONS "${NEW_LINK_OPTIONS} /NXCOMPAT /CETCOMPAT")

elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang|GNU")
set(NEW_CXX_DEFINITIONS "${NEW_CXX_DEFINITIONS} -D_GLIBCXX_ASSERTIONS")
list(APPEND NEW_CXX_DEFINITIONS -D_GLIBCXX_ASSERTIONS)
message(STATUS "*** GLIBC++ Assertions (vector[], string[], ...) enabled")

set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
list(APPEND NEW_COMPILE_OPTIONS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3)
message(STATUS "*** g++/clang _FORTIFY_SOURCE=3 enabled")

# check_cxx_compiler_flag(-fpie PIE)
Expand All @@ -32,15 +32,15 @@ macro(

check_cxx_compiler_flag(-fstack-protector-strong STACK_PROTECTOR)
if(STACK_PROTECTOR)
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -fstack-protector-strong")
list(APPEND NEW_COMPILE_OPTIONS -fstack-protector-strong)
message(STATUS "*** g++/clang -fstack-protector-strong enabled")
else()
message(STATUS "*** g++/clang -fstack-protector-strong NOT enabled (not supported)")
endif()

check_cxx_compiler_flag(-fcf-protection CF_PROTECTION)
if(CF_PROTECTION)
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -fcf-protection")
list(APPEND NEW_COMPILE_OPTIONS -fcf-protection)
message(STATUS "*** g++/clang -fcf-protection enabled")
else()
message(STATUS "*** g++/clang -fcf-protection NOT enabled (not supported)")
Expand All @@ -49,7 +49,7 @@ macro(
check_cxx_compiler_flag(-fstack-clash-protection CLASH_PROTECTION)
if(CLASH_PROTECTION)
if(LINUX OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -fstack-clash-protection")
list(APPEND NEW_COMPILE_OPTIONS -fstack-clash-protection)
message(STATUS "*** g++/clang -fstack-clash-protection enabled")
else()
message(STATUS "*** g++/clang -fstack-clash-protection NOT enabled (clang on non-Linux)")
Expand All @@ -63,12 +63,12 @@ macro(
check_cxx_compiler_flag("-fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-minimal-runtime"
MINIMAL_RUNTIME)
if(MINIMAL_RUNTIME)
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -fsanitize=undefined -fsanitize-minimal-runtime")
set(NEW_LINK_OPTIONS "${NEW_LINK_OPTIONS} -fsanitize=undefined -fsanitize-minimal-runtime")
list(APPEND NEW_COMPILE_OPTIONS -fsanitize=undefined -fsanitize-minimal-runtime)
list(APPEND NEW_LINK_OPTIONS -fsanitize=undefined -fsanitize-minimal-runtime)

if(NOT ${global})
set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -fno-sanitize-recover=undefined")
set(NEW_LINK_OPTIONS "${NEW_LINK_OPTIONS} -fno-sanitize-recover=undefined")
list(APPEND NEW_COMPILE_OPTIONS -fno-sanitize-recover=undefined)
list(APPEND NEW_LINK_OPTIONS -fno-sanitize-recover=undefined)
else()
message(STATUS "** not enabling -fno-sanitize-recover=undefined for global consumption")
endif()
Expand Down