1#!/bin/sh 2# 3# Creates fuzzer builds of various kinds 4# - oss-fuzz emulated mode (makes sure a simulated invocation by oss-fuzz works) 5# - libFuzzer build (you will need clang) 6# - afl build (you will need afl) 7# 8# 9# Copyright (c) 2019 Paul Dreik 10# 11# For the license information refer to format.h. 12 13set -e 14me=$(basename $0) 15root=$(readlink -f "$(dirname "$0")/../..") 16 17 18echo $me: root=$root 19 20here=$(pwd) 21 22CXXFLAGSALL="-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g" 23CMAKEFLAGSALL="$root -GNinja -DCMAKE_BUILD_TYPE=Debug -DFMT_DOC=Off -DFMT_TEST=Off -DFMT_FUZZ=On -DCMAKE_CXX_STANDARD=17" 24 25# For performance analysis of the fuzzers. 26builddir=$here/build-fuzzers-perfanalysis 27mkdir -p $builddir 28cd $builddir 29CXX="ccache g++" CXXFLAGS="$CXXFLAGSALL -g" cmake \ 30$CMAKEFLAGSALL \ 31-DFMT_FUZZ_LINKMAIN=On \ 32-DCMAKE_BUILD_TYPE=Release 33 34cmake --build $builddir 35 36# Builds the fuzzers as oss-fuzz does. 37builddir=$here/build-fuzzers-ossfuzz 38mkdir -p $builddir 39cd $builddir 40CXX="clang++" \ 41CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link" cmake \ 42cmake $CMAKEFLAGSALL \ 43-DFMT_FUZZ_LINKMAIN=Off \ 44-DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" 45 46cmake --build $builddir 47 48 49# Builds fuzzers for local fuzzing with libfuzzer with asan+usan. 50builddir=$here/build-fuzzers-libfuzzer 51mkdir -p $builddir 52cd $builddir 53CXX="clang++" \ 54CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link,address,undefined" cmake \ 55cmake $CMAKEFLAGSALL \ 56-DFMT_FUZZ_LINKMAIN=Off \ 57-DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" 58 59cmake --build $builddir 60 61# Builds a fast fuzzer for making coverage fast. 62builddir=$here/build-fuzzers-fast 63mkdir -p $builddir 64cd $builddir 65CXX="clang++" \ 66CXXFLAGS="$CXXFLAGSALL -fsanitize=fuzzer-no-link -O3" cmake \ 67cmake $CMAKEFLAGSALL \ 68-DFMT_FUZZ_LINKMAIN=Off \ 69-DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" \ 70 -DCMAKE_BUILD_TYPE=Release 71 72cmake --build $builddir 73 74 75# Builds fuzzers for local fuzzing with afl. 76builddir=$here/build-fuzzers-afl 77mkdir -p $builddir 78cd $builddir 79CXX="afl-g++" \ 80CXXFLAGS="$CXXFLAGSALL -fsanitize=address,undefined" \ 81cmake $CMAKEFLAGSALL \ 82-DFMT_FUZZ_LINKMAIN=On 83 84cmake --build $builddir 85 86 87echo $me: all good 88 89