Skip to content

Commit 7305f93

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. There are options to use sanitizers: Use ASAN and UBSAN for Debug and Sanitize build types: ./configure.py Use specified sanitizers for Debug and Sanitize build types: ./configure.py --sanitizer address --sanitizer undefined_behavior Do not use sanitizers for any build type: ./configure.py --no-sanitizers Enabling sanitizers is consistently with Seastar_SANITIZE option. Specified sanitizers are passed to Seastar_SANITIZERS list.
1 parent a30ec0c commit 7305f93

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

Diff for: CMakeLists.txt

+24-11
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,6 +397,15 @@ 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
#
@@ -883,19 +898,17 @@ if (Seastar_DPDK)
883898
DPDK::dpdk)
884899
endif ()
885900

886-
include (TriStateOption)
887-
tri_state_option (${Seastar_SANITIZE}
888-
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
889-
CONDITION condition)
890-
if (condition)
901+
if (sanitizers_enabled)
891902
if (NOT Sanitizers_FOUND)
892903
message (FATAL_ERROR "Sanitizers not found!")
893904
endif ()
894-
set (Seastar_Sanitizers_OPTIONS ${Sanitizers_COMPILE_OPTIONS})
895-
target_link_libraries (seastar
896-
PUBLIC
897-
$<${condition}:Sanitizers::address>
898-
$<${condition}:Sanitizers::undefined_behavior>)
905+
set (Seastar_Sanitizers_OPTIONS $<${sanitizers_enabled}:${Sanitizers_COMPILE_OPTIONS}>)
906+
foreach (component ${Seastar_SANITIZERS})
907+
string (TOUPPER ${component} COMPONENT)
908+
target_link_libraries (seastar
909+
PUBLIC
910+
$<${sanitizers_enabled}:Sanitizers::${component}>)
911+
endforeach ()
899912
endif ()
900913

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

Diff for: cmake/SeastarDependencies.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ macro (seastar_find_dependencies)
141141
seastar_set_dep_args (rt REQUIRED)
142142
seastar_set_dep_args (numactl
143143
OPTION ${Seastar_NUMA})
144+
seastar_set_dep_args (Sanitizers
145+
COMPONENTS
146+
${Seastar_SANITIZERS})
144147
seastar_set_dep_args (ucontext REQUIRED)
145148
seastar_set_dep_args (yaml-cpp REQUIRED
146149
VERSION 0.5.1)

Diff for: configure.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ 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('--sanitizer', dest='sanitizers', action='append', default=[], help='Use specified sanitizer')
146+
arg_parser.add_argument('--no-sanitizers', dest='no_sanitizers', action='store_true', default=False, help='Do not use sanitizers')
145147
args = arg_parser.parse_args()
146148

147149

@@ -175,11 +177,17 @@ def identify_best_standard(cpp_standards, compiler):
175177
def configure_mode(mode):
176178
BUILD_PATH = seastar_cmake.build_path(mode, build_root=args.build_root)
177179

178-
CFLAGS = seastar_cmake.convert_strings_to_cmake_list(
180+
CFLAGS = seastar_cmake.whitespace_separated_strings_to_cmake_list(
179181
args.user_cflags,
180182
args.user_optflags if seastar_cmake.is_release_mode(mode) else '')
181183

182-
LDFLAGS = seastar_cmake.convert_strings_to_cmake_list(args.user_ldflags)
184+
LDFLAGS = seastar_cmake.whitespace_separated_strings_to_cmake_list(args.user_ldflags)
185+
186+
SANITIZERS = seastar_cmake.strings_to_cmake_list(args.sanitizers) if len(args.sanitizers) > 0 else None
187+
188+
enable_sanitizers = None
189+
if args.no_sanitizers:
190+
enable_sanitizers = False
183191

184192
TRANSLATED_ARGS = [
185193
'-DCMAKE_BUILD_TYPE={}'.format(MODE_TO_CMAKE_BUILD_TYPE[mode]),
@@ -209,6 +217,8 @@ def configure_mode(mode):
209217
tr(args.deferred_action_require_noexcept, 'DEFERRED_ACTION_REQUIRE_NOEXCEPT'),
210218
tr(args.unused_result_error, 'UNUSED_RESULT_ERROR'),
211219
tr(args.debug_shared_ptr, 'DEBUG_SHARED_PTR', value_when_none='default'),
220+
tr(enable_sanitizers, 'SANITIZE', value_when_none='default'),
221+
tr(SANITIZERS, 'SANITIZERS', value_when_none='address;undefined_behavior'),
212222
]
213223

214224
ingredients_to_cook = set(args.cook)

Diff for: seastar_cmake.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ def build_path(mode, build_root):
3434
def is_release_mode(mode):
3535
return mode == 'release'
3636

37-
def convert_strings_to_cmake_list(*args):
37+
def strings_to_cmake_list(iterable):
38+
return ';'.join(iterable)
39+
40+
def whitespace_separated_strings_to_cmake_list(*args):
3841
"""Converts a sequence of whitespace-separated strings of tokens into a semicolon-separated
3942
string of tokens for CMake.
40-
4143
"""
42-
return ';'.join(' '.join(args).split())
44+
return strings_to_cmake_list(' '.join(args).split())
4345

4446
def translate_arg(arg, new_name, value_when_none='no'):
4547
"""

0 commit comments

Comments
 (0)