2018-08-02 05:59:31 +00:00
|
|
|
if(NOT Sanitizers_FIND_COMPONENTS)
|
|
|
|
set(Sanitizers_FIND_COMPONENTS
|
2018-08-11 04:30:31 +00:00
|
|
|
address undefined_behavior)
|
2018-08-02 05:59:31 +00:00
|
|
|
endif()
|
|
|
|
if(HAVE_JEMALLOC)
|
|
|
|
message(WARNING "JeMalloc does not work well with sanitizers")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(Sanitizers_OPTIONS)
|
|
|
|
|
|
|
|
foreach(component ${Sanitizers_FIND_COMPONENTS})
|
|
|
|
if(component STREQUAL "address")
|
2018-08-11 04:30:31 +00:00
|
|
|
set(Sanitizers_address_COMPILE_OPTIONS "address")
|
2018-08-02 05:59:31 +00:00
|
|
|
elseif(component STREQUAL "leak")
|
2018-08-11 04:30:31 +00:00
|
|
|
set(Sanitizers_leak_COMPILE_OPTIONS "leak")
|
2018-08-02 05:59:31 +00:00
|
|
|
elseif(component STREQUAL "thread")
|
2018-08-11 04:30:31 +00:00
|
|
|
if ("address" IN_LIST ${Sanitizers_FIND_COMPONENTS} OR
|
|
|
|
"leak" IN_LIST ${Sanitizers_FIND_COMPONENTS})
|
2018-08-02 05:59:31 +00:00
|
|
|
message(SEND_ERROR "Cannot combine -fsanitize-leak w/ -fsanitize-thread")
|
|
|
|
elseif(NOT CMAKE_POSITION_INDEPENDENT_CODE)
|
|
|
|
message(SEND_ERROR "TSan requires all code to be position independent")
|
|
|
|
endif()
|
|
|
|
set(Sanitizers_Thread_COMPILE_OPTIONS "thread")
|
2018-08-11 04:30:31 +00:00
|
|
|
elseif(component STREQUAL "undefined_behavior")
|
|
|
|
set(Sanitizers_undefined_behavior_COMPILE_OPTIONS "undefined")
|
2018-08-02 05:59:31 +00:00
|
|
|
else()
|
|
|
|
message(SEND_ERROR "Unsupported sanitizer: ${component}")
|
|
|
|
endif()
|
2018-08-11 04:30:31 +00:00
|
|
|
list(APPEND Sanitizers_OPTIONS "${Sanitizers_${component}_COMPILE_OPTIONS}")
|
2018-08-02 05:59:31 +00:00
|
|
|
endforeach()
|
|
|
|
|
2018-10-22 06:06:38 +00:00
|
|
|
if(Sanitizers_address_COMPILE_OPTIONS OR Sanitizers_leak_COMPILE_OPTIONS)
|
|
|
|
# ASAN_LIBRARY will be read by ceph.in to preload the asan library
|
|
|
|
find_library(ASAN_LIBRARY
|
|
|
|
NAMES
|
|
|
|
libasan.so.5
|
|
|
|
libasan.so.4
|
|
|
|
libasan.so.3)
|
|
|
|
endif()
|
|
|
|
|
2018-08-02 05:59:31 +00:00
|
|
|
if(Sanitizers_OPTIONS)
|
|
|
|
string(REPLACE ";" ","
|
|
|
|
Sanitizers_COMPILE_OPTIONS
|
|
|
|
"${Sanitizers_OPTIONS}")
|
|
|
|
set(Sanitizers_COMPILE_OPTIONS
|
|
|
|
"-fsanitize=${Sanitizers_COMPILE_OPTIONS} -fno-omit-frame-pointer")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS ${Sanitizers_COMPILE_OPTIONS})
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${Sanitizers_COMPILE_OPTIONS})
|
|
|
|
check_cxx_source_compiles("int main() {}"
|
|
|
|
Sanitizers_ARE_SUPPORTED)
|
|
|
|
|
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(Sanitizers
|
|
|
|
REQUIRED_VARS
|
|
|
|
Sanitizers_ARE_SUPPORTED
|
|
|
|
Sanitizers_COMPILE_OPTIONS)
|
|
|
|
|
|
|
|
if(Sanitizers_FOUND)
|
|
|
|
if(NOT TARGET Sanitizers::Sanitizers)
|
|
|
|
add_library(Sanitizers::Sanitizers INTERFACE IMPORTED)
|
|
|
|
set_target_properties(Sanitizers::Sanitizers PROPERTIES
|
|
|
|
INTERFACE_COMPILE_OPTIONS ${Sanitizers_COMPILE_OPTIONS}
|
|
|
|
INTERFACE_LINK_LIBRARIES ${Sanitizers_COMPILE_OPTIONS})
|
|
|
|
endif()
|
|
|
|
foreach(component ${Sanitizers_FIND_COMPONENTS})
|
|
|
|
if(NOT TARGET Sanitizers::${component})
|
|
|
|
set(target Sanitizers::${component})
|
|
|
|
set(compile_option "-fsanitize=${Sanitizers_${component}_COMPILE_OPTIONS}")
|
|
|
|
add_library(${target} INTERFACE IMPORTED)
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
INTERFACE_COMPILE_OPTIONS ${compile_option}
|
|
|
|
INTERFACE_LINK_LIBRARIES ${compile_option})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|