Skip to content

Commit

Permalink
Merge pull request ceph#56241 from tchaikov/wip-cmake-enable-sanitizers
Browse files Browse the repository at this point in the history
cmake: enable building with Sanitizers

Reviewed-by: Casey Bodley <[email protected]>
  • Loading branch information
tchaikov authored Mar 27, 2024
2 parents ca414b0 + 1a80165 commit 87a931c
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 5 deletions.
16 changes: 16 additions & 0 deletions cmake/modules/AddCephTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ function(add_ceph_test test_name test_path)
PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}:${CMAKE_SOURCE_DIR}/src:$ENV{PATH}
PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cython_modules/lib.3:${CMAKE_SOURCE_DIR}/src/pybind
CEPH_BUILD_VIRTUALENV=${CEPH_BUILD_VIRTUALENV})
if(WITH_UBSAN)
set_property(TEST ${test_name}
APPEND
PROPERTY ENVIRONMENT
UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1)
endif()
if(WITH_ASAN)
# AddressSanitizer: odr-violation: global 'ceph::buffer::list::always_empty_bptr' at
# /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/buffer.cc:1267:34
# see https://tracker.ceph.com/issues/65098
set_property(TEST ${test_name}
APPEND
PROPERTY ENVIRONMENT
ASAN_OPTIONS=detect_odr_violation=0
LSAN_OPTIONS=suppressions=${CMAKE_SOURCE_DIR}/qa/lsan.supp)
endif()
set_property(TEST ${test_name}
PROPERTY TIMEOUT ${CEPH_TEST_TIMEOUT})
# Crimson seastar unittest always run with --smp N to start N threads. By default, crimson seastar unittest
Expand Down
6 changes: 4 additions & 2 deletions cmake/modules/Distutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function(distutils_add_cython_module target name src)
set(PY_CC ${compiler_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1})
set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1})
set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
string(REPLACE " " ";" PY_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
list(APPEND PY_LDFLAGS -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

execute_process(COMMAND "${Python3_EXECUTABLE}" -c
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
Expand All @@ -98,7 +100,7 @@ function(distutils_add_cython_module target name src)
CXX="${PY_CXX}"
LDSHARED="${PY_LDSHARED}"
OPT=\"-DNDEBUG -g -fwrapv -O2 -w\"
LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
LDFLAGS="${PY_LDFLAGS}"
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
${Python3_EXECUTABLE} ${setup_py}
Expand Down Expand Up @@ -130,7 +132,7 @@ function(distutils_install_cython_module name)
-D'void0=dead_function\(void\)' \
-D'__Pyx_check_single_interpreter\(ARG\)=ARG\#\#0' \
${CFLAG_DISABLE_VTA}\")
set(ENV{LDFLAGS} \"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
set(ENV{LDFLAGS} \"${PY_LDFLAGS}\")
set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\")
set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/FindSanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ foreach(component ${Sanitizers_FIND_COMPONENTS})
elseif(component STREQUAL "leak")
set(Sanitizers_leak_COMPILE_OPTIONS "-fsanitize=leak")
elseif(component STREQUAL "thread")
if ("address" IN_LIST ${Sanitizers_FIND_COMPONENTS} OR
"leak" IN_LIST ${Sanitizers_FIND_COMPONENTS})
if ("address" IN_LIST "${Sanitizers_FIND_COMPONENTS}" OR
"leak" IN_LIST "${Sanitizers_FIND_COMPONENTS}")
message(SEND_ERROR "Cannot combine -fsanitize-leak w/ -fsanitize-thread")
elseif(NOT CMAKE_POSITION_INDEPENDENT_CODE)
message(SEND_ERROR "TSan requires all code to be position independent")
Expand Down
3 changes: 3 additions & 0 deletions qa/lsan.supp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# LSAN_OPTIONS="suppressions=../qa/lsan.supp"
# export ASAN_OPTIONS="detect_odr_violation=0"

# gperftools allocates a singleton of MallocExtension and never frees it
leak:^MallocExtension::Initialize

# from perfglue/heap_profiler.cc
# gperftools allocates a singleton and never frees it
leak:^InitModule
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12) # require >= clang-12
message(FATAL_ERROR "C++20 support requires a minimum Clang version of 12.")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_EXPORTS_C_FLAG}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_EXPORTS_C_FLAG}")
string(APPEND CMAKE_LINKER_FLAGS " -rdynamic -export-dynamic ${CMAKE_EXE_EXPORTS_C_FLAG}")
string(PREPEND CMAKE_CXX_FLAGS_DEBUG "-g ")
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-inconsistent-missing-override>)
Expand Down
5 changes: 5 additions & 0 deletions src/pybind/cephfs/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ def check_sanity():
extra_preargs=['-iquote{path}'.format(path=os.path.join(CEPH_SRC_DIR, 'include'))]
)

if ldflags := os.environ.get('LDFLAGS'):
extra_postargs = ldflags.split()
else:
extra_postargs = None
compiler.link_executable(
objects=link_objects,
output_progname=os.path.join(tmp_dir, 'cephfs_dummy'),
libraries=['cephfs'],
extra_postargs=extra_postargs,
output_dir=tmp_dir,
)

Expand Down
5 changes: 5 additions & 0 deletions src/pybind/rados/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ def check_sanity():
sources=[tmp_file],
output_dir=tmp_dir
)
if ldflags := os.environ.get('LDFLAGS'):
extra_postargs = ldflags.split()
else:
extra_postargs = None
compiler.link_executable(
objects=link_objects,
output_progname=os.path.join(tmp_dir, 'rados_dummy'),
libraries=['rados'],
extra_postargs=extra_postargs,
output_dir=tmp_dir,
)

Expand Down
5 changes: 5 additions & 0 deletions src/pybind/rbd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@ def check_sanity():
output_dir=tmp_dir
)

if ldflags := os.environ.get('LDFLAGS'):
extra_postargs = ldflags.split()
else:
extra_postargs = None
compiler.link_executable(
objects=link_objects,
output_progname=os.path.join(tmp_dir, 'rbd_dummy'),
libraries=['rbd', 'rados'],
extra_postargs=extra_postargs,
output_dir=tmp_dir,
)

Expand Down
5 changes: 5 additions & 0 deletions src/pybind/rgw/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@ def check_sanity():
output_dir=tmp_dir,
)

if ldflags := os.environ.get('LDFLAGS'):
extra_postargs = ldflags.split()
else:
extra_postargs = None
compiler.link_executable(
objects=link_objects,
output_progname=os.path.join(tmp_dir, 'rgw_dummy'),
libraries=['rgw', 'rados'],
extra_postargs=extra_postargs,
output_dir=tmp_dir,
)

Expand Down

0 comments on commit 87a931c

Please sign in to comment.