diff --git a/CMakeLists.txt b/CMakeLists.txt index 864a2abc12..4b41c33b54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,11 @@ if(WITH_OSS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WITH_OSS") endif() +if(OB_USE_ASAN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DOB_USE_ASAN") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOB_USE_ASAN") +endif() + message(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR}) message(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_DIR}) diff --git a/cmake/Env.cmake b/cmake/Env.cmake index 9769f19f67..9792a94fa4 100644 --- a/cmake/Env.cmake +++ b/cmake/Env.cmake @@ -60,6 +60,12 @@ if (OB_USE_CLANG) set(BUILD_OPT "${BUILD_OPT} -I${DEVTOOLS_DIR}/lib/clang/11.0.1/include") set(LD_OPT "${LD_OPT} -Wl,-z,noexecstack") + if (OB_USE_ASAN) + ob_define(CMAKE_ASAN_FLAG "-fstack-protector-strong -fsanitize=address -fno-optimize-sibling-calls") + set(BUILD_OPT "${BUILD_OPT} ${CMAKE_ASAN_FLAG} ") + endif() + + if (OB_USE_LLVM_LIBTOOLS) set(LD_OPT "${LD_OPT} -fuse-ld=${LD_BIN}") endif() diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp index 2afe961d8a..d9ae19b307 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp @@ -54,8 +54,8 @@ void* ObMallocAllocator::alloc(const int64_t size) void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAttr& attr) { -#if PERF_MODE - UNUSED(_attr); +#ifdef OB_USE_ASAN + UNUSED(attr); return ::malloc(size); #else int ret = E(EventTable::EN_4) OB_SUCCESS; @@ -111,12 +111,12 @@ void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt } return ptr; -#endif // PERF_MODE +#endif } void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const oceanbase::lib::ObMemAttr& attr) { -#if PERF_MODE +#ifdef OB_USE_ASAN UNUSED(attr); return ::realloc(const_cast(ptr), size); #else @@ -157,12 +157,12 @@ void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const ocea } return nptr; ; -#endif // PERF_MODE +#endif } void ObMallocAllocator::free(void* ptr) { -#if PERF_MODE +#ifdef OB_USE_ASAN ::free(ptr); #else // directly free object instead of using tenant allocator. diff --git a/deps/oblib/src/lib/resource/achunk_mgr.h b/deps/oblib/src/lib/resource/achunk_mgr.h index 8922edcec5..ddf1c799fa 100644 --- a/deps/oblib/src/lib/resource/achunk_mgr.h +++ b/deps/oblib/src/lib/resource/achunk_mgr.h @@ -46,13 +46,22 @@ public: pushes_(0), pops_(0), with_mutex_(with_mutex) - {} + { +#ifdef OB_USE_ASAN + max_chunk_cache_cnt_ = 0; +#endif + } virtual ~AChunkList() {} void set_max_chunk_cache_cnt(const int cnt) { +#ifdef OB_USE_ASAN + UNUSED(cnt); + max_chunk_cache_cnt_ = 0; +#else max_chunk_cache_cnt_ = cnt; +#endif } inline bool push(AChunk* chunk) diff --git a/deps/oblib/src/lib/signal/ob_signal_handlers.cpp b/deps/oblib/src/lib/signal/ob_signal_handlers.cpp index b223c3ae89..6ec8fbffad 100644 --- a/deps/oblib/src/lib/signal/ob_signal_handlers.cpp +++ b/deps/oblib/src/lib/signal/ob_signal_handlers.cpp @@ -25,16 +25,19 @@ namespace oceanbase { namespace common { static const int SIG_SET[] = {SIGABRT, SIGBUS, SIGFPE, SIGSEGV, SIGURG}; -static inline void handler(int sig, siginfo_t* s, void* p) +#ifndef OB_USE_ASAN +static inline void handler(int sig, siginfo_t *s, void *p) { if (tl_handler != nullptr) { tl_handler(sig, s, p); } } +#endif int install_ob_signal_handler() { int ret = OB_SUCCESS; +#ifndef OB_USE_ASAN struct sigaction sa; sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER | SA_ONSTACK; sa.sa_sigaction = handler; @@ -44,6 +47,7 @@ int install_ob_signal_handler() ret = OB_INIT_FAIL; } } +#endif return ret; } diff --git a/deps/oblib/src/lib/utility/utility.cpp b/deps/oblib/src/lib/utility/utility.cpp index d4d016b0f2..8633a892d8 100644 --- a/deps/oblib/src/lib/utility/utility.cpp +++ b/deps/oblib/src/lib/utility/utility.cpp @@ -1103,7 +1103,7 @@ const char* get_default_if() if (file) { char dest[16] = {}; char gw[16] = {}; - char remain[1024] = {}; + char remain[1024 + 1] = {}; if (1 == fscanf(file, "%1024[^\n]\n", remain)) { while (1) { int r = fscanf(file, "%127s\t%15s\t%15s\t%1023[^\n]\n", ifname, dest, gw, remain); diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt index de169fa551..47f87f93cf 100644 --- a/src/observer/CMakeLists.txt +++ b/src/observer/CMakeLists.txt @@ -320,13 +320,18 @@ if (OB_STATIC_LINK_LGPL_DEPS) endif() add_executable(observer) + +if (NOT OB_USE_ASAN) + set(link_malloc_hook malloc_hook) +endif() + target_link_libraries(observer PRIVATE ob_main oceanbase_static -static-libgcc -static-libstdc++ - malloc_hook + ${link_malloc_hook} ${LGPL_DEPS} ) execute_process( diff --git a/src/observer/main.cpp b/src/observer/main.cpp index ea13cb19f3..4c7b700d6d 100644 --- a/src/observer/main.cpp +++ b/src/observer/main.cpp @@ -361,7 +361,9 @@ static void print_all_limits() int main(int argc, char* argv[]) { +#ifndef OB_USE_ASAN init_malloc_hook(); +#endif int64_t memory_used = get_virtual_memory_used(); /** signal handler stack diff --git a/src/observer/table/ob_table_rpc_processor.cpp b/src/observer/table/ob_table_rpc_processor.cpp index d028705103..90a5033e43 100644 --- a/src/observer/table/ob_table_rpc_processor.cpp +++ b/src/observer/table/ob_table_rpc_processor.cpp @@ -958,16 +958,6 @@ void ObTableRpcProcessor::set_req_has_wokenup() RpcProcessor::req_has_wokenup_ = true; } -template -int64_t ObTableRpcProcessor::get_timeout_ts() const -{ - int64_t ts = 0; - if (NULL != RpcProcessor::rpc_pkt_) { - ts = RpcProcessor::get_receive_timestamp() + RpcProcessor::rpc_pkt_->get_timeout(); - } - return ts; -} - template void ObTableRpcProcessor::save_request_string() { diff --git a/src/observer/table/ob_table_rpc_processor.h b/src/observer/table/ob_table_rpc_processor.h index 593cbb1f0e..0120f0857d 100644 --- a/src/observer/table/ob_table_rpc_processor.h +++ b/src/observer/table/ob_table_rpc_processor.h @@ -214,7 +214,18 @@ protected: }; -} // end namespace observer -} // end namespace oceanbase + +template +int64_t ObTableRpcProcessor::get_timeout_ts() const +{ + int64_t ts = 0; + if (NULL != RpcProcessor::rpc_pkt_) { + ts = RpcProcessor::get_receive_timestamp() + RpcProcessor::rpc_pkt_->get_timeout(); + } + return ts; +} + +} // end namespace observer +} // end namespace oceanbase #endif /* _OB_TABLE_RPC_PROCESSOR_H */