Skip to content

Commit

Permalink
Enable -flto and -fsanitize=cfi in clang
Browse files Browse the repository at this point in the history
  • Loading branch information
RossBrunton committed Oct 18, 2024
1 parent b6af5c5 commit 3ca0332
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ function(add_ur_target_compile_options name)
# Hardening options
-fPIC
-fstack-protector-strong
-fvisibility=hidden # Required for -fsanitize=cfi
# -fsanitize=cfi requires -flto, which breaks a lot of things
# See: https://github.com/oneapi-src/unified-runtime/issues/2120
# -flto
# $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fsanitize=cfi>
-fvisibility=hidden
# cfi-icall requires called functions in shared libraries to also be built with cfi-icall, which we can't
# guarantee. -fsanitize=cfi depends on -flto
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-flto -fsanitize=cfi -fno-sanitize=cfi-icall>
$<$<BOOL:${CXX_HAS_FCF_PROTECTION_FULL}>:-fcf-protection=full>
# -fstack-clash-protection is not supported in apple clang or GCC < 8
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,8>>:-fstack-clash-protection>
Expand Down Expand Up @@ -118,7 +117,10 @@ endfunction()
function(add_ur_target_link_options name)
if(NOT MSVC)
if (NOT APPLE)
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now,-z,noexecstack")
target_link_options(${name} PRIVATE
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-flto -fsanitize=cfi -fno-sanitize=cfi-icall>
"LINKER:-z,relro,-z,now,-z,noexecstack"
)
if (UR_DEVELOPER_MODE)
target_link_options(${name} PRIVATE -Werror -Wextra)
endif()
Expand Down

0 comments on commit 3ca0332

Please sign in to comment.