diff --git a/infra/base-images/base-libfuzzer/Dockerfile b/infra/base-images/base-libfuzzer/Dockerfile index 3ce1c9e45..b9a31c567 100644 --- a/infra/base-images/base-libfuzzer/Dockerfile +++ b/infra/base-images/base-libfuzzer/Dockerfile @@ -23,12 +23,17 @@ ENV SANITIZER_FLAGS_undefined "-fsanitize=bool,signed-integer-overflow,shift,vpt # Default sanitizer to use ENV SANITIZER="address" +ENV FUZZING_ENGINE="libfuzzer" ENV COV_FLAGS="-fsanitize-coverage=edge,indirect-calls,8bit-counters" ENV ASAN_OPTIONS="symbolize=1:detect_leaks=0" + +ENV LIBFUZZER_LIB="/usr/lib/libFuzzingEngine.a" + +# TODO: remove after tpm2 catchup ENV FUZZER_LDFLAGS "" -COPY coverage_report compile srcmap reproduce run just_run \ +COPY coverage_report compile compile_libfuzzer srcmap reproduce run just_run \ /usr/local/bin/ WORKDIR $SRC diff --git a/infra/base-images/base-libfuzzer/compile b/infra/base-images/base-libfuzzer/compile index 280506b6d..87fe77102 100755 --- a/infra/base-images/base-libfuzzer/compile +++ b/infra/base-images/base-libfuzzer/compile @@ -17,20 +17,12 @@ echo "---------------------------------------------------------------" -pushd . > /dev/null 2>&1 - if [ -z "${SANITIZER_FLAGS+}" ]; then FLAGS_VAR="SANITIZER_FLAGS_${SANITIZER}" - SANITIZER_FLAGS=$(echo ${!FLAGS_VAR}) + export SANITIZER_FLAGS=$(echo ${!FLAGS_VAR}) fi -echo -n "Compiling libFuzzer into /usr/lib/libfuzzer.a ..." -mkdir -p $WORK/libfuzzer -cd $WORK/libfuzzer -$CXX $CXXFLAGS -std=c++11 $SANITIZER_FLAGS -c $SRC/libfuzzer/*.cpp -I$SRC/libfuzzer -ar ruv /usr/lib/libFuzzingEngine.a $WORK/libfuzzer/*.o > /dev/null 2>&1 -ln -s /usr/lib/libFuzzingEngine.a /usr/lib/libfuzzer.a -echo " done." +bash compile_${FUZZING_ENGINE} export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COV_FLAGS" export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA" @@ -42,5 +34,4 @@ echo "CXXFLAGS=$CXXFLAGS" echo "---------------------------------------------------------------" -popd >/dev/null 2>&1 bash -x $SRC/build.sh diff --git a/infra/base-images/base-libfuzzer/compile_libfuzzer b/infra/base-images/base-libfuzzer/compile_libfuzzer new file mode 100755 index 000000000..d10b75c41 --- /dev/null +++ b/infra/base-images/base-libfuzzer/compile_libfuzzer @@ -0,0 +1,26 @@ +#!/bin/bash -eu +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +echo -n "Compiling libFuzzer into $LIBFUZZER_LIB ..." +mkdir -p $WORK/libfuzzer +cd $WORK/libfuzzer +$CXX $CXXFLAGS -std=c++11 $SANITIZER_FLAGS -c $SRC/libfuzzer/*.cpp -I$SRC/libfuzzer +ar r $LIBFUZZER_LIB $WORK/libfuzzer/*.o +# TODO: remove once migration is complete +ln -s $LIBFUZZER_LIB /usr/lib/libfuzzer.a +rm -rf $WORK/libfuzzer +echo " done."