• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2016 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18echo -n "Compiling afl to $LIB_FUZZING_ENGINE ..."
19
20# afl needs its special coverage flags
21export COVERAGE_FLAGS="-fsanitize-coverage=trace-pc-guard"
22
23mkdir -p $WORK/afl
24pushd $WORK/afl > /dev/null
25# Add -Wno-pointer-sign to silence warning (AFL is compiled this way).
26$CC $CFLAGS -Wno-pointer-sign -c $SRC/afl/llvm_mode/afl-llvm-rt.o.c
27$CXX $CXXFLAGS -std=c++11 -O2 -c $SRC/libfuzzer/afl/*.cpp -I$SRC/libfuzzer
28ar r $LIB_FUZZING_ENGINE $WORK/afl/*.o
29popd > /dev/null
30rm -rf $WORK/afl
31
32# Build and copy afl tools necessary for fuzzing.
33pushd $SRC/afl > /dev/null
34
35# Unset CFLAGS and CXXFLAGS while building AFL since we don't want to slow it
36# down with sanitizers.
37INITIAL_CXXFLAGS=$CXXFLAGS
38INITIAL_CFLAGS=$CFLAGS
39unset CXXFLAGS
40unset CFLAGS
41make clean && AFL_NO_X86=1 make
42CFLAGS=$INITIAL_CFLAGS
43CXXFLAGS=$INITIAL_CXXFLAGS
44
45find . -name 'afl-*' -executable -type f | xargs cp -t $OUT
46popd > /dev/null
47
48echo " done."
49