| 1 |
XEN_ROOT=$(CURDIR)/../../.. |
| 2 |
include $(XEN_ROOT)/tools/Rules.mk |
| 3 |
|
| 4 |
.PHONY: x86-insn-fuzz-all |
| 5 |
ifeq ($(CONFIG_X86_64),y) |
| 6 |
x86-insn-fuzz-all: x86-insn-fuzzer.a fuzz-emul.o afl |
| 7 |
else |
| 8 |
x86-insn-fuzz-all: |
| 9 |
endif |
| 10 |
|
| 11 |
|
| 12 |
%.c: $(XEN_ROOT)/xen/lib/x86/%.c FORCE |
| 13 |
ln -nsf $< $@ |
| 14 |
|
| 15 |
x86_emulate: FORCE |
| 16 |
mkdir -p $@ |
| 17 |
ln -sf $(XEN_ROOT)/xen/arch/x86/$@/*.[ch] $@/ |
| 18 |
|
| 19 |
x86_emulate/%.c: x86_emulate ; |
| 20 |
x86_emulate/%.h: x86_emulate ; |
| 21 |
|
| 22 |
%.c: $(XEN_ROOT)/tools/tests/x86_emulator/%.c FORCE |
| 23 |
ln -nsf $< $@ |
| 24 |
%.h: $(XEN_ROOT)/tools/tests/x86_emulator/%.h FORCE |
| 25 |
ln -nsf $< $@ |
| 26 |
|
| 27 |
CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -iquote . |
| 28 |
cpuid.o: CFLAGS += -iquote $(XEN_ROOT)/xen/lib/x86 |
| 29 |
|
| 30 |
GCOV_FLAGS := --coverage |
| 31 |
%-cov.o: %.c |
| 32 |
$(CC) -c $(CFLAGS) $(GCOV_FLAGS) $< -o $@ |
| 33 |
|
| 34 |
OBJS := fuzz-emul.o x86-emulate.o |
| 35 |
OBJS += x86_emulate/0f01.o x86_emulate/0fae.o x86_emulate/0fc7.o |
| 36 |
OBJS += x86_emulate/decode.o x86_emulate/fpu.o |
| 37 |
|
| 38 |
WRAPPED = $(shell sed -n 's,^ *WRAP(\([[:alnum:]_]*\));,\1,p' x86-emulate.h) |
| 39 |
|
| 40 |
private.h := x86-emulate.h x86_emulate/x86_emulate.h x86_emulate/private.h |
| 41 |
|
| 42 |
x86-emulate.h: x86_emulate/x86_emulate.h |
| 43 |
x86-emulate.o x86-emulate-cov.o: x86_emulate/x86_emulate.c $(private.h) |
| 44 |
fuzz-emul.o fuzz-emul-cov.o wrappers.o: x86-emulate.h |
| 45 |
|
| 46 |
$(filter x86_emulate/%.o,$(OBJS)): x86_emulate/%.o: x86_emulate/%.c $(private.h) |
| 47 |
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -c -o $@ $< $(APPEND_CFLAGS) |
| 48 |
|
| 49 |
$(patsubst %.o,%-cov.o,$(filter x86_emulate/%.o,$(OBJS))): x86_emulate/%-cov.o: x86_emulate/%.c $(private.h) |
| 50 |
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) $(GCOV_FLAGS) -c -o $@ $< $(APPEND_CFLAGS) |
| 51 |
|
| 52 |
x86-insn-fuzzer.a: $(OBJS) cpuid.o |
| 53 |
$(AR) rc $@ $^ |
| 54 |
|
| 55 |
afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o |
| 56 |
$(CC) $(CFLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ |
| 57 |
|
| 58 |
afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o |
| 59 |
$(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ |
| 60 |
|
| 61 |
libfuzzer-harness: $(OBJS) cpuid.o wrappers.o |
| 62 |
$(CC) $(CFLAGS) $(LIB_FUZZING_ENGINE) -fsanitize=fuzzer $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ |
| 63 |
|
| 64 |
|
| 65 |
.PHONY: all |
| 66 |
all: x86-insn-fuzz-all |
| 67 |
|
| 68 |
.PHONY: distclean |
| 69 |
distclean: clean |
| 70 |
|
| 71 |
.PHONY: clean |
| 72 |
clean: |
| 73 |
rm -f *.a *.o $(DEPS_RM) *.gcda *.gcno *.gcov |
| 74 |
rm -f afl-harness afl-harness-cov libfuzzer-harness |
| 75 |
rm -rf x86_emulate x86-emulate.c x86-emulate.h wrappers.c cpuid.c |
| 76 |
|
| 77 |
.PHONY: install |
| 78 |
install: all |
| 79 |
|
| 80 |
.PHONY: uninstall |
| 81 |
|
| 82 |
.PHONY: afl |
| 83 |
afl: afl-harness |
| 84 |
|
| 85 |
.PHONY: afl-cov |
| 86 |
afl-cov: afl-harness-cov |
| 87 |
|
| 88 |
-include $(DEPS_INCLUDE) |