commit 4ab164af72b65c58a08c9c2e4cea46730242bb29 from: Sergey Bronnikov date: Wed Oct 16 15:42:17 2024 UTC cmake: fix build with GCC's UBSan GNU GCC compiler has UndefinedBehaviour sanitizer support since 4.9.0 [1], but it was unsupported in tarantool's build. The patch fixes a build by GNU GCC with enabled UBSan. 1. https://gcc.gnu.org/gcc-4.9/changes.html NO_CHANGELOG=build NO_DOC=build NO_TEST=build commit - f75c5d58b6ec7eb52d53fae387bfacfb4793d727 commit + 4ab164af72b65c58a08c9c2e4cea46730242bb29 blob - b3d445818c86fbb0039acfea87d6f3e1f253f024 blob + 590153b2ffc2eca0676a2d1aef49ed57e7f7c9f0 --- cmake/compiler.cmake +++ cmake/compiler.cmake @@ -224,8 +224,11 @@ macro(enable_tnt_compile_flags) endif() if (ENABLE_UB_SANITIZER) - if (NOT CMAKE_COMPILER_IS_CLANG) - message(FATAL_ERROR "Undefined behaviour sanitizer only available for clang") + # UndefinedBehaviourSanitizer has been added to GCC since + # version 4.9.0, see https://gcc.gnu.org/gcc-4.9/changes.html. + if (CMAKE_COMPILER_IS_GNUCC AND + CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9.0) + message(FATAL_ERROR "UndefinedBehaviourSanitizer is unsupported in GCC ${CMAKE_C_COMPILER_VERSION}") endif() # Use all needed checks from the UndefinedBehaviorSanitizer # documentation: @@ -262,9 +265,16 @@ macro(enable_tnt_compile_flags) returns-nonnull-attribute nullability-assign nullability-return - # Not interested in function type mismatch errors. - function ) + # GCC has no "function" UB check. See details here: + # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dundefined + if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU") + string(JOIN "," UBSAN_IGNORE_OPTIONS + ${UBSAN_IGNORE_OPTIONS} + # Not interested in function type mismatch errors. + function + ) + endif() # XXX: To get nicer stack traces in error messages. set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer") # Enable UndefinedBehaviorSanitizer support.