xref: /freebsd/contrib/libfido2/fuzz/build-coverage (revision a64729f5077d77e13b9497cb33ecb3c82e606ee8)
1#!/bin/sh -eux
2
3# Copyright (c) 2019 Yubico AB. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6# SPDX-License-Identifier: BSD-2-Clause
7
8LIBCBOR="$1"
9LIBFIDO2="$2"
10
11CC="${CC:-clang}"
12CXX="${CXX:-clang++}"
13PKG_CONFIG_PATH="${PKG_CONFIG_PATH:-${LIBCBOR}/install/lib/pkgconfig}"
14export CC PKG_CONFIG_PATH
15
16# Clean up.
17rm -rf "${LIBCBOR}/build" "${LIBCBOR}/install" "${LIBFIDO2}/build"
18
19# Patch, build, and install libcbor.
20(cd "${LIBCBOR}" && patch -N -l -s -p0 < "${LIBFIDO2}/fuzz/README") || true
21mkdir "${LIBCBOR}/build" "${LIBCBOR}/install"
22(cd "${LIBCBOR}/build" && cmake -DBUILD_SHARED_LIBS=ON \
23	-DCMAKE_INSTALL_PREFIX="${LIBCBOR}/install" ..)
24make -C "${LIBCBOR}/build" VERBOSE=1 all install
25
26# Build libfido2.
27mkdir -p "${LIBFIDO2}/build"
28export CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
29export CFLAGS="${CFLAGS} -fsanitize=fuzzer-no-link"
30export LDFLAGS="${CFLAGS}"
31export FUZZ_LDFLAGS="${LDFLAGS} -fsanitize=fuzzer"
32(cd "${LIBFIDO2}/build" && cmake -DFUZZ=ON -DFUZZ_LDFLAGS="${FUZZ_LDFLAGS}" \
33	-DCMAKE_BUILD_TYPE=Debug ..)
34make -C "${LIBFIDO2}/build"
35