Skip to content

Commit 6badc41

Browse files
devDDentchaikov
authored andcommitted
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 90e2d3c commit 6badc41

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

CMakeLists.txt

+34-11
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,13 @@ set (Seastar_SANITIZE
356356
"DEFAULT"
357357
CACHE
358358
STRING
359-
"Enable ASAN and UBSAN. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
359+
"Enable sanitizers. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
360+
361+
set (Seastar_SANITIZERS
362+
"address;undefined_behavior"
363+
CACHE
364+
STRING
365+
"Sanitizers enabled when building Seastar")
360366

361367
set (Seastar_DEBUG_SHARED_PTR
362368
"DEFAULT"
@@ -372,10 +378,30 @@ set (Seastar_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
372378
set (Seastar_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
373379
set (Seastar_GEN_BINARY_DIR ${Seastar_BINARY_DIR}/gen)
374380

381+
include (TriStateOption)
382+
tri_state_option (${Seastar_SANITIZE}
383+
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
384+
CONDITION sanitizers_enabled)
385+
386+
if (NOT sanitizers_enabled)
387+
set (Seastar_SANITIZERS "")
388+
endif ()
389+
375390
#
376391
# Dependencies.
377392
#
378393

394+
if (NOT Seastar_SANITIZE)
395+
# Sanitizers are disabled for all build modes
396+
set (Seastar_SANITIZERS_COMPONENTS)
397+
elseif (Seastar_SANITIZE STREQUAL "ON")
398+
# Sanitizers are enabled for all build modes
399+
set (Seastar_SANITIZERS_COMPONENTS ${Seastar_SANITIZERS})
400+
elseif (CMAKE_BUILD_TYPE MATCHES "Debug|Sanitize")
401+
# Sanitizers are enabled only for preconfigured modes
402+
set (Seastar_SANITIZERS_COMPONENTS ${Seastar_SANITIZERS})
403+
endif ()
404+
379405
include (SeastarDependencies)
380406
seastar_find_dependencies ()
381407

@@ -863,19 +889,16 @@ if (Seastar_DPDK)
863889
DPDK::dpdk)
864890
endif ()
865891

866-
include (TriStateOption)
867-
tri_state_option (${Seastar_SANITIZE}
868-
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
869-
CONDITION condition)
870-
if (condition)
892+
if (sanitizers_enabled)
871893
if (NOT Sanitizers_FOUND)
872894
message (FATAL_ERROR "Sanitizers not found!")
873895
endif ()
874-
set (Seastar_Sanitizers_OPTIONS $<${condition}:${Sanitizers_COMPILE_OPTIONS}>)
875-
target_link_libraries (seastar
876-
PUBLIC
877-
$<${condition}:Sanitizers::address>
878-
$<${condition}:Sanitizers::undefined_behavior>)
896+
set (Seastar_Sanitizers_OPTIONS $<${sanitizers_enabled}:${Sanitizers_COMPILE_OPTIONS}>)
897+
foreach (component ${Seastar_SANITIZERS})
898+
target_link_libraries (seastar
899+
PUBLIC
900+
$<${sanitizers_enabled}:Sanitizers::${component}>)
901+
endforeach ()
879902
endif ()
880903

881904
# We only need valgrind to find uninitialized memory uses, so disable

cmake/SeastarConfig.cmake.in

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ include (SeastarDependencies)
5656
set (Seastar_DPDK @Seastar_DPDK@)
5757
set (Seastar_IO_URING @Seastar_IO_URING@)
5858
set (Seastar_HWLOC @Seastar_HWLOC@)
59+
set (Seastar_SANITIZERS_COMPONENTS @Seastar_SANITIZERS_COMPONENTS@)
60+
5961
seastar_find_dependencies ()
6062

6163
if (NOT TARGET Seastar::seastar)

cmake/SeastarDependencies.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ macro (seastar_find_dependencies)
9393
seastar_find_dep (LibUring 2.0 REQUIRED)
9494
endif()
9595
seastar_find_dep (LinuxMembarrier)
96-
seastar_find_dep (Sanitizers)
96+
if (Seastar_SANITIZERS_COMPONENTS)
97+
seastar_find_dep (Sanitizers
98+
COMPONENTS
99+
${Seastar_SANITIZERS_COMPONENTS})
100+
endif ()
97101
seastar_find_dep (SourceLocation)
98102
seastar_find_dep (StdAtomic REQUIRED)
99103
seastar_find_dep (SystemTap-SDT)

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)