From dc3de5dae074a3ef58ba1919299b3ebddddf40e3 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 9 Jun 2021 06:51:29 +0800 Subject: [PATCH] Feature/sangshuduo/td 4198 support address sanitizer (#6419) * cherry pick from develop branch. * cherry pick from develop branch. * add static lib link. --- cmake/define.inc | 24 ++++++++++++++++++------ cmake/input.inc | 5 +++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmake/define.inc b/cmake/define.inc index e825dce024..da80baabbb 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -117,10 +117,14 @@ IF (TD_LINUX) ADD_DEFINITIONS(-D_TD_NINGSI_60) MESSAGE(STATUS "set ningsi macro to true") ENDIF () - - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-O3 -Wno-error") - + IF (${COVER} MATCHES "true") MESSAGE(STATUS "Test coverage mode, add extra flags") SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") @@ -139,7 +143,11 @@ IF (TD_DARWIN_64) ADD_DEFINITIONS(-DUSE_LIBICONV) MESSAGE(STATUS "darwin64 is defined") SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") - SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -O0 -g3 -DDEBUG") + ELSE () + SET(DEBUG_FLAGS "-O0 -g3 -DDEBUG") + ENDIF () SET(RELEASE_FLAGS "-Og") INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) @@ -157,7 +165,11 @@ IF (TD_WINDOWS) IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") ENDIF () - SET(DEBUG_FLAGS "/Zi /W3 /GL") + IF (TD_MEMORY_SANITIZER) + SET(DEBUG_FLAGS "/fsanitize=address /Zi /W3 /GL") + ELSE () + SET(DEBUG_FLAGS "/Zi /W3 /GL") + ENDIF () SET(RELEASE_FLAGS "/W0 /O3 /GL") ENDIF () @@ -166,7 +178,7 @@ IF (TD_WINDOWS) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/wepoll/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/MsvcLibX/include) -ENDIF () +ENDIF () IF (TD_WINDOWS_64) ADD_DEFINITIONS(-D_M_X64) diff --git a/cmake/input.inc b/cmake/input.inc index 5841a46567..ca1a27ec44 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -78,3 +78,8 @@ SET(TD_BUILD_JDBC TRUE) IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () + +SET(TD_MEMORY_SANITIZER FALSE) +IF (${MEMORY_SANITIZER} MATCHES "true") + SET(TD_MEMORY_SANITIZER TRUE) +ENDIF () -- GitLab