From 7afe183172f1ca509add4e6af5685a269e3e5eca Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 24 Jul 2024 20:09:05 -0600 Subject: [PATCH] CMake: Add proper sanitizer options for Swift files Apparently UBSAN + Swift doesn't work on Linux :< --- CMakeLists.txt | 8 +++----- Meta/Lagom/CMakeLists.txt | 12 ++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 20c507af1a5..dd0681c6ced 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,13 +43,10 @@ endif() if (ENABLE_MEMORY_SANITIZER) add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer) add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins) - add_swift_compile_options(-sanitize=memory) - add_swift_link_options(-sanitize=memory) endif() -if (ENABLE_UNDEFINED_SANITIZER) +if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT)) add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) - add_swift_compile_options(-sanitize=address) if (UNDEFINED_BEHAVIOR_IS_FATAL) add_cxx_compile_options(-fno-sanitize-recover=undefined) endif() @@ -57,7 +54,8 @@ if (ENABLE_UNDEFINED_SANITIZER) add_cxx_compile_options(-fno-sanitize=function) endif() add_cxx_link_options(-fsanitize=undefined) - add_swift_link_options(-sanitize=address) + add_swift_compile_options(-sanitize=undefined) + add_swift_link_options(-sanitize=undefined) endif() if (HAIKU) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index a942fef2962..7eb7ddc62a2 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -94,15 +94,17 @@ endif() if (ENABLE_ADDRESS_SANITIZER) add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer) - set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address") + add_cxx_link_options(-fsanitize=address) + add_swift_compile_options(-sanitize=address) + add_swift_link_options(-sanitize=address) endif() if (ENABLE_MEMORY_SANITIZER) add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer) - set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins") + add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins) endif() -if (ENABLE_UNDEFINED_SANITIZER) +if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT)) add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) if (UNDEFINED_BEHAVIOR_IS_FATAL) add_cxx_compile_options(-fno-sanitize-recover=undefined) @@ -110,7 +112,9 @@ if (ENABLE_UNDEFINED_SANITIZER) if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17") add_cxx_compile_options(-fno-sanitize=function) endif() - set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined") + add_cxx_link_options(-fsanitize=undefined) + add_swift_compile_options(-sanitize=undefined) + add_swift_link_options(-sanitize=undefined) endif() if (ENABLE_COMPILETIME_FORMAT_CHECK)