From ccc7f034a58f63768110e9b4b82324eee3597706 Mon Sep 17 00:00:00 2001 From: anton Date: Sun, 19 Aug 2018 11:42:34 +0000 Subject: Add kcov(4), a kernel code coverage tracing driver. It's used in conjunction with the syzkaller kernel fuzzer. So far, 8 distinct panics have been found and fixed. This effort will continue. kcov is limited to architectures using Clang as their default compiler and is not enabled by default. With help from mpi@, thanks! ok kettenis@ mpi@ visa@ --- sys/arch/amd64/conf/GENERIC | 5 ++++- sys/arch/amd64/conf/Makefile.amd64 | 12 +++++++++++- sys/arch/amd64/conf/files.amd64 | 8 +++++++- 3 files changed, 22 insertions(+), 3 deletions(-) (limited to 'sys/arch/amd64/conf') diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index d07eb346fce..d3b593f71f4 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.457 2018/08/03 01:50:14 kevlo Exp $ +# $OpenBSD: GENERIC,v 1.458 2018/08/19 11:42:33 anton Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -658,6 +658,9 @@ pseudo-device hotplug 1 # devices hot plugging # mouse & keyboard multiplexor pseudo-devices pseudo-device wsmux 2 +# kernel code coverage +pseudo-device kcov 1 + # Virtio devices virtio* at pci? # Virtio PCI device vioblk* at virtio? # Virtio block device diff --git a/sys/arch/amd64/conf/Makefile.amd64 b/sys/arch/amd64/conf/Makefile.amd64 index 3950ac592dc..f6f6f286aa9 100644 --- a/sys/arch/amd64/conf/Makefile.amd64 +++ b/sys/arch/amd64/conf/Makefile.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.amd64,v 1.98 2018/07/13 08:10:56 deraadt Exp $ +# $OpenBSD: Makefile.amd64,v 1.99 2018/08/19 11:42:33 anton Exp $ # For instructions on building kernels consult the config(8) and options(4) # manual pages. @@ -43,6 +43,10 @@ SORTR= cat .else CMACHFLAGS+= -mretpoline .endif +.if ${IDENT:M-DKCOV} && ${COMPILER_VERSION:Mclang} +CMACHFLAGS+= -fno-ret-protector +PROF= -fsanitize-coverage=trace-pc +.endif .if ${COMPILER_VERSION:Mclang} NO_INTEGR_AS= -no-integrated-as .endif @@ -135,6 +139,12 @@ vers.o: ${SYSTEM_DEP:Ngap.o} sh $S/conf/newvers.sh ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c +.if ${IDENT:M-DKCOV} && ${COMPILER_VERSION:Mclang} +kcov.o: $S/dev/kcov.c + ${NORMAL_C} -fno-sanitize-coverage=trace-pc +.endif + + clean: rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \ gap.link ld.script lorder makegap.sh param.c diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 6da1a7b0aa6..a4b89dde769 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.amd64,v 1.97 2018/07/12 12:46:00 fcambus Exp $ +# $OpenBSD: files.amd64,v 1.98 2018/08/19 11:42:33 anton Exp $ maxpartitions 16 maxusers 2 16 128 @@ -244,6 +244,12 @@ attach vmm at mainbus file arch/amd64/amd64/vmm.c vmm needs-flag file arch/amd64/amd64/vmm_support.S vmm +# +# KCOV +# +pseudo-device kcov +file dev/kcov.c kcov + # # Machine-independent SD/MMC drivers # -- cgit v1.2.3