Skip to content

Commit 87a931c

Browse files
authored
Merge pull request ceph#56241 from tchaikov/wip-cmake-enable-sanitizers
cmake: enable building with Sanitizers Reviewed-by: Casey Bodley <[email protected]>
2 parents ca414b0 + 1a80165 commit 87a931c

File tree

9 files changed

+46
-5
lines changed

9 files changed

+46
-5
lines changed

cmake/modules/AddCephTest.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ function(add_ceph_test test_name test_path)
1919
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
2020
PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cython_modules/lib.3:${CMAKE_SOURCE_DIR}/src/pybind
2121
CEPH_BUILD_VIRTUALENV=${CEPH_BUILD_VIRTUALENV})
22+
if(WITH_UBSAN)
23+
set_property(TEST ${test_name}
24+
APPEND
25+
PROPERTY ENVIRONMENT
26+
UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1)
27+
endif()
28+
if(WITH_ASAN)
29+
# AddressSanitizer: odr-violation: global 'ceph::buffer::list::always_empty_bptr' at
30+
# /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/buffer.cc:1267:34
31+
# see https://tracker.ceph.com/issues/65098
32+
set_property(TEST ${test_name}
33+
APPEND
34+
PROPERTY ENVIRONMENT
35+
ASAN_OPTIONS=detect_odr_violation=0
36+
LSAN_OPTIONS=suppressions=${CMAKE_SOURCE_DIR}/qa/lsan.supp)
37+
endif()
2238
set_property(TEST ${test_name}
2339
PROPERTY TIMEOUT ${CEPH_TEST_TIMEOUT})
2440
# Crimson seastar unittest always run with --smp N to start N threads. By default, crimson seastar unittest

cmake/modules/Distutils.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ function(distutils_add_cython_module target name src)
7373
set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1})
7474
set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
7575
set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
76+
string(REPLACE " " ";" PY_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
77+
list(APPEND PY_LDFLAGS -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
7678

7779
execute_process(COMMAND "${Python3_EXECUTABLE}" -c
7880
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
@@ -98,7 +100,7 @@ function(distutils_add_cython_module target name src)
98100
CXX="${PY_CXX}"
99101
LDSHARED="${PY_LDSHARED}"
100102
OPT=\"-DNDEBUG -g -fwrapv -O2 -w\"
101-
LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
103+
LDFLAGS="${PY_LDFLAGS}"
102104
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
103105
CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
104106
${Python3_EXECUTABLE} ${setup_py}
@@ -130,7 +132,7 @@ function(distutils_install_cython_module name)
130132
-D'void0=dead_function\(void\)' \
131133
-D'__Pyx_check_single_interpreter\(ARG\)=ARG\#\#0' \
132134
${CFLAG_DISABLE_VTA}\")
133-
set(ENV{LDFLAGS} \"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
135+
set(ENV{LDFLAGS} \"${PY_LDFLAGS}\")
134136
set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\")
135137
set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
136138

cmake/modules/FindSanitizers.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ foreach(component ${Sanitizers_FIND_COMPONENTS})
1414
elseif(component STREQUAL "leak")
1515
set(Sanitizers_leak_COMPILE_OPTIONS "-fsanitize=leak")
1616
elseif(component STREQUAL "thread")
17-
if ("address" IN_LIST ${Sanitizers_FIND_COMPONENTS} OR
18-
"leak" IN_LIST ${Sanitizers_FIND_COMPONENTS})
17+
if ("address" IN_LIST "${Sanitizers_FIND_COMPONENTS}" OR
18+
"leak" IN_LIST "${Sanitizers_FIND_COMPONENTS}")
1919
message(SEND_ERROR "Cannot combine -fsanitize-leak w/ -fsanitize-thread")
2020
elseif(NOT CMAKE_POSITION_INDEPENDENT_CODE)
2121
message(SEND_ERROR "TSan requires all code to be position independent")

qa/lsan.supp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# LSAN_OPTIONS="suppressions=../qa/lsan.supp"
44
# export ASAN_OPTIONS="detect_odr_violation=0"
55

6+
# gperftools allocates a singleton of MallocExtension and never frees it
7+
leak:^MallocExtension::Initialize
8+
69
# from perfglue/heap_profiler.cc
710
# gperftools allocates a singleton and never frees it
811
leak:^InitModule

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
143143
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12) # require >= clang-12
144144
message(FATAL_ERROR "C++20 support requires a minimum Clang version of 12.")
145145
endif()
146-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_EXPORTS_C_FLAG}")
146+
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_EXPORTS_C_FLAG}")
147147
string(APPEND CMAKE_LINKER_FLAGS " -rdynamic -export-dynamic ${CMAKE_EXE_EXPORTS_C_FLAG}")
148148
string(PREPEND CMAKE_CXX_FLAGS_DEBUG "-g ")
149149
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-inconsistent-missing-override>)

src/pybind/cephfs/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,15 @@ def check_sanity():
117117
extra_preargs=['-iquote{path}'.format(path=os.path.join(CEPH_SRC_DIR, 'include'))]
118118
)
119119

120+
if ldflags := os.environ.get('LDFLAGS'):
121+
extra_postargs = ldflags.split()
122+
else:
123+
extra_postargs = None
120124
compiler.link_executable(
121125
objects=link_objects,
122126
output_progname=os.path.join(tmp_dir, 'cephfs_dummy'),
123127
libraries=['cephfs'],
128+
extra_postargs=extra_postargs,
124129
output_dir=tmp_dir,
125130
)
126131

src/pybind/rados/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,15 @@ def check_sanity():
112112
sources=[tmp_file],
113113
output_dir=tmp_dir
114114
)
115+
if ldflags := os.environ.get('LDFLAGS'):
116+
extra_postargs = ldflags.split()
117+
else:
118+
extra_postargs = None
115119
compiler.link_executable(
116120
objects=link_objects,
117121
output_progname=os.path.join(tmp_dir, 'rados_dummy'),
118122
libraries=['rados'],
123+
extra_postargs=extra_postargs,
119124
output_dir=tmp_dir,
120125
)
121126

src/pybind/rbd/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,15 @@ def check_sanity():
116116
output_dir=tmp_dir
117117
)
118118

119+
if ldflags := os.environ.get('LDFLAGS'):
120+
extra_postargs = ldflags.split()
121+
else:
122+
extra_postargs = None
119123
compiler.link_executable(
120124
objects=link_objects,
121125
output_progname=os.path.join(tmp_dir, 'rbd_dummy'),
122126
libraries=['rbd', 'rados'],
127+
extra_postargs=extra_postargs,
123128
output_dir=tmp_dir,
124129
)
125130

src/pybind/rgw/setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,15 @@ def check_sanity():
116116
output_dir=tmp_dir,
117117
)
118118

119+
if ldflags := os.environ.get('LDFLAGS'):
120+
extra_postargs = ldflags.split()
121+
else:
122+
extra_postargs = None
119123
compiler.link_executable(
120124
objects=link_objects,
121125
output_progname=os.path.join(tmp_dir, 'rgw_dummy'),
122126
libraries=['rgw', 'rados'],
127+
extra_postargs=extra_postargs,
123128
output_dir=tmp_dir,
124129
)
125130

0 commit comments

Comments
 (0)