Skip to content

Commit

Permalink
build: add sanitizer support (#446)
Browse files Browse the repository at this point in the history
foreverneverer authored and neverchanje committed Mar 31, 2020
1 parent 216cfeb commit dea79a0
Showing 2 changed files with 29 additions and 1 deletion.
22 changes: 21 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -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 <type> 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"
8 changes: 8 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
@@ -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" ]

0 comments on commit dea79a0

Please sign in to comment.