Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 46 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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
Expand Down Expand Up @@ -518,6 +520,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" \
Expand All @@ -531,8 +572,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"
Expand Down
7 changes: 6 additions & 1 deletion tests/fuzz/check-fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading