tango-controls/cppTango

Integration with sanitizers

mliszcz opened this issue · 1 comments

As discussed in Tango Kernel meeting on 22-10-2020, it would be good to have sanitizer (ASan, TSan and UBSan) jobs in CI.

See https://github.com/google/sanitizers for more detail on sanitizers.

This can be integrated into cppTango in few steps:

  • Add flag to cmake to enable sanitizers. There is no 'standard' way of doing this:

    • some people use CMAKE_BUILD_TYPE=ASAN, etc but this probably would break things for us as we expect build type to be only Debug or Release in a lot of places,
    • have a set of cmake options to enable different sanitizers (-DTANGO_SANITIZE_ADDRESS)
    • have one common option to enable sanitizers (-DTANGO_SANITIZE=ADDRESS) - because for instance g++ disallows mixing TSan and ASan

    We'd need to make sure that this works on both clang and g++

  • Change how tests are run by CTest. After each test we'd need to wait for the device servers to be killed and to check exit codes. This is required as well for Valgrind in #795.
    We also need a suppression files for false positives and things we want to ignore.

  • Add two (or more?) jobs to Travis. TSan needs to run alone. ASan and UBSan can probably be enabled in the same job.
    For investigating jobs failures we'd need access to the device server logs (job artifact storage is needed).

t-b commented

Thanks for the issue.

Add two (or more?) jobs to Travis.

Didn't we want to add the jobs in github actions?

Here are the settings we use internally

  IF(${SANITIZER})
    MESSAGE(STATUS "Building with sanitizer support.")
    TARGET_COMPILE_OPTIONS(${libname} PRIVATE $<$<CONFIG:DEBUG>:-g -O2
                           -fsanitize=address -fsanitize=undefined -fsanitize=integer
                           -fsanitize=nullability -fno-omit-frame-pointer -fno-sanitize-recover=all
                           -fsanitize-recover=unsigned-integer-overflow>)
    TARGET_LINK_OPTIONS(${libname} PRIVATE $<$<CONFIG:DEBUG>:-fsanitize=address
                        -fsanitize=undefined -fsanitize=integer -fsanitize=nullability
                        -fno-omit-frame-pointer -fno-sanitize-recover=all
                        -fsanitize-recover=unsigned-integer-overflow>)
  ENDIF()

and called via

 - export UBSAN_OPTIONS=print_stacktrace=1,suppressions=$(pwd)/UBSAN.supp,log_path=$(pwd)/sanitizer.log
- DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/${MACOSX_XCODE_VERSION}/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
- $callExecutable

This is designed for clang on MacOSX and uses UBSAN and ASAN.