diff --git a/infra/base-images/base-builder/Dockerfile b/infra/base-images/base-builder/Dockerfile index 4a45cb2be..1436f3838 100644 --- a/infra/base-images/base-builder/Dockerfile +++ b/infra/base-images/base-builder/Dockerfile @@ -26,6 +26,9 @@ ENV SANITIZER_FLAGS_memory "-fsanitize=memory -fsanitize-memory-track-origins" # Default build flags for coverage. ENV COVERAGE_FLAGS="-fsanitize-coverage=trace-pc-guard,trace-cmp" +# Coverage flags for generating coverage reports. +ENV COVERAGE_FLAGS_coverage="-fsanitize-coverage=bb,no-prune,trace-pc-guard" + # Default sanitizer and fuzzing engine to use. ENV SANITIZER="address" ENV FUZZING_ENGINE="libfuzzer" diff --git a/infra/base-images/base-builder/compile b/infra/base-images/base-builder/compile index 0d229ff7f..089813152 100755 --- a/infra/base-images/base-builder/compile +++ b/infra/base-images/base-builder/compile @@ -19,7 +19,7 @@ echo "---------------------------------------------------------------" if [ -z "${SANITIZER_FLAGS-}" ]; then FLAGS_VAR="SANITIZER_FLAGS_${SANITIZER}" - export SANITIZER_FLAGS=$(echo ${!FLAGS_VAR}) + export SANITIZER_FLAGS=${!FLAGS_VAR-} fi # compile script might override environment, use . to call it. @@ -32,10 +32,16 @@ then cp -R /usr/msan/lib/* /usr/lib/ fi +# Coverage flag overrides. +COVERAGE_FLAGS_VAR="COVERAGE_FLAGS_$SANITIZER" +if [[ -n ${!COVERAGE_FLAGS_VAR-} ]] +then + export COVERAGE_FLAGS="${!COVERAGE_FLAGS_VAR}" +fi + export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COVERAGE_FLAGS" export CXXFLAGS="$CFLAGS $CXXFLAGS_EXTRA" - echo "CC=$CC" echo "CXX=$CXX" echo "CFLAGS=$CFLAGS" diff --git a/infra/gcb/build.py b/infra/gcb/build.py index f0d38a552..3fbf66cad 100755 --- a/infra/gcb/build.py +++ b/infra/gcb/build.py @@ -24,6 +24,7 @@ CONFIGURATIONS = { 'sanitizer-address' : [ 'SANITIZER=address' ], 'sanitizer-memory' : [ 'SANITIZER=memory' ], 'sanitizer-undefined' : [ 'SANITIZER=undefined' ], + 'sanitizer-coverage' : [ 'SANITIZER=coverage' ], 'engine-libfuzzer' : [ 'FUZZING_ENGINE=libfuzzer' ], 'engine-afl' : [ 'FUZZING_ENGINE=afl' ], } @@ -34,7 +35,7 @@ EngineInfo = collections.namedtuple( ENGINE_INFO = { 'libfuzzer': EngineInfo( upload_bucket='clusterfuzz-builds', - supported_sanitizers=['address', 'memory', 'undefined']), + supported_sanitizers=['address', 'memory', 'undefined', 'coverage']), 'afl': EngineInfo( upload_bucket='clusterfuzz-builds-afl', supported_sanitizers=['address']),