mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
CMake: Add support for building with sanitizers on Windows
This commit is contained in:
parent
3fd05306fc
commit
35d39e6cbc
Notes:
github-actions[bot]
2025-06-17 21:34:57 +00:00
Author: https://github.com/ayeteadoe
Commit: 35d39e6cbc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4962
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/R-Goc
1 changed files with 36 additions and 14 deletions
|
@ -1,8 +1,24 @@
|
|||
function(get_clang_resource_dir result_dir)
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-resource-dir
|
||||
OUTPUT_VARIABLE CLANG_RESOURCE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
file(TO_CMAKE_PATH "${CLANG_RESOURCE_DIR}" CLANG_RESOURCE_DIR)
|
||||
set(${result_dir} "${CLANG_RESOURCE_DIR}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
if (ENABLE_ADDRESS_SANITIZER)
|
||||
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||
add_cxx_link_options(-fsanitize=address)
|
||||
add_swift_compile_options(-sanitize=address)
|
||||
add_swift_link_options(-sanitize=address)
|
||||
if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
add_cxx_compile_options(-fsanitize=address /clang:-fno-omit-frame-pointer)
|
||||
# FIXME: Windows on ARM
|
||||
link_libraries(clang_rt.asan_dynamic-x86_64.lib -wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib)
|
||||
get_clang_resource_dir(CLANG_RESOURCE_DIR)
|
||||
file(COPY "${CLANG_RESOURCE_DIR}/lib/windows/clang_rt.asan_dynamic-x86_64.dll" DESTINATION "${CMAKE_BINARY_DIR}/bin")
|
||||
else()
|
||||
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||
add_cxx_link_options(-fsanitize=address)
|
||||
add_swift_compile_options(-sanitize=address)
|
||||
add_swift_link_options(-sanitize=address)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ENABLE_MEMORY_SANITIZER)
|
||||
|
@ -10,15 +26,21 @@ if (ENABLE_MEMORY_SANITIZER)
|
|||
add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
|
||||
endif()
|
||||
|
||||
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)
|
||||
if (ENABLE_UNDEFINED_SANITIZER)
|
||||
if (WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
add_cxx_compile_options(-fsanitize=undefined)
|
||||
# FIXME: Windows on ARM
|
||||
link_libraries(clang_rt.ubsan_standalone-x86_64.lib clang_rt.ubsan_standalone_cxx-x86_64.lib)
|
||||
elseif (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)
|
||||
endif()
|
||||
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()
|
||||
add_cxx_link_options(-fsanitize=undefined)
|
||||
add_swift_compile_options(-sanitize=undefined)
|
||||
add_swift_link_options(-sanitize=undefined)
|
||||
endif()
|
||||
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()
|
||||
add_cxx_link_options(-fsanitize=undefined)
|
||||
add_swift_compile_options(-sanitize=undefined)
|
||||
add_swift_link_options(-sanitize=undefined)
|
||||
endif()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue