2021-01-20 10:14:20 +00:00
|
|
|
if(DRACO_CMAKE_DRACO_SANITIZER_CMAKE_)
|
|
|
|
return()
|
|
|
|
endif() # DRACO_CMAKE_DRACO_SANITIZER_CMAKE_
|
|
|
|
set(DRACO_CMAKE_DRACO_SANITIZER_CMAKE_ 1)
|
|
|
|
|
|
|
|
# Handles the details of enabling sanitizers.
|
|
|
|
macro(draco_configure_sanitizer)
|
2021-05-21 11:25:36 +00:00
|
|
|
if(DRACO_SANITIZE AND NOT EMSCRIPTEN AND NOT MSVC)
|
2021-01-20 10:14:20 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
if(DRACO_SANITIZE MATCHES "cfi")
|
2021-05-21 11:25:36 +00:00
|
|
|
list(APPEND SAN_CXX_FLAGS "-flto" "-fno-sanitize-trap=cfi")
|
|
|
|
list(APPEND SAN_LINKER_FLAGS "-flto" "-fno-sanitize-trap=cfi"
|
2021-01-20 10:14:20 +00:00
|
|
|
"-fuse-ld=gold")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4
|
|
|
|
AND DRACO_SANITIZE MATCHES "integer|undefined")
|
2021-05-21 11:25:36 +00:00
|
|
|
list(APPEND SAN_LINKER_FLAGS "--rtlib=compiler-rt" "-lgcc_s")
|
2021-01-20 10:14:20 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-05-21 11:25:36 +00:00
|
|
|
list(APPEND SAN_CXX_FLAGS "-fsanitize=${DRACO_SANITIZE}")
|
|
|
|
list(APPEND SAN_LINKER_FLAGS "-fsanitize=${DRACO_SANITIZE}")
|
2021-01-20 10:14:20 +00:00
|
|
|
|
|
|
|
# Make sanitizer callstacks accurate.
|
2021-05-21 11:25:36 +00:00
|
|
|
list(APPEND SAN_CXX_FLAGS "-fno-omit-frame-pointer")
|
|
|
|
list(APPEND SAN_CXX_FLAGS "-fno-optimize-sibling-calls")
|
2021-01-20 10:14:20 +00:00
|
|
|
|
2021-05-21 11:25:36 +00:00
|
|
|
draco_test_cxx_flag(FLAG_LIST_VAR_NAMES SAN_CXX_FLAGS FLAG_REQUIRED)
|
|
|
|
draco_test_exe_linker_flag(FLAG_LIST_VAR_NAME SAN_LINKER_FLAGS)
|
2021-01-20 10:14:20 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|