Skip to content

Commit 7b7009b

Browse files
committed
build: Add options to select sanitizers in configure.py
We are going to add ThreadSanitizer that can't be used together with AddressSanitizer. We want to choose which sanitizers to use. Sanitizers can be specified as semicolon separated list: ./configure.py --sanitizers address;undefined_behavior Specified sanitizers are passed to Seastar_SANITIZERS list. Enabling sanitizers is consistently with Seastar_SANITIZE option.
1 parent fba36a3 commit 7b7009b

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

Diff for: CMakeLists.txt

+53-13
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,13 @@ set (Seastar_SANITIZE
375375
"DEFAULT"
376376
CACHE
377377
STRING
378-
"Enable ASAN and UBSAN. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
378+
"Enable sanitizers. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
379+
380+
set (Seastar_SANITIZERS
381+
"address;undefined_behavior"
382+
CACHE
383+
STRING
384+
"Sanitizers enabled when building Seastar")
379385

380386
set (Seastar_DEBUG_SHARED_PTR
381387
"DEFAULT"
@@ -391,11 +397,27 @@ set (Seastar_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
391397
set (Seastar_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
392398
set (Seastar_GEN_BINARY_DIR ${Seastar_BINARY_DIR}/gen)
393399

400+
include (TriStateOption)
401+
tri_state_option (${Seastar_SANITIZE}
402+
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
403+
CONDITION sanitizers_enabled)
404+
405+
if (NOT sanitizers_enabled)
406+
set (Seastar_SANITIZERS "")
407+
endif ()
408+
394409
#
395410
# Dependencies.
396411
#
397412

398-
include (SeastarDependencies)
413+
set (Seastar_SANITIZERS_DEPENDENCY_STRING ${Seastar_SANITIZERS})
414+
415+
configure_file (
416+
${CMAKE_CURRENT_LIST_DIR}/cmake/SeastarDependencies.cmake.in
417+
${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies-build.cmake
418+
@ONLY)
419+
420+
include (SeastarDependencies-build)
399421
seastar_find_dependencies ()
400422

401423
# Private build dependencies not visible to consumers
@@ -880,19 +902,16 @@ if (Seastar_DPDK)
880902
DPDK::dpdk)
881903
endif ()
882904

883-
include (TriStateOption)
884-
tri_state_option (${Seastar_SANITIZE}
885-
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
886-
CONDITION condition)
887-
if (condition)
905+
if (sanitizers_enabled)
888906
if (NOT Sanitizers_FOUND)
889907
message (FATAL_ERROR "Sanitizers not found!")
890908
endif ()
891-
set (Seastar_Sanitizers_OPTIONS ${Sanitizers_COMPILE_OPTIONS})
892-
target_link_libraries (seastar
893-
PUBLIC
894-
$<${condition}:Sanitizers::address>
895-
$<${condition}:Sanitizers::undefined_behavior>)
909+
set (Seastar_Sanitizers_OPTIONS $<${sanitizers_enabled}:${Sanitizers_COMPILE_OPTIONS}>)
910+
foreach (component ${Seastar_SANITIZERS})
911+
target_link_libraries (seastar
912+
PUBLIC
913+
$<${sanitizers_enabled}:Sanitizers::${component}>)
914+
endforeach ()
896915
endif ()
897916

898917
# We only need valgrind to find uninitialized memory uses, so disable
@@ -1349,6 +1368,23 @@ if (Seastar_INSTALL)
13491368
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/seastar-testing-install.pc
13501369
INPUT ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-testing-install.pc.in)
13511370

1371+
if (_is_Multi_Config)
1372+
set (Seastar_CMAKE "_$<CONFIG>.cmake")
1373+
else ()
1374+
set (Seastar_CMAKE ".cmake")
1375+
endif ()
1376+
1377+
set (Seastar_SANITIZERS_DEPENDENCY_STRING "$<${sanitizers_enabled}:${Seastar_SANITIZERS}>")
1378+
1379+
configure_file (
1380+
${CMAKE_CURRENT_LIST_DIR}/cmake/SeastarDependencies.cmake.in
1381+
${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies.cmake.in
1382+
@ONLY)
1383+
1384+
file (GENERATE
1385+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies${Seastar_CMAKE}
1386+
INPUT ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies.cmake.in)
1387+
13521388
include (CMakePackageConfigHelpers)
13531389
set (install_cmakedir ${CMAKE_INSTALL_LIBDIR}/cmake/Seastar)
13541390

@@ -1395,6 +1431,11 @@ if (Seastar_INSTALL)
13951431
${CMAKE_CURRENT_BINARY_DIR}/SeastarConfigVersion.cmake
13961432
DESTINATION ${install_cmakedir})
13971433

1434+
install (
1435+
FILES ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies${Seastar_CMAKE}
1436+
DESTINATION ${install_cmakedir}
1437+
RENAME SeastarDependencies.cmake)
1438+
13981439
install (
13991440
FILES
14001441
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGnuTLS.cmake
@@ -1412,7 +1453,6 @@ if (Seastar_INSTALL)
14121453
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findrt.cmake
14131454
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Finducontext.cmake
14141455
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findyaml-cpp.cmake
1415-
${CMAKE_CURRENT_SOURCE_DIR}/cmake/SeastarDependencies.cmake
14161456
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibUring.cmake
14171457
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSystemTap-SDT.cmake
14181458
DESTINATION ${install_cmakedir})

Diff for: cmake/SeastarDependencies.cmake renamed to cmake/SeastarDependencies.cmake.in

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ macro (seastar_find_dependencies)
137137
seastar_set_dep_args (rt REQUIRED)
138138
seastar_set_dep_args (numactl
139139
OPTION ${Seastar_NUMA})
140+
seastar_set_dep_args (Sanitizers
141+
COMPONENTS
142+
@Seastar_SANITIZERS_DEPENDENCY_STRING@)
140143
seastar_set_dep_args (ucontext REQUIRED)
141144
seastar_set_dep_args (yaml-cpp REQUIRED
142145
VERSION 0.5.1)

Diff for: configure.py

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def standard_supported(standard, compiler='g++'):
142142
arg_parser.add_argument('--dpdk-machine', default='native', help='Specify the target architecture')
143143
add_tristate(arg_parser, name='deferred-action-require-noexcept', dest='deferred_action_require_noexcept', help='noexcept requirement for deferred actions', default=True)
144144
arg_parser.add_argument('--prefix', dest='install_prefix', default='/usr/local', help='Root installation path of Seastar files')
145+
arg_parser.add_argument('--sanitizers', action='store', dest='sanitizers', default='address;undefined_behavior', help='Use specified sanitizers')
145146
args = arg_parser.parse_args()
146147

147148

@@ -209,6 +210,7 @@ def configure_mode(mode):
209210
tr(args.deferred_action_require_noexcept, 'DEFERRED_ACTION_REQUIRE_NOEXCEPT'),
210211
tr(args.unused_result_error, 'UNUSED_RESULT_ERROR'),
211212
tr(args.debug_shared_ptr, 'DEBUG_SHARED_PTR', value_when_none='default'),
213+
tr(args.sanitizers, 'SANITIZERS'),
212214
]
213215

214216
ingredients_to_cook = set(args.cook)

0 commit comments

Comments
 (0)