Skip to content

build: Add options to select sanitizers in configure.py #2437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 53 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,13 @@ 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)")

set (Seastar_SANITIZERS
"address;undefined_behavior"
CACHE
STRING
"Sanitizers enabled when building Seastar")

set (Seastar_DEBUG_SHARED_PTR
"DEFAULT"
Expand All @@ -391,11 +397,27 @@ 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)
Comment on lines +401 to +403
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you moving this command up here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sanitizers are disabled for this build type we don't need to find them


if (NOT sanitizers_enabled)
set (Seastar_SANITIZERS "")
endif ()

#
# Dependencies.
#

include (SeastarDependencies)
set (Seastar_SANITIZERS_DEPENDENCY_STRING ${Seastar_SANITIZERS})

configure_file (
${CMAKE_CURRENT_LIST_DIR}/cmake/SeastarDependencies.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies-build.cmake
@ONLY)

include (SeastarDependencies-build)
seastar_find_dependencies ()

# Private build dependencies not visible to consumers
Expand Down Expand Up @@ -880,19 +902,16 @@ 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_COMPILE_OPTIONS})
target_link_libraries (seastar
PUBLIC
$<${condition}:Sanitizers::address>
$<${condition}:Sanitizers::undefined_behavior>)
set (Seastar_Sanitizers_OPTIONS $<${sanitizers_enabled}:${Sanitizers_COMPILE_OPTIONS}>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you extract this change into a separate commit, and accompany it with rationales in the commit message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in this PR

foreach (component ${Seastar_SANITIZERS})
target_link_libraries (seastar
PUBLIC
$<${sanitizers_enabled}:Sanitizers::${component}>)
endforeach ()
endif ()

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

if (_is_Multi_Config)
set (Seastar_CMAKE "_$<CONFIG>.cmake")
else ()
set (Seastar_CMAKE ".cmake")
endif ()

set (Seastar_SANITIZERS_DEPENDENCY_STRING "$<${sanitizers_enabled}:${Seastar_SANITIZERS}>")

configure_file (
${CMAKE_CURRENT_LIST_DIR}/cmake/SeastarDependencies.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies.cmake.in
@ONLY)

file (GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies${Seastar_CMAKE}
INPUT ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies.cmake.in)

include (CMakePackageConfigHelpers)
set (install_cmakedir ${CMAKE_INSTALL_LIBDIR}/cmake/Seastar)

Expand Down Expand Up @@ -1395,6 +1431,11 @@ if (Seastar_INSTALL)
${CMAKE_CURRENT_BINARY_DIR}/SeastarConfigVersion.cmake
DESTINATION ${install_cmakedir})

install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/SeastarDependencies${Seastar_CMAKE}
DESTINATION ${install_cmakedir}
RENAME SeastarDependencies.cmake)

install (
FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGnuTLS.cmake
Expand All @@ -1412,7 +1453,6 @@ if (Seastar_INSTALL)
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findrt.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Finducontext.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findyaml-cpp.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/SeastarDependencies.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibUring.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSystemTap-SDT.cmake
DESTINATION ${install_cmakedir})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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_DEPENDENCY_STRING@)
seastar_set_dep_args (ucontext REQUIRED)
seastar_set_dep_args (yaml-cpp REQUIRED
VERSION 0.5.1)
Expand Down
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ 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('--sanitizers', action='store', dest='sanitizers', default='address;undefined_behavior', help='Use specified sanitizers')
args = arg_parser.parse_args()


Expand Down Expand Up @@ -209,6 +210,7 @@ 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(args.sanitizers, 'SANITIZERS'),
]

ingredients_to_cook = set(args.cook)
Expand Down