From eed73082f54f9235b91af8311f0da9d05aad880a Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Tue, 16 May 2023 10:48:18 -0500 Subject: [PATCH] make: build dependencies with fuzzing flags By using fuzzer instrumentation for dependencies, we get more coverage signal during fuzzing. This is useful when the fuzzer must figure out how to take certain branches in a dependency. In our case, the fuzz-bip32 target was failing to create a data buffer that successfully passed fromwire_ext_key() parsing because the fuzzer couldn't see what was happening inside libwally-core. --- configure | 5 ++++- external/Makefile | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 9295c461a..144f3f90d 100755 --- a/configure +++ b/configure @@ -148,6 +148,7 @@ set_defaults() ASAN=${ASAN:-0} UBSAN=${UBSAN:-0} FUZZING=${FUZZING:-0} + FUZZFLAGS="" CSANFLAGS="" if [ "$ASAN" != 0 ]; then CSANFLAGS="$CSANFLAGS -fsanitize=address" @@ -162,7 +163,8 @@ set_defaults() fi fi if [ "$FUZZING" != 0 ]; then - CSANFLAGS="$CSANFLAGS -fsanitize=fuzzer-no-link" + FUZZFLAGS="-fsanitize=fuzzer-no-link" + CSANFLAGS="$CSANFLAGS $FUZZFLAGS" fi echo CSANFLAGS = $CSANFLAGS PYTEST=${PYTEST-$(default_pytest)} @@ -473,6 +475,7 @@ add_var CWARNFLAGS "$CWARNFLAGS" add_var CDEBUGFLAGS "$CDEBUGFLAGS" add_var COPTFLAGS "$COPTFLAGS" add_var CSANFLAGS "$CSANFLAGS" +add_var FUZZFLAGS "$FUZZFLAGS" add_var SQLITE3_CFLAGS "$SQLITE3_CFLAGS" add_var SQLITE3_LDLIBS "$SQLITE3_LDLIBS" add_var POSTGRES_INCLUDE "$POSTGRES_INCLUDE" diff --git a/external/Makefile b/external/Makefile index a41aa1c03..725019576 100644 --- a/external/Makefile +++ b/external/Makefile @@ -71,7 +71,7 @@ $(TARGET_DIR)/libsodium.a: $(TARGET_DIR)/libsodium-build/src/libsodium/libsodium $(TARGET_DIR)/libsodium-build/src/libsodium/libsodium.la: external/libsodium/src/libsodium/include/sodium.h cd external/libsodium && ./autogen.sh mkdir -p ${TARGET_DIR}/libsodium-build - cd $(TARGET_DIR)/libsodium-build && $(TOP)/libsodium/configure CC="$(CC)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE) + cd $(TARGET_DIR)/libsodium-build && $(TOP)/libsodium/configure CC="$(CC)" CFLAGS="$(FUZZFLAGS)" LDFLAGS="$(FUZZFLAGS)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE) # libsecp included in libwally. # Wildcards here are magic. See http://stackoverflow.com/questions/2973445/gnu-makefile-rule-generating-a-few-targets-from-a-single-source-file @@ -83,7 +83,7 @@ $(TARGET_DIR)/libwally-core-build/src/libwallycore.% $(TARGET_DIR)/libwally-core cd external/libwally-core && ./tools/autogen.sh mkdir -p ${TARGET_DIR}/libwally-core-build cd ${TARGET_DIR}/libwally-core-build \ - && PYTHON_VERSION=3 CFLAGS=-std=c99 ${TOP}/libwally-core/configure CC="$(CC)" \ + && PYTHON_VERSION=3 CFLAGS="-std=c99 $(FUZZFLAGS)" LDFLAGS="$(FUZZFLAGS)" ${TOP}/libwally-core/configure CC="$(CC)" \ --enable-static=yes \ $(CROSSCOMPILE_OPTS) \ --enable-module-recovery \ @@ -115,7 +115,7 @@ $(TARGET_DIR)/libbacktrace.a: external/libbacktrace/backtrace.h $(MAKE) -C $(TARGET_DIR)/libbacktrace-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec $(TARGET_DIR)/lowdown-build/bin/lowdown: external/lowdown/lowdown.h - cd external/lowdown && CC="$(CC)" ./configure PREFIX=`pwd`/$(TOP)/$(TARGET_DIR)/lowdown-build/ + cd external/lowdown && CC="$(CC)" CFLAGS="$(FUZZFLAGS)" ./configure LDFLAGS="$(FUZZFLAGS)" PREFIX=`pwd`/$(TOP)/$(TARGET_DIR)/lowdown-build/ $(MAKE) -C external/lowdown install distclean: external-distclean