From e49cc561991be4013751737f71a8899b5c6c7d54 Mon Sep 17 00:00:00 2001 From: Jens Alfke Date: Fri, 13 Sep 2024 17:24:56 -0700 Subject: [PATCH] Enable sanitizers for GCC too --- cmake/platform_unix.cmake | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmake/platform_unix.cmake b/cmake/platform_unix.cmake index aae286622..0a4de876c 100644 --- a/cmake/platform_unix.cmake +++ b/cmake/platform_unix.cmake @@ -51,22 +51,32 @@ function(setup_litecore_build_unix) endif() - if (LITECORE_SANITIZE AND NOT CODE_COVERAGE_ENABLED AND (CMAKE_CXX_COMPILER_ID MATCHES Clang)) + if (LITECORE_SANITIZE AND NOT CODE_COVERAGE_ENABLED AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")) set(LITECORE_COMPILE_OPTIONS -fstack-protector -fsanitize=address - -fsanitize-address-use-after-return=always -fsanitize-address-use-after-scope -fsanitize=undefined - -fsanitize=nullability -fno-sanitize-recover=all # Always exit after UBSan warning # Note: _FORTIFY_SOURCE is incompatible with ASan; defining it will cause build errors ) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(LITECORE_COMPILE_OPTIONS + ${LITECORE_COMPILE_OPTIONS} + -fsanitize=nullability + -fsanitize-address-use-after-return=always + ) + endif () foreach(target LiteCore CppTests C4Tests) target_link_options(${target} PRIVATE -fsanitize=address -fsanitize=undefined ) +# if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") +# target_link_options(${target} PRIVATE +# -static-libasan +# ) +# endif () endforeach () else() set(LITECORE_COMPILE_OPTIONS @@ -105,7 +115,7 @@ function(setup_litecore_build_unix) ) if(LITECORE_WARNINGS_HARDCORE) - if (CMAKE_CXX_COMPILER_ID MATCHES Clang) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(LITECORE_CXX_WARNINGS -Werror -Weverything # "WARN ALL THE THINGS!!!"