Merge pull request #4567 from akallabeth/sanitizer_checks_refined
Refined checks for sanitizers.
This commit is contained in:
commit
fc6780a865
118
CMakeLists.txt
118
CMakeLists.txt
@ -328,102 +328,104 @@ endif()
|
|||||||
|
|
||||||
# Enable address sanitizer, where supported and when required
|
# Enable address sanitizer, where supported and when required
|
||||||
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCC)
|
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCC)
|
||||||
|
set(CMAKE_REQUIRED_FLAGS_SAVED ${CMAKE_REQUIRED_FLAGS})
|
||||||
|
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
|
||||||
|
|
||||||
|
file(WRITE ${CMAKE_BINARY_DIR}/foo.txt "")
|
||||||
if(WITH_SANITIZE_ADDRESS)
|
if(WITH_SANITIZE_ADDRESS)
|
||||||
if (DEFINED CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
||||||
endif()
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
|
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
|
||||||
CHECK_C_COMPILER_FLAG ("-fsanitize=address" fsanitize-address)
|
CHECK_C_COMPILER_FLAG ("-fsanitize=address" fsanitize-address)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${CMAKE_BINARY_DIR}/foo.txt" fsanitize-blacklist)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-address-use-after-scope" fsanitize-address-use-after-scope)
|
||||||
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
|
|
||||||
if(fsanitize-address)
|
if(fsanitize-address)
|
||||||
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-address-sanitizer.txt")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope")
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Missing support for address sanitizer!")
|
|
||||||
endif()
|
|
||||||
if (DEFINED SAVE_CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
|
|
||||||
else()
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
|
if(fsanitize-blacklist)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-address-sanitizer.txt")
|
||||||
|
endif(fsanitize-blacklist)
|
||||||
|
|
||||||
|
if(fsanitize-address-use-after-scope)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-address-use-after-scope")
|
||||||
|
endif(fsanitize-address-use-after-scope)
|
||||||
|
|
||||||
|
else(fsanitize-address)
|
||||||
|
message(WARNING "Missing support for address sanitizer!")
|
||||||
|
endif(fsanitize-address)
|
||||||
|
|
||||||
if(fno-omit-frame-pointer)
|
if(fno-omit-frame-pointer)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
||||||
endif()
|
endif()
|
||||||
elseif(WITH_SANITIZE_MEMORY)
|
elseif(WITH_SANITIZE_MEMORY)
|
||||||
if (DEFINED CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
||||||
endif()
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-fsanitize=memory")
|
set(CMAKE_REQUIRED_FLAGS "-fsanitize=memory")
|
||||||
CHECK_C_COMPILER_FLAG ("-fsanitize=memory" fsanitize-memory)
|
CHECK_C_COMPILER_FLAG ("-fsanitize=memory" fsanitize-memory)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${CMAKE_BINARY_DIR}/foo.txt" fsanitize-blacklist)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-memory-use-after-dtor" fsanitize-memory-use-after-dtor)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-memory-track-origins" fsanitize-memory-track-origins)
|
||||||
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
|
|
||||||
if(fsanitize-memory)
|
if(fsanitize-memory)
|
||||||
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-memory-sanitizer.txt")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fsanitize-memory-use-after-dtor")
|
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=memory")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=memory")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory")
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Missing support for memory sanitizer!")
|
|
||||||
endif()
|
|
||||||
if (DEFINED SAVE_CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
|
|
||||||
else()
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
|
if(fsanitize-blacklist)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-memory-sanitizer.txt")
|
||||||
|
endif(fsanitize-blacklist)
|
||||||
|
|
||||||
|
if (fsanitize-memory-use-after-dtor)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-use-after-dtor")
|
||||||
|
endif(fsanitize-memory-use-after-dtor)
|
||||||
|
|
||||||
|
if (fsanitize-memory-track-origins)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins")
|
||||||
|
endif(fsanitize-memory-track-origins)
|
||||||
|
|
||||||
|
else(fsanitize-memory)
|
||||||
|
message(WARNING "Missing support for memory sanitizer!")
|
||||||
|
endif(fsanitize-memory)
|
||||||
|
|
||||||
if(fno-omit-frame-pointer)
|
if(fno-omit-frame-pointer)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
||||||
endif()
|
endif()
|
||||||
elseif(WITH_SANITIZE_THREAD)
|
elseif(WITH_SANITIZE_THREAD)
|
||||||
if (DEFINED CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
||||||
endif()
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-fsanitize=thread")
|
|
||||||
CHECK_C_COMPILER_FLAG ("-fsanitize=thread" fsanitize-thread)
|
CHECK_C_COMPILER_FLAG ("-fsanitize=thread" fsanitize-thread)
|
||||||
|
CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${CMAKE_BINARY_DIR}/foo.txt" fsanitize-blacklist)
|
||||||
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
if(fsanitize-thread)
|
if(fsanitize-thread)
|
||||||
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
|
set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize=thread")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-thread-sanitizer.txt")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
||||||
|
if(fsanitize-blacklist)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/scripts/blacklist-thread-sanitizer.txt")
|
||||||
|
endif(fsanitize-blacklist)
|
||||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
|
||||||
else()
|
else(fsanitize-thread)
|
||||||
message(FATAL_ERROR "Missing support for thread sanitizer!")
|
message(WARNING "Missing support for thread sanitizer!")
|
||||||
endif()
|
endif(fsanitize-thread)
|
||||||
if (DEFINED SAVE_CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
|
|
||||||
else()
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
|
|
||||||
if(fno-omit-frame-pointer)
|
if(fno-omit-frame-pointer)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
file(REMOVE ${CMAKE_BINARY_DIR}/foo.txt)
|
||||||
|
|
||||||
if (WITH_NO_UNDEFINED)
|
if (WITH_NO_UNDEFINED)
|
||||||
if (DEFINED CMAKE_REQUIRED_FLAGS)
|
|
||||||
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
|
||||||
endif()
|
|
||||||
set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
|
set(CMAKE_REQUIRED_FLAGS "-Wl,--no-undefined")
|
||||||
CHECK_C_COMPILER_FLAG (-Wl,--no-undefined no-undefined)
|
CHECK_C_COMPILER_FLAG (-Wl,--no-undefined no-undefined)
|
||||||
if (DEFINED SAVE_CMAKE_REQUIRED_FLAGS)
|
unset(CMAKE_REQUIRED_FLAGS)
|
||||||
set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
|
|
||||||
unset(SAVE_CMAKE_REQUIRED_FLAGS)
|
|
||||||
else()
|
|
||||||
unset(CMAKE_REQUIRED_FLAGS)
|
|
||||||
endif()
|
|
||||||
if(no-undefined)
|
if(no-undefined)
|
||||||
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
|
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVED})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
@ -850,7 +852,7 @@ find_feature(GSSAPI ${GSSAPI_FEATURE_TYPE} ${GSSAPI_FEATURE_PURPOSE} ${GSSAPI_FE
|
|||||||
if ( (WITH_GSSAPI) AND (NOT GSS_FOUND))
|
if ( (WITH_GSSAPI) AND (NOT GSS_FOUND))
|
||||||
message(WARNING "-DWITH_GSSAPI=ON is set, but not GSSAPI implementation was found, disabling")
|
message(WARNING "-DWITH_GSSAPI=ON is set, but not GSSAPI implementation was found, disabling")
|
||||||
elseif(WITH_GSSAPI)
|
elseif(WITH_GSSAPI)
|
||||||
if(GSS_FLAVOUR STREQUAL "MIT")
|
if(GSS_FLAVOUR STREQUAL "MIT")
|
||||||
add_definitions("-DWITH_GSSAPI -DWITH_GSSAPI_MIT")
|
add_definitions("-DWITH_GSSAPI -DWITH_GSSAPI_MIT")
|
||||||
if(GSS_VERSION_1_13)
|
if(GSS_VERSION_1_13)
|
||||||
add_definitions("-DHAVE_AT_LEAST_KRB_V1_13")
|
add_definitions("-DHAVE_AT_LEAST_KRB_V1_13")
|
||||||
|
Loading…
Reference in New Issue
Block a user