Skip to content

Commit

Permalink
build: Add options to select sanitizers in configure.py
Browse files Browse the repository at this point in the history
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

Do not use sanitizers for any build type:
./configure.py --no-sanitizers

Enabling santizers is consistently with Seastar_SANITIZE option.

Specified sanitizers are passed to Seastar_SANITIZERS list. If it
is empty and Seastar_SANITIZE option is enabled for this build,
the content of Seastar_DEFAULT_SANITIZERS will be used.
  • Loading branch information
devDDen committed Sep 16, 2024
1 parent e5d33ea commit 798bd72
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
33 changes: 23 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ set (Seastar_SANITIZE
"DEFAULT"
CACHE
STRING
"Enable ASAN and UBSAN. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
"Enable sanitizers. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")

list (APPEND Seastar_DEFAULT_SANITIZERS address undefined_behavior)

set (Seastar_DEBUG_SHARED_PTR
"DEFAULT"
Expand All @@ -391,6 +393,19 @@ set (Seastar_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set (Seastar_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set (Seastar_GEN_BINARY_DIR ${Seastar_BINARY_DIR}/gen)

include (TriStateOption)
tri_state_option (${Seastar_SANITIZE}
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
CONDITION sanitizers_enabled)

if (sanitizers_enabled)
if ((NOT Seastar_SANITIZERS) OR (Seastar_SANITIZERS STREQUAL ""))
set (Seastar_SANITIZERS ${Seastar_DEFAULT_SANITIZERS})
endif ()
else ()
set (Seastar_SANITIZERS "")
endif ()

#
# Dependencies.
#
Expand Down Expand Up @@ -875,19 +890,17 @@ if (Seastar_DPDK)
DPDK::dpdk)
endif ()

include (TriStateOption)
tri_state_option (${Seastar_SANITIZE}
DEFAULT_BUILD_TYPES "Debug" "Sanitize"
CONDITION condition)
if (condition)
if (sanitizers_enabled)
if (NOT Sanitizers_FOUND)
message (FATAL_ERROR "Sanitizers not found!")
endif ()
set (Seastar_Sanitizers_OPTIONS ${Sanitizers_COMPILER_OPTIONS})
target_link_libraries (seastar
PUBLIC
$<${condition}:Sanitizers::address>
$<${condition}:Sanitizers::undefined_behavior>)
foreach (component ${Seastar_SANITIZERS})
string (TOUPPER ${component} COMPONENT)
target_link_libraries (seastar
PUBLIC
Sanitizers::${component})
endforeach ()
endif ()

# We only need valgrind to find uninitialized memory uses, so disable
Expand Down
3 changes: 3 additions & 0 deletions cmake/SeastarDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ macro (seastar_find_dependencies)
seastar_set_dep_args (rt REQUIRED)
seastar_set_dep_args (numactl
OPTION ${Seastar_NUMA})
seastar_set_dep_args (Sanitizers
COMPONENTS
${Seastar_SANITIZERS})
seastar_set_dep_args (ucontext REQUIRED)
seastar_set_dep_args (yaml-cpp REQUIRED
VERSION 0.5.1)
Expand Down
16 changes: 14 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def standard_supported(standard, compiler='g++'):
arg_parser.add_argument('--dpdk-machine', default='native', help='Specify the target architecture')
add_tristate(arg_parser, name='deferred-action-require-noexcept', dest='deferred_action_require_noexcept', help='noexcept requirement for deferred actions', default=True)
arg_parser.add_argument('--prefix', dest='install_prefix', default='/usr/local', help='Root installation path of Seastar files')
arg_parser.add_argument('--sanitizer', dest='sanitizers', action='append', default=[], help='Use specified sanitizer')
arg_parser.add_argument('--no-sanitizers', dest='no_sanitizers', action='store_true', default=False, help='Do not use sanitizers')
args = arg_parser.parse_args()


Expand Down Expand Up @@ -171,15 +173,23 @@ def identify_best_standard(cpp_standards, compiler):

MODE_TO_CMAKE_BUILD_TYPE = {'release': 'RelWithDebInfo', 'debug': 'Debug', 'dev': 'Dev', 'sanitize': 'Sanitize' }

SANITIZER_TO_CMAKE = {'address': 'address', 'undefined': 'undefined_behavior'}


def configure_mode(mode):
BUILD_PATH = seastar_cmake.build_path(mode, build_root=args.build_root)

CFLAGS = seastar_cmake.convert_strings_to_cmake_list(
CFLAGS = seastar_cmake.whitespace_separated_strings_to_cmake_list(
args.user_cflags,
args.user_optflags if seastar_cmake.is_release_mode(mode) else '')

LDFLAGS = seastar_cmake.convert_strings_to_cmake_list(args.user_ldflags)
LDFLAGS = seastar_cmake.whitespace_separated_strings_to_cmake_list(args.user_ldflags)

SANITIZERS = seastar_cmake.strings_to_cmake_list(map(lambda s: SANITIZER_TO_CMAKE[s], args.sanitizers))

enable_sanitizers = None
if args.no_sanitizers:
enable_sanitizers = False

TRANSLATED_ARGS = [
'-DCMAKE_BUILD_TYPE={}'.format(MODE_TO_CMAKE_BUILD_TYPE[mode]),
Expand Down Expand Up @@ -209,6 +219,8 @@ def configure_mode(mode):
tr(args.deferred_action_require_noexcept, 'DEFERRED_ACTION_REQUIRE_NOEXCEPT'),
tr(args.unused_result_error, 'UNUSED_RESULT_ERROR'),
tr(args.debug_shared_ptr, 'DEBUG_SHARED_PTR', value_when_none='default'),
tr(enable_sanitizers, 'SANITIZE', value_when_none='default'),
tr(SANITIZERS, 'SANITIZERS'),
]

ingredients_to_cook = set(args.cook)
Expand Down
8 changes: 5 additions & 3 deletions seastar_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ def build_path(mode, build_root):
def is_release_mode(mode):
return mode == 'release'

def convert_strings_to_cmake_list(*args):
def strings_to_cmake_list(iterable):
return ';'.join(iterable)

def whitespace_separated_strings_to_cmake_list(*args):
"""Converts a sequence of whitespace-separated strings of tokens into a semicolon-separated
string of tokens for CMake.
"""
return ';'.join(' '.join(args).split())
return strings_to_cmake_list(' '.join(args).split())

def translate_arg(arg, new_name, value_when_none='no'):
"""
Expand Down

0 comments on commit 798bd72

Please sign in to comment.