diff --git a/CMakeLists.txt b/CMakeLists.txt index dec306881..4cf55534a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,7 +195,6 @@ endif() option(WITH_ASAN "build with ASAN" OFF) if(WITH_ASAN) - add_definitions(-DROCKSDB_TSAN_RUN) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") @@ -207,7 +206,6 @@ endif() option(WITH_TSAN "build with TSAN" OFF) if(WITH_TSAN) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie") - add_definitions(-DROCKSDB_TSAN_RUN) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fPIC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC") if(WITH_JEMALLOC) @@ -217,6 +215,7 @@ endif() option(WITH_UBSAN "build with UBSAN" OFF) if(WITH_UBSAN) + add_definitions(-DROCKSDB_UBSAN_RUN) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") diff --git a/Makefile b/Makefile index b0108ca23..1b97ce036 100644 --- a/Makefile +++ b/Makefile @@ -193,8 +193,8 @@ endif ifdef COMPILE_WITH_TSAN DISABLE_JEMALLOC=1 EXEC_LDFLAGS += -fsanitize=thread - PLATFORM_CCFLAGS += -fsanitize=thread -fPIC -DROCKSDB_TSAN_RUN - PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC -DROCKSDB_TSAN_RUN + PLATFORM_CCFLAGS += -fsanitize=thread -fPIC + PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC # Turn off -pg when enabling TSAN testing, because that induces # a link failure. TODO: find the root cause PROFILING_FLAGS = @@ -211,8 +211,8 @@ endif ifdef COMPILE_WITH_UBSAN DISABLE_JEMALLOC=1 EXEC_LDFLAGS += -fsanitize=undefined - PLATFORM_CCFLAGS += -fsanitize=undefined - PLATFORM_CXXFLAGS += -fsanitize=undefined + PLATFORM_CCFLAGS += -fsanitize=undefined -DROCKSDB_UBSAN_RUN + PLATFORM_CXXFLAGS += -fsanitize=undefined -DROCKSDB_UBSAN_RUN endif ifndef DISABLE_JEMALLOC diff --git a/db/db_test_util.h b/db/db_test_util.h index f729f50c9..384b19243 100644 --- a/db/db_test_util.h +++ b/db/db_test_util.h @@ -49,10 +49,7 @@ #include "util/mutexlock.h" #include "util/string_util.h" -// SyncPoint is not supported in Released Windows Mode. -#if !(defined NDEBUG) || !defined(OS_WIN) #include "util/sync_point.h" -#endif // !(defined NDEBUG) || !defined(OS_WIN) #include "util/testharness.h" #include "util/testutil.h" #include "utilities/merge_operators.h" diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc index 7fb708aa5..98b9b9b97 100644 --- a/db/fault_injection_test.cc +++ b/db/fault_injection_test.cc @@ -230,10 +230,12 @@ class FaultInjectionTest : public testing::Test, return Status::OK(); } -#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9) -__attribute__((__no_sanitize__("undefined"))) -#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("shift"), no_sanitize("signed-integer-overflow"))) +#elif defined(__GNUC__) __attribute__((__no_sanitize_undefined__)) +#endif #endif // Return the ith key Slice Key(int i, std::string* storage) const { diff --git a/util/coding.h b/util/coding.h index 2cc6f30e7..be33dba8d 100644 --- a/util/coding.h +++ b/util/coding.h @@ -354,6 +354,13 @@ inline Slice GetSliceUntil(Slice* slice, char delimiter) { } template +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("alignment"))) +#elif defined(__GNUC__) +__attribute__((__no_sanitize_undefined__)) +#endif +#endif inline void PutUnaligned(T *memory, const T &value) { #if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED) char *nonAlignedMemory = reinterpret_cast(memory); @@ -364,6 +371,13 @@ inline void PutUnaligned(T *memory, const T &value) { } template +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("alignment"))) +#elif defined(__GNUC__) +__attribute__((__no_sanitize_undefined__)) +#endif +#endif inline void GetUnaligned(const T *memory, T *value) { #if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED) char *nonAlignedMemory = reinterpret_cast(value); diff --git a/util/hash.cc b/util/hash.cc index 02b59952d..5af5c5a1d 100644 --- a/util/hash.cc +++ b/util/hash.cc @@ -15,12 +15,13 @@ namespace rocksdb { -// This function may intentionally do a left shift on a -ve number -#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9) -__attribute__((__no_sanitize__("undefined"))) -#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("shift"))) +#elif defined(__GNUC__) __attribute__((__no_sanitize_undefined__)) #endif +#endif uint32_t Hash(const char* data, size_t n, uint32_t seed) { // Similar to murmur hash const uint32_t m = 0xc6a4a793; diff --git a/utilities/col_buf_encoder.cc b/utilities/col_buf_encoder.cc index 5335498c6..4e5f7e130 100644 --- a/utilities/col_buf_encoder.cc +++ b/utilities/col_buf_encoder.cc @@ -46,11 +46,13 @@ ColBufEncoder *ColBufEncoder::NewColBufEncoder( return nullptr; } -#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9) -__attribute__((__no_sanitize__("undefined"))) -#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) +#ifdef ROCKSDB_UBSAN_RUN +#if defined(__clang__) +__attribute__((__no_sanitize__("shift"))) +#elif defined(__GNUC__) __attribute__((__no_sanitize_undefined__)) #endif +#endif size_t FixedLengthColBufEncoder::Append(const char *buf) { if (nullable_) { if (buf == nullptr) {