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

fix: hardening handle flags for exe and shared #72

Merged
merged 1 commit into from
Apr 1, 2024
Merged
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
10 changes: 6 additions & 4 deletions cmake/build/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ else()
-Wl,-z,now # Mark relocation table entries resolved at load-time as
# read-only. It impacts startup performance
-fsanitize=undefined # Undefined behavior sanitizer
-fsanitize-minimal-runtime # Minimal runtime checks
-fno-sanitize-recover=undefined # Undefined behavior sanitizer recover
-fno-delete-null-pointer-checks
-fno-strict-overflow
Expand All @@ -65,7 +64,6 @@ else()

set(USE_HARDENING_LINKS
-fsanitize=undefined # Undefined behavior sanitizer
-fsanitize-minimal-runtime # Minimal runtime checks
-fno-sanitize-recover=undefined # Undefined behavior sanitizer recover
-Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects
-Wl,-z,noexecstack # Enable data execution prevention by marking stack
Expand Down Expand Up @@ -140,9 +138,13 @@ function(harden_target target)
set(LINKS ${hardening_links})
else()
if(_target_type STREQUAL "EXECUTABLE")
set(FLAGS ${hardening_flags} -fPIE -pie)
check_and_append_flag(FLAGS "-fPIE -pie" TARGETS exe_flags)
flags_to_list(exe_flags "${exe_flags}")
set(FLAGS ${hardening_flags} ${exe_flags})
elseif(_target_type STREQUAL "SHARED_LIBRARY")
set(FLAGS ${hardening_flags} -fPIC -shared)
check_and_append_flag(FLAGS "-fPIC -shared" TARGETS shared_flags)
flags_to_list(shared_flags "${shared_flags}")
set(FLAGS ${hardening_flags} ${shared_flags})
endif()
endif()

Expand Down
Loading