mirror of https://github.com/facebook/rocksdb.git
Avoid unsupported attributes when not building with UBSAN
Summary: yiwu-arbug see individual commits. Closes https://github.com/facebook/rocksdb/pull/2318 Differential Revision: D5141520 Pulled By: yiwu-arbug fbshipit-source-id: 7987c92ab4461eef36afce5a133d3a0ee0c96300
This commit is contained in:
parent
5fd04566c4
commit
103d0692ea
|
@ -195,7 +195,6 @@ endif()
|
||||||
|
|
||||||
option(WITH_ASAN "build with ASAN" OFF)
|
option(WITH_ASAN "build with ASAN" OFF)
|
||||||
if(WITH_ASAN)
|
if(WITH_ASAN)
|
||||||
add_definitions(-DROCKSDB_TSAN_RUN)
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
|
||||||
|
@ -207,7 +206,6 @@ endif()
|
||||||
option(WITH_TSAN "build with TSAN" OFF)
|
option(WITH_TSAN "build with TSAN" OFF)
|
||||||
if(WITH_TSAN)
|
if(WITH_TSAN)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
|
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_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread -fPIC")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread -fPIC")
|
||||||
if(WITH_JEMALLOC)
|
if(WITH_JEMALLOC)
|
||||||
|
@ -217,6 +215,7 @@ endif()
|
||||||
|
|
||||||
option(WITH_UBSAN "build with UBSAN" OFF)
|
option(WITH_UBSAN "build with UBSAN" OFF)
|
||||||
if(WITH_UBSAN)
|
if(WITH_UBSAN)
|
||||||
|
add_definitions(-DROCKSDB_UBSAN_RUN)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -193,8 +193,8 @@ endif
|
||||||
ifdef COMPILE_WITH_TSAN
|
ifdef COMPILE_WITH_TSAN
|
||||||
DISABLE_JEMALLOC=1
|
DISABLE_JEMALLOC=1
|
||||||
EXEC_LDFLAGS += -fsanitize=thread
|
EXEC_LDFLAGS += -fsanitize=thread
|
||||||
PLATFORM_CCFLAGS += -fsanitize=thread -fPIC -DROCKSDB_TSAN_RUN
|
PLATFORM_CCFLAGS += -fsanitize=thread -fPIC
|
||||||
PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC -DROCKSDB_TSAN_RUN
|
PLATFORM_CXXFLAGS += -fsanitize=thread -fPIC
|
||||||
# Turn off -pg when enabling TSAN testing, because that induces
|
# Turn off -pg when enabling TSAN testing, because that induces
|
||||||
# a link failure. TODO: find the root cause
|
# a link failure. TODO: find the root cause
|
||||||
PROFILING_FLAGS =
|
PROFILING_FLAGS =
|
||||||
|
@ -211,8 +211,8 @@ endif
|
||||||
ifdef COMPILE_WITH_UBSAN
|
ifdef COMPILE_WITH_UBSAN
|
||||||
DISABLE_JEMALLOC=1
|
DISABLE_JEMALLOC=1
|
||||||
EXEC_LDFLAGS += -fsanitize=undefined
|
EXEC_LDFLAGS += -fsanitize=undefined
|
||||||
PLATFORM_CCFLAGS += -fsanitize=undefined
|
PLATFORM_CCFLAGS += -fsanitize=undefined -DROCKSDB_UBSAN_RUN
|
||||||
PLATFORM_CXXFLAGS += -fsanitize=undefined
|
PLATFORM_CXXFLAGS += -fsanitize=undefined -DROCKSDB_UBSAN_RUN
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef DISABLE_JEMALLOC
|
ifndef DISABLE_JEMALLOC
|
||||||
|
|
|
@ -49,10 +49,7 @@
|
||||||
#include "util/mutexlock.h"
|
#include "util/mutexlock.h"
|
||||||
|
|
||||||
#include "util/string_util.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"
|
#include "util/sync_point.h"
|
||||||
#endif // !(defined NDEBUG) || !defined(OS_WIN)
|
|
||||||
#include "util/testharness.h"
|
#include "util/testharness.h"
|
||||||
#include "util/testutil.h"
|
#include "util/testutil.h"
|
||||||
#include "utilities/merge_operators.h"
|
#include "utilities/merge_operators.h"
|
||||||
|
|
|
@ -230,10 +230,12 @@ class FaultInjectionTest : public testing::Test,
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9)
|
#ifdef ROCKSDB_UBSAN_RUN
|
||||||
__attribute__((__no_sanitize__("undefined")))
|
#if defined(__clang__)
|
||||||
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
__attribute__((__no_sanitize__("shift"), no_sanitize("signed-integer-overflow")))
|
||||||
|
#elif defined(__GNUC__)
|
||||||
__attribute__((__no_sanitize_undefined__))
|
__attribute__((__no_sanitize_undefined__))
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// Return the ith key
|
// Return the ith key
|
||||||
Slice Key(int i, std::string* storage) const {
|
Slice Key(int i, std::string* storage) const {
|
||||||
|
|
|
@ -354,6 +354,13 @@ inline Slice GetSliceUntil(Slice* slice, char delimiter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
#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) {
|
inline void PutUnaligned(T *memory, const T &value) {
|
||||||
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
|
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
|
||||||
char *nonAlignedMemory = reinterpret_cast<char*>(memory);
|
char *nonAlignedMemory = reinterpret_cast<char*>(memory);
|
||||||
|
@ -364,6 +371,13 @@ inline void PutUnaligned(T *memory, const T &value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
#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) {
|
inline void GetUnaligned(const T *memory, T *value) {
|
||||||
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
|
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
|
||||||
char *nonAlignedMemory = reinterpret_cast<char*>(value);
|
char *nonAlignedMemory = reinterpret_cast<char*>(value);
|
||||||
|
|
|
@ -15,12 +15,13 @@
|
||||||
|
|
||||||
namespace rocksdb {
|
namespace rocksdb {
|
||||||
|
|
||||||
// This function may intentionally do a left shift on a -ve number
|
#ifdef ROCKSDB_UBSAN_RUN
|
||||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9)
|
#if defined(__clang__)
|
||||||
__attribute__((__no_sanitize__("undefined")))
|
__attribute__((__no_sanitize__("shift")))
|
||||||
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
#elif defined(__GNUC__)
|
||||||
__attribute__((__no_sanitize_undefined__))
|
__attribute__((__no_sanitize_undefined__))
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
uint32_t Hash(const char* data, size_t n, uint32_t seed) {
|
uint32_t Hash(const char* data, size_t n, uint32_t seed) {
|
||||||
// Similar to murmur hash
|
// Similar to murmur hash
|
||||||
const uint32_t m = 0xc6a4a793;
|
const uint32_t m = 0xc6a4a793;
|
||||||
|
|
|
@ -46,11 +46,13 @@ ColBufEncoder *ColBufEncoder::NewColBufEncoder(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 9)
|
#ifdef ROCKSDB_UBSAN_RUN
|
||||||
__attribute__((__no_sanitize__("undefined")))
|
#if defined(__clang__)
|
||||||
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
__attribute__((__no_sanitize__("shift")))
|
||||||
|
#elif defined(__GNUC__)
|
||||||
__attribute__((__no_sanitize_undefined__))
|
__attribute__((__no_sanitize_undefined__))
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
size_t FixedLengthColBufEncoder::Append(const char *buf) {
|
size_t FixedLengthColBufEncoder::Append(const char *buf) {
|
||||||
if (nullable_) {
|
if (nullable_) {
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
|
|
Loading…
Reference in New Issue