Skip to content

Commit 72fc7a8

Browse files
committed
makefile: enable fuzzing support on macOS
Enable fuzzing support on macOS by configuring the build system to use Homebrew LLVM toolchain and handle macOS-specific linking requirements. The `make check-fuzz` command was failing on macOS because: - System clang lacks fuzzer runtime library support - Homebrew LLVM's stricter warnings cause build failures with `-Werror` - Linking issues with fuzzer targets - Test script attempts to execute debug symbol files This PR adds macOS-specific configuration to: - Use Homebrew LLVM toolchain for fuzzer support - Disable `-Werror` on macOS to prevent build failures - Explicitly link fuzzer libraries - Exclude `.dSYM` directories from test discovery All 76 fuzzer targets now build and pass on macOS.
1 parent c7531b0 commit 72fc7a8

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ BOLTVERSION := $(DEFAULT_BOLTVERSION)
3232

3333
-include config.vars
3434

35+
# Use Homebrew LLVM toolchain for fuzzing support on macOS
36+
ifeq ($(OS),Darwin)
37+
export PATH := /opt/homebrew/opt/llvm/bin:$(PATH)
38+
export DYLD_LIBRARY_PATH := /opt/homebrew/opt/llvm/lib:$(DYLD_LIBRARY_PATH)
39+
# Disable -Werror on macOS because Homebrew LLVM is stricter than system clang
40+
# and catches pre-existing bugs (like uninitialized variables) that cause build failures
41+
CWARNFLAGS := $(subst -Werror,,$(CWARNFLAGS))
42+
endif
43+
44+
# Define EXTERNAL_LDLIBS for linking external libraries
45+
EXTERNAL_LDLIBS=$(SODIUM_LDLIBS) $(SQLITE3_LDLIBS) $(POSTGRES_LDLIBS)
46+
3547
SORT=LC_ALL=C sort
3648

3749

@@ -698,11 +710,15 @@ endif
698710

699711
# We special case the fuzzing target binaries, as they need to link against libfuzzer,
700712
# which brings its own main().
713+
ifeq ($(OS),Darwin)
714+
FUZZ_LDFLAGS = /opt/homebrew/Cellar/llvm/21.1.2/lib/clang/21/lib/darwin/libclang_rt.fuzzer_osx.a -L/opt/homebrew/opt/llvm/lib/c++ -lc++ -L/opt/homebrew/opt/openssl@3/lib -lcrypto -lssl
715+
$(ALL_FUZZ_TARGETS):
716+
@$(call VERBOSE, "ld $@", $(CXX) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $(FUZZ_LDFLAGS) -o $@)
717+
@$(call VERBOSE, "dsymutil $@", dsymutil $@)
718+
else
701719
FUZZ_LDFLAGS = -fsanitize=fuzzer
702720
$(ALL_FUZZ_TARGETS):
703721
@$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) libccan.a $(FUZZ_LDFLAGS) -o $@)
704-
ifeq ($(OS),Darwin)
705-
@$(call VERBOSE, "dsymutil $@", dsymutil $@)
706722
endif
707723

708724

configure

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ set_defaults()
152152
if [ "$(uname -s)" = "Darwin" ]; then
153153
# Always override to avoid DWARF 5
154154
CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong"
155+
# Set SDKROOT for macOS
156+
SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
155157

156158
# Optional: confirm dsymutil is available
157159
if ! command -v dsymutil >/dev/null 2>&1; then
@@ -531,6 +533,9 @@ add_var CONFIGURATOR_CC "$CONFIGURATOR_CC"
531533
add_var CWARNFLAGS "$CWARNFLAGS"
532534
add_var CDEBUGFLAGS "$CDEBUGFLAGS"
533535
add_var COPTFLAGS "$COPTFLAGS"
536+
if [ -n "${SDKROOT:-}" ]; then
537+
add_var SDKROOT "$SDKROOT"
538+
fi
534539
add_var CSANFLAGS "$CSANFLAGS"
535540
add_var FUZZFLAGS "$FUZZFLAGS"
536541
add_var SQLITE3_CFLAGS "$SQLITE3_CFLAGS"

tests/fuzz/check-fuzz.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
# Runs each fuzz target on its seed corpus and prints any failures.
44
FUZZ_DIR=$(dirname "$0")
55
readonly FUZZ_DIR
6-
TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*")
6+
# On macOS, exclude debug symbol files from fuzzer target discovery
7+
if [[ "$OSTYPE" == "darwin"* ]]; then
8+
TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*" ! -path "*.dSYM/*")
9+
else
10+
TARGETS=$(find "${FUZZ_DIR}" -type f -name "fuzz-*" ! -name "*.*")
11+
fi
712
readonly TARGETS
813

914
export UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1"

0 commit comments

Comments
 (0)