From dea79a07e1d54a60ed1a0cbb98b83cbffc44d550 Mon Sep 17 00:00:00 2001 From: Shuo Date: Fri, 20 Dec 2019 10:37:53 +0800 Subject: [PATCH] build: add sanitizer support (#446) --- run.sh | 22 +++++++++++++++++++++- src/build.sh | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 64e4669ffd..ed5e7047d1 100755 --- a/run.sh +++ b/run.sh @@ -71,10 +71,16 @@ function usage_build() echo " -v|--verbose build in verbose mode, default no" echo " --disable_gperf build without gperftools, this flag is mainly used" echo " to enable valgrind memcheck, default no" + echo " --sanitizer build with sanitizer to check potential problems, + type: address|leak|thread|undefined" echo " --skip_thirdparty whether to skip building thirdparties, default no" } function run_build() { + # Note(jiashuo1): No "memory" check mode, because MemorySanitizer is only available in Clang for Linux x86_64 targets + # # https://www.jetbrains.com/help/clion/google-sanitizers.html + SANITIZERS=("address" "leak" "thread" "undefined") + C_COMPILER="gcc" CXX_COMPILER="g++" BUILD_TYPE="release" @@ -88,6 +94,7 @@ function run_build() RUN_VERBOSE=NO DISABLE_GPERF=NO SKIP_THIRDPARTY=NO + SANITIZER="" TEST_MODULE="" while [[ $# > 0 ]]; do key="$1" @@ -134,6 +141,16 @@ function run_build() --enable_gcov) ENABLE_GCOV=YES ;; + --sanitizer) + IS_SANITIZERS=`echo ${SANITIZERS[@]} | grep -w $2` + if [[ -z ${IS_SANITIZERS} ]]; then + echo "ERROR: unknown sanitizer type \"$2\"" + usage_build + exit 1 + fi + SANITIZER="$2" + shift + ;; -v|--verbose) RUN_VERBOSE=YES ;; @@ -200,6 +217,9 @@ function run_build() if [ "$SKIP_THIRDPARTY" == "YES" ]; then OPT="$OPT --skip_thirdparty" fi + if [ ! -z $SANITIZER ]; then + OPT="$OPT --sanitizer $SANITIZER" + fi ./run.sh build $OPT --notest if [ $? -ne 0 ]; then echo "ERROR: build rdsn failed" @@ -283,7 +303,7 @@ function run_build() cd $ROOT/src C_COMPILER="$C_COMPILER" CXX_COMPILER="$CXX_COMPILER" BUILD_TYPE="$BUILD_TYPE" \ CLEAR="$CLEAR" PART_CLEAR="$PART_CLEAR" JOB_NUM="$JOB_NUM" \ - BOOST_DIR="$BOOST_DIR" WARNING_ALL="$WARNING_ALL" ENABLE_GCOV="$ENABLE_GCOV" \ + BOOST_DIR="$BOOST_DIR" WARNING_ALL="$WARNING_ALL" ENABLE_GCOV="$ENABLE_GCOV" SANITIZER="$SANITIZER"\ RUN_VERBOSE="$RUN_VERBOSE" TEST_MODULE="$TEST_MODULE" DISABLE_GPERF="$DISABLE_GPERF" ./build.sh if [ $? -ne 0 ]; then echo "ERROR: build pegasus failed" diff --git a/src/build.sh b/src/build.sh index e86ff040e0..f7b3dbdafe 100755 --- a/src/build.sh +++ b/src/build.sh @@ -79,6 +79,14 @@ else echo "ENABLE_GCOV=NO" fi +if [ ! -z "$SANITIZER" ] +then + echo "SANITIZER=$SANITIZER" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DSANITIZER=$SANITIZER" +else + echo "Build without sanitizer" +fi + # valgrind can not work together with gpertools # you may want to use this option when you want to run valgrind if [ "$DISABLE_GPERF" == "YES" ]