Skip to content

Commit 84c33d8

Browse files
committed
Update Sanitizers with PR feedback and edge cases
Updates the Sanitizers to handle whitespace anywhere in the selected sanitizer mode Fixes an issue where undefined sanitizer would not work (generator expressions do not handle whitespace) Updates documentation following some feedback, and drops some old information (such as min CMake version) Fix indentation and suppress all Python warnings Reverts the indentation changes introduced in an earlier commit by auto formatting tools. Changes the regex for the address suppressions so we match Python 2 and 3
1 parent 48794ff commit 84c33d8

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

buildconfig/CMake/Sanitizers.cmake

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ set_property(CACHE USE_SANITIZER PROPERTY STRINGS
99
string(TOLOWER "${USE_SANITIZER}" USE_SANITIZERS_LOWER)
1010

1111
if(NOT ${USE_SANITIZERS_LOWER} MATCHES "off")
12+
# Check we have a supported compiler
1213
if(WIN32)
1314
message(FATAL_ERROR "Windows does not support sanitizers")
1415
endif()
1516

17+
if(CMAKE_COMPILER_IS_GNUCXX AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8))
18+
message(FATAL_ERROR "GCC 7 and below do not support sanitizers")
19+
endif()
20+
1621
# Check and warn if we are not in a mode without debug symbols
1722
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
1823
if("${build_type_lower}" MATCHES "release" OR "${build_type_lower}" MATCHES "minsizerel" )
@@ -35,22 +40,24 @@ if(NOT ${USE_SANITIZERS_LOWER} MATCHES "off")
3540

3641
# Address
3742
add_compile_options(
38-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"address">:-fsanitize=address>)
43+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"address">:-fsanitize=address>)
3944
add_link_options(
40-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"address">:-fsanitize=address>)
45+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"address">:-fsanitize=address>)
4146

4247
# Thread
4348
add_compile_options(
44-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"thread">:-fsanitize=thread>)
49+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"thread">:-fsanitize=thread>)
4550
add_link_options(
46-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"thread">:-fsanitize=thread>)
51+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"thread">:-fsanitize=thread>)
4752

4853
# Undefined
4954
# RTTI information is not exported for some classes causing the
5055
# linker to fail whilst adding vptr instrumentation
5156
add_compile_options(
52-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"undefined">:-fsanitize=undefined -fno-sanitize=vptr>)
57+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"undefined">:-fsanitize=undefined>
58+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"undefined">:-fno-sanitize=vptr>)
59+
5360
add_link_options(
54-
$<$<STREQUAL:$<LOWER_CASE:${USE_SANITIZER}>,"undefined">:-fsanitize=undefined>)
61+
$<$<STREQUAL:$<LOWER_CASE:"${USE_SANITIZER}">,"undefined">:-fsanitize=undefined>)
5562

5663
endif()

buildconfig/Jenkins/buildscript

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ SANITIZER_FLAGS=''
317317
if [[ ${JOB_NAME} == *address* ]]; then
318318
SANITIZER_FLAGS="-DUSE_SANITIZER=Address"
319319

320-
elif [[ ${JOB_NAME} == *memory* ]]; then
320+
elif [[ ${JOB_NAME} == *memory* ]]; then
321321
SANITIZER_FLAGS="-DUSE_SANITIZER=memory"
322322

323-
elif [[ ${JOB_NAME} == *thread* ]]; then
323+
elif [[ ${JOB_NAME} == *thread* ]]; then
324324
SANITIZER_FLAGS="-DUSE_SANITIZER=thread"
325325

326-
elif [[ ${JOB_NAME} == *undefined* ]]; then
326+
elif [[ ${JOB_NAME} == *undefined* ]]; then
327327
SANITIZER_FLAGS="-DUSE_SANITIZER=undefined"
328328
fi
329329

dev-docs/source/RunningSanitizers.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Pre-requisites
1818

1919
The following tooling is required:
2020

21-
- CMake 13.0 onwards (instructions for Ubuntu `here <https://apt.kitware.com/>`__)
2221
- GCC-8 onwards
22+
- Clang 3.2 onwards
2323

2424

2525
Switching to Sanitizer Build
@@ -28,7 +28,6 @@ Switching to Sanitizer Build
2828
The following sanitizers modes are available:
2929

3030
- Address
31-
- Memory (Not implemented yet, requires clang support)
3231
- Thread
3332
- Undefined
3433

tools/Sanitizer/Address.supp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file is a placeholder for future suppressions. It is passed through
2+
# the ctest harness to the currently running test

tools/Sanitizer/Leak.supp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1+
# NeXus has a known memory leak when reading attributes.
2+
# It is fixed upstream but not made it to distribution packages
3+
# Direct leak of 12114 byte(s) in 1346 object(s) allocated from:
4+
# #0 0x7fb126db5538 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x77538)
5+
# #1 0x7fb120a534cb (/usr/lib/libNeXus.so.0+0xc4cb)
6+
# #2 0x7fb100000000 (<unknown module>)
17
leak:libNeXus
2-
leak:libTKernel
8+
9+
# OpenCascade memory allocation seems to confuse ASAN
10+
# Direct leak of 544 byte(s) in 1 object(s) allocated from:
11+
# #0 0x7f77eec3a618 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0618)
12+
# #1 0x7f77e4141b08 (/usr/lib/x86_64-linux-gnu/libTKernel.so.11+0x7bb08)
13+
leak:libTKernel
14+
15+
# TBB leaks some memory allocated in singleton depending on deinitialization order
16+
# Direct leak of 1560 byte(s) in 3 object(s) allocated from:
17+
# #0 0x7f7ae72a80a0 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc80a0)
18+
# #1 0x7f7ae595d13e (/usr/lib/x86_64-linux-gnu/libtbb.so.2+0x2213e)
19+
leak:libtbb
20+
21+
# Python and associated libraries *appears* to leak memory.
22+
leak:libpython
23+
leak:umath
24+
leak:multiarray
25+
leak:_ctypes

0 commit comments

Comments
 (0)