Add UBSAN flag to builds
The -DWITH_UBSAN flag enables the undefined behavior detection provided by GCC.
This commit is contained in:
@ -48,6 +48,7 @@ find_package(GSSAPI)
|
|||||||
find_package(SQLite)
|
find_package(SQLite)
|
||||||
find_package(ASAN)
|
find_package(ASAN)
|
||||||
find_package(TSAN)
|
find_package(TSAN)
|
||||||
|
find_package(UBSAN)
|
||||||
|
|
||||||
# Build PCRE2 so we always know the version
|
# Build PCRE2 so we always know the version
|
||||||
# Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target
|
# Read BuildPCRE2 for details about how to add pcre2 as a dependency to a target
|
||||||
@ -154,6 +155,9 @@ if (WITH_ASAN AND ASAN_FOUND)
|
|||||||
elseif (WITH_TSAN AND TSAN_FOUND)
|
elseif (WITH_TSAN AND TSAN_FOUND)
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
|
||||||
|
elseif (WITH_UBSAN AND UBSAN_FOUND)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_GNU_SOURCE=1 ${FLAGS}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_GNU_SOURCE=1 ${FLAGS}")
|
||||||
|
|||||||
14
cmake/FindUBSAN.cmake
Normal file
14
cmake/FindUBSAN.cmake
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Find UBSan libraries
|
||||||
|
#
|
||||||
|
# The following variables are set:
|
||||||
|
# UBSAN_FOUND - If UBSan was found
|
||||||
|
# UBSAN_LIBRARIES - Path to the libubsan library
|
||||||
|
|
||||||
|
find_library(UBSAN_LIBRARIES NAMES libubsan.so.0 libubsan.so.1 libubsan.so.2 libubsan.so.3 libubsan.so.4)
|
||||||
|
|
||||||
|
if (UBSAN_LIBRARIES)
|
||||||
|
message(STATUS "Found UBSan libraries: ${UBSAN_LIBRARIES}")
|
||||||
|
set(UBSAN_FOUND TRUE CACHE INTERNAL "")
|
||||||
|
else()
|
||||||
|
message(STATUS "Could not find UBSan")
|
||||||
|
endif()
|
||||||
@ -72,6 +72,8 @@ target_link_libraries(maxscale-common
|
|||||||
|
|
||||||
if(WITH_ASAN AND ASAN_FOUND)
|
if(WITH_ASAN AND ASAN_FOUND)
|
||||||
target_link_libraries(maxscale-common ${ASAN_LIBRARIES})
|
target_link_libraries(maxscale-common ${ASAN_LIBRARIES})
|
||||||
|
elseif(WITH_UBSAN AND UBSAN_FOUND)
|
||||||
|
target_link_libraries(maxscale-common ${UBSAN_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_library(HAVE_LIBDL NAMES dl)
|
find_library(HAVE_LIBDL NAMES dl)
|
||||||
|
|||||||
Reference in New Issue
Block a user