Skip to content

Commit

Permalink
Merge pull request #2405 from RossBrunton/ross/cfiblocklist
Browse files Browse the repository at this point in the history
Add sanitizer ignorelist for cfi
  • Loading branch information
RossBrunton authored Dec 3, 2024
2 parents c6206db + 008c998 commit e7ee297
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
14 changes: 10 additions & 4 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ else()
set(CXX_HAS_CFI_SANITIZE OFF)
endif()

set(CFI_FLAGS "")
if (CFI_HAS_CFI_SANITIZE)
# 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
set(CFI_FLAGS "-flto -fsanitize=cfi -fno-sanitize=cfi-icall -fsanitize-ignorelist=${CMAKE_SOURCE_DIR}/sanitizer-ignorelist.txt")
endif()

function(add_ur_target_compile_options name)
if(NOT MSVC)
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
Expand All @@ -95,9 +102,8 @@ function(add_ur_target_compile_options name)
-fPIC
-fstack-protector-strong
-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
$<$<BOOL:${CXX_HAS_CFI_SANITIZE}>:-flto -fsanitize=cfi -fno-sanitize=cfi-icall>

${CFI_FLAGS}
$<$<BOOL:${CXX_HAS_FCF_PROTECTION_FULL}>:-fcf-protection=full>
$<$<BOOL:${CXX_HAS_FSTACK_CLASH_PROTECTION}>:-fstack-clash-protection>

Expand Down Expand Up @@ -135,7 +141,7 @@ function(add_ur_target_link_options name)
if(NOT MSVC)
if (NOT APPLE)
target_link_options(${name} PRIVATE
$<$<BOOL:${CXX_HAS_CFI_SANITIZE}>:-flto -fsanitize=cfi -fno-sanitize=cfi-icall>
${CFI_FLAGS}
"LINKER:-z,relro,-z,now,-z,noexecstack"
)
if (UR_DEVELOPER_MODE)
Expand Down
6 changes: 6 additions & 0 deletions sanitizer-ignorelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[cfi-unrelated-cast]
# std::_Sp_counted_ptr_inplace::_Sp_counted_ptr_inplace() (libstdc++).
# This ctor is used by std::make_shared and needs to cast to uninitialized T*
# in order to call std::allocator_traits<T>::construct.
# See: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/cfi/cfi_ignorelist.txt
fun:_ZNSt23_Sp_counted_ptr_inplace*

This file was deleted.

This file was deleted.

0 comments on commit e7ee297

Please sign in to comment.