diff --git a/buildconfig/CMake/Sanitizers.cmake b/buildconfig/CMake/Sanitizers.cmake index ec1967bd8b0472755fb8983726f2dc8cf771162a..3ab418aea981d80bbfa3e196f2574669f5236757 100644 --- a/buildconfig/CMake/Sanitizers.cmake +++ b/buildconfig/CMake/Sanitizers.cmake @@ -4,9 +4,11 @@ set(USE_SANITIZER "Off" CACHE STRING "Sanitizer mode to enable") set_property(CACHE USE_SANITIZER PROPERTY STRINGS - Off Address Address+Leak Leak Memory Thread Undefined) + Off Address Memory Thread Undefined) -if(NOT ${USE_SANITIZER} MATCHES "Off") +string(TOLOWER "${USE_SANITIZER}" USE_SANITIZERS_LOWER) + +if(NOT ${USE_SANITIZERS_LOWER} MATCHES "off") if(${CMAKE_VERSION} VERSION_LESS "3.13.0") # Version 13 is needed for add_link_options, but not all platforms # currently have it @@ -19,7 +21,7 @@ if(NOT ${USE_SANITIZER} MATCHES "Off") # Check and warn if we are not in a mode without debug symbols string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower) - if(${build_type_lower} MATCHES "release" OR ${build_type_lower} MATCHES "minsizerel" ) + if("${build_type_lower}" MATCHES "release" OR "${build_type_lower}" MATCHES "minsizerel" ) message(WARNING "You are running address sanitizers without debug information, try RelWithDebInfo") elseif(${build_type_lower} MATCHES "relwithdebinfo") @@ -39,37 +41,25 @@ if(NOT ${USE_SANITIZER} MATCHES "Off") # N.b. we can switch this to add_link_options in CMake 3.13 # rather than have to check the linker options etc - if (USE_SANITIZER STREQUAL "Address") + if (USE_SANITIZERS_LOWER STREQUAL "address") message(STATUS "Enabling address sanitizer") add_compile_options(-fsanitize=address) add_link_options(-fsanitize=address) - elseif (USE_SANITIZER STREQUAL "Address+Leak") - message(STATUS "Enabling address and leak sanitizer") - - add_compile_options(-fsanitize=address,leak) - add_link_options(-fsanitize=address,leak) - - elseif (USE_SANITIZER STREQUAL "Leak") - message(STATUS "Enabling leak sanitizer") - - add_compile_options(-fsanitize=leak) - add_link_options(-fsanitize=leak) - - elseif (USE_SANITIZER STREQUAL "Memory") + elseif (USE_SANITIZERS_LOWER STREQUAL "memory") # Requires Clang > 10 and libc++ (rather than libstdc++) # so we will wire up later message(FATAL_ERROR "Not Enabled Yet") message(STATUS "Enabling Memory sanitizer") - elseif (USE_SANITIZER STREQUAL "Thread") + elseif (USE_SANITIZERS_LOWER STREQUAL "thread") message(STATUS "Enabling Thread sanitizer") add_compile_options(-fsanitize=thread) add_link_options(-fsanitize=thread) - elseif (USE_SANITIZER STREQUAL "Undefined") + elseif (USE_SANITIZERS_LOWER STREQUAL "undefined") message(STATUS "Enabling undefined behaviour sanitizer") add_compile_options( diff --git a/buildconfig/Jenkins/buildscript b/buildconfig/Jenkins/buildscript index e385e77c85baf50e6cbfe66723b93836f0c8dbe4..b5e4e8b6ff5d3ea8018d677e868085b73a72704e 100755 --- a/buildconfig/Jenkins/buildscript +++ b/buildconfig/Jenkins/buildscript @@ -9,6 +9,9 @@ # corresponds to any labels set on a slave. BUILD_THREADS & # PARAVIEW_DIR should be set in the configuration of each slave. ############################################################################### +# Set all string comparisons to case insensitive (i.e. Release == release) +shopt -s nocasematch + SCRIPT_DIR=$(dirname "$0") XVFB_SERVER_NUM=101 ULIMIT_CORE_ORIG=$(ulimit -c) @@ -305,6 +308,36 @@ if [[ ${DO_BUILD_PKG} == true ]]; then fi fi +############################################################################### +# Figure out if were doing a sanitizer build and setup any steps we need +############################################################################### +ASAN_OPTIONS='' +LSAN_OPTIONS='' + +SANITIZER_FLAGS='' + +SUPPRESSIONS_DIR="${WORKSPACE}/buildconfig/Sanitizer" + +if [[ ${JOB_NAME} == *address* ]]; then + SANITIZER_FLAGS="-DUSE_SANITIZER=Address" + + ASAN_OPTIONS="suppressions=${SUPPRESSIONS_DIR}/Address.supp:detect_stack_use_after_return=true:halt_on_error=false:verify_asan=0" + LSAN_OPTIONS="suppressions=${SUPPRESSIONS_DIR}/Leak.supp" + + elif [[ ${JOB_NAME} == *memory* ]]; then + SANITIZER_FLAGS="-DUSE_SANITIZER=memory" + + elif [[ ${JOB_NAME} == *thread* ]]; then + SANITIZER_FLAGS="-DUSE_SANITIZER=thread" + + elif [[ ${JOB_NAME} == *undefined* ]]; then + SANITIZER_FLAGS="-DUSE_SANITIZER=undefined" +fi + +if [[ -v ${SANITIZER_FLAGS} ]]; then + # Force build to RelWithDebInfo + BUILD_CONFIG="RelWithDebInfo" +fi ############################################################################### # Generator @@ -333,7 +366,7 @@ rm -f -- *.dmg *.rpm *.deb *.tar.gz *.tar.xz ############################################################################### # CMake configuration ############################################################################### -$SCL_ENABLE "${CMAKE_EXE} ${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} -DENABLE_CPACK=ON -DMAKE_VATES=ON -DParaView_DIR=${PARAVIEW_DIR} -DMANTID_DATA_STORE=${MANTID_DATA_STORE} -DDOCS_HTML=ON -DENABLE_CONDA=ON -DCOLORED_COMPILER_OUTPUT=OFF ${DIST_FLAGS} ${PACKAGINGVARS} ${CLANGTIDYVAR} .." +$SCL_ENABLE "${CMAKE_EXE} ${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${BUILD_CONFIG} -DENABLE_CPACK=ON -DMAKE_VATES=ON -DParaView_DIR=${PARAVIEW_DIR} -DMANTID_DATA_STORE=${MANTID_DATA_STORE} -DDOCS_HTML=ON -DENABLE_CONDA=ON -DCOLORED_COMPILER_OUTPUT=OFF ${DIST_FLAGS} ${PACKAGINGVARS} ${CLANGTIDYVAR} ${SANITIZER_FLAGS} .." ############################################################################### # Coverity build should exit early @@ -368,6 +401,9 @@ if [[ $USE_CLANG ]] && [[ ${JOB_NAME} == *clang_tidy* ]]; then exit 0 fi +# Set any ASAN options in the environment +export ASAN_OPTIONS=${ASAN_OPTIONS} + ############################################################################### # Run the unit tests diff --git a/buildconfig/Sanitizer/Address.supp b/buildconfig/Sanitizer/Address.supp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/buildconfig/Sanitizer/Leak.supp b/buildconfig/Sanitizer/Leak.supp new file mode 100644 index 0000000000000000000000000000000000000000..8bb47e18c2c5305a2df71c876a3063ef9017a2d0 --- /dev/null +++ b/buildconfig/Sanitizer/Leak.supp @@ -0,0 +1,2 @@ +leak:libNeXus +leak:libTKernel \ No newline at end of file