diff --git a/CMakeLists.txt b/CMakeLists.txt index 7945ee63a3078..40c88e00050b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,10 +297,8 @@ if(asan) set(ASAN_EXTRA_LD_PRELOAD "${CMAKE_BINARY_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}ROOTSanitizerConfig${CMAKE_SHARED_LIBRARY_SUFFIX}:${ASAN_RUNTIME_LIBRARY}") endif() - foreach(item IN LISTS ASAN_EXTRA_CXX_FLAGS) - add_compile_options($<$:${item}>) - endforeach() - #add_link_options() not available in our CMake version: + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_EXTRA_CXX_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ASAN_EXTRA_CXX_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${ASAN_EXTRA_SHARED_LINKER_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ASAN_EXTRA_EXE_LINKER_FLAGS}") endif() @@ -731,6 +729,28 @@ if(LLVM_LINKER_IS_MOLD) endif() endif() +if(asan) + # Now sanitize all executables that are not created with ROOT_EXECUTABLE() + # See core/sanitizer for details + function(sanitize_all_targets DIR_TO_SEARCH) + get_property(subdirs DIRECTORY "${DIR_TO_SEARCH}" PROPERTY SUBDIRECTORIES) + foreach(subdir IN LISTS subdirs) + sanitize_all_targets("${subdir}") + endforeach() + + get_directory_property(directory_targets DIRECTORY "${DIR_TO_SEARCH}" BUILDSYSTEM_TARGETS) + foreach(target IN LISTS directory_targets) + get_target_property(target_type ${target} TYPE) + get_target_property(target_libs ${target} LINK_LIBRARIES) + if(target_type STREQUAL EXECUTABLE AND NOT target STREQUAL ROOTStaticSanitizerConfig AND NOT target_libs MATCHES "ROOTStaticSanitizerConfig") + target_link_libraries(${target} PRIVATE ROOTStaticSanitizerConfig) + message(VERBOSE "Adding sanitizer library to ${target} (not created via a ROOT macro): ${target_libs}") + endif() + endforeach() + endfunction() + sanitize_all_targets(${CMAKE_CURRENT_SOURCE_DIR}) +endif() + cmake_host_system_information(RESULT PROCESSOR QUERY PROCESSOR_DESCRIPTION) message(STATUS "ROOT Configuration \n diff --git a/bindings/pyroot/pythonizations/test/import_load_libs.py b/bindings/pyroot/pythonizations/test/import_load_libs.py index 4212812a54853..2dcae3efa7e59 100644 --- a/bindings/pyroot/pythonizations/test/import_load_libs.py +++ b/bindings/pyroot/pythonizations/test/import_load_libs.py @@ -80,6 +80,7 @@ class ImportLoadLibs(unittest.TestCase): "libatomic", # AddressSanitizer runtime and ROOT configuration "libclang_rt.asan-.*", + "libasan", "libROOTSanitizerConfig", "libjitterentropy", # by libssl on openSUSE "libsandbox", # Gentoo portage test environment diff --git a/builtins/gtest/CMakeLists.txt b/builtins/gtest/CMakeLists.txt index 2492a05cb0cdb..3db2993c80d2c 100644 --- a/builtins/gtest/CMakeLists.txt +++ b/builtins/gtest/CMakeLists.txt @@ -32,7 +32,6 @@ if(MSVC) if(NOT winrtdebug) set(gtestbuild "RelWithDebInfo") endif() - set(GTEST_CXX_FLAGS "${ROOT_EXTERNAL_CXX_FLAGS} ${ASAN_EXTRA_CXX_FLAGS}") endif() set(EXTRA_GTEST_OPTS -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG} diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake index a365b15ee6b4f..0ca0070f40da7 100644 --- a/cmake/modules/RootBuildOptions.cmake +++ b/cmake/modules/RootBuildOptions.cmake @@ -191,7 +191,7 @@ option(rootbench "Build rootbench if rootbench exists in root or if it is a sibl option(roottest "Build roottest (implies testing=ON)" OFF) option(test_roofit_hs3testsuite "Setup and use the HS3 conformance test suite (requires network)" OFF) option(testing "Enable testing with CTest" OFF) -option(asan "Build ROOT with address sanitizer instrumentation (only GCC is currently supported)" OFF) +option(asan "Build ROOT with address sanitizer instrumentation (see core/sanitizer for details)" OFF) option(_wheel_build "ROOT is being packaged as a wheel, do not install .dist-info metadata" OFF) set(gcctoolchain "" CACHE PATH "Set path to GCC toolchain used to build llvm/clang") diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake index d51f69846b7d2..387b722115b21 100644 --- a/cmake/modules/RootConfiguration.cmake +++ b/cmake/modules/RootConfiguration.cmake @@ -454,6 +454,11 @@ if (tmva-pymva) else() set(haspymva undef) endif() +if (tmva-sofie) + set(hastmvasofie define) +else() + set(hastmvasofie undef) +endif() if (uring) set(hasuring define) else() @@ -713,9 +718,7 @@ else() # Needed by ACLIC, while in ROOT we are using everywhere C++ standard via CMake features that are requested to build target set(CMAKE_CXX_ACLIC_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION}") if(asan) - # Replace the semicolon with space so that the produced compiler invokation still makes sense - string (REPLACE ";" " " ASAN_EXTRA_CXX_FLAGS_STR "${ASAN_EXTRA_CXX_FLAGS}") - set(CMAKE_CXX_ACLIC_FLAGS "${CMAKE_CXX_ACLIC_FLAGS} ${ASAN_EXTRA_CXX_FLAGS_STR}") + set(CMAKE_CXX_ACLIC_FLAGS "${CMAKE_CXX_ACLIC_FLAGS} ${ASAN_EXTRA_CXX_FLAGS}") endif() if(ROOT_COMPILEDATA_IGNORE_BUILD_NODE_CHANGES) # Only set the compiledata parameter if the CMake variable is 'true' diff --git a/cmake/modules/RootMacros.cmake b/cmake/modules/RootMacros.cmake index 567aaf8bc3a00..6163a9ce814cb 100644 --- a/cmake/modules/RootMacros.cmake +++ b/cmake/modules/RootMacros.cmake @@ -1477,9 +1477,9 @@ function(ROOT_EXECUTABLE executable) endif() endforeach() endif() - if(TARGET ROOT::ROOTStaticSanitizerConfig) + if(TARGET ROOTStaticSanitizerConfig) set_property(TARGET ${executable} - APPEND PROPERTY LINK_LIBRARIES ROOT::ROOTStaticSanitizerConfig) + APPEND PROPERTY LINK_LIBRARIES ROOTStaticSanitizerConfig) endif() #----Installation details------------------------------------------------------ if(NOT ARG_NOINSTALL AND CMAKE_RUNTIME_OUTPUT_DIRECTORY) @@ -2872,19 +2872,13 @@ macro(ROOTTEST_GENERATE_EXECUTABLE executable) set(libraries ${libraries} ${library}) endif() endforeach() - target_link_libraries(${executable} ${libraries}) + target_link_libraries(${executable} PUBLIC ${libraries}) else() - target_link_libraries(${executable} ${ARG_LIBRARIES}) + target_link_libraries(${executable} PUBLIC ${ARG_LIBRARIES}) endif() endif() - if(MSVC AND DEFINED ROOT_SOURCE_DIR) - if(TARGET ROOTStaticSanitizerConfig) - target_link_libraries(${executable} ROOTStaticSanitizerConfig) - endif() - else() - if(TARGET ROOT::ROOTStaticSanitizerConfig) - target_link_libraries(${executable} ROOT::ROOTStaticSanitizerConfig) - endif() + if(TARGET ROOTStaticSanitizerConfig) + target_link_libraries(${executable} PRIVATE ROOTStaticSanitizerConfig) endif() if(ARG_COMPILE_FLAGS) @@ -3493,14 +3487,8 @@ function(ROOTTEST_ADD_UNITTEST_DIR) target_link_libraries(${binary} PRIVATE GTest::gtest GTest::gtest_main ${libraries}) set_property(TARGET ${binary} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) # will never be installed anyway - if(MSVC AND DEFINED ROOT_SOURCE_DIR) - if(TARGET ROOTStaticSanitizerConfig) - target_link_libraries(${binary} ROOTStaticSanitizerConfig) - endif() - else() - if(TARGET ROOT::ROOTStaticSanitizerConfig) - target_link_libraries(${binary} PRIVATE ROOT::ROOTStaticSanitizerConfig) - endif() + if(TARGET ROOTStaticSanitizerConfig) + target_link_libraries(${binary} PRIVATE ROOTStaticSanitizerConfig) endif() # Mark the test as known to fail. diff --git a/cmake/modules/SetUpFreeBSD.cmake b/cmake/modules/SetUpFreeBSD.cmake index ac368effac46e..53a061e6d5ce7 100644 --- a/cmake/modules/SetUpFreeBSD.cmake +++ b/cmake/modules/SetUpFreeBSD.cmake @@ -74,7 +74,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) if(asan) # See also core/sanitizer/README.md for what's happening. execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) - set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address) + set(ASAN_EXTRA_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -z undefs") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") endif() @@ -97,7 +97,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(ASAN_RUNTIME_LIBRARY STREQUAL "libclang_rt.asan-x86_64.so") execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) endif() - set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope) + set(ASAN_EXTRA_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") endif() diff --git a/cmake/modules/SetUpLinux.cmake b/cmake/modules/SetUpLinux.cmake index 8f276487f3c47..acb1e24c4b1f7 100644 --- a/cmake/modules/SetUpLinux.cmake +++ b/cmake/modules/SetUpLinux.cmake @@ -86,8 +86,11 @@ if(CMAKE_COMPILER_IS_GNUCXX) if(asan) # See also core/sanitizer/README.md for what's happening. - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) - set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libasan.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT EXISTS "${ASAN_RUNTIME_LIBRARY}") + message(WARNING "'${ASAN_RUNTIME_LIBRARY}' does not seem to be a valid sanitizer library. ROOT's Python tests cannot be sanitised.") + endif() + set(ASAN_EXTRA_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -z undefs") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") endif() @@ -105,12 +108,16 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang) if(asan) # See also core/sanitizer/README.md for what's happening. - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan-x86_64.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) - # Since a while now, Clang installs libclang_rt.asan.so in an architecture dependent directory. - if(ASAN_RUNTIME_LIBRARY STREQUAL "libclang_rt.asan-x86_64.so") - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan.so OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + foreach(libname libclang_rt.asan-x86_64.so libclang_rt.asan.so) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=${libname} OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) + if(EXISTS ${ASAN_RUNTIME_LIBRARY}) + break() + endif() + endforeach() + if(NOT EXISTS "${ASAN_RUNTIME_LIBRARY}") + message(WARNING "'${ASAN_RUNTIME_LIBRARY}' does not seem to be a valid sanitizer library. ROOT's Python tests cannot be sanitized.") endif() - set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope) + set(ASAN_EXTRA_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -static-libsan -z undefs -Wl,--undefined=__asan_default_options -Wl,--undefined=__lsan_default_options -Wl,--undefined=__lsan_default_suppressions") endif() diff --git a/cmake/modules/SetUpMacOS.cmake b/cmake/modules/SetUpMacOS.cmake index e69ed179b0b5d..73297065cd08e 100644 --- a/cmake/modules/SetUpMacOS.cmake +++ b/cmake/modules/SetUpMacOS.cmake @@ -63,7 +63,7 @@ if (CMAKE_SYSTEM_NAME MATCHES Darwin) if(asan) # See also core/sanitizer/README.md for what's happening. execute_process(COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libclang_rt.asan_osx_dynamic.dylib OUTPUT_VARIABLE ASAN_RUNTIME_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE) - set(ASAN_EXTRA_CXX_FLAGS -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope) + set(ASAN_EXTRA_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "-fsanitize=address") set(ASAN_EXTRA_EXE_LINKER_FLAGS "-fsanitize=address -Wl,-U,__asan_default_options -Wl,-U,__lsan_default_options -Wl,-U,__lsan_default_suppressions") endif() diff --git a/cmake/modules/SetUpWindows.cmake b/cmake/modules/SetUpWindows.cmake index 43b5a71cf8942..e21aab51573d3 100644 --- a/cmake/modules/SetUpWindows.cmake +++ b/cmake/modules/SetUpWindows.cmake @@ -69,7 +69,7 @@ elseif(MSVC) endif() if(asan) - set(ASAN_EXTRA_CXX_FLAGS /fsanitize=address /wd5072) + set(ASAN_EXTRA_CXX_FLAGS "/fsanitize=address /wd5072") set(ASAN_EXTRA_SHARED_LINKER_FLAGS "/InferASanLibs /incremental:no /DEBUG") set(ASAN_EXTRA_EXE_LINKER_FLAGS "/InferASanLibs /incremental:no /DEBUG") endif() diff --git a/config/RConfigure.in b/config/RConfigure.in index 2b2370256b4ed..a15e94a8262e3 100644 --- a/config/RConfigure.in +++ b/config/RConfigure.in @@ -60,6 +60,7 @@ #@hastmvagpu@ R__HAS_TMVAGPU /**/ #@hastmvacudnn@ R__HAS_CUDNN /**/ #@haspymva@ R__HAS_PYMVA /**/ +#@hastmvasofie@ R__HAS_TMVASOFIE /*SOFIE is enabled*/ #@hasuring@ R__HAS_URING /**/ diff --git a/core/sanitizer/CMakeLists.txt b/core/sanitizer/CMakeLists.txt index 6c79d72e6206b..aa8481f37e486 100644 --- a/core/sanitizer/CMakeLists.txt +++ b/core/sanitizer/CMakeLists.txt @@ -18,10 +18,3 @@ target_link_libraries(${library} INTERFACE ${ASAN_EXTRA_EXE_LINKER_FLAGS}) # Make it visible to the outside to sanitize e.g. roottest executables set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS ${library}) add_library(ROOT::${library} ALIAS ${library}) - -# Now sanitize executables that are not created with ROOT_EXECUTABLE(): -foreach(target llvm-min-tblgen llvm-tblgen clang-tblgen cppinterop-tblgen) - if(TARGET ${target}) - target_link_libraries(${target} PRIVATE ${library}) - endif() -endforeach() diff --git a/graf2d/graf/src/TLatex.cxx b/graf2d/graf/src/TLatex.cxx index 94379764f6f36..0a09a75fb41b1 100644 --- a/graf2d/graf/src/TLatex.cxx +++ b/graf2d/graf/src/TLatex.cxx @@ -1778,10 +1778,7 @@ TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, const TextSpec_t return TLatexFormSize(0,0,0); } TextSpec_t newSpec = spec; - Char_t *url = new Char_t[opSquareCurly-opUrl-4]; - strncpy(url,text+opUrl+5,opSquareCurly-opUrl-5); - fName = url; - delete[] url; + fName = TString(text + opUrl + 5, opSquareCurly - opUrl - 5); if (!fShow) { result = Anal1(newSpec,text+opSquareCurly+1,length-opSquareCurly-1); } else { diff --git a/interpreter/cling/tools/plugins/clad/CMakeLists.txt b/interpreter/cling/tools/plugins/clad/CMakeLists.txt index 5a2c99da44a26..24a772adc01f2 100644 --- a/interpreter/cling/tools/plugins/clad/CMakeLists.txt +++ b/interpreter/cling/tools/plugins/clad/CMakeLists.txt @@ -20,9 +20,6 @@ if(MSVC AND NOT CMAKE_GENERATOR MATCHES Ninja) else() set(_clad_build_type Release) endif() - if(asan) - set(CLAD_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASAN_EXTRA_CXX_FLAGS}") - endif() set(EXTRA_BUILD_ARGS --config ${_clad_build_type}) endif() if(NOT _clad_build_type STREQUAL "" AND NOT _clad_build_type STREQUAL ".") diff --git a/math/mathcore/inc/Math/CladDerivator.h b/math/mathcore/inc/Math/CladDerivator.h index 0eedbbca9889f..9fc0eaa482883 100644 --- a/math/mathcore/inc/Math/CladDerivator.h +++ b/math/mathcore/inc/Math/CladDerivator.h @@ -1074,6 +1074,7 @@ extern "C" void sgemm_(const char *transa, const char *transb, const int *m, con namespace clad::custom_derivatives { +#ifdef R__HAS_TMVASOFIE namespace TMVA::Experimental::SOFIE { inline void Gemm_Call_pullback(float *output, bool transa, bool transb, int m, int n, int k, float alpha, @@ -1156,6 +1157,8 @@ inline void Relu_pullback(float *output, const float *input, int size, float *_d } // namespace TMVA::Experimental::SOFIE +#endif // R__HAS_TMVASOFIE + } // namespace clad::custom_derivatives #endif // CLAD_DERIVATOR