Skip to content

Commit

Permalink
Add asan support to cmake/nix (#4194)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart authored Sep 19, 2023
1 parent 3758f4b commit 1640db5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(S2N_INTEG_TESTS "Enable the integrationv2 tests" OFF)
option(S2N_FAST_INTEG_TESTS "Enable the integrationv2 with more parallelism, only has effect if S2N_INTEG_TESTS=ON" OFF)
option(S2N_INSTALL_S2NC_S2ND "Install the binaries s2nc and s2nd" OFF)
option(TSAN "Enable ThreadSanitizer to test thread safety" OFF)
option(ASAN "Enable AddressSanitizer to test memory safety" OFF)

# Turn BUILD_TESTING=ON by default
include(CTest)
Expand Down Expand Up @@ -218,6 +219,16 @@ if(TSAN)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=thread)
endif()

if(ASAN)
target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=address -DS2N_ADDRESS_SANITIZER=1)
target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=address)
endif()

if(TSAN OR ASAN)
# no-omit-frame-pointer and no-optimize-sibling-calls provide better stack traces
target_compile_options(${PROJECT_NAME} PUBLIC -fno-omit-frame-pointer -fno-optimize-sibling-calls)
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

if (NOT $ENV{S2N_LIBCRYPTO} MATCHES "awslc")
Expand Down Expand Up @@ -503,12 +514,14 @@ if (BUILD_TESTING)
add_library(allocator_overrides SHARED ${TEST_LD_PRELOAD})

set(UNIT_TEST_ENVS S2N_DONT_MLOCK=1)
if (TSAN OR ASAN)
set(UNIT_TEST_ENVS ${UNIT_TEST_ENVS} S2N_ADDRESS_SANITIZER=1)
endif()
if(TSAN)
set(TSAN_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/tests/.tsan_suppressions)
if(NOT EXISTS ${TSAN_SUPPRESSIONS_FILE})
message(FATAL_ERROR "TSAN suppression file ${TSAN_SUPPRESSIONS_FILE} missing")
endif()
set(UNIT_TEST_ENVS ${UNIT_TEST_ENVS} S2N_ADDRESS_SANITIZER=1)
set(TSAN_OPTIONS suppressions=${TSAN_SUPPRESSIONS_FILE})
if(DEFINED ENV{TSAN_OPTIONS})
set(TSAN_OPTIONS "${TSAN_OPTIONS} $ENV{TSAN_OPTIONS}")
Expand Down
3 changes: 2 additions & 1 deletion nix/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ banner()


function clean {
banner "Cleanup up ./build"
banner "Cleanup ./build"
rm -rf ./build
}

Expand All @@ -23,6 +23,7 @@ function configure {
-DS2N_INSTALL_S2NC_S2ND=ON \
-DS2N_INTEG_NIX=ON \
-DBUILD_SHARED_LIBS=ON \
$S2N_CMAKE_OPTIONS \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
}

Expand Down

0 comments on commit 1640db5

Please sign in to comment.