makefile: enable fuzzing support on macOS
What changed, and why it matters
This commit is a build-system fix that lets developers run fuzz tests on macOS. It changes compiler/linker paths, adds Homebrew LLVM detection, and skips macOS debug-symbol folders when looking for test programs. There is no change to how the lightning node handles money, network messages, or cryptography, and nothing here looks like a security vulnerability or backdoor.
No security action needed. Treat as a normal build/CI improvement. Reviewers may want to confirm the hard-coded `/opt/homebrew` paths are acceptable for the project's supported macOS configurations.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch enables make check-fuzz on macOS by: (1) exporting Homebrew LLVM paths in the Makefile, (2) detecting libclang_rt.fuzzer_osx.a and libc++ paths in configure, (3) passing FUZZER_LIB/LLVM_LDFLAGS instead of -fsanitize=fuzzer on Darwin, (4) adding OpenSSL include/lib paths for Darwin-arm64, (5) setting SDKROOT, and (6) excluding .dSYM directories in tests/fuzz/check-fuzz.sh. It is a portability/build fix with no runtime behavior changes to Core Lightning.
Changed components
Makefileconfiguretests/fuzz/check-fuzz.shInspect captured patch +73 / −3
diff --git a/Makefile b/Makefile
index 32f92e67..f9e10415 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,15 @@ BOLTVERSION := $(DEFAULT_BOLTVERSION)
-include config.vars
+# Use Homebrew LLVM toolchain for fuzzing support on macOS
+ifeq ($(OS),Darwin)
+export PATH := /opt/homebrew/opt/llvm/bin:$(PATH)
+export DYLD_LIBRARY_PATH := /opt/homebrew/opt/llvm/lib:$(DYLD_LIBRARY_PATH)
+endif
+
+# Define EXTERNAL_LDLIBS for linking external libraries
+EXTERNAL_LDLIBS=$(SODIUM_LDLIBS) $(SQLITE3_LDLIBS) $(POSTGRES_LDLIBS)
+
SORT=LC_ALL=C sort
@@ -254,8 +263,8 @@ man8dir = $(mandir)/man8
ifeq ("$(OS)-$(ARCH)", "Darwin-arm64")
CPATH := /opt/homebrew/include
LIBRARY_PATH := /opt/homebrew/lib
-LDFLAGS := -L/opt/homebrew/opt/sqlite/lib
-CPPFLAGS := -I/opt/homebrew/opt/sqlite/include
+LDFLAGS := -L/opt/homebrew/opt/sqlite/lib -L/opt/homebrew/opt/openssl@3/lib
+CPPFLAGS := -I/opt/homebrew/opt/sqlite/include -I/opt/homebrew/opt/openssl@3/include
PKG_CONFIG_PATH=/opt/homebrew/opt/sqlite/lib/pkgconfig
else
CPATH := /usr/local/include
@@ -698,7 +707,17 @@ endif
# We special case the fuzzing target binaries, as they need to link against libfuzzer,
# which brings its own main().
+# FUZZER_LIB and LLVM_LDFLAGS are set by configure script on macOS
+ifeq ($(OS),Darwin)
+ifneq ($(FUZZER_LIB),)
+FUZZ_LDFLAGS = $(FUZZER_LIB) $(LLVM_LDFLAGS)
+else
FUZZ_LDFLAGS = -fsanitize=fuzzer
+endif
+else
+FUZZ_LDFLAGS = -fsanitize=fuzzer
+endif
+
$(ALL_FUZZ_TARGETS):
@$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $(FUZZ_LDFLAGS) -o $@)
ifeq ($(OS),Darwin)
diff --git a/configure b/configure
index 10ab1762..5e480e9b 100755
--- a/configure
+++ b/configure
@@ -170,6 +170,8 @@ set_defaults()
if [ "$(uname -s)" = "Darwin" ]; then
# Always override to avoid DWARF 5
CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
+ # Set SDKROOT for macOS
+ SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
# Optional: confirm dsymutil is available
if ! command -v dsymutil >/dev/null 2>&1; then
@@ -538,6 +540,45 @@ if ! check_command 'jq' jq; then
exit 1
fi
+# Detect LLVM paths for fuzzing on macOS
+LLVM_LIBDIR=""
+FUZZER_LIB=""
+LLVM_LDFLAGS=""
+if [ "$OS" = "Darwin" ] && [ "$FUZZING" = "1" ]; then
+ echo -n "Detecting LLVM paths for fuzzing... "
+
+ # Try to find LLVM using Homebrew
+ if command -v brew >/dev/null 2>&1; then
+ LLVM_PREFIX=$(brew --prefix llvm 2>/dev/null || echo "")
+ if [ -n "$LLVM_PREFIX" ]; then
+ LLVM_LIBDIR="$LLVM_PREFIX/lib"
+
+ # Find the fuzzer library
+ # Look for libclang_rt.fuzzer_osx.a in the clang lib directories
+ CLANG_VERSION=$(ls -1 "$LLVM_LIBDIR/clang" 2>/dev/null | sort -V | tail -n1)
+ if [ -n "$CLANG_VERSION" ]; then
+ FUZZER_LIB="$LLVM_LIBDIR/clang/$CLANG_VERSION/lib/darwin/libclang_rt.fuzzer_osx.a"
+ if [ ! -f "$FUZZER_LIB" ]; then
+ echo "Warning: Could not find fuzzer library at $FUZZER_LIB" >&2
+ FUZZER_LIB=""
+ fi
+ fi
+
+ # Set LLVM C++ library path
+ if [ -d "$LLVM_PREFIX/lib/c++" ]; then
+ LLVM_LDFLAGS="-L$LLVM_PREFIX/lib/c++ -lc++"
+ fi
+
+ echo "found at $LLVM_PREFIX"
+ else
+ echo "not found"
+ echo "Warning: LLVM not found via Homebrew. Fuzzing may not work." >&2
+ fi
+ else
+ echo "not found (Homebrew not available)"
+ fi
+fi
+
# Now we can finally set our warning flags
if [ -z ${CWARNFLAGS+x} ]; then
CWARNFLAGS=$(default_cwarnflags "$COPTFLAGS" \
@@ -551,8 +592,13 @@ add_var CONFIGURATOR_CC "$CONFIGURATOR_CC"
add_var CWARNFLAGS "$CWARNFLAGS"
add_var CDEBUGFLAGS "$CDEBUGFLAGS"
add_var COPTFLAGS "$COPTFLAGS"
+if [ -n "${SDKROOT:-}" ]; then
+ add_var SDKROOT "$SDKROOT"
+fi
add_var CSANFLAGS "$CSANFLAGS"
add_var FUZZFLAGS "$FUZZFLAGS"
+add_var FUZZER_LIB "$FUZZER_LIB"
+add_var LLVM_LDFLAGS "$LLVM_LDFLAGS"
add_var SQLITE3_CFLAGS "$SQLITE3_CFLAGS"
add_var SQLITE3_LDLIBS "$SQLITE3_LDLIBS"
add_var POSTGRES_INCLUDE "$POSTGRES_INCLUDE"
diff --git a/tests/fuzz/check-fuzz.sh b/tests/fuzz/check-fuzz.sh
index a182f474..3ed98bfe 100755
--- a/tests/fuzz/check-fuzz.sh
+++ b/tests/fuzz/check-fuzz.sh
@@ -3,7 +3,12 @@
# Runs each fuzz target on its seed corpus and prints any failures.
FUZZ_DIR=$(dirname "$0")
readonly FUZZ_DIR
-TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*")
+# On macOS, exclude debug symbol files from fuzzer target discovery
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*" ! -path "*.dSYM/*")
+else
+ TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*")
+fi
readonly TARGETS
export UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1"
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.