support asan and fix several memory bug
This commit is contained in:
@ -21,6 +21,11 @@ if(WITH_OSS)
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WITH_OSS")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WITH_OSS")
|
||||||
endif()
|
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 BINARY dir " ${PROJECT_BINARY_DIR})
|
||||||
message(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_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(BUILD_OPT "${BUILD_OPT} -I${DEVTOOLS_DIR}/lib/clang/11.0.1/include")
|
||||||
set(LD_OPT "${LD_OPT} -Wl,-z,noexecstack")
|
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)
|
if (OB_USE_LLVM_LIBTOOLS)
|
||||||
set(LD_OPT "${LD_OPT} -fuse-ld=${LD_BIN}")
|
set(LD_OPT "${LD_OPT} -fuse-ld=${LD_BIN}")
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
12
deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp
vendored
12
deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp
vendored
@ -54,8 +54,8 @@ void* ObMallocAllocator::alloc(const int64_t size)
|
|||||||
|
|
||||||
void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAttr& attr)
|
void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAttr& attr)
|
||||||
{
|
{
|
||||||
#if PERF_MODE
|
#ifdef OB_USE_ASAN
|
||||||
UNUSED(_attr);
|
UNUSED(attr);
|
||||||
return ::malloc(size);
|
return ::malloc(size);
|
||||||
#else
|
#else
|
||||||
int ret = E(EventTable::EN_4) OB_SUCCESS;
|
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;
|
return ptr;
|
||||||
#endif // PERF_MODE
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const oceanbase::lib::ObMemAttr& attr)
|
void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const oceanbase::lib::ObMemAttr& attr)
|
||||||
{
|
{
|
||||||
#if PERF_MODE
|
#ifdef OB_USE_ASAN
|
||||||
UNUSED(attr);
|
UNUSED(attr);
|
||||||
return ::realloc(const_cast<void*>(ptr), size);
|
return ::realloc(const_cast<void*>(ptr), size);
|
||||||
#else
|
#else
|
||||||
@ -157,12 +157,12 @@ void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const ocea
|
|||||||
}
|
}
|
||||||
return nptr;
|
return nptr;
|
||||||
;
|
;
|
||||||
#endif // PERF_MODE
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObMallocAllocator::free(void* ptr)
|
void ObMallocAllocator::free(void* ptr)
|
||||||
{
|
{
|
||||||
#if PERF_MODE
|
#ifdef OB_USE_ASAN
|
||||||
::free(ptr);
|
::free(ptr);
|
||||||
#else
|
#else
|
||||||
// directly free object instead of using tenant allocator.
|
// directly free object instead of using tenant allocator.
|
||||||
|
|||||||
11
deps/oblib/src/lib/resource/achunk_mgr.h
vendored
11
deps/oblib/src/lib/resource/achunk_mgr.h
vendored
@ -46,13 +46,22 @@ public:
|
|||||||
pushes_(0),
|
pushes_(0),
|
||||||
pops_(0),
|
pops_(0),
|
||||||
with_mutex_(with_mutex)
|
with_mutex_(with_mutex)
|
||||||
{}
|
{
|
||||||
|
#ifdef OB_USE_ASAN
|
||||||
|
max_chunk_cache_cnt_ = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
virtual ~AChunkList()
|
virtual ~AChunkList()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void set_max_chunk_cache_cnt(const int cnt)
|
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;
|
max_chunk_cache_cnt_ = cnt;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool push(AChunk* chunk)
|
inline bool push(AChunk* chunk)
|
||||||
|
|||||||
@ -25,16 +25,19 @@ namespace oceanbase {
|
|||||||
namespace common {
|
namespace common {
|
||||||
static const int SIG_SET[] = {SIGABRT, SIGBUS, SIGFPE, SIGSEGV, SIGURG};
|
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) {
|
if (tl_handler != nullptr) {
|
||||||
tl_handler(sig, s, p);
|
tl_handler(sig, s, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int install_ob_signal_handler()
|
int install_ob_signal_handler()
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
|
#ifndef OB_USE_ASAN
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER | SA_ONSTACK;
|
sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_NODEFER | SA_ONSTACK;
|
||||||
sa.sa_sigaction = handler;
|
sa.sa_sigaction = handler;
|
||||||
@ -44,6 +47,7 @@ int install_ob_signal_handler()
|
|||||||
ret = OB_INIT_FAIL;
|
ret = OB_INIT_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
deps/oblib/src/lib/utility/utility.cpp
vendored
2
deps/oblib/src/lib/utility/utility.cpp
vendored
@ -1103,7 +1103,7 @@ const char* get_default_if()
|
|||||||
if (file) {
|
if (file) {
|
||||||
char dest[16] = {};
|
char dest[16] = {};
|
||||||
char gw[16] = {};
|
char gw[16] = {};
|
||||||
char remain[1024] = {};
|
char remain[1024 + 1] = {};
|
||||||
if (1 == fscanf(file, "%1024[^\n]\n", remain)) {
|
if (1 == fscanf(file, "%1024[^\n]\n", remain)) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int r = fscanf(file, "%127s\t%15s\t%15s\t%1023[^\n]\n", ifname, dest, gw, remain);
|
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()
|
endif()
|
||||||
|
|
||||||
add_executable(observer)
|
add_executable(observer)
|
||||||
|
|
||||||
|
if (NOT OB_USE_ASAN)
|
||||||
|
set(link_malloc_hook malloc_hook)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(observer
|
target_link_libraries(observer
|
||||||
PRIVATE
|
PRIVATE
|
||||||
ob_main
|
ob_main
|
||||||
oceanbase_static
|
oceanbase_static
|
||||||
-static-libgcc
|
-static-libgcc
|
||||||
-static-libstdc++
|
-static-libstdc++
|
||||||
malloc_hook
|
${link_malloc_hook}
|
||||||
${LGPL_DEPS}
|
${LGPL_DEPS}
|
||||||
)
|
)
|
||||||
execute_process(
|
execute_process(
|
||||||
|
|||||||
@ -361,7 +361,9 @@ static void print_all_limits()
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
#ifndef OB_USE_ASAN
|
||||||
init_malloc_hook();
|
init_malloc_hook();
|
||||||
|
#endif
|
||||||
int64_t memory_used = get_virtual_memory_used();
|
int64_t memory_used = get_virtual_memory_used();
|
||||||
/**
|
/**
|
||||||
signal handler stack
|
signal handler stack
|
||||||
|
|||||||
@ -958,16 +958,6 @@ void ObTableRpcProcessor<T>::set_req_has_wokenup()
|
|||||||
RpcProcessor::req_has_wokenup_ = true;
|
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>
|
template<class T>
|
||||||
void ObTableRpcProcessor<T>::save_request_string()
|
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 */
|
#endif /* _OB_TABLE_RPC_PROCESSOR_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user