Add checks for compiler when building fuzz targets.

This commit is contained in:
daniel.zatovic
2022-09-09 16:17:07 +02:00
committed by Milan Broz
parent f58aff21a9
commit 99e8ee6b7e
2 changed files with 12 additions and 5 deletions

View File

@@ -221,6 +221,9 @@ AC_ARG_ENABLE([fuzz-targets],
AM_CONDITIONAL(ENABLE_FUZZ_TARGETS, test "x$enable_fuzz_targets" = "xyes")
if test "x$enable_fuzz_targets" = "xyes"; then
if test "x$CC" != "xclang" || test "x$CXX" != "xclang++"; then
AC_MSG_ERROR([Building fuzz targets is only supported using clang. Please set CC=clang CXX=clang++])
fi
PKG_CHECK_MODULES([PROTOBUF], [protobuf],,
AC_MSG_ERROR([You need protobuf library to build fuzz targets.]))
AC_SUBST([PROTOBUF_LIBS])

View File

@@ -8,7 +8,7 @@ TESTS = crypt2_load_fuzz crypt_load_fuzz
LIB_FUZZING_ENGINE := $(if $(LIB_FUZZING_ENGINE),$(LIB_FUZZING_ENGINE),"-fsanitize=fuzzer")
crypt2_load_fuzz_SOURCES = crypt2_load_fuzz.cc common.c
crypt2_load_fuzz_LDADD = $(LDADD) ../../libcryptsetup.la
crypt2_load_fuzz_LDADD = ../../libcryptsetup.la ../../libcrypto_backend.la
crypt2_load_fuzz_LDFLAGS = $(AM_LDFLAGS) $(LIB_FUZZING_ENGINE) -static
crypt2_load_fuzz_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz -fsanitize=fuzzer-no-link
crypt2_load_fuzz_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz -fsanitize=fuzzer-no-link
@@ -37,10 +37,14 @@ crypt2_load_proto_fuzz_CXXFLAGS = \
proto_to_luks2_SOURCES = proto_to_luks2.cc common.c LUKS2.pb.cc proto_to_luks2_converter.cc
proto_to_luks2_LDADD = ../../libcryptsetup.la ../../libcrypto_backend.la @PROTOBUF_LIBS@
proto_to_luks2_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer-no-link
proto_to_luks2_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz -fsanitize=fuzzer-no-link
proto_to_luks2_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz -fsanitize=fuzzer-no-link
proto_to_luks2_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer-no-link -static
proto_to_luks2_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz
proto_to_luks2_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)/lib -I$(top_srcdir)/tests/fuzz
check_PROGRAMS = crypt2_load_fuzz crypt2_load_proto_fuzz proto_to_luks2
fuzz-targets: $(check_PROGRAMS)
clang-only:
@test "$(CC)" == "clang" || (echo "Building fuzz targets is only supported using clang. Please set CC=clang CXX=clang++" && exit 1)
@test "$(CXX)" == "clang++" || (echo "Building fuzz targets is only supported using clang. Please set CC=clang CXX=clang++" && exit 1)
fuzz-targets: clang-only $(check_PROGRAMS)