@@ -590,6 +590,8 @@ XDIFF_OBJS =
590
590
VCSSVN_OBJS =
591
591
GENERATED_H =
592
592
EXTRA_CPPFLAGS =
593
+ FUZZ_OBJS =
594
+ FUZZ_PROGRAMS =
593
595
LIB_OBJS =
594
596
PROGRAM_OBJS =
595
597
PROGRAMS =
@@ -682,6 +684,13 @@ SCRIPTS = $(SCRIPT_SH_INS) \
682
684
683
685
ETAGS_TARGET = TAGS
684
686
687
+ FUZZ_OBJS += fuzz-pack-headers.o
688
+
689
+ # Always build fuzz objects even if not testing, to prevent bit-rot.
690
+ all :: $(FUZZ_OBJS )
691
+
692
+ FUZZ_PROGRAMS += $(patsubst % .o,% ,$(FUZZ_OBJS ) )
693
+
685
694
# Empty...
686
695
EXTRA_PROGRAMS =
687
696
@@ -2250,6 +2259,7 @@ TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST
2250
2259
OBJECTS := $(LIB_OBJS ) $(BUILTIN_OBJS ) $(PROGRAM_OBJS ) $(TEST_OBJS ) \
2251
2260
$(XDIFF_OBJS ) \
2252
2261
$(VCSSVN_OBJS ) \
2262
+ $(FUZZ_OBJS ) \
2253
2263
common-main.o \
2254
2264
git.o
2255
2265
ifndef NO_CURL
@@ -2937,6 +2947,7 @@ clean: profile-clean coverage-clean cocciclean
2937
2947
$(RM ) $(LIB_FILE ) $(XDIFF_LIB ) $(VCSSVN_LIB )
2938
2948
$(RM ) $(ALL_PROGRAMS ) $(SCRIPT_LIB ) $(BUILT_INS ) git$X
2939
2949
$(RM ) $(TEST_PROGRAMS ) $(NO_INSTALL )
2950
+ $(RM ) $(FUZZ_PROGRAMS )
2940
2951
$(RM ) -r bin-wrappers $(dep_dirs )
2941
2952
$(RM ) -r po/build/
2942
2953
$(RM ) * .pyc * .pyo * /* .pyc * /* .pyo command-list.h $(ETAGS_TARGET ) tags cscope*
@@ -3061,3 +3072,24 @@ cover_db: coverage-report
3061
3072
cover_db_html : cover_db
3062
3073
cover -report html -outputdir cover_db_html cover_db
3063
3074
3075
+
3076
+ # ## Fuzz testing
3077
+ #
3078
+ # Building fuzz targets generally requires a special set of compiler flags that
3079
+ # are not necessarily appropriate for general builds, and that vary greatly
3080
+ # depending on the compiler version used.
3081
+ #
3082
+ # An example command to build against libFuzzer from LLVM 4.0.0:
3083
+ #
3084
+ # make CC=clang CXX=clang++ \
3085
+ # CFLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address" \
3086
+ # LIB_FUZZING_ENGINE=/usr/lib/llvm-4.0/lib/libFuzzer.a \
3087
+ # fuzz-all
3088
+ #
3089
+ .PHONY : fuzz-all
3090
+
3091
+ $(FUZZ_PROGRAMS ) : all
3092
+ $(QUIET_LINK )$(CXX ) $(CFLAGS ) $(LIB_OBJS ) $(BUILTIN_OBJS ) \
3093
+ $(XDIFF_OBJS ) $(EXTLIBS ) git.o $@ .o $(LIB_FUZZING_ENGINE ) -o $@
3094
+
3095
+ fuzz-all : $(FUZZ_PROGRAMS )
0 commit comments