Skip to content
Snippets Groups Projects
Commit e13c7ed2 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Sergey Kaplun
Browse files

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

(cherry picked from commit 511e0f50e4b817d576ef4001611fba718ef1bdae)
parent 2f28137b
No related branches found
No related tags found
No related merge requests found
...@@ -234,8 +234,11 @@ macro(enable_tnt_compile_flags) ...@@ -234,8 +234,11 @@ macro(enable_tnt_compile_flags)
endif() endif()
if (ENABLE_UB_SANITIZER) if (ENABLE_UB_SANITIZER)
if (NOT CMAKE_COMPILER_IS_CLANG) # UndefinedBehaviourSanitizer has been added to GCC since
message(FATAL_ERROR "Undefined behaviour sanitizer only available for clang") # 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() endif()
# Use all needed checks from the UndefinedBehaviorSanitizer # Use all needed checks from the UndefinedBehaviorSanitizer
# documentation: # documentation:
...@@ -255,9 +258,16 @@ macro(enable_tnt_compile_flags) ...@@ -255,9 +258,16 @@ macro(enable_tnt_compile_flags)
# "UBSan: check nonnull-attribute is globally suppressed", # "UBSan: check nonnull-attribute is globally suppressed",
# https://github.com/tarantool/tarantool/issues/10740 # https://github.com/tarantool/tarantool/issues/10740
nonnull-attribute nonnull-attribute
# 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. # XXX: To get nicer stack traces in error messages.
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer") set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer")
# Enable UndefinedBehaviorSanitizer support. # Enable UndefinedBehaviorSanitizer support.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment