From patchwork Fri Aug 25 16:43:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 9922495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DAC406022E for ; Fri, 25 Aug 2017 16:46:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAFE0281D2 for ; Fri, 25 Aug 2017 16:46:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFF3F283CF; Fri, 25 Aug 2017 16:46:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5E624281D2 for ; Fri, 25 Aug 2017 16:46:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlHiF-00052s-75; Fri, 25 Aug 2017 16:44:03 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlHiE-00050A-3G for xen-devel@lists.xenproject.org; Fri, 25 Aug 2017 16:44:02 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 2B/33-01731-1D350A95; Fri, 25 Aug 2017 16:44:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42JxWrrBXvdC8IJ Igy8XTSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxnD48zF7TJV8y8J9TAeFyqi5GTQ0LAX+Lv pb3MIDabgJ7EvONfWboYOThEBFQkbu816GLk4mAW2M8o0fv1BxtIjbCArcT8eX9ZQWwWAVWJa W+OMoHYvEDxJ3ffsEDMlJc49+A2M8gcTgE7iV0nuUBMIaCSF2f0QCqEgDoXPzjKDtEpKHFy5h OwTmYBCYmDL14wT2DknYUkNQtJagEj0ypG9eLUorLUIl0TvaSizPSMktzEzBxdQwNTvdzU4uL E9NScxKRiveT83E2MwKBhAIIdjLf6nA8xSnIwKYnyWr+cHynEl5SfUpmRWJwRX1Sak1p8iFGG g0NJglcuaEGkkGBRanpqRVpmDjB8YdISHDxKIrxcIGne4oLE3OLMdIjUKUZdjg2r139hEmLJy 89LlRLn/RMIVCQAUpRRmgc3AhZLlxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMawuyiiczrw Ru0yugI5iAjph0Yg7IESWJCCmpBsYIYd7GRTbtz4O2aC485vMh9v2coAiPYuv+a6YT3jEc+/r kpXDapy3fpvA/VV/LZSZzrdtgdXioS3zmEo0NLcxPt2V+EFyYXsmzhkuBtzxAdPFvUec/Bo94 v2anTXulrhFtH1jzkKX4X5J34nLz6XH3f61bEZ73sMHX9q3a/zJmr7sstxYH5SmxFGckGmoxF xUnAgAUGV5hoAIAAA== X-Env-Sender: prvs=4030414b0=George.Dunlap@citrix.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1503679437!87780548!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 36825 invoked from network); 25 Aug 2017 16:44:00 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-11.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 25 Aug 2017 16:44:00 -0000 X-IronPort-AV: E=Sophos;i="5.41,426,1498521600"; d="scan'208";a="445163893" From: George Dunlap To: Date: Fri, 25 Aug 2017 17:43:37 +0100 Message-ID: <20170825164343.29015-8-george.dunlap@citrix.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170825164343.29015-1-george.dunlap@citrix.com> References: <20170825164343.29015-1-george.dunlap@citrix.com> MIME-Version: 1.0 Cc: Ian Jackson , Wei Liu , George Dunlap , Jan Beulich , Andrew Cooper Subject: [Xen-devel] [PATCH 08/14] fuzz/x86_emulate: Add 'afl-cov' target X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ...to generate a "normal" coverage-instrumented binary, suitable for use with gcov or afl-cov. This is slightly annoying because: - Every object file needs to have been instrumented to work effectively - You generally want to have both an afl-instrumented binary and a gcov-instrumented binary at the same time, but - gcov instrumentation and afl instrumentation are mutually exclusive So when making the `afl-cov` target, generate a second set of object files and a second binary with the `-cov` suffix. Signed-off-by: George Dunlap --- CC: Ian Jackson CC: Wei Liu CC: Andrew Cooper CC: Jan Beulich --- .gitignore | 1 + tools/fuzz/README.afl | 14 ++++++++++++++ tools/fuzz/x86_instruction_emulator/Makefile | 19 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 594ffd9a7f..66bceb3ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -159,6 +159,7 @@ tools/fuzz/libelf/afl-libelf-fuzzer tools/fuzz/x86_instruction_emulator/asm tools/fuzz/x86_instruction_emulator/x86_emulate* tools/fuzz/x86_instruction_emulator/afl-harness +tools/fuzz/x86_instruction_emulator/afl-harness-cov tools/helpers/_paths.h tools/helpers/init-xenstore-domain tools/helpers/xen-init-dom0 diff --git a/tools/fuzz/README.afl b/tools/fuzz/README.afl index 4758de2490..0d955b2687 100644 --- a/tools/fuzz/README.afl +++ b/tools/fuzz/README.afl @@ -41,3 +41,17 @@ Use the x86 instruction emulator fuzzer as an example. $ $AFLPATH/afl-fuzz -t 1000 -i testcase_dir -o findings_dir -- ./afl-harness Please see AFL documentation for more information. + +# GENERATING COVERAGE INFORMATION + +To use afl-cov or gcov, you need a separate binary instrumented to +generate coverage data. To do this, use the target `afl-cov`: + + $ make afl-cov #produces afl-harness-cov + +NOTE: Please also note that the coverage instrumentation hard-codes +the absolute path for the instrumentation read and write files in the +binary; so coverage data will always show up in the build directory no +matter where you run the binary from. + +Please see afl-cov and/or gcov documentation for more information. \ No newline at end of file diff --git a/tools/fuzz/x86_instruction_emulator/Makefile b/tools/fuzz/x86_instruction_emulator/Makefile index 10009dc08f..629e191029 100644 --- a/tools/fuzz/x86_instruction_emulator/Makefile +++ b/tools/fuzz/x86_instruction_emulator/Makefile @@ -23,19 +23,33 @@ x86_emulate_user.c x86_emulate_user.h: %: CFLAGS += $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -I. +GCOV_FLAGS=--coverage + x86.h := asm/x86-vendors.h asm/x86-defns.h asm/msr-index.h x86_emulate.h := x86_emulate_user.h x86_emulate/x86_emulate.h $(x86.h) x86_emulate_user.o: x86_emulate_user.c x86_emulate/x86_emulate.c $(x86_emulate.h) +x86_emulate_user-cov.o: x86_emulate_user.c x86_emulate/x86_emulate.c $(x86_emulate.h) + $(CC) -c $(CFLAGS) $(GCOV_FLAGS) -o $@ x86_emulate_user.c + fuzz-emul.o: $(x86_emulate.h) +fuzz-emul-cov.o: fuzz-emul.c $(x86_emulate.h) + $(CC) -c $(CFLAGS) $(GCOV_FLAGS) -o $@ fuzz-emul.c + +afl-harness-cov.o: afl-harness.c + $(CC) -c $(CFLAGS) $(GCOV_FLAGS) $^ -o $@ + x86-insn-fuzzer.a: fuzz-emul.o x86_emulate_user.o $(AR) rc $@ $^ afl-harness: afl-harness.o fuzz-emul.o x86_emulate_user.o $(CC) $(CFLAGS) $^ -o $@ +afl-harness-cov: afl-harness-cov.o fuzz-emul-cov.o x86_emulate_user-cov.o + $(CC) $(CFLAGS) $(GCOV_FLAGS) $^ -o $@ + # Common targets .PHONY: all all: x86-insn-fuzz-all @@ -46,7 +60,7 @@ distclean: clean .PHONY: clean clean: - rm -f *.a *.o .*.d afl-harness + rm -f *.a *.o .*.d afl-harness afl-harness-cov *.gcda *.gcno *.gcov .PHONY: install install: all @@ -55,3 +69,6 @@ install: all .PHONY: afl afl: afl-harness + +.PHONY: afl-cov +afl-cov: afl-harness-cov