Skip to content
Snippets Groups Projects
Commit 4122ea15 authored by David Fairbrother's avatar David Fairbrother
Browse files

Update build script to include sanitizers and leak suppressions

Adds a step to the build scripts for jenkins to run sanitized builds
with the correct environment variables. Also adds leak suppressions for
upstream libraries too
parent 551bac26
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
set(USE_SANITIZER "Off" CACHE STRING "Sanitizer mode to enable") set(USE_SANITIZER "Off" CACHE STRING "Sanitizer mode to enable")
set_property(CACHE USE_SANITIZER PROPERTY STRINGS 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") if(${CMAKE_VERSION} VERSION_LESS "3.13.0")
# Version 13 is needed for add_link_options, but not all platforms # Version 13 is needed for add_link_options, but not all platforms
# currently have it # currently have it
...@@ -19,7 +21,7 @@ if(NOT ${USE_SANITIZER} MATCHES "Off") ...@@ -19,7 +21,7 @@ if(NOT ${USE_SANITIZER} MATCHES "Off")
# Check and warn if we are not in a mode without debug symbols # Check and warn if we are not in a mode without debug symbols
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower) 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") message(WARNING "You are running address sanitizers without debug information, try RelWithDebInfo")
elseif(${build_type_lower} MATCHES "relwithdebinfo") elseif(${build_type_lower} MATCHES "relwithdebinfo")
...@@ -39,37 +41,25 @@ if(NOT ${USE_SANITIZER} MATCHES "Off") ...@@ -39,37 +41,25 @@ if(NOT ${USE_SANITIZER} MATCHES "Off")
# N.b. we can switch this to add_link_options in CMake 3.13 # N.b. we can switch this to add_link_options in CMake 3.13
# rather than have to check the linker options etc # 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") message(STATUS "Enabling address sanitizer")
add_compile_options(-fsanitize=address) add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address) add_link_options(-fsanitize=address)
elseif (USE_SANITIZER STREQUAL "Address+Leak") elseif (USE_SANITIZERS_LOWER STREQUAL "memory")
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")
# Requires Clang > 10 and libc++ (rather than libstdc++) # Requires Clang > 10 and libc++ (rather than libstdc++)
# so we will wire up later # so we will wire up later
message(FATAL_ERROR "Not Enabled Yet") message(FATAL_ERROR "Not Enabled Yet")
message(STATUS "Enabling Memory sanitizer") message(STATUS "Enabling Memory sanitizer")
elseif (USE_SANITIZER STREQUAL "Thread") elseif (USE_SANITIZERS_LOWER STREQUAL "thread")
message(STATUS "Enabling Thread sanitizer") message(STATUS "Enabling Thread sanitizer")
add_compile_options(-fsanitize=thread) add_compile_options(-fsanitize=thread)
add_link_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") message(STATUS "Enabling undefined behaviour sanitizer")
add_compile_options( add_compile_options(
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
# corresponds to any labels set on a slave. BUILD_THREADS & # corresponds to any labels set on a slave. BUILD_THREADS &
# PARAVIEW_DIR should be set in the configuration of each slave. # 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") SCRIPT_DIR=$(dirname "$0")
XVFB_SERVER_NUM=101 XVFB_SERVER_NUM=101
ULIMIT_CORE_ORIG=$(ulimit -c) ULIMIT_CORE_ORIG=$(ulimit -c)
...@@ -305,6 +308,36 @@ if [[ ${DO_BUILD_PKG} == true ]]; then ...@@ -305,6 +308,36 @@ if [[ ${DO_BUILD_PKG} == true ]]; then
fi fi
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 # Generator
...@@ -333,7 +366,7 @@ rm -f -- *.dmg *.rpm *.deb *.tar.gz *.tar.xz ...@@ -333,7 +366,7 @@ rm -f -- *.dmg *.rpm *.deb *.tar.gz *.tar.xz
############################################################################### ###############################################################################
# CMake configuration # 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 # Coverity build should exit early
...@@ -368,6 +401,9 @@ if [[ $USE_CLANG ]] && [[ ${JOB_NAME} == *clang_tidy* ]]; then ...@@ -368,6 +401,9 @@ if [[ $USE_CLANG ]] && [[ ${JOB_NAME} == *clang_tidy* ]]; then
exit 0 exit 0
fi fi
# Set any ASAN options in the environment
export ASAN_OPTIONS=${ASAN_OPTIONS}
############################################################################### ###############################################################################
# Run the unit tests # Run the unit tests
......
leak:libNeXus
leak:libTKernel
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment