From f67f237fecfbbe8e68f7050ac236412bd9c65592 Mon Sep 17 00:00:00 2001 From: Benjamin Barenblat Date: Mon, 18 Jul 2022 20:25:40 -0400 Subject: mosh: fix code coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update Mosh’s build.sh to pass appropriate configure options when coverage is requested, as well as to pass CXXFLAGS through to the actual build. These fix ClusterFuzz code coverage reports. Along the way, enable verbose build rules, since they’re useful for debugging build failures. --- projects/mosh/Dockerfile | 2 +- projects/mosh/build.sh | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/projects/mosh/Dockerfile b/projects/mosh/Dockerfile index c3497e91..50fb55d0 100644 --- a/projects/mosh/Dockerfile +++ b/projects/mosh/Dockerfile @@ -16,7 +16,7 @@ FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get install -y autoconf automake protobuf-compiler \ - libprotobuf-dev pkg-config zlib1g-dev libncurses5-dev libssl-dev clang + libprotobuf-dev pkg-config zlib1g-dev libncurses5-dev libssl-dev clang lcov RUN git clone --depth 1 https://github.com/mobile-shell/mosh.git WORKDIR mosh COPY build.sh $SRC/ diff --git a/projects/mosh/build.sh b/projects/mosh/build.sh index 87526a18..cf6039c0 100755 --- a/projects/mosh/build.sh +++ b/projects/mosh/build.sh @@ -19,16 +19,33 @@ set -eu ./autogen.sh +# Sniff $CXXFLAGS to figure out what to pass to ./configure. +configure_flags= +case $CXXFLAGS in + *-fsanitize=address*) + configure_flags="$configure_flags --enable-asan" + ;; +esac +case $CXXFLAGS in + *-fcoverage*) + configure_flags="$configure_flags --enable-code-coverage" + ;; +esac + +# Use libstdc++, not libc++, since the base image's prebuild libraries require +# libstdc++. +export CXXFLAGS="$CXXFLAGS -stdlib=libstdc++" + # Clear CFLAGS and CXXFLAGS during configure tests so configure won't try to # link with -fsanitize=fuzz. -CFLAGS= CXXFLAGS= ./configure --enable-fuzzing --enable-asan --enable-static-libraries +CFLAGS= CXXFLAGS= ./configure --disable-silent-rules --enable-fuzzing --enable-static-libraries $configure_flags n=$(nproc) -make -j$n +make -j$n CFLAGS+="$CFLAGS" CXXFLAGS+="$CXXFLAGS" cd src/fuzz -make -j$n +make -j$n CFLAGS+="$CFLAGS" CXXFLAGS+="$CXXFLAGS" for fuzzer in *_fuzzer; do cp $fuzzer $OUT -- cgit v1.2.3