提交 137a8f1f 编写于 作者: X xuhuleon 提交者: wangzelin.wzl

support asan and fix several memory bug

上级 e4b3157f
......@@ -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})
......
......@@ -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()
......
......@@ -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<void*>(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.
......
......@@ -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)
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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(
......
......@@ -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
......
......@@ -958,16 +958,6 @@ void ObTableRpcProcessor<T>::set_req_has_wokenup()
RpcProcessor::req_has_wokenup_ = true;
}
template<class T>
int64_t ObTableRpcProcessor<T>::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<class T>
void ObTableRpcProcessor<T>::save_request_string()
{
......
......@@ -214,7 +214,18 @@ protected:
};
} // end namespace observer
} // end namespace oceanbase
template<class T>
int64_t ObTableRpcProcessor<T>::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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册