diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-03-19 13:42:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-19 13:42:25 -0400 |
commit | 5726f33e8caaa5967c4ae93972a9eaec0b9c0c82 (patch) | |
tree | 91c3f64e2a1355a1ea1bb9c90d8c31b90bbf9092 /src | |
parent | 8786b2066d39e45295eacfe7b10263af4a330f2e (diff) | |
parent | 17ce634b8f44e218270ee472599edf4cf3ba0fac (diff) | |
download | rneovim-5726f33e8caaa5967c4ae93972a9eaec0b9c0c82.tar.gz rneovim-5726f33e8caaa5967c4ae93972a9eaec0b9c0c82.tar.bz2 rneovim-5726f33e8caaa5967c4ae93972a9eaec0b9c0c82.zip |
Merge #22691 build!: sanitizers for gcc
Diffstat (limited to 'src')
-rw-r--r-- | src/.asan-blacklist | 3 | ||||
-rwxr-xr-x | src/nvim/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/nvim/README.md | 6 | ||||
-rw-r--r-- | src/nvim/eval/typval.h | 4 | ||||
-rw-r--r-- | src/nvim/event/multiqueue.c | 1 | ||||
-rw-r--r-- | src/nvim/func_attr.h | 15 | ||||
-rw-r--r-- | src/uncrustify.cfg | 1 |
7 files changed, 30 insertions, 15 deletions
diff --git a/src/.asan-blacklist b/src/.asan-blacklist deleted file mode 100644 index 928d81bd5a..0000000000 --- a/src/.asan-blacklist +++ /dev/null @@ -1,3 +0,0 @@ -# multiqueue.h pointer arithmetic is not accepted by asan -fun:multiqueue_node_data -fun:tv_dict_watcher_node_data diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 9b42a442a1..2117bc375c 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -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) diff --git a/src/nvim/README.md b/src/nvim/README.md index 5a6d63c662..69d5939c70 100644 --- a/src/nvim/README.md +++ b/src/nvim/README.md @@ -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: diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h index 4a2654f03e..84e4067f9d 100644 --- a/src/nvim/eval/typval.h +++ b/src/nvim/eval/typval.h @@ -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); } diff --git a/src/nvim/event/multiqueue.c b/src/nvim/event/multiqueue.c index e05084b656..8f8a36eff9 100644 --- a/src/nvim/event/multiqueue.c +++ b/src/nvim/event/multiqueue.c @@ -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); } diff --git a/src/nvim/func_attr.h b/src/nvim/func_attr.h index 6c049df6ff..4b434f6771 100644 --- a/src/nvim/func_attr.h +++ b/src/nvim/func_attr.h @@ -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 diff --git a/src/uncrustify.cfg b/src/uncrustify.cfg index f9e6617d40..9c6b6bac6c 100644 --- a/src/uncrustify.cfg +++ b/src/uncrustify.cfg @@ -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 |