diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b664c8a0..3017ba4df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ find_package(GSSAPI) find_package(SQLite) find_package(ASAN) find_package(TSAN) +find_package(UBSAN) # Build PCRE2 so we always know the version # 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) set(CMAKE_C_FLAGS "${CMAKE_C_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() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -D_GNU_SOURCE=1 ${FLAGS}") diff --git a/cmake/FindUBSAN.cmake b/cmake/FindUBSAN.cmake new file mode 100644 index 000000000..f0afc71c7 --- /dev/null +++ b/cmake/FindUBSAN.cmake @@ -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() diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 9a4e6f2f7..8f3d83614 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -72,6 +72,8 @@ target_link_libraries(maxscale-common if(WITH_ASAN AND ASAN_FOUND) target_link_libraries(maxscale-common ${ASAN_LIBRARIES}) +elseif(WITH_UBSAN AND UBSAN_FOUND) + target_link_libraries(maxscale-common ${UBSAN_LIBRARIES}) endif() find_library(HAVE_LIBDL NAMES dl)