From 0b3458054177629ef0afde4e57641ed91e168428 Mon Sep 17 00:00:00 2001 From: Lindsay Stewart Date: Thu, 15 Jun 2023 00:01:23 +0000 Subject: [PATCH] PR comments: rework compiler flags --- CMakeLists.txt | 12 +++++------- utils/s2n_atomic.c | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ac35fbff4..bc8e6554842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,6 +221,11 @@ if(S2N_UNSAFE_FUZZING_MODE) target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize-coverage=trace-pc-guard -fsanitize=address,undefined,leak -fuse-ld=gold -DS2N_ADDRESS_SANITIZER=1) endif() +if(TSAN) + target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=thread -DS2N_THREAD_SANITIZER=1) + target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=thread) +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") if (NOT $ENV{S2N_LIBCRYPTO} MATCHES "awslc") @@ -352,13 +357,6 @@ if (NOT S2N_EXECINFO_AVAILABLE) endif() feature_probe_result(S2N_STACKTRACE ${S2N_STACKTRACE}) -if(TSAN) - target_compile_options(${PROJECT_NAME} PUBLIC -fsanitize=thread) - target_link_options(${PROJECT_NAME} PUBLIC -fsanitize=thread) - # For now, only enable real atomics for TSAN - feature_probe_result(S2N_ATOMIC_ENABLED ${S2N_ATOMIC_SUPPORTED}) -endif() - set(S2N_KYBER512R3_AVX2_BMI2 FALSE) if(NOT S2N_NO_PQ_ASM) # Kyber Round-3 code has several different optimizations which require diff --git a/utils/s2n_atomic.c b/utils/s2n_atomic.c index 3fa931b7b6e..8496bd40732 100644 --- a/utils/s2n_atomic.c +++ b/utils/s2n_atomic.c @@ -21,7 +21,7 @@ S2N_RESULT s2n_atomic_init() { -#if S2N_ATOMIC_ENABLED +#if S2N_ATOMIC_SUPPORTED && S2N_THREAD_SANITIZER RESULT_ENSURE(__atomic_always_lock_free(sizeof(s2n_atomic_bool), NULL), S2N_ERR_ATOMIC); #endif return S2N_RESULT_OK; @@ -29,7 +29,7 @@ S2N_RESULT s2n_atomic_init() void s2n_atomic_store(s2n_atomic_bool *var, bool val) { -#if S2N_ATOMIC_ENABLED +#if S2N_ATOMIC_SUPPORTED && S2N_THREAD_SANITIZER sig_atomic_t input = val; __atomic_store(&var->val, &input, __ATOMIC_RELAXED); #else @@ -39,7 +39,7 @@ void s2n_atomic_store(s2n_atomic_bool *var, bool val) bool s2n_atomic_load(s2n_atomic_bool *var) { -#if S2N_ATOMIC_ENABLED +#if S2N_ATOMIC_SUPPORTED && S2N_THREAD_SANITIZER sig_atomic_t result = 0; __atomic_load(&var->val, &result, __ATOMIC_RELAXED); return result;