Merge #22691 build!: sanitizers for gcc

This commit is contained in:
Justin M. Keyes
2023-03-19 13:42:25 -04:00
committed by GitHub
13 changed files with 48 additions and 31 deletions

View File

@@ -1,3 +0,0 @@
# multiqueue.h pointer arithmetic is not accepted by asan
fun:multiqueue_node_data
fun:tv_dict_watcher_node_data

View File

@@ -200,9 +200,9 @@ endif()
option(ENABLE_GCOV "Enable gcov support" OFF)
if(ENABLE_GCOV)
if(CLANG_TSAN)
if(ENABLE_TSAN)
# GCOV and TSAN results in false data race reports
message(FATAL_ERROR "ENABLE_GCOV cannot be used with CLANG_TSAN")
message(FATAL_ERROR "ENABLE_GCOV cannot be used with ENABLE_TSAN")
endif()
message(STATUS "Enabling gcov support")
target_compile_options(main_lib INTERFACE --coverage)
@@ -378,7 +378,7 @@ else()
target_compile_definitions(nvim PRIVATE $<$<CONFIG:Debug>:NVIM_LOG_DEBUG>)
endif()
if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN)
if(ENABLE_ASAN_UBSAN OR ENABLE_MSAN OR ENABLE_TSAN)
target_compile_definitions(main_lib INTERFACE EXITFREE)
endif()
@@ -791,7 +791,7 @@ set_target_properties(
target_compile_definitions(libnvim PRIVATE MAKE_LIB)
target_link_libraries(libnvim PRIVATE main_lib PUBLIC libuv)
if(CLANG_ASAN_UBSAN)
if(ENABLE_ASAN_UBSAN)
message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
if(CI_BUILD)
# Try to recover from all sanitize issues so we get reports about all failures
@@ -803,10 +803,9 @@ if(CLANG_ASAN_UBSAN)
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-fsanitize=address
-fsanitize=undefined
-fsanitize-blacklist=${PROJECT_SOURCE_DIR}/src/.asan-blacklist)
-fsanitize=undefined)
target_link_libraries(nvim PRIVATE -fsanitize=address -fsanitize=undefined)
elseif(CLANG_MSAN)
elseif(ENABLE_MSAN)
message(STATUS "Enabling Clang memory sanitizer for nvim.")
target_compile_options(nvim PRIVATE
-fsanitize=memory
@@ -814,7 +813,7 @@ elseif(CLANG_MSAN)
-fno-omit-frame-pointer
-fno-optimize-sibling-calls)
target_link_libraries(nvim PRIVATE -fsanitize=memory -fsanitize-memory-track-origins)
elseif(CLANG_TSAN)
elseif(ENABLE_TSAN)
message(STATUS "Enabling Clang thread sanitizer for nvim.")
target_compile_options(nvim PRIVATE -fsanitize=thread -fPIE)
target_link_libraries(nvim PRIVATE -fsanitize=thread)

View File

@@ -60,9 +60,9 @@ Requires clang 3.4 or later, and `llvm-symbolizer` must be in `$PATH`:
Build Nvim with sanitizer instrumentation (choose one):
CC=clang make CMAKE_EXTRA_FLAGS="-DCLANG_ASAN_UBSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DCLANG_MSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DCLANG_TSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_ASAN_UBSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_MSAN=ON"
CC=clang make CMAKE_EXTRA_FLAGS="-DENABLE_TSAN=ON"
Create a directory to store logs:

View File

@@ -518,13 +518,15 @@ static inline bool tv_get_float_chk(const typval_T *const tv, float_T *const ret
static inline DictWatcher *tv_dict_watcher_node_data(QUEUE *q)
REAL_FATTR_NONNULL_ALL REAL_FATTR_NONNULL_RET REAL_FATTR_PURE
REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE;
REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
FUNC_ATTR_NO_SANITIZE_ADDRESS;
/// Compute the `DictWatcher` address from a QUEUE node.
///
/// This only exists for .asan-blacklist (ASAN doesn't handle QUEUE_DATA pointer
/// arithmetic).
static inline DictWatcher *tv_dict_watcher_node_data(QUEUE *q)
FUNC_ATTR_NO_SANITIZE_ADDRESS
{
return QUEUE_DATA(q, DictWatcher, node);
}

View File

@@ -245,6 +245,7 @@ static void multiqueue_push(MultiQueue *this, Event event)
}
static MultiQueueItem *multiqueue_node_data(QUEUE *q)
FUNC_ATTR_NO_SANITIZE_ADDRESS
{
return QUEUE_DATA(q, MultiQueueItem, node);
}

View File

@@ -99,6 +99,10 @@
# undef FUNC_ATTR_NO_SANITIZE_UNDEFINED
#endif
#ifdef FUNC_ATTR_NO_SANITIZE_ADDRESS
# undef FUNC_ATTR_NO_SANITIZE_ADDRESS
#endif
#ifdef FUNC_ATTR_PRINTF
# undef FUNC_ATTR_PRINTF
#endif
@@ -139,6 +143,11 @@
# define REAL_FATTR_NO_SANITIZE_UNDEFINED \
__attribute__((no_sanitize("undefined")))
# endif
# if NVIM_HAS_ATTRIBUTE(no_sanitize_address)
# define REAL_FATTR_NO_SANITIZE_ADDRESS \
__attribute__((no_sanitize_address))
# endif
# endif
// Define attributes that are not defined for this compiler.
@@ -199,6 +208,10 @@
# define REAL_FATTR_NO_SANITIZE_UNDEFINED
# endif
# ifndef REAL_FATTR_NO_SANITIZE_ADDRESS
# define REAL_FATTR_NO_SANITIZE_ADDRESS
# endif
# ifndef REAL_FATTR_PRINTF
# define REAL_FATTR_PRINTF(x, y)
# endif
@@ -233,6 +246,7 @@
# define FUNC_ATTR_NONNULL_RET REAL_FATTR_NONNULL_RET
# define FUNC_ATTR_NORETURN REAL_FATTR_NORETURN
# define FUNC_ATTR_NO_SANITIZE_UNDEFINED REAL_FATTR_NO_SANITIZE_UNDEFINED
# define FUNC_ATTR_NO_SANITIZE_ADDRESS REAL_FATTR_NO_SANITIZE_ADDRESS
# define FUNC_ATTR_PRINTF(x, y) REAL_FATTR_PRINTF(x, y)
#elif !defined(DO_NOT_DEFINE_EMPTY_ATTRIBUTES)
# define FUNC_ATTR_MALLOC
@@ -249,5 +263,6 @@
# define FUNC_ATTR_NONNULL_RET
# define FUNC_ATTR_NORETURN
# define FUNC_ATTR_NO_SANITIZE_UNDEFINED
# define FUNC_ATTR_NO_SANITIZE_ADDRESS
# define FUNC_ATTR_PRINTF(x, y)
#endif

View File

@@ -3504,6 +3504,7 @@ set QUESTION FUNC_ATTR_NONNULL_ARG
set QUESTION FUNC_ATTR_NONNULL_RET
set QUESTION FUNC_ATTR_NORETURN
set QUESTION FUNC_ATTR_NO_SANITIZE_UNDEFINED
set QUESTION FUNC_ATTR_NO_SANITIZE_ADDRESS
set QUESTION FUNC_ATTR_PRINTF
set QUESTION FUNC_ATTR_PURE
set QUESTION FUNC_ATTR_UNUSED