From 048089ce447fdb46c4d2ce88ca7c5248d82f98c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Svensson?= Date: Mon, 2 Feb 2026 14:49:45 +0100 Subject: [PATCH] Disable sanitizer recovery mode by default in CMake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we want to find sanitizer issues when running with `-DENABLE_SANITIZERS=ON` we disable the recovery mode by default. By adding the compile flag `-fno-sanitize-recover=all` a testcase will now terminate instead of just print out any recoverable ASAN/UBSAN issue. Issues are visible in local test runs and in CI. The following CMake option is added and can be used by projects that has known issues: -DENABLE_SANITIZER_RECOVERY=ON Signed-off-by: Björn Svensson --- README.md | 1 + cmake/AwsSanitizers.cmake | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 0d26b1020..f1cfb8c96 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Or on windows, ### CMake Options * -DCMAKE_CLANG_TIDY=/path/to/clang-tidy (or just clang-tidy or clang-tidy-7.0 if it is in your PATH) - Runs clang-tidy as part of your build. * -DENABLE_SANITIZERS=ON - Enables gcc/clang sanitizers, by default this adds -fsanitizer=address,undefined to the compile flags for projects that call aws_add_sanitizers. +* -DENABLE_SANITIZER_RECOVERY=ON - Enables sanitizer error recovery for projects with known sanitizer issues. Error recovery mode is disabled by default. * -DENABLE_FUZZ_TESTS=ON - Includes fuzz tests in the unit test suite. Off by default, because fuzz tests can take a long time. Set -DFUZZ_TESTS_MAX_TIME=N to determine how long to run each fuzz test (default 60s). * -DCMAKE_INSTALL_PREFIX=/path/to/install - Standard way of installing to a user defined path. If specified when configuring aws-c-common, ensure the same prefix is specified when configuring other aws-c-* SDKs. * -DAWS_STATIC_MSVC_RUNTIME_LIBRARY=ON - Windows-only. Turn ON to use the statically-linked MSVC runtime lib, instead of the DLL. diff --git a/cmake/AwsSanitizers.cmake b/cmake/AwsSanitizers.cmake index 54202006e..3856b7f3a 100644 --- a/cmake/AwsSanitizers.cmake +++ b/cmake/AwsSanitizers.cmake @@ -4,6 +4,7 @@ include(CheckCCompilerFlag) option(ENABLE_SANITIZERS "Enable sanitizers in debug builds" OFF) +option(ENABLE_SANITIZER_RECOVERY "Enable sanitizer recovery mode" OFF) set(SANITIZERS "address;undefined" CACHE STRING "List of sanitizers to build with") # This function checks if a sanitizer is available @@ -70,6 +71,15 @@ function(aws_add_sanitizers target) target_compile_options(${target} PRIVATE -fno-omit-frame-pointer -fsanitize=${PRESENT_SANITIZERS}) target_link_libraries(${target} PUBLIC "-fno-omit-frame-pointer -fsanitize=${PRESENT_SANITIZERS}") + if(NOT ENABLE_SANITIZER_RECOVERY) + # Disable error recovery mode for sanitizers when the compiler supports it. + set(sanitizer_flag "-fno-sanitize-recover=all") + check_c_compiler_flag(${sanitizer_flag} HAS_NO_SANITIZE_RECOVER_ALL) + if(HAS_NO_SANITIZE_RECOVER_ALL) + target_compile_options(${target} PRIVATE ${sanitizer_flag}) + endif() + endif() + string(REPLACE "," ";" PRESENT_SANITIZERS "${PRESENT_SANITIZERS}") set(${target}_SANITIZERS ${PRESENT_SANITIZERS} PARENT_SCOPE) endif()