From patchwork Fri Apr 13 05:06:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133320 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp345373ljb; Thu, 12 Apr 2018 22:10:05 -0700 (PDT) X-Google-Smtp-Source: AIpwx49AB/+Mn9HaX0AJtKvX6ghOPmo1zKwmeR2fRitXKUzfhYSFWOLOSJaPTXl7Dq6YZRdSodRE X-Received: by 2002:a17:902:d681:: with SMTP id v1-v6mr3863236ply.120.1523596205697; Thu, 12 Apr 2018 22:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596205; cv=none; d=google.com; s=arc-20160816; b=ZK0iHMcwgGGtpHh9C6gs/xpi5cZMF+jUMDOQQkYKUBBtKIg69+FLkMPl6I5UIlSGDh 9CMdsXHyO5LOb25uOKC0HZUqYeVFjvPXYuL+ObklCrdW4sEs8/5dMN3juW0Me9e12M8L RJMJLsPeTTgSewFW1KJHhvl0+ohYFRW7LakCWl/3ysj7nMYwDGF1vFFE+1wf99bkWjB1 E3DZVf/+73FFGwmvOEO/Ouu1XeXNOr+dxVdW5IyAojvF28AezMvplYoOY4UkyGz8ly61 ah9x+tNMMNaN/fsMqjeDATjHCMQS+/2xQ810HQNc6oOL9TOxq3XlbEOMKCWl2o3HTpYj 4XrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=tWif1eeybdpHPv0AQramYjqCdXdJwW6M2DxOnGaKLZY=; b=JapVTSXWR/kq6YiqCRZbulGYSKdtvHWfbgswKXT3Yab7IXnNZYZLBXRqbJN4NaxGXV j/wv3/HrVuJJ4H+BgYpGgxRtmCiPSo7kjg/Lpxv/3Qwpi3YMs2qnMx4BZb3kecC3wZHK tCfbTouO5+jTJ/590YAb/CmHNX1syAkNJ1OS9UJdMl5wt/2Ar0snrdbqoa20aK3EDyNT k+XfmfVyKBwyoULiIdnXgjoj2NARK7aO94KiwubNLoubA2G90187Mz7VzsoTcIRlgK+2 tNycCAbt2GBxqGGqcKbkbsn10Zhat2iMyPHLD0uXVLupIl3kdD7zxx3fatNsxKisZzG0 oc2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ODxxy2nR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5-v6si4774104plx.148.2018.04.12.22.10.05; Thu, 12 Apr 2018 22:10:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ODxxy2nR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753742AbeDMFKD (ORCPT + 29 others); Fri, 13 Apr 2018 01:10:03 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55830 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753254AbeDMFJA (ORCPT ); Fri, 13 Apr 2018 01:09:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id w3D56lgJ029209; Fri, 13 Apr 2018 14:07:10 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgJ029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596031; bh=tWif1eeybdpHPv0AQramYjqCdXdJwW6M2DxOnGaKLZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODxxy2nRI2tEq7uNef9ZJHnivM9tTNg247i2gQhfH657yFCUbHXWoMZkS8+4uEbLz jh0syxGABtGHu0SJe/Lzvabtv5ZYstgi+BQwz5gCu2c88jmRIinx6TLOsW5k9JE3Qw Iv6Qow2CHtSE/PzPalBNv6VfaPqsOFXdCFIuxdc+6l2gzFs2PHTSYZbM5RIi8kW8lI 0j4Nf8E7Gxgs1gpitmRU147q9rAxMITek6iqQAvzjS9be8tmv9AI9DW/0AyiWkypSY YRynKj74vnNsY2j99AN3ODWV0jGBSQ3UyVDuZ8/7fJPOmvRywH8imQpz12nlNYaSFI oOYJZBT1kaDaA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 25/30] kcov: test compiler capability in Kconfig and correct dependency Date: Fri, 13 Apr 2018 14:06:34 +0900 Message-Id: <1523595999-27433-26-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> References: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As Documentation/kbuild/kconfig-language.txt notes, 'select' should be be used with care - it forces a lower limit of another symbol, ignoring the dependency. Currently, KCOV can select GCC_PLUGINS even if arch does not select HAVE_GCC_PLUGINS. This could cause the unmet direct dependency. Now that Kconfig can test compiler capability, let's handle this in a more sophisticated way. There are two ways to enable KCOV; use the compiler that natively supports -fsanitize-coverage=trace-pc, or build the SANCOV plugin if the compiler has ability to build GCC plugins. Hence, the correct dependency for KCOV is: depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS You do not need to build the SANCOV plugin if the compiler already supports -fsanitize-coverage=trace-pc. Hence, the select should be: select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC With this, GCC_PLUGIN_SANCOV is selected only when necessary, so scripts/Makefile.gcc-plugins can be cleaner. I also cleaned up Kconfig and scripts/Makefile.kcov as well. Signed-off-by: Masahiro Yamada --- Changes in v3: - Replace the previous 'select -> imply' patch with a new approach Changes in v2: - Drop depends on GCC_VERSION Makefile | 2 +- lib/Kconfig.debug | 11 +++++++---- scripts/Makefile.gcc-plugins | 6 +----- scripts/Makefile.kcov | 10 ++++++---- 4 files changed, 15 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 889d002..88733b7 100644 --- a/Makefile +++ b/Makefile @@ -623,7 +623,7 @@ all: vmlinux KBUILD_CFLAGS += $(call cc-option,-fno-PIE) KBUILD_AFLAGS += $(call cc-option,-fno-PIE) CFLAGS_GCOV := -fprofile-arcs -ftest-coverage -fno-tree-loop-im $(call cc-disable-warning,maybe-uninitialized,) -export CFLAGS_GCOV CFLAGS_KCOV +export CFLAGS_GCOV # The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default # values of the respective KBUILD_* variables diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index c40c7b7..1335717 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -736,12 +736,15 @@ config ARCH_HAS_KCOV only for x86_64. KCOV requires testing on other archs, and most likely disabling of instrumentation for some early boot code. +config CC_HAS_SANCOV_TRACE_PC + def_bool $(cc-option -fsanitize-coverage=trace-pc) + config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV + depends on CC_HAS_SANCOV_TRACE_PC || GCC_PLUGINS select DEBUG_FS - select GCC_PLUGINS if !COMPILE_TEST - select GCC_PLUGIN_SANCOV if !COMPILE_TEST + select GCC_PLUGIN_SANCOV if !CC_HAS_SANCOV_TRACE_PC help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). @@ -755,7 +758,7 @@ config KCOV config KCOV_ENABLE_COMPARISONS bool "Enable comparison operands collection by KCOV" depends on KCOV - default n + depends on $(cc-option -fsanitize-coverage=trace-cmp) help KCOV also exposes operands of every comparison in the instrumented code along with operand sizes and PCs of the comparison instructions. @@ -765,7 +768,7 @@ config KCOV_ENABLE_COMPARISONS config KCOV_INSTRUMENT_ALL bool "Instrument all code by default" depends on KCOV - default y if KCOV + default y help If you are doing generic system call fuzzing (like e.g. syzkaller), then you will want to instrument the whole kernel and you should diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 7f5c862..0ce3802 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -14,16 +14,12 @@ ifdef CONFIG_GCC_PLUGINS endif ifdef CONFIG_GCC_PLUGIN_SANCOV - ifeq ($(strip $(CFLAGS_KCOV)),) # It is needed because of the gcc-plugin.sh and gcc version checks. gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so - ifneq ($(PLUGINCC),) - CFLAGS_KCOV := $(SANCOV_PLUGIN) - else + ifeq ($(PLUGINCC),) $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) endif - endif endif gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so diff --git a/scripts/Makefile.kcov b/scripts/Makefile.kcov index 5cc7203..d71ba73 100644 --- a/scripts/Makefile.kcov +++ b/scripts/Makefile.kcov @@ -1,7 +1,9 @@ ifdef CONFIG_KCOV -CFLAGS_KCOV := $(call cc-option,-fsanitize-coverage=trace-pc,) -ifeq ($(CONFIG_KCOV_ENABLE_COMPARISONS),y) -CFLAGS_KCOV += $(call cc-option,-fsanitize-coverage=trace-cmp,) -endif + +kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc +kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp +kcov-flags-$(CONFIG_GCC_PLUGIN_SANKOV) += -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so + +export CFLAGS_KCOV := $(kcov-flags-y) endif