2022-10-06 04:57:47 +00:00
|
|
|
# The MIT License (MIT)
|
|
|
|
#
|
|
|
|
# Copyright (c)
|
|
|
|
# 2013 Matthew Arsenault
|
|
|
|
# 2015-2016 RWTH Aachen University, Federal Republic of Germany
|
|
|
|
# 2021 Markus Eggenbauer
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in all
|
|
|
|
# copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
# If any of the used compiler is a GNU compiler, add a second option to static
|
|
|
|
# link against the sanitizers.
|
|
|
|
option(SANITIZE_LINK_STATIC "Try to link static against sanitizers." Off)
|
|
|
|
|
|
|
|
set(FIND_QUIETLY_FLAG "")
|
|
|
|
if(DEFINED Sanitizers_FIND_QUIETLY)
|
|
|
|
set(FIND_QUIETLY_FLAG "QUIET")
|
|
|
|
endif()
|
|
|
|
|
2022-10-06 18:07:22 +00:00
|
|
|
find_package(ASan REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(TSan REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(MSan REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(UBSan REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(LeakSan REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(CFI REQUIRED ${FIND_QUIETLY_FLAG})
|
|
|
|
find_package(SS REQUIRED ${FIND_QUIETLY_FLAG})
|
2022-10-06 04:57:47 +00:00
|
|
|
|
|
|
|
function(sanitizer_add_blacklist_file FILE)
|
|
|
|
if(NOT IS_ABSOLUTE ${FILE})
|
|
|
|
set(FILE "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}")
|
|
|
|
endif()
|
|
|
|
get_filename_component(FILE "${FILE}" REALPATH)
|
|
|
|
|
|
|
|
sanitizer_check_compiler_flags("-fsanitize-blacklist=${FILE}" "SanitizerBlacklist" "SanBlist")
|
|
|
|
endfunction()
|
|
|
|
|
2022-10-06 18:07:22 +00:00
|
|
|
function(myxx_add_sanitizers ...)
|
2022-10-06 04:57:47 +00:00
|
|
|
# If no sanitizer is enabled, return immediately.
|
|
|
|
if(NOT
|
|
|
|
(SANITIZE_ADDRESS
|
|
|
|
OR SANITIZE_MEMORY
|
|
|
|
OR SANITIZE_THREAD
|
|
|
|
OR SANITIZE_UNDEFINED
|
|
|
|
OR SANITIZE_LEAK
|
|
|
|
OR SANITIZE_CFI
|
|
|
|
OR SANITIZE_SS))
|
|
|
|
message(STATUS "No sanitizer selected.")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SANITIZE_ADDRESS AND SANITIZE_THREAD)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Incompatible Sanitizer combination enabled: AddressSanitizer, ThreadSanitizer")
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_ADDRESS AND SANITIZE_MEMORY)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Incompatible Sanitizer combination enabled: AddressSanitizer, MemorySanitizer")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(SANITIZE_MEMORY AND SANITIZE_THREAD)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Incompatible Sanitizer combination enabled: MemorySanitizer, ThreadSanitizer")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(TARGET ${ARGV})
|
|
|
|
sanitizer_check_target(${TARGET})
|
|
|
|
|
|
|
|
# Add sanitizers for target.
|
|
|
|
if(SANITIZE_ADDRESS)
|
|
|
|
add_sanitize_address(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_THREAD)
|
|
|
|
add_sanitize_thread(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_MEMORY)
|
|
|
|
add_sanitize_memory(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_UNDEFINED)
|
|
|
|
add_sanitize_undefined(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_LEAK)
|
|
|
|
add_sanitize_leak(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_CFI)
|
|
|
|
add_sanitize_cfi(${TARGET})
|
|
|
|
endif()
|
|
|
|
if(SANITIZE_SS)
|
|
|
|
add_sanitize_ss(${TARGET})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2022-10-06 18:07:22 +00:00
|
|
|
endfunction(myxx_add_sanitizers)
|