#!/usr/bin/env bash set -ex -o pipefail instrument=( "\/src$" ) if [ "$override_instrument" != "" ] then instrument = $override_instrument fi # Store the command line we were given to a file (echo "$ARGS" ; pwd) >> "$AFL_LOG_DIR/zcash-build-wrapper.log" # Work out which compiler we were called as case $0 in *zcash-wrapper-g++) OCOMPILER="g++" ACOMPILER=$OCOMPILER ;; *zcash-wrapper-gcc) OCOMPILER="gcc" ACOMPILER=$OCOMPILER ;; *zcash-wrapper-clang) OCOMPILER="clang-6.0" ACOMPILER="clang-fast" CFLAGS="-fsanitize=address -static" ;; *zcash-wrapper-clang++) OCOMPILER="clang++-6.0" ACOMPILER="clang-fast++" CPPFLAGS="-fsanitize=address -static" ;; *zcash-wrapper) echo "Call this script instead of your regular compiler, and if the absolute path of the CWD the wrapper was called from matches a regex in the array 'instrument', it will call AFL to instrument the resulting binary. Otherwise it will call either g++ or gcc depending on how it was invoked. \$AFL_INSTALL_DIR must be set to the path where AFL is installed." exit ;; esac # Check if we should instrument for i in "${instrument[@]}" do if echo -- "`pwd`" | grep "$i"; then # We found a match, let's instrument this one. echo "Matched directory `pwd` to instrument element $i. Instrumenting this call." >> "$AFL_LOG_DIR/zcash-build-wrapper.log" exec -- "$AFL_INSTALL_DIR/afl-$ACOMPILER" "$@" fi done # No match, just pass-through. exec -- "$OCOMPILER" "$@"