From ed7bf08186d83cc82d06ed191fea73e9e18174b2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 2 Jan 2024 05:34:17 -0300 Subject: Makefile: Add support for LLVM fuzzer --- .gitignore | 5 ++++- Makefile | 19 ++++++++++++++++++- deps.mk | 10 ++++++++++ mkdeps.sh | 9 ++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a515310..3bd5ddd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,8 @@ /src/*.c.txt /src/*.cat /doc/*.[0-9] -/tests/slurp.o +/tests/fuzz/*.o +/tests/fuzz/*.xa +/tests/fuzz/*.bin /tests/fuzz/corpus/ +/tests/slurp.o diff --git a/Makefile b/Makefile index 79eda83..45fe1a2 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,9 @@ sources.o = $(sources.c:.c=.o) sources.to = $(sources.c:.c=.to) sources.xa = $(sources.c:.c=.xa) sources.bin = $(sources.c:.c=.bin) +fuzz.o = $(fuzz.c:.c=.o) +fuzz.xa = $(fuzz.c:.c=.xa) +fuzz.bin = $(fuzz.c:.c=.bin) sources = \ $(sources.c) \ @@ -79,6 +82,9 @@ derived-assets = \ src/main.bin \ side-assets = \ + $(fuzz.o) \ + $(fuzz.xa) \ + $(fuzz.bin) \ src/logerr.c.txt \ src/catalog.c.txt \ @@ -91,12 +97,13 @@ all: $(derived-assets) lib$(NAME).a: $(sources.o) src/main.xa: $(sources.o) src/main.o +$(fuzz.bin): lib$(NAME).a $(manpages) src/config.h: Makefile deps.mk $(sources.o) $(sources.to): src/config.h Makefile deps.mk tests/slurp.o: src/config.h Makefile deps.mk -lib$(NAME).a $(sources.xa) src/main.xa: +lib$(NAME).a $(sources.xa) src/main.xa $(fuzz.xa): $(AR) $(ARFLAGS) $@ $? src/$(NAME).en.cat: src/i18n.bin @@ -125,6 +132,16 @@ check-unit: $(sources.bin-check) check: check-unit + +fuzz.bin-check = $(fuzz.c:.c=.bin-check) +$(fuzz.bin-check): + $(EXEC)$*.bin tests/fuzz/corpus/ $(FUZZFLAGS) + +## Run fuzzing targets indefinitely. +fuzz: $(fuzz.bin-check) + + + ## Remove *all* derived artifacts produced during the build. ## A dedicated test asserts that this is always true. clean: diff --git a/deps.mk b/deps.mk index aa56673..80296ec 100644 --- a/deps.mk +++ b/deps.mk @@ -11,6 +11,16 @@ manpages.in = $(manpages.en.in) catalogs.en.msg = src/pindaiba.en.msg catalogs.msg = $(catalogs.en.msg) +fuzz.c = \ + tests/fuzz/another.c \ + tests/fuzz/hello.c \ + +tests/fuzz/another.xa: tests/fuzz/another.o +tests/fuzz/hello.xa: tests/fuzz/hello.o +tests/fuzz/another.bin-check: tests/fuzz/another.bin +tests/fuzz/hello.bin-check: tests/fuzz/hello.bin + + sources.c = \ src/catalog.c \ src/hash.c \ diff --git a/mkdeps.sh b/mkdeps.sh index 1ec12fb..4970dc8 100755 --- a/mkdeps.sh +++ b/mkdeps.sh @@ -12,10 +12,17 @@ cfiles() { } export LANG=POSIX.UTF-8 + find doc/*.en.*.in 2>/dev/null | sort | varlist 'manpages.en.in' ||: echo 'manpages.in = $(manpages.en.in)' printf 'catalogs.en.msg = %s\n' "$(find src/ -name '*.msg')" echo 'catalogs.msg = $(catalogs.en.msg)' -echo '' +printf '\n' + +find tests/fuzz/*.c | sort | varlist 'fuzz.c' +find tests/fuzz/*.c | sort | awk -F. '{ printf "%s.xa: %s.o\n", $1, $1 }' +find tests/fuzz/*.c | sort | awk -F. '{ printf "%s.bin-check: %s.bin\n", $1, $1 }' +printf '\n\n' + cfiles | varlist 'sources.c' ldev deps $(cfiles) -- cgit v1.2.3