1#! /bin/sh 2# 3# SPDX-License-Identifier: BSD-2-Clause 4# 5# Copyright (c) 2018-2023 Gavin D. Howard and contributors. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# * Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation 15# and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28# 29 30# Just print the usage and exit with an error. This can receive a message to 31# print. 32# @param 1 A message to print. 33usage() { 34 if [ $# -eq 1 ]; then 35 printf '%s\n\n' "$1" 36 fi 37 printf 'usage: %s [-a] [afl_compiler]\n' "$0" 38 printf '\n' 39 printf ' If -a is given, then an ASan ready build is created.\n' 40 printf ' Otherwise, a normal fuzz build is created.\n' 41 printf ' The ASan-ready build is for running under\n' 42 printf ' `tests/afl.py --asan`, which checks that there were no\n' 43 printf ' memory errors in any path found by the fuzzer.\n' 44 printf ' It might also be useful to run scripts/randmath.py on an\n' 45 printf ' ASan-ready binary.\n' 46 exit 1 47} 48 49script="$0" 50scriptdir=$(dirname "$script") 51 52. "$scriptdir/functions.sh" 53 54asan=0 55 56# Process command-line arguments. 57while getopts "a" opt; do 58 59 case "$opt" in 60 a) asan=1 ;; 61 ?) usage "Invalid option: $opt" ;; 62 esac 63 64done 65shift $(($OPTIND - 1)) 66 67if [ $# -lt 1 ]; then 68 CC=afl-clang-lto 69else 70 CC="$1" 71fi 72 73# We want this for extra sensitive crashing 74AFL_HARDEN=1 75 76cd "$scriptdir/.." 77 78set -e 79 80CFLAGS="-flto -fstack-protector-all -fsanitize=shadow-call-stack -ffixed-x18 -fsanitize=cfi -fvisibility=hidden" 81 82if [ "$asan" -ne 0 ]; then 83 CFLAGS="$CFLAGS -fsanitize=address" 84fi 85 86# We want a debug build because asserts are counted as crashes too. 87CC="$CC" CFLAGS="$CFLAGS" ./configure.sh -gO3 -z 88 89make -j16 90