Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add sanitizer support #446

Merged
merged 7 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -88,6 +94,7 @@ function run_build()
RUN_VERBOSE=NO
DISABLE_GPERF=NO
SKIP_THIRDPARTY=NO
SANITIZER=""
TEST_MODULE=""
while [[ $# > 0 ]]; do
key="$1"
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down