Merge branch 'js/build-fuzz-more-often'

In addition to building the objects needed, try to link the objects
that are used in fuzzer tests, to make sure at least they build
without bitrot, in Linux CI runs.

* js/build-fuzz-more-often:
  fuzz: link fuzz programs with `make all` on Linux
This commit is contained in:
Junio C Hamano 2024-04-30 14:49:44 -07:00
commit 473dcb4d89
3 changed files with 32 additions and 22 deletions

View file

@ -409,6 +409,9 @@ include shared.mak
# to the "<name>" of the corresponding `compat/fsmonitor/fsm-settings-<name>.c` # to the "<name>" of the corresponding `compat/fsmonitor/fsm-settings-<name>.c`
# that implements the `fsm_os_settings__*()` routines. # that implements the `fsm_os_settings__*()` routines.
# #
# Define LINK_FUZZ_PROGRAMS if you want `make all` to also build the fuzz test
# programs in oss-fuzz/.
#
# === Optional library: libintl === # === Optional library: libintl ===
# #
# Define NO_GETTEXT if you don't want Git output to be translated. # Define NO_GETTEXT if you don't want Git output to be translated.
@ -752,23 +755,6 @@ SCRIPTS = $(SCRIPT_SH_GEN) \
ETAGS_TARGET = TAGS ETAGS_TARGET = TAGS
# If you add a new fuzzer, please also make sure to run it in
# ci/run-build-and-minimal-fuzzers.sh so that we make sure it still links and
# runs in the future.
FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
FUZZ_OBJS += oss-fuzz/fuzz-config.o
FUZZ_OBJS += oss-fuzz/fuzz-date.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
.PHONY: fuzz-objs
fuzz-objs: $(FUZZ_OBJS)
# Always build fuzz objects even if not testing, to prevent bit-rot.
all:: $(FUZZ_OBJS)
FUZZ_PROGRAMS += $(patsubst %.o,%,$(filter-out %dummy-cmd-main.o,$(FUZZ_OBJS)))
# Empty... # Empty...
EXTRA_PROGRAMS = EXTRA_PROGRAMS =
@ -2373,6 +2359,29 @@ ifndef NO_TCLTK
endif endif
$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)' $(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1) SHELL_PATH='$(SHELL_PATH_SQ)' PERL_PATH='$(PERL_PATH_SQ)'
# If you add a new fuzzer, please also make sure to run it in
# ci/run-build-and-minimal-fuzzers.sh so that we make sure it still links and
# runs in the future.
FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
FUZZ_OBJS += oss-fuzz/fuzz-config.o
FUZZ_OBJS += oss-fuzz/fuzz-date.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
FUZZ_OBJS += oss-fuzz/fuzz-pack-idx.o
.PHONY: fuzz-objs
fuzz-objs: $(FUZZ_OBJS)
# Always build fuzz objects even if not testing, to prevent bit-rot.
all:: $(FUZZ_OBJS)
FUZZ_PROGRAMS += $(patsubst %.o,%,$(filter-out %dummy-cmd-main.o,$(FUZZ_OBJS)))
# Build fuzz programs when possible, even without the necessary fuzzing support,
# to prevent bit-rot.
ifdef LINK_FUZZ_PROGRAMS
all:: $(FUZZ_PROGRAMS)
endif
please_set_SHELL_PATH_to_a_more_modern_shell: please_set_SHELL_PATH_to_a_more_modern_shell:
@$$(:) @$$(:)
@ -3858,22 +3867,22 @@ cover_db_html: cover_db
# #
# An example command to build against libFuzzer from LLVM 11.0.0: # An example command to build against libFuzzer from LLVM 11.0.0:
# #
# make CC=clang CXX=clang++ \ # make CC=clang FUZZ_CXX=clang++ \
# CFLAGS="-fsanitize=fuzzer-no-link,address" \ # CFLAGS="-fsanitize=fuzzer-no-link,address" \
# LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \ # LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
# fuzz-all # fuzz-all
# #
FUZZ_CXX ?= $(CC)
FUZZ_CXXFLAGS ?= $(ALL_CFLAGS) FUZZ_CXXFLAGS ?= $(ALL_CFLAGS)
.PHONY: fuzz-all .PHONY: fuzz-all
fuzz-all: $(FUZZ_PROGRAMS)
$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS $(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
$(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \ $(QUIET_LINK)$(FUZZ_CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
-Wl,--allow-multiple-definition \ -Wl,--allow-multiple-definition \
$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE) $(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
fuzz-all: $(FUZZ_PROGRAMS)
$(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_DIR)/test-lib.o $(GITLIBS) GIT-LDFLAGS $(UNIT_TEST_PROGS): $(UNIT_TEST_BIN)/%$X: $(UNIT_TEST_DIR)/%.o $(UNIT_TEST_DIR)/test-lib.o $(GITLIBS) GIT-LDFLAGS
$(call mkdir_p_parent_template) $(call mkdir_p_parent_template)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \ $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \

View file

@ -7,7 +7,7 @@
group "Build fuzzers" make \ group "Build fuzzers" make \
CC=clang \ CC=clang \
CXX=clang++ \ FUZZ_CXX=clang++ \
CFLAGS="-fsanitize=fuzzer-no-link,address" \ CFLAGS="-fsanitize=fuzzer-no-link,address" \
LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \ LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
fuzz-all fuzz-all

View file

@ -68,6 +68,7 @@ ifeq ($(uname_S),Linux)
ifneq ($(findstring .el7.,$(uname_R)),) ifneq ($(findstring .el7.,$(uname_R)),)
BASIC_CFLAGS += -std=c99 BASIC_CFLAGS += -std=c99
endif endif
LINK_FUZZ_PROGRAMS = YesPlease
endif endif
ifeq ($(uname_S),GNU/kFreeBSD) ifeq ($(uname_S),GNU/kFreeBSD)
HAVE_ALLOCA_H = YesPlease HAVE_ALLOCA_H = YesPlease