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

AFL capability added to common.sh, corresponding changes to build.sh for LCMS and re2 #14

Merged
merged 8 commits into from
Jul 13, 2017
35 changes: 34 additions & 1 deletion common.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#!/bin/bash
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2017 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");

# Don't allow to call these scripts from their directories.
[ -e $(basename $0) ] && echo "PLEASE USE THIS SCRIPT FROM ANOTHER DIR" && exit 1

# Ensure that argument, if present, is either "libfuzzer" or "afl"
FUZZER=${1-"libfuzzer"}
[[ $FUZZER != "libfuzzer" ]] && [[ $FUZZER != "afl" ]] && echo "USAGE: If present, argument \$1 should be either 'afl' or 'libfuzzer'" && exit 1
echo "Building with $FUZZER"

SCRIPT_DIR=$(dirname $0)
EXECUTABLE_NAME_BASE=$(basename $SCRIPT_DIR)
LIBFUZZER_SRC=$(dirname $(dirname $SCRIPT_DIR))/Fuzzer
AFL_DRIVER=$LIBFUZZER_SRC/afl/afl_driver.cpp
AFL_SRC=$(dirname $(dirname $SCRIPT_DIR))/AFL
FUZZ_CXXFLAGS="-O2 -fno-omit-frame-pointer -g -fsanitize=address -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-gep,trace-div"
CORPUS=CORPUS-$EXECUTABLE_NAME_BASE
JOBS=8

CC=${CC:-"clang"}
CXX=${CXX:-"clang++"}
CFLAGS=${CFLAGS:-"$FUZZ_CXXFLAGS"}
CXXFLAGS=${CXXFLAGS:-"$FUZZ_CXXFLAGS"}
LIB_FUZZING_ENGINE="libFuzzingEngine.a"

# Additional build flags (e.g. for libFuzzer) can be passed to build.sh as $UNIQUE_BUILD

get_git_revision() {
GIT_REPO="$1"
GIT_REVISION="$2"
Expand All @@ -32,6 +48,23 @@ get_svn_revision() {
[ ! -e $TO_DIR ] && svn co -r$SVN_REVISION $SVN_REPO $TO_DIR
}

build_afl() {
$CC $CFLAGS -c -w $AFL_SRC/llvm_mode/afl-llvm-rt.o.c
$CXX $CXXFLAGS -std=c++11 -O2 -c $LIBFUZZER_SRC/afl/*.cpp -I$LIBFUZZER_SRC
ar r $LIB_FUZZING_ENGINE *.o
rm *.o

BINARY_NAME_EXT="_${FUZZER}"
}

build_libfuzzer() {
$LIBFUZZER_SRC/build.sh
#mv libFuzzer.a $LIB_FUZZING_ENGINE # more consistent style, breaks backwards compatibility
LIB_FUZZING_ENGINE="libFuzzer.a"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe don't do this, instead change all the build.sh files to use $LIB_FUZZING_ENGINE

rm *.o
}

build_fuzzer() {
LIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE}_${FUZZER}
build_${FUZZER}
}
11 changes: 6 additions & 5 deletions lcms-2017-03-21/build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/bash
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2017 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
. $(dirname $0)/../common.sh

. $(dirname $0)/../common.sh $1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove $1
instead, use env var, e.g. FUZZING_ENGINE
Default (empty) means libFuzzer


build_lib() {
rm -rf BUILD
cp -rf SRC BUILD
(cd BUILD && ./autogen.sh && CXX="clang++ $FUZZ_CXXFLAGS" CC="clang $FUZZ_CXXFLAGS" CCLD="clang++ $FUZZ_CXXFLAGS" ./configure && make -j $JOBS)
(cd BUILD && ./autogen.sh && ./configure && make -j $JOBS)
}

get_git_revision https://github.com/mm2/Little-CMS.git f9d75ccef0b54c9f4167d95088d4727985133c52 SRC
build_lib
build_libfuzzer
build_fuzzer
set -x
clang++ $SCRIPT_DIR/cms_transform_fuzzer.c -I BUILD/include/ $FUZZ_CXXFLAGS BUILD/src/.libs/liblcms2.a libFuzzer.a -o $EXECUTABLE_NAME_BASE
$CXX $CXXFLAGS ${SCRIPT_DIR}/cms_transform_fuzzer.c -I BUILD/include/ BUILD/src/.libs/liblcms2.a $LIB_FUZZING_ENGINE -o ${EXECUTABLE_NAME_BASE}${BINARY_NAME_EXT}
12 changes: 7 additions & 5 deletions re2-2014-12-09/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash
# Copyright 2016 Google Inc. All Rights Reserved.
# Copyright 2017 Google Inc. All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
. $(dirname $0)/../common.sh

. $(dirname $0)/../common.sh $1

build_lib() {
rm -rf BUILD
cp -rf SRC BUILD
(cd BUILD && make clean && CXX=clang++ CXXFLAGS="$FUZZ_CXXFLAGS" make -j)
(cd BUILD && make clean && make -j)
}

get_git_revision https://github.com/google/re2.git 499ef7eff7455ce9c9fae86111d4a77b6ac335de SRC
build_lib
build_libfuzzer
clang++ -g $SCRIPT_DIR/target.cc -I BUILD BUILD/obj/libre2.a libFuzzer.a $FUZZ_CXXFLAGS -o $EXECUTABLE_NAME_BASE
build_fuzzer
set -x
$CXX $CXXFLAGS ${SCRIPT_DIR}/target.cc -I BUILD/ BUILD/obj/libre2.a -lpthread $LIB_FUZZING_ENGINE -o ${EXECUTABLE_NAME_BASE}${BINARY_NAME_EXT}