Skip to content

Commit cc01b89

Browse files
committed
[asan] Sanitize all executables defined in ROOT's build system.
Instead of sanitizing only a few hand-picked executables, recursively search all executables defined in the build system. Sanitize all that don't link to ROOTStaticSanitizerConfig. Since roottest is part of ROOT, several special cases could be removed.
1 parent 54e2a1d commit cc01b89

3 files changed

Lines changed: 30 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,28 @@ if(LLVM_LINKER_IS_MOLD)
729729
endif()
730730
endif()
731731

732+
if(asan)
733+
# Now sanitize all executables that are not created with ROOT_EXECUTABLE()
734+
# See core/sanitizer for details
735+
function(sanitize_all_targets DIR_TO_SEARCH)
736+
get_property(subdirs DIRECTORY "${DIR_TO_SEARCH}" PROPERTY SUBDIRECTORIES)
737+
foreach(subdir IN LISTS subdirs)
738+
sanitize_all_targets("${subdir}")
739+
endforeach()
740+
741+
get_directory_property(directory_targets DIRECTORY "${DIR_TO_SEARCH}" BUILDSYSTEM_TARGETS)
742+
foreach(target IN LISTS directory_targets)
743+
get_target_property(target_type ${target} TYPE)
744+
get_target_property(target_libs ${target} LINK_LIBRARIES)
745+
if(target_type STREQUAL EXECUTABLE AND NOT target STREQUAL ROOTStaticSanitizerConfig AND NOT target_libs MATCHES "ROOTStaticSanitizerConfig")
746+
target_link_libraries(${target} PRIVATE ROOTStaticSanitizerConfig)
747+
message(VERBOSE "Adding sanitizer library to ${target} (not created via a ROOT macro): ${target_libs}")
748+
endif()
749+
endforeach()
750+
endfunction()
751+
sanitize_all_targets(${CMAKE_CURRENT_SOURCE_DIR})
752+
endif()
753+
732754
cmake_host_system_information(RESULT PROCESSOR QUERY PROCESSOR_DESCRIPTION)
733755

734756
message(STATUS "ROOT Configuration \n

cmake/modules/RootMacros.cmake

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,9 +1477,9 @@ function(ROOT_EXECUTABLE executable)
14771477
endif()
14781478
endforeach()
14791479
endif()
1480-
if(TARGET ROOT::ROOTStaticSanitizerConfig)
1480+
if(TARGET ROOTStaticSanitizerConfig)
14811481
set_property(TARGET ${executable}
1482-
APPEND PROPERTY LINK_LIBRARIES ROOT::ROOTStaticSanitizerConfig)
1482+
APPEND PROPERTY LINK_LIBRARIES ROOTStaticSanitizerConfig)
14831483
endif()
14841484
#----Installation details------------------------------------------------------
14851485
if(NOT ARG_NOINSTALL AND CMAKE_RUNTIME_OUTPUT_DIRECTORY)
@@ -2872,19 +2872,13 @@ macro(ROOTTEST_GENERATE_EXECUTABLE executable)
28722872
set(libraries ${libraries} ${library})
28732873
endif()
28742874
endforeach()
2875-
target_link_libraries(${executable} ${libraries})
2875+
target_link_libraries(${executable} PUBLIC ${libraries})
28762876
else()
2877-
target_link_libraries(${executable} ${ARG_LIBRARIES})
2877+
target_link_libraries(${executable} PUBLIC ${ARG_LIBRARIES})
28782878
endif()
28792879
endif()
2880-
if(MSVC AND DEFINED ROOT_SOURCE_DIR)
2881-
if(TARGET ROOTStaticSanitizerConfig)
2882-
target_link_libraries(${executable} ROOTStaticSanitizerConfig)
2883-
endif()
2884-
else()
2885-
if(TARGET ROOT::ROOTStaticSanitizerConfig)
2886-
target_link_libraries(${executable} ROOT::ROOTStaticSanitizerConfig)
2887-
endif()
2880+
if(TARGET ROOTStaticSanitizerConfig)
2881+
target_link_libraries(${executable} PRIVATE ROOTStaticSanitizerConfig)
28882882
endif()
28892883
28902884
if(ARG_COMPILE_FLAGS)
@@ -3493,14 +3487,8 @@ function(ROOTTEST_ADD_UNITTEST_DIR)
34933487
target_link_libraries(${binary} PRIVATE GTest::gtest GTest::gtest_main ${libraries})
34943488
set_property(TARGET ${binary} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway
34953489

3496-
if(MSVC AND DEFINED ROOT_SOURCE_DIR)
3497-
if(TARGET ROOTStaticSanitizerConfig)
3498-
target_link_libraries(${binary} ROOTStaticSanitizerConfig)
3499-
endif()
3500-
else()
3501-
if(TARGET ROOT::ROOTStaticSanitizerConfig)
3502-
target_link_libraries(${binary} PRIVATE ROOT::ROOTStaticSanitizerConfig)
3503-
endif()
3490+
if(TARGET ROOTStaticSanitizerConfig)
3491+
target_link_libraries(${binary} PRIVATE ROOTStaticSanitizerConfig)
35043492
endif()
35053493

35063494
# Mark the test as known to fail.

core/sanitizer/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,3 @@ target_link_libraries(${library} INTERFACE ${ASAN_EXTRA_EXE_LINKER_FLAGS})
1818
# Make it visible to the outside to sanitize e.g. roottest executables
1919
set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS ${library})
2020
add_library(ROOT::${library} ALIAS ${library})
21-
22-
# Now sanitize executables that are not created with ROOT_EXECUTABLE():
23-
foreach(target llvm-min-tblgen llvm-tblgen clang-tblgen cppinterop-tblgen)
24-
if(TARGET ${target})
25-
target_link_libraries(${target} PRIVATE ${library})
26-
endif()
27-
endforeach()

0 commit comments

Comments
 (0)