From patchwork Fri Apr 13 05:06:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133327 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346543ljb; Thu, 12 Apr 2018 22:11:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx48L34YFqUtQ5kfFa5KruqYZfKMN/JkooP3F/pevfEn6le9ZAfhKB3VGg9fd4ZKThu8s/Yph X-Received: by 2002:a17:902:30f:: with SMTP id 15-v6mr3800541pld.365.1523596315225; Thu, 12 Apr 2018 22:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596315; cv=none; d=google.com; s=arc-20160816; b=t2hGIBJl6PU2aq6QTJxrZQf6j0U/4eX1z8UZqRCHHa26qY6vSUOIig5/eiAzfURBNA w98ul15bquTHNC98om9XUpyCJgdaa2LUV3KdioQhETAmTm1Vvvt2rnbC/zczDunxbxWN nQYjPrBJ6p8j6YG36ncnXGdER793URh2gHVBrrDv3vOV9FV81RNTLjM2sU8IyEdVLfuX /H7oVygfluiJ2DXVbGE+HO1jaIdgir+Oql5e+P3SwowojVD0D9pOvKcsoLWvUu/JzAUj GlQmYmCTNkK3YvWrxmNjlwtRGO6Y8mqyvLITeFR5lHlhORDQ+zOHkHMb7DLPD5WgHhnl JYnQ== 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=nudY1K8WMveNcJteVTbrIjEri2FTAVU/SMH55MObhu4=; b=qUnBtZAPVwq+84qtL77FEy5KD9JXvYhniNfUAWjweG8MKhHE0gOMEm0KYk+eWL9PaN Lzf5t+1p2WPwTBkVld411admej2NHmr0U1Zmjsl2m3LuubA5JhRXX4hZGPJwalK3HCwt ygalWpSYjssiOZC0gQRAzZYTi58chAU33QPXIYpoUxxx98stJP7XGO9aQF1Iwq/CAqZ3 wKCRKcCU/yJI6HErfhXCHBJaIV7l/6uaJlrAiskYZ2OFf6DMaMDTqMMdl4uUxNWq3woZ wcqVKDbzw4zaJWOZ5Jai63GK7wWHrW8KHmxjtOYlxF7GxGGdJyJBTg3+YSRl/0lPPsVN Cbpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=kTv6aHXe; 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 v145si1745943pgb.203.2018.04.12.22.11.54; Thu, 12 Apr 2018 22:11:55 -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=kTv6aHXe; 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 S1751776AbeDMFIU (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:20 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54459 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750761AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lft029209; Fri, 13 Apr 2018 14:06:48 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lft029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596009; bh=nudY1K8WMveNcJteVTbrIjEri2FTAVU/SMH55MObhu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTv6aHXeRAaBr7EKLtTscht01iZYn60wdvsttXo3cXUjftIC6JTnXQwUYtbg1cClJ U1fr8g/cjCgsMmmQYC/20I4CA8iRYa2YMRXQ6c94ViKejlGL4UHgRipwIiNtFZyI7F EFG0bY9ZrHYDDib69bJ2zpZcAXWNqAByU7QKG7fiNpaMm0DyuhkM834J1KEBZxdFJ3 Yao8t37lx8pq+XmBJEPXqLa3PT57hczl2hZnrRtjJwisVw2F2jGXQHl3syTqwi6vcb fOfCPC5HkB79j7Ok4A59dlfy4PmTXXiJfnN6rAM4zwPZm/3F6tRElmBKvL7PSygAtB IFm68c36QYYBA== 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 01/30] gcc-plugins: fix build condition of SANCOV plugin Date: Fri, 13 Apr 2018 14:06:10 +0900 Message-Id: <1523595999-27433-2-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 Since commit d677a4d60193 ("Makefile: support flag -fsanitizer-coverage=trace-cmp"), you miss to build the SANCOV plugin under some circumstances. CONFIG_KCOV=y CONFIG_KCOV_ENABLE_COMPARISONS=y Your compiler does not support -fsanitize-coverage=trace-pc Your compiler does not support -fsanitize-coverage=trace-cmp Under this condition, $(CFLAGS_KCOV) is not empty but contains a space, so the following ifeq-conditional is false. ifeq ($(CFLAGS_KCOV),) Then, scripts/Makefile.gcc-plugins misses to add sancov_plugin.so to gcc-plugin-y while the SANCOV plugin is necessary as an alternative means. Fixes: d677a4d60193 ("Makefile: support flag -fsanitizer-coverage=trace-cmp") Signed-off-by: Masahiro Yamada --- Changes in v3: - newly added Changes in v2: None scripts/Makefile.gcc-plugins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 Acked-by: Kees Cook diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index b2a95af..7f5c862 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -14,7 +14,7 @@ ifdef CONFIG_GCC_PLUGINS endif ifdef CONFIG_GCC_PLUGIN_SANCOV - ifeq ($(CFLAGS_KCOV),) + 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 From patchwork Fri Apr 13 05:06:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133324 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346121ljb; Thu, 12 Apr 2018 22:11:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx49qNFHtLLC66oWNTUG+uEufAwHfPB+PwQWwW7sjnAnPk6zgqSAHnZemcJ34tnc4ViWssFPb X-Received: by 10.99.117.83 with SMTP id f19mr2921655pgn.189.1523596274466; Thu, 12 Apr 2018 22:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596274; cv=none; d=google.com; s=arc-20160816; b=lEBi1I4I/3KEHxvrMxolw/lEc4fZDULuROrQ73ahrFtl9Fh81ctfKqQe5dh++c35Rf cghqx1Re9IaXz3OV7fE+CCtLifw6acZJGkjdkIRS7oRKI1xLFd/jeWJkFSLIaJh8sFat ls6eQXDbb/IdBjjfUyETq5bgQhGJx/pu0fTQymj/BGj7T8FEKuGWyFQiSGQuk6Cm0XXs jleZCXgWQC4HMtwaI3KY9wUNuQv0/k8UEiXwb8HjengqrBGcWp5F+RQ4C6S+YlqJxxGT XBXLnZz7AJZ8eoSvmhYl6NxKZZP5rpz4EZO6gcRGEAF0Ev1LrPew0oCS2cBquIFEoykc rceQ== 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=XNv9xbGWgdT4WJudNdR5bXPrvss4pwTIL5Skvb6QiQY=; b=Fuc+pi2xNgrqRQSaPue9Pb6CGgmGsAHyOCOA3tCD4nDOGDR4CNgOhfQoYGXPaY/FxP 0yDRAYhAXKmPh8HUicg1VvnISDKoVIuaWWIgBV8yWsC2k9mfJqFCiKmnv0zWhKrVae25 6ATaSZfYe5aMGmdW1qB8T8ACfe+Cdmo3daDhh3mFf0Dy2u7yLkbBA8fmKxDiV0gkATIK s54vqhNweWsKOYrH2mLQUIu27kZMb/EnKlTarAtR3b5U9eT6C9HDEtVzmR2+dLpQWxLL cUfzmgIMtDPHTRogb4Bx3y/3vkLGC5SGBgWnuwDLnh4PZ1lQkhVudj4mCX7T/rY4ECMh g71w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=zyvXHkQu; 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 g8si784683pgv.281.2018.04.12.22.11.14; Thu, 12 Apr 2018 22:11:14 -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=zyvXHkQu; 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 S1753919AbeDMFLM (ORCPT + 29 others); Fri, 13 Apr 2018 01:11:12 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55004 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752366AbeDMFIc (ORCPT ); Fri, 13 Apr 2018 01:08:32 -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 w3D56lfu029209; Fri, 13 Apr 2018 14:06:49 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lfu029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596010; bh=XNv9xbGWgdT4WJudNdR5bXPrvss4pwTIL5Skvb6QiQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zyvXHkQuKpha4pnmAf4gfzYJw+ABcquX+E05DIsPR5Sc3ccERKrPQ1nOVgDgr2mdD qwpIUNMDA1tYlV9GZuykLLOnQTJoXd06e46l8XbNoc2YnLHSuXOTbzOh8z5m9Xnk4V hJqkZtEbOaY/4J6rtQXH1VP0LL4mz1B86DatJWVC3C3wmpkAoE4Jlfe/ETzP0fUGEu mFhMvVZLxsxCZYGnxAgNH5befvRiuED+VB8lNUMH9t6QVzfxYm52MCiaGsSQoeG5/m S8yPhUI6x6ehlKlORHAnSiJfT2fWrMsl+X2m7ix/P/5PUOrqmir5Z2QB1giJznuDpd 60KhcgyzeElXw== 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 02/30] kbuild: remove kbuild cache Date: Fri, 13 Apr 2018 14:06:11 +0900 Message-Id: <1523595999-27433-3-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 The kbuild cache was introduced to remember the result of shell commands, some of which are expensive to compute, such as $(call cc-option,...). However, this turned out not so clever as I had first expected. Actually, it is problematic. For example, "$(CC) -print-file-name" is cached. If the compiler is updated, the stale search path causes build error, which is difficult to figure out. Another problem scenario is cache files could be touched while install targets are running under the root permission. We can patch them if desired, but the build infrastructure is getting uglier and uglier. Now, we are going to move compiler flag tests to the configuration phase. If this is completed, the result of compiler tests will be naturally cached in the .config file. We will not have performance issues of incremental building since this testing only happens at Kconfig time. To start this work with a cleaner code base, remove the kbuild cache first. Revert the following commits: Commit 9a234a2e3843 ("kbuild: create directory for make cache only when necessary") Commit e17c400ae194 ("kbuild: shrink .cache.mk when it exceeds 1000 lines") Commit 4e56207130ed ("kbuild: Cache a few more calls to the compiler") Commit 3298b690b21c ("kbuild: Add a cache for generated variables") Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None Makefile | 5 +-- scripts/Kbuild.include | 101 +++++++------------------------------------------ 2 files changed, 16 insertions(+), 90 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index c1a608a..d85cee0 100644 --- a/Makefile +++ b/Makefile @@ -501,7 +501,7 @@ RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$( export RETPOLINE_CFLAGS # check for 'asm goto' -ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y) +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y) CC_HAVE_ASM_GOTO := 1 KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO @@ -804,7 +804,7 @@ KBUILD_CFLAGS += $(call cc-option,-fdata-sections,) endif # arch Makefile may override CC so keep this after arch Makefile is included -NOSTDINC_FLAGS += -nostdinc -isystem $(call shell-cached,$(CC) -print-file-name=include) +NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) CHECKFLAGS += $(NOSTDINC_FLAGS) # warn about C99 declaration after statement @@ -1617,7 +1617,6 @@ clean: $(clean-dirs) -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name .cache.mk \ -o -name '*.c.[012]*.*' \ -o -name '*.ll' \ -o -name '*.gcno' \) -type f -print | xargs rm -f diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index cce31ee..9f7eb10 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -8,8 +8,6 @@ squote := ' empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ -right_paren := ) -left_paren := ( ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o @@ -82,71 +80,6 @@ cc-cross-prefix = \ echo $(c); \ fi))) -# Tools for caching Makefile variables that are "expensive" to compute. -# -# Here we want to help deal with variables that take a long time to compute -# by making it easy to store these variables in a cache. -# -# The canonical example here is testing for compiler flags. On a simple system -# each call to the compiler takes 10 ms, but on a system with a compiler that's -# called through various wrappers it can take upwards of 100 ms. If we have -# 100 calls to the compiler this can take 1 second (on a simple system) or 10 -# seconds (on a complicated system). -# -# The "cache" will be in Makefile syntax and can be directly included. -# Any time we try to reference a variable that's not in the cache we'll -# calculate it and store it in the cache for next time. - -# Include values from last time -make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk -$(make-cache): ; --include $(make-cache) - -cached-data := $(filter __cached_%, $(.VARIABLES)) - -# If cache exceeds 1000 lines, shrink it down to 500. -ifneq ($(word 1000,$(cached-data)),) -$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \ - mv $(make-cache).tmp $(make-cache)) -endif - -create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1)) - -# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios) -# -# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_' -__sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$(subst \,_,$(subst =,_,$(subst $(space),_,$(subst $(comma),_,$(subst :,_,$(1))))))))) - -# Usage: $(call shell-cached,shell_command) -# Example: $(call shell-cached,md5sum /usr/bin/gcc) -# -# If we've already seen a call to this exact shell command (even in a -# previous invocation of make!) we'll return the value. If not, we'll -# compute it and store the result for future runs. -# -# This is a bit of voodoo, but basic explanation is that if the variable -# was undefined then we'll evaluate the shell command and store the result -# into the variable. We'll then store that value in the cache and finally -# output the value. -# -# NOTE: The $$(2) here isn't actually a parameter to __run-and-store. We -# happen to know that the caller will have their shell command in $(2) so the -# result of "call"ing this will produce a reference to that $(2). The reason -# for this strangeness is to avoid an extra level of eval (and escaping) of -# $(2). -define __run-and-store -ifeq ($(origin $(1)),undefined) - $$(eval $(1) := $$(shell $$(2))) -ifeq ($(create-cache-dir),1) - $$(shell mkdir -p $(dir $(make-cache))) - $$(eval create-cache-dir :=) -endif - $$(shell echo '$(1) := $$($(1))' >> $(make-cache)) -endif -endef -__shell-cached = $(eval $(call __run-and-store,$(1)))$($(1)) -shell-cached = $(call __shell-cached,__cached_$(call __sanitize-opt,$(1)),$(1)) - # output directory for tests below TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) @@ -154,36 +87,30 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) # Exit code chooses option. "$$TMP" serves as a temporary file and is # automatically cleaned up. -__try-run = set -e; \ +try-run = $(shell set -e; \ TMP="$(TMPOUT).$$$$.tmp"; \ TMPO="$(TMPOUT).$$$$.o"; \ if ($(1)) >/dev/null 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; \ fi; \ - rm -f "$$TMP" "$$TMPO" - -try-run = $(shell $(__try-run)) - -# try-run-cached -# This works like try-run, but the result is cached. -try-run-cached = $(call shell-cached,$(__try-run)) + rm -f "$$TMP" "$$TMPO") # as-option # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) -as-option = $(call try-run-cached,\ +as-option = $(call try-run,\ $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) # as-instr # Usage: cflags-y += $(call as-instr,instr,option1,option2) -as-instr = $(call try-run-cached,\ +as-instr = $(call try-run,\ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) # __cc-option # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) -__cc-option = $(call try-run-cached,\ +__cc-option = $(call try-run,\ $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) # Do not attempt to build with gcc plugins during cc-option tests. @@ -203,23 +130,23 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\ # cc-option-yn # Usage: flag := $(call cc-option-yn,-march=winchip-c6) -cc-option-yn = $(call try-run-cached,\ +cc-option-yn = $(call try-run,\ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) # cc-disable-warning # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) -cc-disable-warning = $(call try-run-cached,\ +cc-disable-warning = $(call try-run,\ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) # cc-name # Expands to either gcc or clang -cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) +cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) # cc-version -cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) +cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) # cc-fullversion -cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \ +cc-fullversion = $(shell $(CONFIG_SHELL) \ $(srctree)/scripts/gcc-version.sh -p $(CC)) # cc-ifversion @@ -232,21 +159,21 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo # cc-ldoption # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) -cc-ldoption = $(call try-run-cached,\ +cc-ldoption = $(call try-run,\ $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) # ld-option # Usage: LDFLAGS += $(call ld-option, -X) -ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) +ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D) # Important: no spaces around options -ar-option = $(call try-run-cached, $(AR) rc$(1) "$$TMP",$(1),$(2)) +ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) # ld-version # Note this is mainly for HJ Lu's 3 number binutil versions -ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version.sh) +ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) # ld-ifversion # Usage: $(call ld-ifversion, -ge, 22252, y) From patchwork Fri Apr 13 05:06:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133332 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347236ljb; Thu, 12 Apr 2018 22:13:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+KVerK97LO79EmqOrIOoIADM+gIBQcj/zADhwN24sHKJ2pAZxu+cra1kyuQLrS9qEpqVTf X-Received: by 2002:a17:902:564:: with SMTP id 91-v6mr3855110plf.63.1523596384781; Thu, 12 Apr 2018 22:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596384; cv=none; d=google.com; s=arc-20160816; b=zmVJPxcAoa4ElRtU7QOwfYUI8kxDe71AY7MK47h05KzvQAfL/3uprCoStbn03McPmI TFyv47BC361sqIBNVhU28qZznO7zjy/5aetvBp5arFaFqmTMHvnTxllUvFVg3ZPPd+9b B824bnCHmXJvz8CwvIJelHNz6v2JHj1aNBy2njLaT6nFqoFsNXz/bzskr+DqzEl9E2/h sJxVmiCA/UJMRI9YYxEG2PFc17LfOLmWX9+iFUtdaA0NaqOa3M5q2HLDqFA5BdhXw8gz 5XsZ7K1kFBSkZpEyLD7qP/WSU2OkjHUC1gfdyC2sbLwXsWOsKK9ghbXF4sHMS86AEZi7 K+wA== 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=VGTQ6LPltIOfbdazpfiHYV5ObDqEGuQ3Q0r7pUiBS/E=; b=lXe2N+iTpernW8S69wiwnH/pQYSliX46Jb1NV1yWoIZgl7Q+IwDINgK/v6cbK8y+Uw gF7iz3YbG/jvWOyppFhf8zyEmdv4Io2VUzIeD0vbWjktKNWUK9lyc2CTyTLS+BY7XEHC UzIkXeyZMlbVYMR8MQpcfy8wAr8KST/FT7dCZ2cHA5hvcKvJ9+z7BXj19/+wRouIIZU4 xMNR4+JLsEb98y/bF5lD4HRdBQx7ZHaP9O4QUtRLtfLV86l3yMCJQDtj1W8N7YRCMkrE Hub2waRTm9TA7zR72aLO3wPkv2vxcf1C5n/E9OAtftOgnPR/c95f+3b12CtPmQ8ce95a nClQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=1Y4z3Bby; 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 m3-v6si4876988pld.351.2018.04.12.22.13.04; Thu, 12 Apr 2018 22:13:04 -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=1Y4z3Bby; 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 S1753276AbeDMFMr (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:47 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54508 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751071AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lfv029209; Fri, 13 Apr 2018 14:06:50 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lfv029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596011; bh=VGTQ6LPltIOfbdazpfiHYV5ObDqEGuQ3Q0r7pUiBS/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1Y4z3BbyHFQ9+yar+cYrciO2l8uuw42sXxFkhdq5B+RcBQ1tvGjya7Iil9gQgoT7l t3mGdOOMQxdUTNUEcN0u9NYha8sPKvufD2eKVPvH5VKcx0hm6oIiVqTX3ipUW+FylC yj6j8/uIOWiLvngtuY8JjcgC4ndKuPg2qkb0K6eYL3geI64cvVjdEYNU6V1Yp6VUaK FEwtgLui+eilgtKIhom1nJ7zLO0XioDcXQLWyP66tElXZ/kQhFnzT+/o8HOsU8SC9s aQXKKZ60Ct1L9LyXQn2Do0Vmyd38/Et6ufSEGe3e/HYN78/nIUZUt3N90gwpdVZvSj bA9/QVX+WTupA== 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 03/30] kbuild: remove CONFIG_CROSS_COMPILE support Date: Fri, 13 Apr 2018 14:06:12 +0900 Message-Id: <1523595999-27433-4-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 Kbuild provides a couple of ways to specify CROSS_COMPILE: [1] Command line [2] Environment [3] arch/*/Makefile (only some architectures) [4] CONFIG_CROSS_COMPILE [4] is problematic for the compiler capability tests in Kconfig. CONFIG_CROSS_COMPILE allows users to change the compiler prefix from 'make menuconfig', etc. It means, the compiler options would have to be all re-calculated everytime CONFIG_CROSS_COMPILE is changed. To avoid complexity and performance issues, I'd like to evaluate the shell commands statically, i.e. only parsing Kconfig files. I guess the majority is [1] or [2]. Currently, there are only 5 defconfig files that specify CONFIG_CROSS_COMPILE. arch/arm/configs/lpc18xx_defconfig arch/hexagon/configs/comet_defconfig arch/nds32/configs/defconfig arch/openrisc/configs/or1ksim_defconfig arch/openrisc/configs/simple_smp_defconfig Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None Makefile | 3 --- init/Kconfig | 9 --------- 2 files changed, 12 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index d85cee0..ca3e3e8 100644 --- a/Makefile +++ b/Makefile @@ -316,12 +316,9 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \ # CROSS_COMPILE can be set on the command line # make CROSS_COMPILE=ia64-linux- # Alternatively CROSS_COMPILE can be set in the environment. -# A third alternative is to store a setting in .config so that plain -# "make" in the configured kernel build directory always uses that. # Default value for CROSS_COMPILE is not to prefix executables # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile ARCH ?= $(SUBARCH) -CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%) # Architecture as present in compile.h UTS_MACHINE := $(ARCH) diff --git a/init/Kconfig b/init/Kconfig index 9d167a5..c1ca920 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -54,15 +54,6 @@ config INIT_ENV_ARG_LIMIT Maximum of each of the number of arguments and environment variables passed to init from the kernel command line. - -config CROSS_COMPILE - string "Cross-compiler tool prefix" - help - Same as running 'make CROSS_COMPILE=prefix-' but stored for - default make runs in this kernel build directory. You don't - need to set this unless you want the configured kernel build - directory to select the cross-compiler automatically. - config COMPILE_TEST bool "Compile also drivers which will not load" depends on !UML From patchwork Fri Apr 13 05:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133315 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344639ljb; Thu, 12 Apr 2018 22:09:03 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/EzSCcpOlsG9EoYXW3rZb6xkZLB12hBl2ZLht9wOrRXNdNDtg5a/+Qi4aLSIuqjFeWewTB X-Received: by 2002:a17:902:7185:: with SMTP id b5-v6mr3784684pll.221.1523596143284; Thu, 12 Apr 2018 22:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596143; cv=none; d=google.com; s=arc-20160816; b=FAI65Hkl97DSCGkRyjpuQU+8PCLr8i5UHNKm4RB93YajFm9APKF8ESUKqqNOVZDMce FwMDjWw/cpogwdkLxzVpT8ypdt8m8eI7m7T4xSttiCmCQWw9lIoFQtQGfcDWo6KHtOCp 0TIeTKPZHd6eBM0hzeVGmu0OemrICishUFE67rOTFOI1L57vybvbygulp/iH130xuIoH sRwzgRSjHUyoP6wF6YJyucGYdg/vjFagA3YfGR3n/dILFY715NjRkiwHAQNk5l0p2ILT zk4ip0+d0F2UW/Q6kG/nsK/CcAnAj5NDP47B5cYw8aIaCWO6vBva81p+PyOvK2NOr/mz ECdg== 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=LTUA2Vc7PeMDN2wEBsy/On6/3N8Ix+ubIek1oLFvHWw=; b=Fo2/GexV+TfDenvSqV9wqtA55MtGnFKqxe1cKZyGmjM56fqgVO4mjWgCo0yU3IzfW5 OGJEmLdwEE7IX7Yy4BhbQ0eW+2B2I/wiFUoDlhexUV433rZIUq6+NPULXbsLQTVN/G9o L8JZ0b9swpSkzYESBFTNFURGsi/rFjruL7E5861AtaN9DyEh1lw9LH7QLfomRqYNMqOz 1L41hJ1IqMMTPordun78AZ/XYzzySzj5QPYf1shLuTfZPAJhebVindpBN1YS5qpx4C0r 4CVPBMlAvOSTbySs9i8Yu29MIlNWgHicPEUmMHyMZ4RiggCiR5SBBSALqMN2Ya8PfD8u ETDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=BmupBGjr; 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 y6si3289303pgo.9.2018.04.12.22.09.02; Thu, 12 Apr 2018 22:09:03 -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=BmupBGjr; 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 S1753356AbeDMFJA (ORCPT + 29 others); Fri, 13 Apr 2018 01:09:00 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55725 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753217AbeDMFI5 (ORCPT ); Fri, 13 Apr 2018 01:08:57 -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 w3D56lfw029209; Fri, 13 Apr 2018 14:06:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lfw029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596011; bh=LTUA2Vc7PeMDN2wEBsy/On6/3N8Ix+ubIek1oLFvHWw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BmupBGjrYVI0UgeZBcETcccgrK/es3TWP0jDfuKrQwf2ekNtx8KAP0afJpZ+WwOfU fsQmwhQHxp+/XGF02e7Aef7i2BTfX7k2rC8QjGEZwHl1RaKhNV8BfEj8igZOnyNiHb 7WY2hAfF+X6xR8rIoC/I/3TgS1gY1PCOpcfXIBoUi1V6KDTjYLtYli8p7ua8/iDl1D 21PC/FOq6YkXSUMfb2V7Xn5aTRbGzpvDdoCanUM2rPh8IIIMpx0SsgUXzqsEF5E9yb wi0MXcHcpSzNw0uvya3SBwTZSAILvukeGX5ABvR3vhvsefiO2Ny03QF5ZwANfICk8+ UnFnsqhhb4kqw== 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 04/30] kconfig: reference environment variables directly and remove 'option env=' Date: Fri, 13 Apr 2018 14:06:13 +0900 Message-Id: <1523595999-27433-5-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 To get access to environment variables, Kconfig needs to define a symbol using "option env=" syntax. It is tedious to add a symbol entry for each environment variable given that we need to define much more such as 'CC', 'AS', 'srctree' etc. to evaluate the compiler capability in Kconfig. Adding '$' for symbol references is grammatically weird. Looking at the code, the symbols prefixed with 'S' are expanded by: - conf_expand_value() This is used to expand 'arch/$ARCH/defconfig' and 'defconfig_list' - sym_expand_string_value() This is used to expand strings in 'source' and 'mainmenu' All of them are fixed values independent of user configuration. So, they can be changed into the direct expansion instead of symbols. This change makes the code much cleaner. The bounce symbols 'SRCARCH', 'ARCH', 'SUBARCH', 'KERNELVERSION' are gone. sym_init() hard-coding 'UNAME_RELEASE' is also gone. 'UNAME_RELEASE' should be replaced with an environment variable. ARCH_DEFCONFIG is a normal symbol, so it should be simply referenced without '$' prefix. The new syntax is addicted by Make. The variable reference needs parentheses, like $(FOO), but you can omit them for single-letter variables, like $F. Yet, in Makefiles, people tend to use the parenthetical form for consistency / clarification. At this moment, only the environment variable is supported, but I will extend the concept of 'variable' later on. The variables are expanded in the lexer so we can simplify the token handling on the parser side. For example, the following code works. [Example code] config MY_TOOLCHAIN_LIST string default "My tools: CC=$(CC), AS=$(AS), CPP=$(CPP)" [Result] $ make -s alldefconfig && tail -n 1 .config CONFIG_MY_TOOLCHAIN_LIST="My tools: CC=gcc, AS=as, CPP=gcc -E" Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: - Reimplement - Variable reference need parentheses except single-letter variable Changes in v2: - Move the string expansion to the lexer phase. - Split environment helpers to env.c Documentation/kbuild/kconfig-language.txt | 8 - Kconfig | 8 +- Makefile | 3 +- arch/sh/Kconfig | 4 +- arch/sparc/Kconfig | 4 +- arch/um/Kconfig.common | 4 - arch/x86/Kconfig | 4 +- arch/x86/um/Kconfig | 6 +- init/Kconfig | 16 +- scripts/kconfig/confdata.c | 31 +--- scripts/kconfig/kconf_id.c | 1 - scripts/kconfig/lkc.h | 4 - scripts/kconfig/lkc_proto.h | 6 + scripts/kconfig/menu.c | 3 - scripts/kconfig/preprocess.c | 261 ++++++++++++++++++++++++++++++ scripts/kconfig/symbol.c | 56 ------- scripts/kconfig/util.c | 18 +-- scripts/kconfig/zconf.l | 67 +++++++- scripts/kconfig/zconf.y | 2 +- 19 files changed, 353 insertions(+), 153 deletions(-) create mode 100644 scripts/kconfig/preprocess.c -- 2.7.4 diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index f5b9493..0e966e8 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt @@ -198,14 +198,6 @@ applicable everywhere (see syntax). enables the third modular state for all config symbols. At most one symbol may have the "modules" option set. - - "env"= - This imports the environment variable into Kconfig. It behaves like - a default, except that the value comes from the environment, this - also means that the behaviour when mixing it with normal defaults is - undefined at this point. The symbol is currently not exported back - to the build environment (if this is desired, it can be done via - another symbol). - - "allnoconfig_y" This declares the symbol as one that should have the value y when using "allnoconfig". Used for symbols that hide other symbols. diff --git a/Kconfig b/Kconfig index 8c4c1cb..4af1b42 100644 --- a/Kconfig +++ b/Kconfig @@ -3,10 +3,6 @@ # For a description of the syntax of this configuration file, # see Documentation/kbuild/kconfig-language.txt. # -mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration" +mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration" -config SRCARCH - string - option env="SRCARCH" - -source "arch/$SRCARCH/Kconfig" +source "arch/$(SRCARCH)/Kconfig" diff --git a/Makefile b/Makefile index ca3e3e8..5298ad7 100644 --- a/Makefile +++ b/Makefile @@ -284,7 +284,8 @@ include scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) -export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION +UNAME_RELEASE := $(shell uname --release) +export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION UNAME_RELEASE # SUBARCH tells the usermode build what the underlying arch is. That is set # first, and if a usermode build is happening, the "ARCH=um" on the command diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 97fe293..19297b9 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -57,7 +57,7 @@ config SUPERH . config SUPERH32 - def_bool ARCH = "sh" + def_bool "$(ARCH)" = "sh" select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_IOREMAP_PROT if MMU && !X2TLB @@ -76,7 +76,7 @@ config SUPERH32 select HAVE_CC_STACKPROTECTOR config SUPERH64 - def_bool ARCH = "sh64" + def_bool "$(ARCH)" = "sh64" select HAVE_EXIT_THREAD select KALLSYMS diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 8767e45..df7410c 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -1,6 +1,6 @@ config 64BIT - bool "64-bit kernel" if ARCH = "sparc" - default ARCH = "sparc64" + bool "64-bit kernel" if "$(ARCH)" = "sparc" + default "$(ARCH)" = "sparc64" help SPARC is a family of RISC microprocessors designed and marketed by Sun Microsystems, incorporated. They are very widely found in Sun diff --git a/arch/um/Kconfig.common b/arch/um/Kconfig.common index c68add8..07f84c8 100644 --- a/arch/um/Kconfig.common +++ b/arch/um/Kconfig.common @@ -54,10 +54,6 @@ config HZ int default 100 -config SUBARCH - string - option env="SUBARCH" - config NR_CPUS int range 1 1 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index d234cca..72350d5 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1,8 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # Select 32 or 64 bit config 64BIT - bool "64-bit kernel" if ARCH = "x86" - default ARCH != "i386" + bool "64-bit kernel" if "$(ARCH)" = "x86" + default "$(ARCH)" != "i386" ---help--- Say yes to build a 64-bit kernel - formerly known as x86_64 Say no to build a 32-bit kernel - formerly known as i386 diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig index 13ed827..6a15c4d 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -mainmenu "User Mode Linux/$SUBARCH $KERNELVERSION Kernel Configuration" +mainmenu "User Mode Linux/$(SUBARCH) $(KERNELVERSION) Kernel Configuration" source "arch/um/Kconfig.common" @@ -16,8 +16,8 @@ config UML_X86 select GENERIC_FIND_FIRST_BIT config 64BIT - bool "64-bit kernel" if SUBARCH = "x86" - default SUBARCH != "i386" + bool "64-bit kernel" if "$(SUBARCH)" = "x86" + default "$(SUBARCH)" != "i386" config X86_32 def_bool !64BIT diff --git a/init/Kconfig b/init/Kconfig index c1ca920..e6dafed5 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1,20 +1,12 @@ -config ARCH - string - option env="ARCH" - -config KERNELVERSION - string - option env="KERNELVERSION" - config DEFCONFIG_LIST string depends on !UML option defconfig_list - default "/lib/modules/$UNAME_RELEASE/.config" + default "/lib/modules/$(UNAME_RELEASE)/.config" default "/etc/kernel-config" - default "/boot/config-$UNAME_RELEASE" - default "$ARCH_DEFCONFIG" - default "arch/$ARCH/defconfig" + default "/boot/config-$(UNAME_RELEASE)" + default ARCH_DEFCONFIG + default "arch/$(ARCH)/defconfig" config CONSTRUCTORS bool diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index df26c7b..0698cc3 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -81,39 +81,13 @@ const char *conf_get_autoconfig_name(void) return name ? name : "include/config/auto.conf"; } -static char *conf_expand_value(const char *in) -{ - struct symbol *sym; - const char *src; - static char res_value[SYMBOL_MAXLENGTH]; - char *dst, name[SYMBOL_MAXLENGTH]; - - res_value[0] = 0; - dst = name; - while ((src = strchr(in, '$'))) { - strncat(res_value, in, src - in); - src++; - dst = name; - while (isalnum(*src) || *src == '_') - *dst++ = *src++; - *dst = 0; - sym = sym_lookup(name, 0); - sym_calc_value(sym); - strcat(res_value, sym_get_string_value(sym)); - in = src; - } - strcat(res_value, in); - - return res_value; -} - char *conf_get_default_confname(void) { struct stat buf; static char fullname[PATH_MAX+1]; char *env, *name; - name = conf_expand_value(conf_defname); + name = expand_string(conf_defname); env = getenv(SRCTREE); if (env) { sprintf(fullname, "%s/%s", env, name); @@ -274,7 +248,8 @@ int conf_read_simple(const char *name, int def) if (expr_calc_value(prop->visible.expr) == no || prop->expr->type != E_SYMBOL) continue; - name = conf_expand_value(prop->expr->left.sym->name); + sym_calc_value(prop->expr->left.sym); + name = sym_get_string_value(prop->expr->left.sym); in = zconf_fopen(name); if (in) { conf_message(_("using defaults found in %s"), diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c index 3ea9c5f..b3e0ea0 100644 --- a/scripts/kconfig/kconf_id.c +++ b/scripts/kconfig/kconf_id.c @@ -32,7 +32,6 @@ static struct kconf_id kconf_id_array[] = { { "on", T_ON, TF_PARAM }, { "modules", T_OPT_MODULES, TF_OPTION }, { "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION }, - { "env", T_OPT_ENV, TF_OPTION }, { "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION }, }; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index f4394af..553098a 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -58,7 +58,6 @@ enum conf_def_mode { #define T_OPT_MODULES 1 #define T_OPT_DEFCONFIG_LIST 2 -#define T_OPT_ENV 3 #define T_OPT_ALLNOCONFIG_Y 4 struct kconf_id { @@ -134,9 +133,6 @@ void str_printf(struct gstr *gs, const char *fmt, ...); const char *str_get(struct gstr *gs); /* symbol.c */ -extern struct expr *sym_env_list; - -void sym_init(void); void sym_clear_all_valid(void); struct symbol *sym_choice_default(struct symbol *sym); const char *sym_get_string_default(struct symbol *sym); diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9dc8abf..9f465fe 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -49,5 +49,11 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); +/* preprocess.c */ +void env_write_dep(FILE *f, const char *auto_conf_name); +char *expand_string(const char *in); +char *expand_dollar(const char **str); +char *expand_one_token(const char **str); + /* expr.c */ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 5c5c137..8148305 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -214,9 +214,6 @@ void menu_add_option(int token, char *arg) zconf_error("trying to redefine defconfig symbol"); sym_defconfig_list->flags |= SYMBOL_AUTO; break; - case T_OPT_ENV: - prop_add_env(arg); - break; case T_OPT_ALLNOCONFIG_Y: current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y; break; diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c new file mode 100644 index 0000000..fa4abc8 --- /dev/null +++ b/scripts/kconfig/preprocess.c @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 Masahiro Yamada + +#include +#include +#include + +#include "list.h" + +/* + * Environment variables + */ +static LIST_HEAD(env_list); + +struct env { + char *name; + char *value; + struct list_head node; +}; + +static void env_add(const char *name, const char *value) +{ + struct env *e; + + e = xmalloc(sizeof(*e)); + e->name = xstrdup(name); + e->value = xstrdup(value); + + list_add_tail(&e->node, &env_list); +} + +static void env_del(struct env *e) +{ + list_del(&e->node); + free(e->name); + free(e->value); + free(e); +} + +/* The returned pointer must be freed when done */ +static char *env_expand(const char *name) +{ + struct env *e; + const char *value; + + list_for_each_entry(e, &env_list, node) { + if (!strcmp(name, e->name)) + return xstrdup(e->value); + } + + value = getenv(name); + if (!value) + value = ""; + + /* + * We need to remember all referenced environments. + * They will be written out to include/config/auto.conf.cmd + */ + env_add(name, value); + + return xstrdup(value); +} + +void env_write_dep(FILE *f, const char *autoconfig_name) +{ + struct env *e, *tmp; + + list_for_each_entry_safe(e, tmp, &env_list, node) { + fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", e->name, e->value); + fprintf(f, "%s: FORCE\n", autoconfig_name); + fprintf(f, "endif\n"); + env_del(e); + } +} + +static char *eval_clause(const char *in) +{ + char *res, *name; + + /* + * Returns an empty string because '$()' should be evaluated + * to a null string. + */ + if (!*in) + return xstrdup(""); + + name = expand_string(in); + + res = env_expand(name); + free(name); + + return res; +} + +/* + * Expand a string that follows '$' + * + * For example, if the input string is + * ($(FOO)$($(BAR)))$(BAZ) + * this helper evaluates + * $($(FOO)$($(BAR))) + * and returns the resulted string, then updates 'str' to point to the next + * character after the corresponding closing parenthesis, in this case, *str + * will be + * $(BAR) + * + * If the input does not start with '(', the first character is assumed as + * a variable name. For example, if the input string is + * ABC + * this helper evaluates + * $A + * and *str will be updated to + * BC + * This is because $ABC is equivalent to $(A)BC. (Like Make, you can omit + * parentheses if the variable name consists of a single character. + */ +char *expand_dollar(const char **str) +{ + const char *p = *str; + const char *q; + char *tmp, *out; + int nest = 0; + + /* + * A standalone '$' at the end of a token is treated as-is. + */ + if (!*p) + return xstrdup("$"); + + /* '$$' represents an escaped '$' */ + if (*p == '$') { + *str = p + 1; + return xstrdup("$"); + } + + /* Single-letter variable like '$A' */ + if (*p != '(') { + tmp = xmalloc(2); + tmp[0] = *p; + tmp[1] = 0; + *str = p + 1; + out = eval_clause(tmp); + free(tmp); + return out; + } + + /* + * Variables that consist of multiple letters + * must be surrounded with parentheses. + * For example, $(FOO) + */ + p++; + q = p; + while (*q) { + switch (*q) { + case '(': + nest++; + break; + case ')': + if (nest-- == 0) { + tmp = xmalloc(q - p + 1); + memcpy(tmp, p, q - p); + tmp[q - p] = 0; + *str = q + 1; + out = eval_clause(tmp); + free(tmp); + return out; + } + break; + default: + break; + } + q++; + } + + fprintf(stderr, "%s:%d:missing ')'\n", zconf_curname(), zconf_lineno()); + exit(1); +} + +/* + * Expand variables in the given string. Undefined variables + * expand to an empty string. + * The returned string must be freed when done. + */ +char *expand_string(const char *in) +{ + const char *prev_in, *p; + char *new, *out; + size_t outlen; + + out = xmalloc(1); + *out = 0; + + while ((p = strchr(in, '$'))) { + prev_in = in; + in = p + 1; + new = expand_dollar(&in); + outlen = strlen(out) + (p - prev_in) + strlen(new) + 1; + out = xrealloc(out, outlen); + strncat(out, prev_in, p - prev_in); + strcat(out, new); + free(new); + } + + outlen = strlen(out) + strlen(in) + 1; + out = xrealloc(out, outlen); + strcat(out, in); + + return out; +} + +/* + * Expand variables in a token. The parsing stops when a token separater + * (in most cases, it is a whitespace) is encountered. 'str' is updated to + * point to the next character. + * + * The returned string must be freed when done. + */ +char *expand_one_token(const char **str) +{ + const char *in, *prev_in, *p; + char *new, *out; + size_t outlen; + + out = xmalloc(1); + *out = 0; + + p = in = *str; + + while (1) { + if (*p == '$') { + prev_in = in; + in = p + 1; + new = expand_dollar(&in); + outlen = strlen(out) + (p - prev_in) + strlen(new) + 1; + out = xrealloc(out, outlen); + strncat(out, prev_in, p - prev_in); + strcat(out, new); + free(new); + p = in; + continue; + } + + /* Valid characters in a symbol (why '.' and '/' ?) */ + if (isalnum(*p) || *p == '_' || *p == '-' || *p == '.' || *p == '/') { + p++; + continue; + } + + break; + } + + outlen = strlen(out) + (p - in) + 1; + out = xrealloc(out, outlen); + strncat(out, in, p - in); + + *str = p; + + return out; +} diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index f0b2e3b..2460648 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -33,33 +33,6 @@ struct symbol *sym_defconfig_list; struct symbol *modules_sym; tristate modules_val; -struct expr *sym_env_list; - -static void sym_add_default(struct symbol *sym, const char *def) -{ - struct property *prop = prop_alloc(P_DEFAULT, sym); - - prop->expr = expr_alloc_symbol(sym_lookup(def, SYMBOL_CONST)); -} - -void sym_init(void) -{ - struct symbol *sym; - struct utsname uts; - static bool inited = false; - - if (inited) - return; - inited = true; - - uname(&uts); - - sym = sym_lookup("UNAME_RELEASE", 0); - sym->type = S_STRING; - sym->flags |= SYMBOL_AUTO; - sym_add_default(sym, uts.release); -} - enum symbol_type sym_get_type(struct symbol *sym) { enum symbol_type type = sym->type; @@ -1401,32 +1374,3 @@ const char *prop_get_type_name(enum prop_type type) } return "unknown"; } - -static void prop_add_env(const char *env) -{ - struct symbol *sym, *sym2; - struct property *prop; - char *p; - - sym = current_entry->sym; - sym->flags |= SYMBOL_AUTO; - for_all_properties(sym, prop, P_ENV) { - sym2 = prop_get_symbol(prop); - if (strcmp(sym2->name, env)) - menu_warn(current_entry, "redefining environment symbol from %s", - sym2->name); - return; - } - - prop = prop_alloc(P_ENV, sym); - prop->expr = expr_alloc_symbol(sym_lookup(env, SYMBOL_CONST)); - - sym_env_list = expr_alloc_one(E_LIST, sym_env_list); - sym_env_list->right.sym = sym; - - p = getenv(env); - if (p) - sym_add_default(sym, p); - else - menu_warn(current_entry, "environment variable %s undefined", env); -} diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index c6f6e21..807147e 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -34,8 +34,6 @@ struct file *file_lookup(const char *name) /* write a dependency file as used by kbuild to track dependencies */ int file_write_dep(const char *name) { - struct symbol *sym, *env_sym; - struct expr *e; struct file *file; FILE *out; @@ -54,21 +52,7 @@ int file_write_dep(const char *name) fprintf(out, "\n%s: \\\n" "\t$(deps_config)\n\n", conf_get_autoconfig_name()); - expr_list_for_each_sym(sym_env_list, e, sym) { - struct property *prop; - const char *value; - - prop = sym_get_env_prop(sym); - env_sym = prop_get_symbol(prop); - if (!env_sym) - continue; - value = getenv(env_sym->name); - if (!value) - value = ""; - fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value); - fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name()); - fprintf(out, "endif\n"); - } + env_write_dep(out, conf_get_autoconfig_name()); fprintf(out, "\n$(deps_config): ;\n"); fclose(out); diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 045093d..9dc5fe3 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -1,6 +1,5 @@ %option nostdinit noyywrap never-interactive full ecs %option 8bit nodefault yylineno -%option noinput %x COMMAND HELP STRING PARAM %{ /* @@ -35,6 +34,8 @@ struct buffer *current_buf; static int last_ts, first_ts; +static char *expand_token(const char *in, size_t n); +static void append_expanded_string(const char *in); static void zconf_endhelp(void); static void zconf_endfile(void); @@ -147,6 +148,13 @@ n [A-Za-z0-9_-] yylval.string = text; return T_WORD; } + ({n}|[/.$])+ { + /* this token includes at least one '$' */ + yylval.string = expand_token(yytext, yyleng); + if (strlen(yylval.string)) + return T_WORD; + free(yylval.string); + } #.* /* comment */ \\\n ; [[:blank:]]+ @@ -157,12 +165,13 @@ n [A-Za-z0-9_-] } { - [^'"\\\n]+/\n { + "$".* append_expanded_string(yytext); + [^$'"\\\n]+/\n { append_string(yytext, yyleng); yylval.string = text; return T_WORD_QUOTE; } - [^'"\\\n]+ { + [^$'"\\\n]+ { append_string(yytext, yyleng); } \\.?/\n { @@ -249,6 +258,58 @@ n [A-Za-z0-9_-] } %% +static char *expand_token(const char *in, size_t n) +{ + char *out; + int c; + char c2; + const char *rest, *end; + + new_string(); + append_string(in, n); + + /* get the whole the line because we do not know the end of token. */ + while ((c = input()) != EOF) { + if (c == '\n') { + unput(c); + break; + } + c2 = c; + append_string(&c2, 1); + } + + rest = text; + out = expand_one_token(&rest); + + /* push back unused characters to the input stream */ + end = rest + strlen(rest); + while (end > rest) + unput(*--end); + + free(text); + + return out; +} + +static void append_expanded_string(const char *str) +{ + const char *end; + char *res; + + str++; + + res = expand_dollar(&str); + + /* push back unused characters to the input stream */ + end = str + strlen(str); + while (end > str) + unput(*--end); + + append_string(res, strlen(res)); + + free(res); +} + void zconf_starthelp(void) { new_string(); diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index ad6305b..3a4a0fa 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -534,7 +534,6 @@ void conf_parse(const char *name) zconf_initscan(name); - sym_init(); _menu_init(); if (getenv("ZCONF_DEBUG")) @@ -780,3 +779,4 @@ void zconfdump(FILE *out) #include "expr.c" #include "symbol.c" #include "menu.c" +#include "preprocess.c" From patchwork Fri Apr 13 05:06:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133326 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346456ljb; Thu, 12 Apr 2018 22:11:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx49oTKvRJIuFcyOA1kYJuA1mMDNRHiHA1QI3zycrV//MWCJR3O7PXISVsdQnyBImANSSqatx X-Received: by 10.98.180.24 with SMTP id h24mr10169876pfn.213.1523596307054; Thu, 12 Apr 2018 22:11:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596307; cv=none; d=google.com; s=arc-20160816; b=pm4agRrPpsng4k+A6oWn99M+pGoodWUTPVV2gEa14SX3WbYGwyAUJ42/V3Eb1cYlKy ThNpC+7nKsDAmmR5YogYxnaHVtIDgYso+rV8jtrXhDWjNCzw3Nuc1Taocif62yw6xDCL y0ZSStQODDgqsHatnDDffeqIsysm4g42Awg2QXUFjEln39nETyqgfDmK1r572Ew+kw4V qJ2hpqszZ+PD8pfN+pnZNZRIXhS6+F6/v3b/VDxyXlKZJHQHzl3iI1gK/qxjTOnC6c+9 Oba7zW6g2emQt4+bJ+bbpbyksjVN0P2khUASG8vqN918P/I3FK7k2B76l8CiqsnqBwKJ /dVw== 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=Va2AisuizRhRW/RFE7j85F4MfFSvDmOzvfaqKUI638k=; b=dBdf+ySuN7hscqk+J1h9vf1ne+xt7JJrJDHLGJHrQ5Tu4AKcg5BRA9Phug4xG3xUfz X4q6VoX7GT9WzSR3tWIAD91ATsxU46XzPgpqPRu+o/Nyms99MwCMgXIaHxJxfwkcwSz6 KiQbw1joPmKFzr3tJPEmiJW8bv6qcsWYmvGuGWU+VFkoCVhf6JC3pKkw2SdIcEUOITNG KAi/s07XWtmBCqvRz04eBiSQgYS/nIHzLrgTJccuANNagL4kqtGFJrtIDK21YpW77X21 eflvtf18KjkiVZ80GW8xKr+DV0K1XYytsSU5qvh6t9IeD66VyD+zxS8AXm3CsLvB+3rr VPlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=X322LuMu; 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 v145si1745943pgb.203.2018.04.12.22.11.46; Thu, 12 Apr 2018 22:11:47 -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=X322LuMu; 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 S1752007AbeDMFIV (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:21 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54457 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750867AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lfx029209; Fri, 13 Apr 2018 14:06:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lfx029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596012; bh=Va2AisuizRhRW/RFE7j85F4MfFSvDmOzvfaqKUI638k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X322LuMuZ7OaFQ9udOIJBZf3IpzecG6UeWDBps5Eb9LxcRmi5xM/tGoWibEoRosx9 /3fdF1J17Hm0NjX0GMx9E5f6S1aC8zeC32wyC4Kp1UkX+Jjzbekk07CRoCsq+pSKpu h1t0GNL4xwxhDFw6SlBSidzkOKgIxV+XDyBiA2F65sVkWOYhpRgKRaRSozh+1aJ8Ug W1S6NNyjyoTqpixwszjsbhvsb224sBMNSrfO8Mh/JOlJLHYe4xtEguZ37OGlfGXoe3 /yoPuhWZr9677OJp/ICDPfEilzfGSgxBESgpA47WoG0S7yseZ9ceLKy5FwCj3vSfZ9 nJd3mvaVIcn0Q== 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 05/30] kconfig: remove string expansion in file_lookup() Date: Fri, 13 Apr 2018 14:06:14 +0900 Message-Id: <1523595999-27433-6-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 There are two callers of file_lookup(), but there is no more reason to expand the given path. [1] zconf_initscan() This is used to open the first Kconfig. sym_expand_string_value() has never been used in a useful way here; before opening the first Kconfig file, obviously there is no symbol to expand. If you use expand_string_value() instead, environments in KBUILD_KCONFIG would be expanded, but I do not see practical benefits for that. [2] zconf_nextfile() This is used to open the next file from 'source' statement. Symbols in the path like "arch/$SRCARCH/Kconfig" needed expanding, but it was replaced with the direct environment expansion. The environment has already been expanded before the token is passed to the parser. By the way, file_lookup() was already buggy; it expanded a given path, but it used the path before expansion for look-up: if (!strcmp(name, file->name)) { Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson --- Changes in v3: None Changes in v2: - Simplify the patch. Just remove text expansion. scripts/kconfig/util.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 807147e..790967df 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -14,18 +14,16 @@ struct file *file_lookup(const char *name) { struct file *file; - char *file_name = sym_expand_string_value(name); for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { - free(file_name); return file; } } file = xmalloc(sizeof(*file)); memset(file, 0, sizeof(*file)); - file->name = file_name; + file->name = xstrdup(name); file->next = file_list; file_list = file; return file; From patchwork Fri Apr 13 05:06:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133323 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp345991ljb; Thu, 12 Apr 2018 22:11:04 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+abQryNXObMDb5+26ek5c639D9OEqtukI7EoL3W6MLVb0JMZ3gn1EpFciVBlhUZHMcmh3t X-Received: by 10.98.89.200 with SMTP id k69mr10270979pfj.100.1523596263976; Thu, 12 Apr 2018 22:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596263; cv=none; d=google.com; s=arc-20160816; b=VAwAVwNJntgSrJ2yWrN8+VSCMoIsyUPNCQrskqDql5pnuJLWfWxG3PCGqqQdfpftBZ bBm+BhZyDydFtQwFu8INNj50mux4xvKiMxfssr4H6kuzAnju2nbO0r4Sjeqx3k61BMSx zRFqK8h3R1hztX200ZsOYv/+9NTjbJROUMlmSIWCjjF7c3pydKApBQP6OXeAX/4V3HE9 EI5hvDf5flqd1K6zvLujn2NnPkPxz42aczchYmw0Zsstmu4Im/zmjj7J8CuG8vry4lsr DSbU+FnbxzUmcPgz4iiyA2Fsho8oZtJ5/EG986gbzHqLgiiQm5H8mTAB7+qiyyo+pZQo mfNg== 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=ApQsRxhg+uQB31OxCSwqeIWF4lqBlzXYJC0ifRjW9TI=; b=cEQmbvSV48680woBIuoMRe21dr2wS2LZ4PY8HsGh4syw9Nf+V01HPVWeOzgcpfRZnb GxbBodVj3ZO7RLRhAMSkiYf06zIVEylg1jkv1Xh2Qr/GrL2yZBtG95Ui/6fFvNT7dcLv hT4ilUZhOEDTCSleBCmJO5fWFIcSRAphrVeB4EOXTeV/D0BAw7rr18vTlAtFANAQC+rd RKUARS/AHGAx5lGeCDl/K6y2HRmBC/2ysePY6hhFC1RG3oCiuZWb3WJ32YgPHmWF6/jZ oi+C2A7wvYJ5FYP/vihBU7CeJBbPv5qMA40rglwEK0dW2RIh5CK7AWdcH3VUG/zCzxei NMWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wdKn9JDV; 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 d19-v6si4913546pls.334.2018.04.12.22.11.03; Thu, 12 Apr 2018 22:11:03 -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=wdKn9JDV; 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 S1752846AbeDMFIe (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:34 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54957 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752223AbeDMFIa (ORCPT ); Fri, 13 Apr 2018 01:08:30 -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 w3D56lg0029209; Fri, 13 Apr 2018 14:06:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg0029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596013; bh=ApQsRxhg+uQB31OxCSwqeIWF4lqBlzXYJC0ifRjW9TI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdKn9JDVOpy0nJHmltiHYZ0uj31Zwy0DtV37sS+NfXueYRKOUJwKlJUU92UWr8+v3 2Pyg2SViVelTGErYFLxj3/TPW4V3g08f5GVVqqu6DAXC9L/Z+cIf8P9TvSXNLdK0xN CugWupm7ywjcP5AXFgY6o2IdwmTuD5ozsowhcBFC2EFgy7epaSp1cICL6phtpWacrr 9d753X9KDjkm5Ksgg4E66VVi349mr6qhXUIVmj27fkL/6sb+hhauKbpg+Edkr8AL2t rs1RxaFI89/GvIPHa1DWPwROo66C7oBx5tDki1Hz1C9KN7VewG/LA43EnhqjVVEyWQ B+dynIz/h1qzA== 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 06/30] kconfig: remove string expansion for mainmenu after yyparse() Date: Fri, 13 Apr 2018 14:06:15 +0900 Message-Id: <1523595999-27433-7-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 Now that environments are expanded in the lexer, conf_parse() does not need to expand them explicitly. The hack introduced by commit 0724a7c32a54 ("kconfig: Don't leak main menus during parsing") can go away. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson --- Changes in v3: None Changes in v2: - Simplify the patch. Just remove the text expansion. scripts/kconfig/zconf.y | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 3a4a0fa..22e318c 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -109,7 +109,7 @@ static struct menu *current_menu, *current_entry; %% input: nl start | start; -start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list; +start: mainmenu_stmt stmt_list | stmt_list; /* mainmenu entry */ @@ -118,19 +118,6 @@ mainmenu_stmt: T_MAINMENU prompt nl menu_add_prompt(P_MENU, $2, NULL); }; -/* Default main menu, if there's no mainmenu entry */ - -no_mainmenu_stmt: /* empty */ -{ - /* - * Hack: Keep the main menu title on the heap so we can safely free it - * later regardless of whether it comes from the 'prompt' in - * mainmenu_stmt or here - */ - menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL); -}; - - stmt_list: /* empty */ | stmt_list common_stmt @@ -528,7 +515,6 @@ word_opt: /* empty */ { $$ = NULL; } void conf_parse(const char *name) { - const char *tmp; struct symbol *sym; int i; @@ -544,10 +530,10 @@ void conf_parse(const char *name) if (!modules_sym) modules_sym = sym_find( "n" ); - tmp = rootmenu.prompt->text; - rootmenu.prompt->text = _(rootmenu.prompt->text); - rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); - free((char*)tmp); + if (!menu_has_prompt(&rootmenu)) { + current_entry = &rootmenu; + menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); + } menu_finalize(&rootmenu); for_all_symbols(i, sym) { From patchwork Fri Apr 13 05:06:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133321 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp345749ljb; Thu, 12 Apr 2018 22:10:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ka9xzNNDRn++SjdYKM2Qh3jOxYBifu4NioWZ3oVbXL6Jye3BrxEZ9yOkkKITuRhNdUQbd X-Received: by 10.99.4.5 with SMTP id 5mr2904606pge.147.1523596240109; Thu, 12 Apr 2018 22:10:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596240; cv=none; d=google.com; s=arc-20160816; b=c2z6lfWPjWLjW8pbqcyxeYTXqjZeZ+bXYE2/JLETsMWnZ7eymWT3JO+YJm1+kQj/jz kjV5IebredtR8wKJnpYZOwIV3NlOPygkTxSx/REgvSSckvkaIc9NunDWafDUa6DpY6oD ck/mekYQLNx+BvN9ND3AvKLWDMZvrxcwsI52sXyogu93H7N52Zre5cI7WTMkny9JKVNZ h0hVc7sIBo5gDJCIdVkbv8ilZchX3Cda8Myul0UPlFU5GL/jAHUXki6RU4mMj/MuJMsv 1rhpgSn27WgifDv4+YdLblfxPWaIm3oCbEyC4E6w7Tj5eQDI8vTjZBd+gE9eHJmm6bj5 3gCg== 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=xf6Ah/J4+SToU+K/ZeZa9XVRX0GK60bEzd6Qz746jQA=; b=kEkiBZwKK1blZTLIfoYNKN6cNuxd+uSC9T10bMIqTxTzLmZkahyBainZqHg9SujZB/ 681thySdV1F/x6bbcKZW5+e/k6WVSvJWOfkkbPUZpC6S+zOSCmlAb2K2JfVuYRxYYmxU jYhsqlDAxqk6i8i0URyWgD5Nvn74s2zyChaJkvPZdmdtKTxi+59lqwFq4lWiSj2a3+Qd /3Ar+ftizsg3f9Mdk5frbMr4G8wJZOP7eTQexAu74wf1MrAFSXT0CxLyA468sMbcLwl2 aVP3uyfAg9AoXr9vWBtS9Eyyh6q+JyFkoiSJ8Jr3X5XB5qSE8I186L8xFv3pHXPo4B3d yHwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=o29xVALm; 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 k9si3443994pgr.146.2018.04.12.22.10.39; Thu, 12 Apr 2018 22:10:40 -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=o29xVALm; 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 S1752986AbeDMFIg (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:36 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54961 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752328AbeDMFIa (ORCPT ); Fri, 13 Apr 2018 01:08:30 -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 w3D56lg1029209; Fri, 13 Apr 2018 14:06:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg1029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596014; bh=xf6Ah/J4+SToU+K/ZeZa9XVRX0GK60bEzd6Qz746jQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o29xVALmDeJG0gPcZlV9wPcupFzaC4lPPa364caqSV0Hg2QIKzwAcWYoNBI4plJR8 aWMWKLpBt2Gy7DDSdDfqjO/UzrsbIBYt7v9MPtAr+/yIeR71YbxtrDYzB8zzrXTOD6 w0whenia2rKTKKLZmH/qnVbVk7GS0/RUtYdF+VmKlV77Zo49MAFuVNR23yxf7lCb+6 CH5HDGAYWHCTkLofELj66tuYmWAiJwtDzIKiRxuQ2oYkE+n0cyXWBa6MU3z81wy1Tj 4fKAi3lAAuOzguYUv866W5i6Pmn8XuRw2N284Ed8zUOJdzOToc8YSYh3hiolT5xb9E VQDO8/M6fTu3w== 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 07/30] kconfig: remove sym_expand_string_value() Date: Fri, 13 Apr 2018 14:06:16 +0900 Message-Id: <1523595999-27433-8-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 There is no more caller of sym_expand_string_value(). Signed-off-by: Masahiro Yamada --- Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 1 - scripts/kconfig/symbol.c | 53 --------------------------------------------- 2 files changed, 54 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9f465fe..c46929f 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -31,7 +31,6 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -char *sym_expand_string_value(const char *in); const char * sym_escape_string_value(const char *in); struct symbol ** sym_re_search(const char *pattern); const char * sym_type_name(enum symbol_type type); diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 2460648..7c9a88e 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -879,59 +879,6 @@ struct symbol *sym_find(const char *name) return symbol; } -/* - * Expand symbol's names embedded in the string given in argument. Symbols' - * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to - * the empty string. - */ -char *sym_expand_string_value(const char *in) -{ - const char *src; - char *res; - size_t reslen; - - /* - * Note: 'in' might come from a token that's about to be - * freed, so make sure to always allocate a new string - */ - reslen = strlen(in) + 1; - res = xmalloc(reslen); - res[0] = '\0'; - - while ((src = strchr(in, '$'))) { - char *p, name[SYMBOL_MAXLENGTH]; - const char *symval = ""; - struct symbol *sym; - size_t newlen; - - strncat(res, in, src - in); - src++; - - p = name; - while (isalnum(*src) || *src == '_') - *p++ = *src++; - *p = '\0'; - - sym = sym_find(name); - if (sym != NULL) { - sym_calc_value(sym); - symval = sym_get_string_value(sym); - } - - newlen = strlen(res) + strlen(symval) + strlen(src) + 1; - if (newlen > reslen) { - reslen = newlen; - res = xrealloc(res, reslen); - } - - strcat(res, symval); - in = src; - } - strcat(res, in); - - return res; -} - const char *sym_escape_string_value(const char *in) { const char *p; From patchwork Fri Apr 13 05:06:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133311 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344176ljb; Thu, 12 Apr 2018 22:08:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx48DEKQxlk6HifAOG/DrWiegt4rt8DLnKCzozWwOAYcE2E0u38cCZtO+a9+OTI+fUQDqeIEV X-Received: by 2002:a17:902:3181:: with SMTP id x1-v6mr3851060plb.2.1523596106614; Thu, 12 Apr 2018 22:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596106; cv=none; d=google.com; s=arc-20160816; b=ItVCjEDp57ZBV2dfC/rbI91nTVKQXLNYIKdtZnDjruhQaj/iM7pQT16w0B5RDdZT9j wNEchFLY+3g84l7vYqZSueWUFh20xRX7HrI15Wyxe102H1UCOLeTbzfKZsu8vqH0X3RM WCKkTlek10UjX06GR5mdXfk9no3MzybeUsP2haxzgucju1Yxt9sqQ0SySr5ZDKtuTf8u rOr2NgsmFfB8KoTp+rVBBH6y5S5kppKDcGQutfPk+IRk63F21b0rSn1/XcVs+xjCC4U+ JC2oa4xElftKt4hbNRTi+sdxMzOZBoDo4BHNM/184VBw7KRYQ2zUK0vR/dBwk0dsVLhr evag== 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=32/sc7ha9TNkBMv72TwSV+Q2kKXWYKuYHYguU7Q1mOM=; b=ddaCohMlSwWndWD7i5enzQ4bzD7eVPl2gwLy8lBQSjuqy/wL9Q0x1f6ThoJLnaEAL7 PG2K2NCv5NudmfXCtdEEMe5Cf0SoXtQ6ow2zq84+VqXWhG6ikhBPMttimW29QwW1sNyG +zfMSUX7UjvBxgXmmt6rBPMtZD3QeNxkimuR3hX4qpLhLHE6hfPoiHCC5M7M9vzYpRIP Dt7NRbt4BOpIKIKRL23fs+xe+0yR9MAosolPxdB0auzLWvcZHLOPsl+UYXpclzuRIAA1 EKbxqQkd56FAeoNcHnhQyqDO0/AOqCQGLdbPx/VBrfNilheHcgz/CRBqLlv0oEzqBOPE bfSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Q6UTAjYg; 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 y7-v6si4722599plt.287.2018.04.12.22.08.25; Thu, 12 Apr 2018 22:08:26 -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=Q6UTAjYg; 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 S1751380AbeDMFIR (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:17 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54456 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750859AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lg2029209; Fri, 13 Apr 2018 14:06:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg2029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596015; bh=32/sc7ha9TNkBMv72TwSV+Q2kKXWYKuYHYguU7Q1mOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6UTAjYgxPjecSrW1d/CFBJS+Khgp33JuedFP2Y5x8yfK1EkR+Tds+5BBS4Jy8d+p wEiHY79H1Ewh9K5S87a1AJbPeAHyJl0PBETKaBpXd9rf/OvheRvZfzjiX6yJLEjEp5 xDW025N0m3j42UB1bdLVd2kNb/s4RiolUDV07Vuvtn/OcFIRZ3Q9qxNsmtxXJU2DlC Hk6rG5Z1AhncPsXqXkrbqXPM1vigvIN5/c9zvi3TSEWm5yxAEZQAOUoCQBMepkA0MS db7a+obJjIzgSGoQy5jbLq+gQRJDuqQ19pxlgiCpUxxXhPBmRCd6vG1IkQDldxjSh5 W365Vhzhc+WFA== 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 08/30] kconfig: add built-in function support Date: Fri, 13 Apr 2018 14:06:17 +0900 Message-Id: <1523595999-27433-9-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 This commit adds a new concept 'function' to do more text processing in Kconfig. A function call looks like this: $(function arg1, arg2, arg3, ...) This commit adds the basic infrastructure to expand functions. Change the text expansion helpers to take arguments. Signed-off-by: Masahiro Yamada --- Changes in v3: - Split base infrastructure and 'shell' function into separate patches. Changes in v2: - Use 'shell' for getting stdout from the comment. It was 'shell-stdout' in the previous version. - Symplify the implementation since the expansion has been moved to lexer. scripts/kconfig/preprocess.c | 142 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 130 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index fa4abc8..e77cf7c 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -8,6 +8,10 @@ #include "list.h" +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +static char *expand_string_with_args(const char *in, int argc, char *argv[]); + /* * Environment variables */ @@ -74,9 +78,47 @@ void env_write_dep(FILE *f, const char *autoconfig_name) } } -static char *eval_clause(const char *in) +/* + * Built-in Functions + */ +struct function { + char *name; + char *(*func)(int argc, char *argv[]); +}; + +static const struct function function_table[] = { +}; + +static char *function_call(const char *name, int argc, char *argv[]) { - char *res, *name; + const struct function *f; + int i; + + for (i = 0; i < ARRAY_SIZE(function_table); i++) { + f = &function_table[i]; + if (!strcmp(f->name, name)) + return f->func(argc, argv); + } + + return NULL; +} + +#define FUNCTION_MAX_ARGS 16 + +/* + * Evaluate a clause with arguments. argc/argv are arguments from the upper + * function call. + * + * Returned string must be freed when done + */ +static char *eval_clause(const char *in, int argc, char *argv[]) +{ + char *tmp, *prev, *p, *res, *name; + char delim = ' '; + int new_argc = 0; + char *new_argv[FUNCTION_MAX_ARGS]; + int nest = 0; + int i; /* * Returns an empty string because '$()' should be evaluated @@ -85,10 +127,73 @@ static char *eval_clause(const char *in) if (!*in) return xstrdup(""); - name = expand_string(in); + tmp = xstrdup(in); + + prev = p = tmp; - res = env_expand(name); + /* + * Split into tokens + * The function name and the first argument are separated by a space. + * Arguments are separated by a comma. + * For example, if the function call is like this: + * $(foo abc,$(x),$(y)) + * + * The input string for this helper should be: + * foo abc,$(x),$(y) + * + * and split into: + * new_argv[0]: foo + * new_argv[1]: abc + * new_argv[2]: $(x) + * new_argv[3]: $(y) + */ + while (*p) { + if (nest == 0 && *p == delim) { + *p = 0; + new_argv[new_argc++] = prev; + prev = p + 1; + delim = ','; + } else if (*p == '(') { + nest++; + } else if (*p == ')') { + nest--; + } + + p++; + } + new_argv[new_argc++] = prev; + + /* + * Shift arguments + * new_argv[0] represents a function name or a variable name. Put it + * into 'name', then shift the rest of the arguments. This simplifies + * 'const' handling. + */ + name = expand_string_with_args(new_argv[0], argc, argv); + new_argc--; + for (i = 0; i < new_argc; i++) + new_argv[i] = expand_string_with_args(new_argv[i + 1], + argc, argv); + + free(tmp); + + /* Look for built-in functions */ + res = function_call(name, new_argc, new_argv); + if (res) + goto out; + + /* Last, try environment variable */ + if (new_argc == 0) { + res = env_expand(name); + if (res) + goto out; + } + + res = xstrdup(""); +out: free(name); + for (i = 0; i < new_argc; i++) + free(new_argv[i]); return res; } @@ -115,7 +220,7 @@ static char *eval_clause(const char *in) * This is because $ABC is equivalent to $(A)BC. (Like Make, you can omit * parentheses if the variable name consists of a single character. */ -char *expand_dollar(const char **str) +static char *expand_dollar_with_args(const char **str, int argc, char *argv[]) { const char *p = *str; const char *q; @@ -124,6 +229,9 @@ char *expand_dollar(const char **str) /* * A standalone '$' at the end of a token is treated as-is. + * For example, the '$' before the comma in $(foo $,A) and the '$' + * before the closing parenthesis in $(shell echo $) lose the special + * meaning. This is the behavior of Make 4.2 or newer. */ if (!*p) return xstrdup("$"); @@ -140,15 +248,15 @@ char *expand_dollar(const char **str) tmp[0] = *p; tmp[1] = 0; *str = p + 1; - out = eval_clause(tmp); + out = eval_clause(tmp, argc, argv); free(tmp); return out; } /* - * Variables that consist of multiple letters + * Variables that consist of multiple letters, and function calls * must be surrounded with parentheses. - * For example, $(FOO) + * For example, $(FOO), $(shell echo helloworld) */ p++; q = p; @@ -163,7 +271,7 @@ char *expand_dollar(const char **str) memcpy(tmp, p, q - p); tmp[q - p] = 0; *str = q + 1; - out = eval_clause(tmp); + out = eval_clause(tmp, argc, argv); free(tmp); return out; } @@ -179,11 +287,11 @@ char *expand_dollar(const char **str) } /* - * Expand variables in the given string. Undefined variables + * Expand variables, functions, etc. in the given string. Undefined variables * expand to an empty string. * The returned string must be freed when done. */ -char *expand_string(const char *in) +static char *expand_string_with_args(const char *in, int argc, char *argv[]) { const char *prev_in, *p; char *new, *out; @@ -195,7 +303,7 @@ char *expand_string(const char *in) while ((p = strchr(in, '$'))) { prev_in = in; in = p + 1; - new = expand_dollar(&in); + new = expand_dollar_with_args(&in, argc, argv); outlen = strlen(out) + (p - prev_in) + strlen(new) + 1; out = xrealloc(out, outlen); strncat(out, prev_in, p - prev_in); @@ -210,6 +318,16 @@ char *expand_string(const char *in) return out; } +char *expand_string(const char *in) +{ + return expand_string_with_args(in, 0, NULL); +} + +char *expand_dollar(const char **str) +{ + return expand_dollar_with_args(str, 0, NULL); +} + /* * Expand variables in a token. The parsing stops when a token separater * (in most cases, it is a whitespace) is encountered. 'str' is updated to From patchwork Fri Apr 13 05:06:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133341 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp348593ljb; Thu, 12 Apr 2018 22:15:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx48AGDsqBrJJNuvXSOrSmvevRj1D0MAbYOz0DTSa4BynuQTYXOzEEzMwzOZX1J1H/dK1CS10 X-Received: by 10.99.113.86 with SMTP id b22mr298874pgn.321.1523596512175; Thu, 12 Apr 2018 22:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596512; cv=none; d=google.com; s=arc-20160816; b=WmMrwh1qh1KhiPU7tvxieCKWgo1shgVXb7mF3cJgsCJyR2zGZvAgcuZdfYSh6Trwzt A0s+iK1fyZv0909ztwor+MUjlsCb3xNJ2glpE2a5R51VKT7NbwmaX+xhqA3rrszs/rB1 HQfWU026HQsaH+rpJYopFuzMWLoyojmZrwIU6oqkkc2uyhhMjnvoCRva3d1iGYafQ024 1HVAqlMn0XJMGkOZ4zocSxxiziXeUrs2KEZuAiBVROSsZGFt8nNYPKfDlO+7TuBQq1uG u0zYsREvTUobfcPhJSBqxexfX/VB2S4oUBjWxTzXlEEfd+uEb1HgOi6vbQ7PTCNEycs2 z1uQ== 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=hCQXgSfnKEzUmJomq6wiVg7pXMa6INgMpB99c5otC70=; b=rxbG3ZqVdQYsD3v1+C5s0hs0a07ZOlCDgdRgUCE7F2LW11u6qW4obXHuTG27i2DGUz 2auV5QQ00jDimnRf1dEPp+uqJtjtnoiDo4HKeg6xbLO2Ztgp8o+bjd9VX56tzAav4QG2 7OL2m0aMDnZ8gCK4mF0WG0uXoLjCM7prNvhTI+39P+8YXJfp9IOr7UqOWsEJxNF+OQKW vgajgeGwjsW9JqNcJkEmGrZYMmRqOrBuKFCy9NrrQpoEqcsOdqBbqIn0EVWCCCYKzi9p EcZ4nCHHw+CwLt4NGhyYfmNUmwZgQdOmYvkhG0U8+DW0w+978NHjke/CoY+SF4sY4i+M DYVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=2TUHcwwY; 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 g3-v6si4915708pld.513.2018.04.12.22.15.11; Thu, 12 Apr 2018 22:15:12 -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=2TUHcwwY; 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 S1753909AbeDMFOo (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:44 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54464 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lg3029209; Fri, 13 Apr 2018 14:06:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg3029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596016; bh=hCQXgSfnKEzUmJomq6wiVg7pXMa6INgMpB99c5otC70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2TUHcwwYx/96q06HzbVXc3gsDfmcbm6MlAzQJxL+ENtPmkuuX3uwJJrn9COxtdqxj GPMt3KhzRHvW0gi++8MAhOPY9wH37cgTCrYmIPtDCu8+Qv8OUhlc39BctZkNK23y6Q V7hbY678plEgpzgvzaYrn3nc3YEaU6EQqwfEneveMBI1oG2/SqfJWKsVU5sIc0dHSW 6inpaVlxod/ov2TEb/gb1msmZCdz4Xg5F7mL2x25N2s6n4QPHMJVJtuFLLusTo+KzR /+zvmo8K15ZAU/yYkBU4VmNzU1UXYfiqE+Dec53atQirhgDDh4jKt0Z/+7GcWdml8i DYuC+/Th3/9dw== 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 09/30] kconfig: add 'shell' built-in function Date: Fri, 13 Apr 2018 14:06:18 +0900 Message-Id: <1523595999-27433-10-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 This accepts a single command to execute. It returns the standard output from it. [Example code] config HELLO string default "$(shell echo hello world)" config Y def_bool $(shell echo y) [Result] $ make -s alldefconfig && tail -n 2 .config CONFIG_HELLO="hello world" CONFIG_Y=y Caveat: Like environments, functions are expanded in the lexer. You cannot pass symbols to function arguments. This is a limitation to simplify the implementation. I want to avoid the dynamic function evaluation, which would introduce much more complexity. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index e77cf7c..f4c606f 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -86,7 +86,73 @@ struct function { char *(*func)(int argc, char *argv[]); }; +/* + * Some commands treats commas verbatim. Concatenate arguments to get + * back the original input. The returned string must be freed when done. + */ +static char *join_args(int argc, char *argv[]) +{ + size_t len = 0; + char *out; + int i; + + for (i = 0; i < argc; i++) + len += strlen(argv[i]) + 1; + + out = xmalloc(len); + out[0] = 0; + for (i = 0; i < argc; i++) { + strcat(out, argv[i]); + if (i != argc - 1) + strcat(out, ","); + } + + return out; +} + +static char *do_shell(int argc, char *argv[]) +{ + FILE *p; + char buf[256]; + char *cmd; + size_t nread; + int i; + + cmd = join_args(argc, argv); + + p = popen(cmd, "r"); + if (!p) { + perror(cmd); + goto free; + } + + nread = fread(buf, 1, sizeof(buf), p); + if (nread == sizeof(buf)) + nread--; + + /* remove trailing new lines */ + while (buf[nread - 1] == '\n') + nread--; + + buf[nread] = 0; + + /* replace a new line with a space */ + for (i = 0; i < nread; i++) { + if (buf[i] == '\n') + buf[i] = ' '; + } + + if (pclose(p) == -1) + perror(cmd); + +free: + free(cmd); + + return xstrdup(buf); +} + static const struct function function_table[] = { + { .name = "shell", .func = do_shell }, }; static char *function_call(const char *name, int argc, char *argv[]) From patchwork Fri Apr 13 05:06:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133312 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344257ljb; Thu, 12 Apr 2018 22:08:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/3JRTaI2/Jt7cnwQ5iRa2EExkIpObvGDGqch7Pj0RiCTSfMoIVsvv2SWMAHVGnNl3D6cIO X-Received: by 10.101.70.72 with SMTP id k8mr2845584pgr.402.1523596115091; Thu, 12 Apr 2018 22:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596115; cv=none; d=google.com; s=arc-20160816; b=sn6+hQkKPQ7zvrEVYktNMOvC+6PydzLPRkoCypaBh9mCBnUNSUF7lCg2IDDl63dkLa xbbV5lBQZyQX4zVkHUFiU59tbr2HXMaCss9r+VFaPGoyhevqD9OXX+VsWdh+Q5fnaf3N vRKXKFKbIfnEop4P9ZYCUeZ/4w73WJEqKwxxujwYtQzYbK7TAwXMp3FIi5P86/puZqY2 Xh9H4JWwESzTjbOzzWeoyV6NDL1cNZx0M0Qf1WUfGtaMoFr124+/ZpDvrNrudYZx+E5g 7APtQVViaTdqUCVM0KeMM6AUC/VediBft+4mJjNnVx55wjDy7Cq5bzHVa5IN22yHwsKe 7cUA== 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=dgPuQuvAnYcI8SIWEi6+4oaT6Am/yO+BkCMNL1AoPuM=; b=pHEeW0Wvee88Nfx3nBZO830gIbdEmJPrlF9LuG430uZ3VmzfUlt0nUHAT9/kAsL33A QhTlvivP/H9gsnMBxl5cAJj2YVXFGlI0gefM8UmwF+Q2+fjFxTai7bHvwnKMWh8ubb+o R83BLtZlK3k7iSzbSI8VWCawj/Zana9Pa9LXZBqA2zORgWVGipmwQ3a/twgV0bHyeD7D A/bOrdk61Q8kx4rd5oWsQnZQACX36NRkMZ33rKkC2Uqrog3YNYPCyEzTGfcErJaj9p7W JlMWoXzVL+jSglMvQgzESdlg/qdHuM0QC/6agPO017WtDY3iJvTObo+uUUM43rTP9uUP BLLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=UK9P8nPX; 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 i129si3280749pgd.206.2018.04.12.22.08.34; Thu, 12 Apr 2018 22:08:35 -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=UK9P8nPX; 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 S1752186AbeDMFIY (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:24 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54461 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750885AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lg4029209; Fri, 13 Apr 2018 14:06:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg4029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596017; bh=dgPuQuvAnYcI8SIWEi6+4oaT6Am/yO+BkCMNL1AoPuM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UK9P8nPXAOnN826BpWTV2j95aOSQGrI57OlE6JJwFOqos7eWli5R99lN9k9QshYS1 pmAbBsK08EO1btVgORuNiciqzfk6q/2dKljQV/KZBraYeCntg1xMqjZU4NfI1ZobnK 8rDVNupB6gqhILij0eQO7Jpm4v2kpPVCxF8Dea2JA5c+VmodniW8Uc0NTHjjiRVU0r 4T4EkCUHItK8IO+fjfiPMPInqs6QQTm27yW/T0Ut/lWFvtmjtuMhPadMEHsa/OxGya QGl1wdQXDunhuL4qb0LJ4vqhmUQu32TSX5HHjK4BlZXO+OeaMCwDA00mkvUQztba/H AJDwPVl/QBq/A== 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 10/30] kconfig: replace $(UNAME_RELEASE) with function call Date: Fri, 13 Apr 2018 14:06:19 +0900 Message-Id: <1523595999-27433-11-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 Now that 'shell' function is supported, this can be self-contained in Kconfig. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson --- Changes in v3: None Changes in v2: None Makefile | 3 +-- init/Kconfig | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 5298ad7..ca3e3e8 100644 --- a/Makefile +++ b/Makefile @@ -284,8 +284,7 @@ include scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) -UNAME_RELEASE := $(shell uname --release) -export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION UNAME_RELEASE +export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION # SUBARCH tells the usermode build what the underlying arch is. That is set # first, and if a usermode build is happening, the "ARCH=um" on the command diff --git a/init/Kconfig b/init/Kconfig index e6dafed5..4b0b636 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2,9 +2,9 @@ config DEFCONFIG_LIST string depends on !UML option defconfig_list - default "/lib/modules/$(UNAME_RELEASE)/.config" + default "/lib/modules/$(shell uname --release)/.config" default "/etc/kernel-config" - default "/boot/config-$(UNAME_RELEASE)" + default "/boot/config-$(shell uname --release)" default ARCH_DEFCONFIG default "arch/$(ARCH)/defconfig" From patchwork Fri Apr 13 05:06:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133314 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344507ljb; Thu, 12 Apr 2018 22:08:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+VIdU6kouISAolUfvn7wcleuDhf4mQmKLvh1yvIQ/kE4fXLJZ2veIFHmwpqEOYQgcou/mM X-Received: by 10.98.93.149 with SMTP id n21mr10237749pfj.222.1523596133741; Thu, 12 Apr 2018 22:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596133; cv=none; d=google.com; s=arc-20160816; b=o23SRKwrmQ8L9uCSp4D2nB/PwyfSgEaMcplGOyy5K3hokqOfXgVUzVSqVuuaWWm8vo lN6/n+NIccqJCMqAfJyMcsMc5mHEHyR1c54zaOGqf47mW42ldmJ7FX9WpZNMH2YCk/Ra a7qmmPIxnhPoJsNh36zKv9elXfWJsTudjYu618UHXukfYwDsbjSEccxUx1zJiqMAQabm LfMGDcuWCJ7rpxw4+Bx3Fwn77m7+yPtrFIwJBCDKzRzASqVrQMRpsWQjk32Xga2kTGaM qDhKRYsgZ92Jeto5WBBOLDw2HsmzE5Wyq54nWTs+YornPrpczkMbeIM4CzVS28qESTVL 3dVA== 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=9rvUmXfQf11J/2cqgPZuueSImibLvpg0deq+wZiy6o0=; b=twm17lq2NER6kAUqo2xgcdQlpbFeDns/pBaQO6Aq2lS/aD2sp3YnM/8b1qlL6iDnub ZELxRL2m/c4Sy0QSp0uvYN3Zz8kGvvEaPBFlvAVV4lyVgET76MXYjhYH0rzZeQPSkZbQ JQfjCe11vU0uzONzXrDUgz3LEQaOQI0EKQ83hJS5UMmq7Qc8bAikjXC/QL6Mh4EcknSF Xp5eXbsawVwbAaVEk6mOSfla22DQ72grMtMAjgSEgWm/FMvdKPeQG1l2EhxAPNg42XAC qLM3UK/dH7DYAAffPT3LCtFw4y0TIJJtsmRX4yLj7EG8A6J/5AxG/ii3UlmzndQ+IzcD E1hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ST6w2QXi; 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 y6si3289303pgo.9.2018.04.12.22.08.53; Thu, 12 Apr 2018 22:08:53 -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=ST6w2QXi; 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 S1753082AbeDMFIi (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:38 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54952 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751771AbeDMFIa (ORCPT ); Fri, 13 Apr 2018 01:08:30 -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 w3D56lg5029209; Fri, 13 Apr 2018 14:06:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg5029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596018; bh=9rvUmXfQf11J/2cqgPZuueSImibLvpg0deq+wZiy6o0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ST6w2QXiuXUcxq20D5dHI0bVfr3HzYodlm8q5SApj3CO5bHeXuDghQG2iZH5NtI8K W2CBYf4pGvQWYUv/qOkEogGlBzJaBSuP8GYIJwsotniiBfv3bxEZW9W8lOwV6rDbC9 kVA76FsB2zSkNyEw9qNchjJ5aI/IJERnLRTdvZZMsD/CmzrKEneQ9iOE59rMZVxdQ2 20rEfjJZ8OWOfvWNfcdQl7rl3pwvZeRlaAXAv22hyFgN1Uwq/8wMk6Ko5Jsmb3xZEG tVBk5cSSjkiggF2dG7AsxMA59MxWZnuFBdkqm+e13Xcm3Vbfo4827p6jqoup0XIXBF qUEOi5avecOGQ== 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 11/30] kconfig: begin PARAM state only when seeing a command keyword Date: Fri, 13 Apr 2018 14:06:20 +0900 Message-Id: <1523595999-27433-12-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 Currently, any statement line starts with a keyword with TF_COMMAND flag. So, the following three lines are dead code. alloc_string(yytext, yyleng); zconflval.string = text; return T_WORD; If a T_WORD token is returned in this context, it will cause syntax error in the parser anyway. The next commit will support the assignment statement where a line starts with an arbitrary identifier. So, I want the lexer to switch to the PARAM state only when it sees a command keyword. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None scripts/kconfig/zconf.l | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 9dc5fe3..5e53348 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -102,10 +102,10 @@ n [A-Za-z0-9_-] { {n}+ { const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); - BEGIN(PARAM); current_pos.file = current_file; current_pos.lineno = yylineno; if (id && id->flags & TF_COMMAND) { + BEGIN(PARAM); yylval.id = id; return id->token; } From patchwork Fri Apr 13 05:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133325 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346290ljb; Thu, 12 Apr 2018 22:11:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/BGxB/SMZDxA8nG+YdmabCELpeFUV4ZQ2WcSEVGkGNKP7s9ZQnoFGR6fEa8Ok/eB1gFnWg X-Received: by 10.101.92.69 with SMTP id v5mr2802916pgr.405.1523596290877; Thu, 12 Apr 2018 22:11:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596290; cv=none; d=google.com; s=arc-20160816; b=PdtWitPSPlh5JjJc2Ko1UTh7vRrIymuTfQUYL6bHxHi785ywdGw/kbMqgNhKJ2syv2 dcYA6zgGXC4FvybzJWWgFa5EAccdmqVdgrQPfLaoMrPCDPHTZr+ffc8147C8whhonJ3D qnEmCd0lP4E6WqgGzazEZmBF4VPw5dIg060Rd4h3k0Kb42HRKF+WZucWnABkpR7DRwIw HSOvwK7YAMV9wjGaRO/PfTHjLQ7698twVCfQEaM268DGyl8FbgqhKurBhuVbdycSdant /nrhBU99PMXNtmOorbDJxv2WbntgrHAqkI6+HQuG9iS0x0VveOauc0cb9Td0xnF3Ohno p78w== 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=l7gnFqmhbzOpfXOlRnTi42wkLrKZ+mjw9Izx9oqbs10=; b=jTM9kpwsigaJZTR5HP3m8OGXFybWq9fu8P6kMpVc7V3Uw6+J+f3DdREd00CpDo6u34 6QI7LNxrXtDc4uJb1AFdmRLIzaMDhhaYFpxfwXQ81PlRfL5PnAT6UnN2iinrD9ecXaHB Vs1OsB9eFo4vRS10KDZb21oZQ61pXsrQwfdFyLT8mno6wslo3rS8XpQWulE9Pq8rqC0+ CG9+01uRQm6vIHSXDqbeO9iHHiZx1L3LzIEoJ/ifhN86dGd4bgZei3lSGEkA5SspeJOP OyR6UwAjzGfhM+7PWHLuF3yG7+OWeIVKjOWnpWusN3jg4IRch0aBvwTGPhnOPBmqGsWW 9UWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wm9t65jH; 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 j21si3908532pfe.132.2018.04.12.22.11.30; Thu, 12 Apr 2018 22:11:30 -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=wm9t65jH; 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 S1753933AbeDMFL0 (ORCPT + 29 others); Fri, 13 Apr 2018 01:11:26 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55001 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752360AbeDMFIc (ORCPT ); Fri, 13 Apr 2018 01:08:32 -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 w3D56lg6029209; Fri, 13 Apr 2018 14:06:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg6029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596019; bh=l7gnFqmhbzOpfXOlRnTi42wkLrKZ+mjw9Izx9oqbs10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wm9t65jHbAqbme4PeD3j46hBMPYkw1q+SiVyPa4ETyVJmGyZHznxMWpnMfEvGMIcC D0punIjYVJcN5Gk8d/GyJDqHEVh6RQY9e4pQ22AEklV4THfDITuwwiu4F11DSDS72W t6PsKAJU+t0Jeh/ShC1WOK968PU8StjxHs3D7n28ZfwUdZbFj7tAHSkrB/sbBdu7kD vJO/djIOGaHwWcr23+VQViFa4SfJ5F7rvV6ZbC/6QIkkvqduPrWexUWYmk4jTOfyiJ 5oBRKLlaC469iSDJUHCN0kTT7lQoC1uJgIEOf9HBHZqj2Xh3yI3epmIIMoEeCsujmE 4L7oG84oXGSSQ== 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 12/30] kconfig: support variable and user-defined function Date: Fri, 13 Apr 2018 14:06:21 +0900 Message-Id: <1523595999-27433-13-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 Now, we got a basic ability to test compiler capability in Kconfig. config CC_HAS_STACKPROTECTOR def_bool $(shell (($(CC) -Werror -fstack-protector -c -x c /dev/null -o /dev/null 2>/dev/null) && echo y) || echo n) This works, but it is ugly to repeat this long boilerplate. We want to describe like this: config CC_HAS_STACKPROTECTOR bool default $(cc-option -fstack-protector) It is straight-forward to add a new function, but I do not like to hard-code specialized functions like this. Hence, here is another feature, user-defined function. This works as a textual shorthand with parameterization. A user-defined function is defined by using the = operator, and can be referenced in the same way as built-in functions. A user-defined function in Make is referenced like $(call func-name, arg1, arg2), but I omitted the 'call' to make the syntax shorter. The definition of a user-defined function contains $(1), $(2), etc. in its body to reference the parameters. It is grammatically valid to pass more or fewer arguments when calling it. We already exploit this feature in our makefiles; scripts/Kbuild.include defines cc-option which takes two arguments at most, but most of the callers pass only one argument. By the way, a variable is supported at a subset of this feature since a variable is "a user-defined function with zero argument". In this context, I mean "variable" as recursively expanded variable. I will add a different flavored variable later on. The code above can be written as follows: [Example Code] success = $(shell ($(1)) >/dev/null 2>&1 && echo y || echo n) cc-option = $(success $(CC) -Werror $(1) -c -x c /dev/null -o /dev/null) config CC_HAS_STACKPROTECTOR def_bool $(cc-option -fstack-protector) [Result] $ make -s alldefconfig && tail -n 1 .config CONFIG_CC_HAS_STACKPROTECTOR=y Signed-off-by: Masahiro Yamada --- Changes in v3: - Re-implement the parse logic - Use = operator to define a user-defined function Changes in v2: - Use 'macro' directly instead of inside the string type symbol. scripts/kconfig/lkc_proto.h | 2 + scripts/kconfig/preprocess.c | 96 +++++++++++++++++++++++++++++++++++++++++++- scripts/kconfig/zconf.l | 17 +++++++- scripts/kconfig/zconf.y | 21 +++++++++- 4 files changed, 132 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index c46929f..2b16d6e 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -50,6 +50,8 @@ const char * prop_get_type_name(enum prop_type type); /* preprocess.c */ void env_write_dep(FILE *f, const char *auto_conf_name); +void variable_add(const char *name, const char *value); +void variable_all_del(void); char *expand_string(const char *in); char *expand_dollar(const char **str); char *expand_one_token(const char **str); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index f4c606f..1b746e0 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -79,6 +79,72 @@ void env_write_dep(FILE *f, const char *autoconfig_name) } /* + * Variables and User-defined Functions + */ +static LIST_HEAD(variable_list); + +struct variable { + char *name; + char *value; + struct list_head node; +}; + +static struct variable *variable_lookup(const char *name) +{ + struct variable *v; + + list_for_each_entry(v, &variable_list, node) { + if (!strcmp(name, v->name)) + return v; + } + + return NULL; +} + +static char *variable_expand(const char *name, int argc, char *argv[]) +{ + struct variable *v; + + v = variable_lookup(name); + if (!v) + return NULL; + + return expand_string_with_args(v->value, argc, argv); +} + +void variable_add(const char *name, const char *value) +{ + struct variable *v; + + v = variable_lookup(name); + if (v) { + free(v->value); + } else { + v = xmalloc(sizeof(*v)); + v->name = xstrdup(name); + list_add_tail(&v->node, &variable_list); + } + + v->value = xstrdup(value); +} + +static void variable_del(struct variable *v) +{ + list_del(&v->node); + free(v->name); + free(v->value); + free(v); +} + +void variable_all_del(void) +{ + struct variable *v, *tmp; + + list_for_each_entry_safe(v, tmp, &variable_list, node) + variable_del(v); +} + +/* * Built-in Functions */ struct function { @@ -175,16 +241,30 @@ static char *function_call(const char *name, int argc, char *argv[]) * Evaluate a clause with arguments. argc/argv are arguments from the upper * function call. * + * Let's say 'foo' is defined as: + * foo = ABC$(1)PQR(2)XYZ + * and you want to evaluate $(foo x,y) + * + * First, this helper is called with: + * in : foo x,y + * argc: 0 + * and then, recursively called with: + * in: ABC$(1)PQR(2)XYZ + * argc: 2 + * argv[0]: x + * argv[1]: y + * * Returned string must be freed when done */ static char *eval_clause(const char *in, int argc, char *argv[]) { - char *tmp, *prev, *p, *res, *name; + char *tmp, *prev, *p, *res, *endptr, *name; char delim = ' '; int new_argc = 0; char *new_argv[FUNCTION_MAX_ARGS]; int nest = 0; int i; + unsigned long n; /* * Returns an empty string because '$()' should be evaluated @@ -193,6 +273,15 @@ static char *eval_clause(const char *in, int argc, char *argv[]) if (!*in) return xstrdup(""); + /* + * If variable name is '1', '2', etc. It is generally an argument + * from a user-function call (i.e. local-scope variable). If not + * available, then look-up global-scope variables. + */ + n = strtoul(in, &endptr, 10); + if (!*endptr && n > 0 && n <= argc) + return xstrdup(argv[n - 1]); + tmp = xstrdup(in); prev = p = tmp; @@ -248,6 +337,11 @@ static char *eval_clause(const char *in, int argc, char *argv[]) if (res) goto out; + /* Search for variable or user-defined function */ + res = variable_expand(name, new_argc, new_argv); + if (res) + goto out; + /* Last, try environment variable */ if (new_argc == 0) { res = env_expand(name); diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 5e53348..19e5ebf 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -1,12 +1,13 @@ %option nostdinit noyywrap never-interactive full ecs %option 8bit nodefault yylineno -%x COMMAND HELP STRING PARAM +%x COMMAND HELP STRING PARAM ASSIGN_VAL %{ /* * Copyright (C) 2002 Roman Zippel * Released under the terms of the GNU GPL v2.0. */ +#include #include #include #include @@ -111,8 +112,10 @@ n [A-Za-z0-9_-] } alloc_string(yytext, yyleng); yylval.string = text; - return T_WORD; + return T_VARIABLE; } + "=" { BEGIN(ASSIGN_VAL); return T_ASSIGN; } + [[:blank:]]+ . warn_ignored_character(*yytext); \n { BEGIN(INITIAL); @@ -120,6 +123,16 @@ n [A-Za-z0-9_-] } } +{ + [^[:blank:]\n]+.* { + alloc_string(yytext, yyleng); + yylval.string = text; + return T_ASSIGN_VAL; + } + \n { BEGIN(INITIAL); return T_EOL; } + . +} + { "&&" return T_AND; "||" return T_OR; diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 22e318c..493388c 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -77,6 +77,9 @@ static struct menu *current_menu, *current_entry; %token T_CLOSE_PAREN %token T_OPEN_PAREN %token T_EOL +%token T_VARIABLE +%token T_ASSIGN +%token T_ASSIGN_VAL %left T_OR %left T_AND @@ -92,7 +95,7 @@ static struct menu *current_menu, *current_entry; %type end %type option_name %type if_entry menu_entry choice_entry -%type symbol_option_arg word_opt +%type symbol_option_arg word_opt assign_val %destructor { fprintf(stderr, "%s:%d: missing end statement for this entry\n", @@ -143,6 +146,7 @@ common_stmt: | config_stmt | menuconfig_stmt | source_stmt + | assignment_stmt ; option_error: @@ -511,6 +515,15 @@ symbol: nonconst_symbol word_opt: /* empty */ { $$ = NULL; } | T_WORD +/* assignment statement */ + +assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3); free($1); free($3); } + +assign_val: + /* empty */ { $$ = xstrdup(""); }; + | T_ASSIGN_VAL +; + %% void conf_parse(const char *name) @@ -525,6 +538,12 @@ void conf_parse(const char *name) if (getenv("ZCONF_DEBUG")) yydebug = 1; yyparse(); + + /* + * Variables are expanded in the parse phase. We can free them here. + */ + variable_all_del(); + if (yynerrs) exit(1); if (!modules_sym) From patchwork Fri Apr 13 05:06:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133337 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp348067ljb; Thu, 12 Apr 2018 22:14:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/iqJYH26EYl2flRRRYhKSW+9IlJgrIy9jCtWmUYanrQ1MCcvPilBpkwwWaBZyxfLhW2yhp X-Received: by 10.101.97.163 with SMTP id i3mr2987505pgv.447.1523596461891; Thu, 12 Apr 2018 22:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596461; cv=none; d=google.com; s=arc-20160816; b=dncgMnKtnpC7vBgl42AewW50WSrynR2f1M8mGwM7WjaHluiDSCQJF9g8QEMQgW5muU NTz3jT3l2j7jP64v43CwlSiVKgn+VQ6XjuxukOJyzHpi2zlaIdiQU7fjOVWWzOVvc333 DbIXVBGiKgIAb/YUOmK4M39WabLtxEAKNIMZrmzOLUzi+PKtwlPWklHwm4To+oTkp5bu C+Dt3bMtjySpGprM89aKBrRoCVlPNf1+OZFP/HUF1B3iEAGHGcKahqmrecZGINVTlOcO gF+zGBVhNajtJGn01fga7zxTaYDAj+vvPoNe8oim8aizyqnspFCJfWABCNhi4XFDs2+Y TUrw== 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=VAG5iCc6jHOtEIQTn1rcxEg20e/EVSb+6WS1yw9L78E=; b=Uc9iWvMcwPOfb7zGlylGySK9wZDBUppcDU/RUNUjMXR5Esam/kz2HoIFad4/1lQ6nW zd8lGREBYLuqkjZ/hzdu3AAultkMqSxKlBx3oGePNyhuSU0eHy9PbLqQbK+3BGNYkjjI 04xj3ZfKIgofsZIElT66l8O2t4LcX70GuGBf1FJPQSLBGclrtT09njuJwpi0r028lcEm 2AArAIwxLuAYYmgngKN6gX6vvI0qZZWKy+Cz/Azmtr73190FW41A6rHLnvh7urMHf3aR yA1hiwg0U0O0lQWsCz6Nl5AoR+Pu5Ivtz/aBvfSQhQEzCJV1g5FgjcBENVFEwq1hKdmK HRRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=q0E81I9t; 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 33-v6si4738149pla.452.2018.04.12.22.14.21; Thu, 12 Apr 2018 22:14:21 -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=q0E81I9t; 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 S1753688AbeDMFOE (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:04 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54462 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lg7029209; Fri, 13 Apr 2018 14:06:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg7029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596020; bh=VAG5iCc6jHOtEIQTn1rcxEg20e/EVSb+6WS1yw9L78E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q0E81I9ttBbopurt3SBwtfQl4Wi16WdisBO/CTONzTrpP5lbdu/fDcKM1auFgpI8G h+aru5spw78s/OHIUJTuhcDcvDIvckJ2s17I4/1xUQfX3veZRPTPvi8fAFZHEQktJ9 z61Edb1I6bttMsL0YfwaFe4lf+7JZX9/69seZo3w+Zkl0VPW3cfxT7DA6mB+jQeTbF 00pGhEraMUL3+yt4JpqJaOCWPwfiZ/gRVbnCpqoczDAYT7l48m7lFI5my6ND+trrLB yIorSFKBuzThrnzV1+xMEkO8Dy0iVqmFD+L/W2UYbZZe0bPi5oMz9aPGTXp9vG2WFm BUQm1Q0Ze7EOQ== 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 13/30] kconfig: support simply expanded variable Date: Fri, 13 Apr 2018 14:06:22 +0900 Message-Id: <1523595999-27433-14-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 The previous commit added variable and user-defined function. They work similarly in the sense that the evaluation is deferred until they are used. This commit adds another type of variable, simply expanded variable, as we see in Make. The := operator defines a simply expanded variable, expanding the righthand side immediately. This works like traditional programming language variables. Signed-off-by: Masahiro Yamada --- Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 7 ++++++- scripts/kconfig/preprocess.c | 6 ++++-- scripts/kconfig/zconf.l | 3 ++- scripts/kconfig/zconf.y | 5 +++-- 4 files changed, 15 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 2b16d6e..6303193 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -49,8 +49,13 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); /* preprocess.c */ +enum variable_flavor { + VAR_SIMPLE, + VAR_RECURSIVE, +}; void env_write_dep(FILE *f, const char *auto_conf_name); -void variable_add(const char *name, const char *value); +void variable_add(const char *name, const char *value, + enum variable_flavor flavor); void variable_all_del(void); char *expand_string(const char *in); char *expand_dollar(const char **str); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 1b746e0..a835c94 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -112,7 +112,8 @@ static char *variable_expand(const char *name, int argc, char *argv[]) return expand_string_with_args(v->value, argc, argv); } -void variable_add(const char *name, const char *value) +void variable_add(const char *name, const char *value, + enum variable_flavor flavor) { struct variable *v; @@ -125,7 +126,8 @@ void variable_add(const char *name, const char *value) list_add_tail(&v->node, &variable_list); } - v->value = xstrdup(value); + v->value = (flavor == VAR_SIMPLE) ? expand_string(value) : + xstrdup(value); } static void variable_del(struct variable *v) diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 19e5ebf..aa76942 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -114,7 +114,8 @@ n [A-Za-z0-9_-] yylval.string = text; return T_VARIABLE; } - "=" { BEGIN(ASSIGN_VAL); return T_ASSIGN; } + "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } + ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } [[:blank:]]+ . warn_ignored_character(*yytext); \n { diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 493388c..1ebbf9e 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -41,6 +41,7 @@ static struct menu *current_menu, *current_entry; struct expr *expr; struct menu *menu; const struct kconf_id *id; + enum variable_flavor flavor; } %token T_MAINMENU @@ -78,7 +79,7 @@ static struct menu *current_menu, *current_entry; %token T_OPEN_PAREN %token T_EOL %token T_VARIABLE -%token T_ASSIGN +%token T_ASSIGN %token T_ASSIGN_VAL %left T_OR @@ -517,7 +518,7 @@ word_opt: /* empty */ { $$ = NULL; } /* assignment statement */ -assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3); free($1); free($3); } +assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); } assign_val: /* empty */ { $$ = xstrdup(""); }; From patchwork Fri Apr 13 05:06:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133331 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347090ljb; Thu, 12 Apr 2018 22:12:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/pbdeN8Q+A0h21o39LIpdLHSnOqv8n3VkBTz353emmeHorLqtgXZIm7EuGJh+hMiGpxihJ X-Received: by 10.98.75.12 with SMTP id y12mr10214992pfa.140.1523596371278; Thu, 12 Apr 2018 22:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596371; cv=none; d=google.com; s=arc-20160816; b=OjHRYgDMA7toHUut67pDnLyiEl4ryKUox6APXZQ6VwwUEbXfA2sA/z+zBzFHk9FReH hL8GCXZOIVV4PRIt2LPjwyjSh9oyW7MoYzaz+nDuYCAVEoEcWfMkPuRKKMbG6hpEiYuC UkyIlYvMYms5LtO2qeDslA2kR+2CpV8gyE6/1AI4xUpmANoKJGELtGf6GZd3z1YU6zZ7 wJKVNqPKj62YGCbT1S9v66xLGX+amt0Xvd7B/It3BJPdek3hy+2zGZvyfshXKfZ6ySAc D/kLY/zJ+2WiLwbSv21vBMcnL9zwE8uz0fooUIJ1bCsiYAUqAbb+z6h4NldG95wASqKa l6uA== 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=lX/bmRepQYJay/hK37IwnIxDgPI78f+j9u25nFP7mMs=; b=J6/aFvNmBo8slZOMpyXbxzDQNBgluoySidGlmnGmAyHqBkSDgK81JawiVZJRd9tc+L 94jbWXTGV8BXpyoUiP9qC8uYaI7rZr46Qox0cZMkS8HQDBcWCL2/a533Sl2JIMYQl2fO wDgy9wJEcE++Ewl2kDxBhEzu9P+VDAFI8IgGBPgo3t79L/lE87Jheq9woy3qiH/Co37y OCQSlFcAO3rns++xMqfZkYWH2D+kzzqTiU7kf0Aaw5UjiAyU34fS0rKIbqi0orNYR3CP XJdCjY0fDLDtYbdcLlr8GV2wqacsMDCUEpNwQfl3QeNE3rdZhOwht4ywUil0n/uEFFIs Wocw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hkGyRQux; 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 t2si3411527pgb.209.2018.04.12.22.12.51; Thu, 12 Apr 2018 22:12:51 -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=hkGyRQux; 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 S1753969AbeDMFMs (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:48 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54504 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lg8029209; Fri, 13 Apr 2018 14:07:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg8029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596020; bh=lX/bmRepQYJay/hK37IwnIxDgPI78f+j9u25nFP7mMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hkGyRQuxEfU+LF36K9zbTCWIlzlMMsWvNxRSBwS1Q+msTuEv6/qWrRXhd72biCt07 nR2Evg/IqgrFL/FucPR6zHC13OgiApCP7E+72hPxPr/umRWdL+9Frq40XGt8o2OOkt YWLzl1RMSMbEM9tRLud8ikFx58IJVwvg8/sVhGtZVRkyZPp7DIFj7icl5WySU8OECl GiukSqBq5s/4anFRIMmzHnJ3SZ4bFOA5+q9zRQqV+E7T6AGP9iuEb8XtgaSCMaXyoi mKNu58ZVU/V+6eevuwQNjM2PhkZvp58XlhBA0fsfcEhXd2cn3mow/EbwqUIPx9uArD DHunFqvWDP9fQ== 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 14/30] kconfig: support append assignment operator Date: Fri, 13 Apr 2018 14:06:23 +0900 Message-Id: <1523595999-27433-15-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 Support += operator. This appends a space and the text on the righthand side to a variable. The timing of the evaluation of the righthand side depends on the flavor of the variable. If the lefthand side was originally defined as a simple variable, the righthand side is expanded immediately. Otherwise, the expansion is deferred. Appending something to an undefined variable results in a recursive variable. To implement this, we need to remember the flavor of variables. Signed-off-by: Masahiro Yamada --- Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/preprocess.c | 29 +++++++++++++++++++++++++++-- scripts/kconfig/zconf.l | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 6303193..a8b7a33 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -52,6 +52,7 @@ const char * prop_get_type_name(enum prop_type type); enum variable_flavor { VAR_SIMPLE, VAR_RECURSIVE, + VAR_APPEND, }; void env_write_dep(FILE *f, const char *auto_conf_name); void variable_add(const char *name, const char *value, diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index a835c94..85972fb 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -86,6 +86,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -116,18 +117,42 @@ void variable_add(const char *name, const char *value, enum variable_flavor flavor) { struct variable *v; + char *new_value; + bool append = false; v = variable_lookup(name); if (v) { - free(v->value); + /* For defined variables, += inherits the existing flavor */ + if (flavor == VAR_APPEND) { + flavor = v->flavor; + append = true; + } else { + free(v->value); + } } else { + /* For undefined variables, += assumes the recursive flavor */ + if (flavor == VAR_APPEND) + flavor = VAR_RECURSIVE; + v = xmalloc(sizeof(*v)); v->name = xstrdup(name); list_add_tail(&v->node, &variable_list); } - v->value = (flavor == VAR_SIMPLE) ? expand_string(value) : + v->flavor = flavor; + + new_value = (flavor == VAR_SIMPLE) ? expand_string(value) : xstrdup(value); + + if (append) { + v->value = xrealloc(v->value, + strlen(v->value) + strlen(new_value) + 2); + strcat(v->value, " "); + strcat(v->value, new_value); + free(new_value); + } else { + v->value = new_value; + } } static void variable_del(struct variable *v) diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index aa76942..c68ca56b 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -116,6 +116,7 @@ n [A-Za-z0-9_-] } "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } + "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; } [[:blank:]]+ . warn_ignored_character(*yytext); \n { From patchwork Fri Apr 13 05:06:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133313 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344368ljb; Thu, 12 Apr 2018 22:08:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+gMXEPIaeLe2DLp0R3rZUBHkuLt65Ptw9lMFvYSO06uZRnsiVA1djlC3frzIWuynDQcr0G X-Received: by 10.98.129.2 with SMTP id t2mr2302490pfd.248.1523596123514; Thu, 12 Apr 2018 22:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596123; cv=none; d=google.com; s=arc-20160816; b=l0FQW8Cmct4ht3XYNYikkovgSLMvzAMkSd3RHzfBF1TAFoWCMmzr0k9ttLbwuCt5l6 2YO9YX9YAysPhvHufdCuirlIgYsywmLmVNA8ysjcWXamDYtLXygLaYrc3tj+mJ99GnAp I3tZBJf8BqlJRxHecEdGaJhzHM02FKGOXr34PdMdEa+8gxnxMKxDE9W6/FRtG1PlpTrK SKHUlUulR/bVZF2ac4i7VYLXE3+s8guHq6vsla3bW0ibPoY+H4TtV+w/g4ZXydtMR6fp FhyxSJ4VPNGrPEWOVujXHIkaM07DGkDf5m0dml0d3ccnBwg7c8DCr+dWHubOXf7yWxxf +9EQ== 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=cjztX1j5+aS/xNoPt3VdmJkM/tSdo2S0cdWoku0J/mU=; b=MptOOY2Ix91UI8VcQcBiktnsfZSIir3WHmZLShVxkaw3/CFmiLa9GidKYnD/3LtBDP YVWg5zYgSgUnFHqWMXOxv/J8chWdCZilzUlR6h01lHrtXNKBfyAE0HYHnRCuN20etyw7 URmEHhvV/wjQEsThAvS2Mqn1dCssifBcBRSNNmA93GonmSwAWx6SzCwMa+PCrNaVfA6h vgg9HpcFH95vvGp6UHWHxHKvMI+EI6BSF0o7law2o8bh9ev67humaJ+X+n6z2meNKb41 KqYIaTyUrcuuM57/qOi8C2YCW3rUGdDWS9d7Y65bBwq8jc0eqgKs8qAltz4YS33ipp7J yPBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=XdcbZEhh; 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 k8si3427622pgp.268.2018.04.12.22.08.43; Thu, 12 Apr 2018 22:08:43 -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=XdcbZEhh; 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 S1753179AbeDMFIj (ORCPT + 29 others); Fri, 13 Apr 2018 01:08:39 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54947 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123AbeDMFIa (ORCPT ); Fri, 13 Apr 2018 01:08:30 -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 w3D56lg9029209; Fri, 13 Apr 2018 14:07:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg9029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596021; bh=cjztX1j5+aS/xNoPt3VdmJkM/tSdo2S0cdWoku0J/mU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XdcbZEhhjPITqsUaSco1zXryhmKG/HtaySb5L9jS2QhuoGOmlICFx27Cd0SuMgzAc 7cFIblwnJH4WAKDl/I0+bXmtAcYtWOgryPWhaDNBQJ6scXoEjPERSfylA6qfFEDJUh u4iobrqQqzmSFkHx68AeMyydFMdxY9tUJAjtU1+BbgetDlJqyseGniybEgDKFLcB0z JWI6cMyxiasslpXb4AZk3tnz7Di5NIU99wNDq6N8SenTqc9B3BK5yeRHqqFfjbYXR0 7ECGfrbFv0ac26RATqBWka1ezIkomtN9zQAw/Cji8igFzL/Dh5tZrLdspH0P5onveK HlMqXtTDH/Eug== 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 15/30] kconfig: expand lefthand side of assignment statement Date: Fri, 13 Apr 2018 14:06:24 +0900 Message-Id: <1523595999-27433-16-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 Make allows variable references in the lefthand side of assignment. X = A Y = B $(X)$(Y) = 1 This does 'AB = 1' Do likewise in Kconfig as well. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None scripts/kconfig/zconf.l | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index c68ca56b..ae33e9b 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -114,6 +114,13 @@ n [A-Za-z0-9_-] yylval.string = text; return T_VARIABLE; } + ({n}|$)+ { + /* this token includes at least one '$' */ + yylval.string = expand_token(yytext, yyleng); + if (strlen(yylval.string)) + return T_VARIABLE; + free(yylval.string); + } "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; } From patchwork Fri Apr 13 05:06:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133333 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347313ljb; Thu, 12 Apr 2018 22:13:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/DrJCQDGnyn5dCNW3fSOsxrOWSnefufd6t6q26O/q0rdrgJxgWNRIZqPbie3IwyWCK2vkC X-Received: by 10.98.68.86 with SMTP id r83mr10206586pfa.145.1523596393114; Thu, 12 Apr 2018 22:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596393; cv=none; d=google.com; s=arc-20160816; b=W1zuZKqLrn0Qa0uNH7paCFNi7rbvxab1eQjDWx3ewPd4OwchiwRX5OBwgq8Gaw4vpo 4igWDiMy6/rzxW29dpl7nN6DDrHfRiyAfOnrW0msBCLse86gFdeAatXQT6eFVUZr4feE 62yESfMyxrJdu52Pgkw9Gc5eXWhOj0fe5obdAOBjnNSNY6A0WHVW52iknvQxRY+uZbo/ 9vSUG9/QVD1cRQkka8qpoKh7ZSfg8DG0GRvAtmSikBUysbTz9dabgKdF7levZ5jyCg68 Gks2c0Pb/UTp2SKxS/us7j/XbRqr70if6AhuyM0ss7mq6adoH7DFFhkwINzYc2fhlfcT Bq0A== 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=IL2qlncW5ohyiKFKEs34ce6mwrxe9/okwLRsL2ZRwwQ=; b=tPc7n07SuI6xkVVMq7tqIa1Pdv/2aWRz1ngBLgT7vFP0nY1AHd+1LSZKEdd0YbNffN jIXG2oWTqe9TL/cti6Z5nwayVLX5KG79PZdmpf9yfPPiZF9coKxh5fXTGUyU8tOFWpJ0 LCLfPO1OV41Tk90XFXBpAsiAKmKG1xZVPDwlb7iwp/GKmkKxsDOzdBcR/nzxwHYuiYt0 DTfEsHqLz7l1hn0SbOB6JdUUbjF8GhvahzTmQxVtee5VdfXJAXgrnUgYX5JVbdoUv2CT rSNpjyLOJkWTCmaILs914zI5QyywPSlyczhXxP/PpJqYmMLM2vP7O7/sNmXooEo/rgcd uF6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=LeWW7d1W; 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 m3-v6si4876988pld.351.2018.04.12.22.13.12; Thu, 12 Apr 2018 22:13:13 -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=LeWW7d1W; 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 S1753945AbeDMFMp (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:45 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54506 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lgA029209; Fri, 13 Apr 2018 14:07:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgA029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596022; bh=IL2qlncW5ohyiKFKEs34ce6mwrxe9/okwLRsL2ZRwwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LeWW7d1WAwqRbKQo+AYacNDw8Hu9vA/QEYYgkwqppxPhTRsIdzJeX2cbN8cSSATEK u6ov96WlFLLpR4au01XwX0JNtH+j5ntHOY0SLUePKzOHH/Ef+NH+Gh2LaOw8ujwigs dTxxXRjPWnW0pCHR/5GQOzty+lK2KvGNuLIj0Fv2yWNkxB3H+NT4a+HPTx+Usfy9mX jHBAR9w9P60r34FrJcSbFVO03lVImj1bF+8Bwby/DDpcNMVLwQBsT7u+REWGRsEfCu 24s+tv8xPCODrVT96WhwMRplw83t25PDBONiVHIU553YBvIGGHAJ6oLDVxONimpTAL vVwQ5K8/flykg== 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 16/30] kconfig: add 'info' and 'warning' built-in functions Date: Fri, 13 Apr 2018 14:06:25 +0900 Message-Id: <1523595999-27433-17-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 Add 'info' and 'warning' functions as in Make. They print messages during parsing Kconfig files, which is useful when debugging Kconfig at least. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 85972fb..f8d06d9 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -203,6 +203,19 @@ static char *join_args(int argc, char *argv[]) return out; } +static char *do_info(int argc, char *argv[]) +{ + char *msg; + + msg = join_args(argc, argv); + + printf("%s\n", msg); + + free(msg); + + return xstrdup(""); +} + static char *do_shell(int argc, char *argv[]) { FILE *p; @@ -244,8 +257,23 @@ static char *do_shell(int argc, char *argv[]) return xstrdup(buf); } +static char *do_warning(int argc, char *argv[]) +{ + char *msg; + + msg = join_args(argc, argv); + + fprintf(stderr, "%s:%d: %s\n", current_file->name, yylineno, msg); + + free(msg); + + return xstrdup(""); +} + static const struct function function_table[] = { + { .name = "info", .func = do_info }, { .name = "shell", .func = do_shell }, + { .name = "warning", .func = do_warning }, }; static char *function_call(const char *name, int argc, char *argv[]) From patchwork Fri Apr 13 05:06:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133336 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347926ljb; Thu, 12 Apr 2018 22:14:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/+ymn4EwM8FIgTXKcHzApBYWkC40QlL2jutILcKBQzODoUSR/AoYoUNkId84aBEjKAUyw5 X-Received: by 2002:a17:902:aa03:: with SMTP id be3-v6mr3787735plb.299.1523596448146; Thu, 12 Apr 2018 22:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596448; cv=none; d=google.com; s=arc-20160816; b=QfR474bCYSlkzx9W77r/ecdD9e7bbHCkUCrmRjGVFs4K0q42Jsm42TeKXAn+hipxHB OhxNOB/PQXgdBPxRZPC3qrrZOw5h5UZR6z0pEZxgsvXfk5WE7D7aJOJuAhL50LFXWlyX 22WGUSwBuA6DcnzM/KoJ0Agsh2JMTLEwxt07NdZRakqRgdbNVET2zNSfxamSg6EkIijs X3oRHzxCeuQUU1EuBg6DMSax248Qpk7YBngucZqhVHRnYH0oSFw1mOZa2B5atUmrY/FI QYLOW/nCJUUAGNNuqSYWVoyoewK+s/CbHLP8m0f2nlXwPdC/lM9o3XKM1CszHeKJFCnQ eqoQ== 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=RUxEWAwZHWR8BHdJTi4OjTw9s8KtzX8Jbbk+C1YNDHg=; b=fma0qKH/NAo6mUo1E2GubkxosFPICA8h0lSBx4mD4Ft9NMtTyZdhCzbOyZ4a/udFnm xWI3COBM4+xLD2LLKt6c04Qjx4ZzTjKyy/VQvhyvvj3Av6QvqF6n1GaDRirRCIwGY1YS rJ2Rdf43DUybQSBJj2XJE70b4J9ehrKY8JoPQQ1y0Tbglj/UGdR2ExHrPls6lR6tYbbN d6sjBmx+IdgbPEcWE8fQjHDmMMryhuW/PCCIjzyBFn5IWcn9yPyRxdsCbGKC0jiasDII +4apOZ1o6f8zMm/WTyU7oZtlF49kDFoc3FTV3OaMrgkTOxiOAGqPBaIn1PnzxCr2fEJh noJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=dTAOeaZT; 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 3-v6si4828759plv.323.2018.04.12.22.14.07; Thu, 12 Apr 2018 22:14:08 -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=dTAOeaZT; 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 S1753859AbeDMFOG (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:06 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54466 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751032AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lgB029209; Fri, 13 Apr 2018 14:07:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgB029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596023; bh=RUxEWAwZHWR8BHdJTi4OjTw9s8KtzX8Jbbk+C1YNDHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTAOeaZTmx3LGufPWeaUkMuS94igXeUC0P9suVj1T1CSU/b3jtFwJvpaXsRwIwon/ 8hYBdHOTNnLXP4XTpUAXrMTjjuI3y4+6cKQMTDs7wDhqJZADeRgXA1GRWyt3QP7vkD YCF2gFMDK4ebI7mLkniTw/juaWUu4+bEt0l+m2xdfDV+k292VNawv7uHnjcrpiJV4l vg4OXaZWqjdBL6j/2WAFfSimrfhTXDpWgqqnH/llCc8iw0YZk7a/j3qHl+gzTzDXGb M2B+BCbS8UT0EI1HnoFiWb/4vVIbhgjKv4A9PWEKB/bdv/29wPxoLlGf/g0J8RbJJk Vxl350eNueUwA== 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 17/30] Documentation: kconfig: document a new Kconfig macro language Date: Fri, 13 Apr 2018 14:06:26 +0900 Message-Id: <1523595999-27433-18-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 Add a document for the macro language introduced to Kconfig. The motivation of this work is to move the compiler option tests to Kconfig from Makefile. A number of kernel features require the compiler support. Enabling such features blindly in Kconfig ends up with a lot of nasty build-time testing in Makefiles. If a chosen feature turns out unsupported by the compiler, what the build system can do is either to disable it (silently!) or to forcibly break the build, despite Kconfig has let the user to enable it. This change was strongly prompted by Linus Torvalds. You can find his suggestions [1] [2] in ML. The original idea was to add a new 'option', but I found generalized text expansion would make Kconfig more powerful and lovely. While polishing up the implementation, I noticed sort of similarity between Make and Kconfig. This might be too immature to be called 'language', but anyway here it is. All ideas are from Make (you can even say it is addicted), so people will easily understand how it works. [1]: https://lkml.org/lkml/2016/12/9/577 [2]: https://lkml.org/lkml/2018/2/7/527 Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None Documentation/kbuild/kconfig-macro-language.txt | 179 ++++++++++++++++++++++++ MAINTAINERS | 2 +- 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 Documentation/kbuild/kconfig-macro-language.txt -- 2.7.4 diff --git a/Documentation/kbuild/kconfig-macro-language.txt b/Documentation/kbuild/kconfig-macro-language.txt new file mode 100644 index 0000000..1f6281b --- /dev/null +++ b/Documentation/kbuild/kconfig-macro-language.txt @@ -0,0 +1,179 @@ +Concept +------- + +The basic idea was inspired by Make. When we look at Make, we notice sort of +two languages in one. One language describes dependency graphs consisting of +targets and prerequisites. The other is a macro language for performing textual +substitution. + +There is clear distinction between the two language stages. For example, you +can write a makefile like follows: + + APP := foo + SRC := foo.c + CC := gcc + + $(APP): $(SRC) + $(CC) -o $(APP) $(SRC) + +The macro language replaces the variable references with their expanded form, +and handles as if the source file were input like follows: + + foo: foo.c + gcc -o foo foo.c + +Then, Make analyzes the dependency graph and determines the targets to be +updated. + +The idea is quite similar in Kconfig - it is possible to describe a Kconfig +file like this: + + CC := gcc + + config CC_HAS_FOO + def_bool $(shell $(srctree)/scripts/gcc-check-foo.sh $(CC)) + +The macro language in Kconfig processes the source file into the following +intermediate: + + config CC_HAS_FOO + def_bool y + +Then, Kconfig moves onto the evaluation stage to resolve inter-symbol +dependency, which is explained in kconfig-language.txt. + + +Variables +--------- + +Like in Make, a variable in Kconfig works as a macro variable. A macro +variable is expanded "in place" to yield a text string that may then expanded +further. To get the value of a variable, enclose the variable name in $( ). +As a special case, single-letter variable names can omit the parentheses and is +simply referenced like $X. Unlike Make, Kconfig does not support curly braces +as in ${CC}. + +There are two types of variables: simply expanded variables and recursively +expanded variables. + +A simply expanded variable is defined using the := assignment operator. Its +righthand side is expanded immediately upon reading the line from the Kconfig +file. + +A recursively expanded variable is defined using the = assignment operator. +Its righthand side is simply stored as the value of the variable without +expanding it in any way. Instead, the expansion is performed when the variable +is used. + +There is another type of assignment operator; += is used to append text to a +variable. The righthand side of += is expanded immediately if the lefthand +side was originally defined as a simple variable. Otherwise, its evaluation is +deferred. + + +Functions +--------- + +Like Make, Kconfig supports both built-in and user-defined functions. A +function invocation looks much like a variable reference, but includes one or +more parameters separated by commas: + + $(function-name arg1, arg2, arg3) + +Some functions are implemented as a built-in function. Currently, Kconfig +supports the following: + + - $(shell command) + + The 'shell' function accepts a single argument that is expanded and passed + to a subshell for execution. The standard output of the command is then read + and returned as the value of the function. Every newline in the output is + replaced with a space. Any trailing newlines are deleted. The standard error + is not returned, nor is any program exit status. + + - $(warning text) + + The 'warning' function prints its arguments to stderr. The output is prefixed + with the name of the current Kconfig file, the current line number. It + evaluates to an empty string. + + - $(info text) + + The 'info' function is similar to 'warning' except that it sends its argument + to stdout without any Kconfig name or line number. + +A user-defined function is defined by using the = operator. The parameters are +referenced within the body definition with $1, $2, etc. (or $(1), $(2), etc.) +In fact, a user-defined function is internally treated as a recursive variable. + +A user-defined function is referenced in the same way as a built-in function: + + $(my_func, arg0, arg1, arg2) + +Note 1: +There is a slight difference in the whitespace handling of the function call +between Make and Kconfig. In Make, leading whitespaces are trimmed from the +first argument. So, $(info FOO) is equivalent to $(info FOO). Kconfig keeps +any leading whitespaces except the one right after the function name, which +works as a separator. So, $(info FOO) prints " FOO" to the stdout. + +Note 2: +In Make, a user-defined function is referenced by using a built-in function, +'call', like this: + + $(call my_func, arg0, arg1, arg2) + +However, Kconfig did not adopt this form just for the purpose of shortening the +syntax. + + +Caveats +------- + +A variable (or function) can not be expanded across tokens. So, you can not use +a variable as a shorthand for an expression that consists of multiple tokens. +The following works: + + RANGE_MIN := 1 + RANGE_MAX := 3 + + config FOO + int "foo" + range $(RANGE_MIN) $(RANGE_MAX) + +But, the following does not work: + + RANGES := 1 3 + + config FOO + int "foo" + range $(RANGES) + +A variable can not be expanded to any keyword in Kconfig. The following does +not work: + + MY_TYPE := tristate + + config FOO + $(MY_TYPE) "foo" + default y + +Obviously from the design, $(shell command) is expanded in the textual +substitution phase. You can not pass symbols to the 'shell' function. +The following does not work as expected. + + config ENDIAN_OPTION + string + default "-mbig-endian" if CPU_BIG_ENDIAN + default "-mlittle-endian" if CPU_LITTLE_ENDIAN + + config CC_HAS_ENDIAN_OPTION + def_bool $(shell $(srctree)/scripts/gcc-check-option ENDIAN_OPTION) + +Instead, you can do like follows so that any function call is statically +expanded. + + config CC_HAS_ENDIAN_OPTION + bool + default $(shell $(srctree)/scripts/gcc-check-option -mbig-endian) if CPU_BIG_ENDIAN + default $(shell $(srctree)/scripts/gcc-check-option -mlittle-endian) if CPU_LITTLE_ENDIAN diff --git a/MAINTAINERS b/MAINTAINERS index b60179d..b9dab38 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7622,7 +7622,7 @@ M: Masahiro Yamada T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git kconfig L: linux-kbuild@vger.kernel.org S: Maintained -F: Documentation/kbuild/kconfig-language.txt +F: Documentation/kbuild/kconfig* F: scripts/kconfig/ KDUMP From patchwork Fri Apr 13 05:06:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133339 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp348324ljb; Thu, 12 Apr 2018 22:14:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx48WkPiBmd8RRoMpCJJgR2CKTfS4Z282CyOTiuEkrb1pYJd8gSgrkCBzrny5i7qzNgsFiCx4 X-Received: by 10.99.112.91 with SMTP id a27mr2927435pgn.432.1523596488775; Thu, 12 Apr 2018 22:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596488; cv=none; d=google.com; s=arc-20160816; b=MjQNUV8CSBiYT+EdJtYSXelUG1P6MySg857oVFPwYEoLiT2LO+x4jD1Wz75iuxtuSa CKgokyHHEXHuU8t8EJlupHMWUMRn4h9bOuhztFnZMfurQPvAusNFYDMOO9a7c81qAbxQ w878ApQKhe31aalkCNpu5kqoNZDwULolPRv026WKo1Ai/F2EmW5v1um1UrVnkJEw017n UlG5Io2Aj7fOwERjUY7I3GzrDhQl60uHAizdMttDPQq3sMZA/nLhw3xtMqplbJYpNN0e rqPBbpzcW6qUtIaovZM8HdPocLFlxopdts71btvNQUax8rf5oTdM8FIRgREelguovDAZ xLGA== 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=e7wUXuL5SzADNiL+yJaCSwzOhck6xulndTS6lyNvdms=; b=XXk4CQnohwRFaelxVUhjGRSjPEzSI+flZXx56Pwo135BSdz0h3h2AVZqIWHRWburIr IX32OVe/8KSMAaHyY8WZiFVgwgkQopBb3YNEVDrIuu905CAbDZezmQVyicAuTdmHVBLT I/B/jPdtd+HYFTJAasgdCi/CfVmtQKVn3KvRReZiQh/YTzqxubrFEhEjSsyS1my9nJVG HVD5luxFp4pPAzG8Yj2MXngAstS+zzu9AlMOTil/nApaF+0G0AgC9F8PrrHgvYrmHqnb wqIoObIOSEmpQe7KYWF1kFK2CyxQrAHK8ZSKSCIWx/Ryu7AqPwy3pTKz9C9663UZnV0r /1ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Ek+DgHzx; 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 a64si3285839pgc.265.2018.04.12.22.14.48; Thu, 12 Apr 2018 22:14:48 -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=Ek+DgHzx; 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 S1753927AbeDMFOp (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:45 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54470 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lgC029209; Fri, 13 Apr 2018 14:07:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgC029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596024; bh=e7wUXuL5SzADNiL+yJaCSwzOhck6xulndTS6lyNvdms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ek+DgHzxt6kTe8MzhlTUV07vfxFe9LKLx9RR158cJ1UqPG2jqBqyuMMaTvRGk09rg 3o+woO+7ZJcsyKY58o8qvwSSE3Jzd7qObOwcd21X5Fsw/EN2eJ+G5WxOdFlbcA+vzf ZbKUSggttccDTsYad4/0rLLQ8BYg5szlh/wQOmcpDgtz3puyHiyMI+LmVbhZx4jKpq PbQa99VWaKZgdE3rAMDPRn77Gxln3b1nU5SwDk9EzIe74wUPgKP4WeGKR9gvG2AxNX rMm/F53QxPQR1hUksd7qrNd51AsUJlyTjIgCO71dJl9e27TARvAp7mZi9H+qlkYJg1 y24o+N3jt0d6g== 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 18/30] kconfig: test: test text expansion Date: Fri, 13 Apr 2018 14:06:27 +0900 Message-Id: <1523595999-27433-19-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 Here are the test cases I used for developing the text expansion feature. I implemented a similar language as you see in Make. The implementation is different (the source code in GNU Make is much longer, so I did not want to pull it in), but the behavior is hopefully almost the same. I intentionally changed some behavior and syntax, but I tried to stick to the make-like behavior where possible. It might be interesting to compare the behavior between Make and Kconfig. [1] Variable test You can directly run scripts/kconfig/tests/preprocess/variable/Kconfig by make. Make and Kconfig produce the exactly the same output for the variable test. The output from Make: $ cd scripts/kconfig/tests/preprocess/variable && make -f Kconfig Kconfig:5: SIMPLE = 1 Kconfig:11: RECURSIVE = 2 Kconfig:17: SIMPLE = 1 3 Kconfig:23: RECURSIVE = 2 4 Kconfig:30: UNDEFINED_VARIABLE = 4 Kconfig:36: AB = 5 Kconfig:39: X = A make: *** No targets. Stop. [2] Built-in function test The output from Make: $ cd scripts/kconfig/tests/preprocess/builtin_func && make -f Kconfig hello,world 0 Kconfig:7: hello,world 1 Kconfig:11: hello, world 2 Kconfig:15: hello,world 3 Kconfig:19: hello, world 4 make: *** No targets. Stop. The output from "$(warning hello, world 2)" is different. "Kconfig:11: hello, world 2" vs "Kconfig:11: hello, world 2" Make strips all leading spaces from the first argument, but does not touch the other arguments. I thought this was inconsistent. So, I changed the behavior to not touch any arguments at all. [3] User-defined function test I changed the syntax for calling a user-defined function. In Make, it is invoked by using the 'call' built-in function as in $(call greeting,Hello,John) but in Kconfig it is invoked without 'call' as in $(greeting Hello,John). Except the syntax difference, the test case works exactly in the same way for Make and Kconfig. [4] Escape sequence test Except the syntax of user-defined function, Make and Kconfig work in the same way. The behavior of a standalone '$' is different among Make versions. By fixing the user-defined function syntax, Make 4.1 or older works like this: Kconfig:5: arg0= arg1= Kconfig:9: arg0=, arg1=, Kconfig:13: ' " '" ' ''' "'" Kconfig:16: $ Kconfig:20: $X Kconfig:26: nasty Kconfig:32: super_nasty Kconfig:41: Kconfig:46: X Kconfig:49: make: *** No targets. Stop. Make 4.2 or newer is like this: Kconfig:5: arg0= arg1= Kconfig:9: arg0=, arg1=, Kconfig:13: ' " '" ' ''' "'" Kconfig:16: $ Kconfig:20: $X Kconfig:26: nasty Kconfig:32: super_nasty Kconfig:41: $ Kconfig:46: $X Kconfig:49: nasty make: *** No targets. Stop. The last three lines are different. I adopted the behavior of the newer Make versions. Of course, you should not write such code. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None .../kconfig/tests/preprocess/builtin_func/Kconfig | 19 +++++++++ .../tests/preprocess/builtin_func/__init__.py | 8 ++++ .../tests/preprocess/builtin_func/expected_stderr | 4 ++ .../tests/preprocess/builtin_func/expected_stdout | 1 + scripts/kconfig/tests/preprocess/escape/Kconfig | 49 ++++++++++++++++++++++ .../kconfig/tests/preprocess/escape/__init__.py | 9 ++++ .../tests/preprocess/escape/expected_stderr | 10 +++++ scripts/kconfig/tests/preprocess/user_func/Kconfig | 19 +++++++++ .../kconfig/tests/preprocess/user_func/__init__.py | 7 ++++ .../tests/preprocess/user_func/expected_stderr | 5 +++ scripts/kconfig/tests/preprocess/variable/Kconfig | 39 +++++++++++++++++ .../kconfig/tests/preprocess/variable/__init__.py | 7 ++++ .../tests/preprocess/variable/expected_stderr | 7 ++++ 13 files changed, 184 insertions(+) create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/builtin_func/expected_stdout create mode 100644 scripts/kconfig/tests/preprocess/escape/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/escape/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/escape/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/user_func/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/user_func/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/user_func/expected_stderr create mode 100644 scripts/kconfig/tests/preprocess/variable/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/variable/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/variable/expected_stderr -- 2.7.4 diff --git a/scripts/kconfig/tests/preprocess/builtin_func/Kconfig b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig new file mode 100644 index 0000000..5dc454e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig @@ -0,0 +1,19 @@ +# 'info' prints the argument to stdout. +# commas are treated verbatim instead of as argument separaters. +$(info hello,world 0) + +# 'warning' is similar, but it sends its argument to stderr, +# and the message is prefixed with the current file name and line number. +$(warning hello,world 1) + +# leading spaces of the first argument are preserved except +# the one right after the function name. (This is different from Make) +$(warning hello, world 2) + +# 'shell' executes a command, and returns its stdout. +# commas are treated verbatim instead of as argument separaters. +$(warning $(shell echo hello,world 3)) + +# Every newline in the output is replaced with a space, +# but any trailing newlines are deleted. +$(warning $(shell printf 'hello,\nworld\n\n4\n\n\n')) diff --git a/scripts/kconfig/tests/preprocess/builtin_func/__init__.py b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py new file mode 100644 index 0000000..ec7c3e2 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py @@ -0,0 +1,8 @@ +""" +Built-in function tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stdout_contains('expected_stdout') + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr new file mode 100644 index 0000000..b6c046e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr @@ -0,0 +1,4 @@ +Kconfig:7: hello,world 1 +Kconfig:11: hello, world 2 +Kconfig:15: hello,world 3 +Kconfig:19: hello, world 4 diff --git a/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout new file mode 100644 index 0000000..036c34a --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout @@ -0,0 +1 @@ +hello,world 0 diff --git a/scripts/kconfig/tests/preprocess/escape/Kconfig b/scripts/kconfig/tests/preprocess/escape/Kconfig new file mode 100644 index 0000000..b99dfa2 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/Kconfig @@ -0,0 +1,49 @@ +foo = arg0=$1 arg1=$2 + +# You can not pass a comma directly as a argument since it is treated as an +# argument separator. In the following, $1 and $2 will be given a null string. +$(warning $(foo ,)) + +# Assign ',' to a variable, then use it if you want to pass in commas +comma := , +$(warning $(foo $(comma),$(comma))) + +# Like Make, single quotes, double quotes, spaces are treated verbatim. +# The following prints the text as-is. +$(warning ' " '" ' ''' "'") + +# You can use '$$' to escape '$' itself +$(warning $$) + +# The escaped '$' loses its special meaning. The following should print '$X'. +# Do not expand '$X' even further. +$(warning $$X) + +# In Make, a variable name can contain almost any characters. The only +# disallowed characters are : # and = +# '$' can be used as a variable name in Kconfig, although it is nasty +$$ = nasty +$(warning $($$)) + +# Even a space can be a variable name by using the following trick. +empty := +space := $(empty) $(empty) +$(space) = super_nasty +$(warning $($(space))) + +# The behavior of a standalone '$' at the end of a token is undefined. +# It is evaluated to an empty string in Make 4.1 or older, while +# to '$' as-is in Make 4.2 or newer. Kconfig follows the behavior of +# the newer Make version, but it is not important. + +# In the implementation of Kconfig, a standalone '$' at the end of a token +# is treated as-is. So, the following also prints '$' +$(warning $) + +# Likewise, a standalone '$' before a comma loses its special meaning. +# The following prints '$X'. Do not expand '$X' even further. +bar = $1$2 +$(warning $(bar $,X)) + +# The following prints the value of the variable '$'. +$(warning $($)) diff --git a/scripts/kconfig/tests/preprocess/escape/__init__.py b/scripts/kconfig/tests/preprocess/escape/__init__.py new file mode 100644 index 0000000..841a754 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/__init__.py @@ -0,0 +1,9 @@ +""" +Escape sequence tests. + +Test tricky cases related to escaping. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/escape/expected_stderr b/scripts/kconfig/tests/preprocess/escape/expected_stderr new file mode 100644 index 0000000..81df7e5 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/expected_stderr @@ -0,0 +1,10 @@ +Kconfig:5: arg0= arg1= +Kconfig:9: arg0=, arg1=, +Kconfig:13: ' " '" ' ''' "'" +Kconfig:16: $ +Kconfig:20: $X +Kconfig:26: nasty +Kconfig:32: super_nasty +Kconfig:41: $ +Kconfig:46: $X +Kconfig:49: nasty diff --git a/scripts/kconfig/tests/preprocess/user_func/Kconfig b/scripts/kconfig/tests/preprocess/user_func/Kconfig new file mode 100644 index 0000000..9d248ca --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/Kconfig @@ -0,0 +1,19 @@ +greeting = $(1), my name is $(2). +$(warning $(greeting Hello,John)) + +# It is allowed to pass more arguments than referenced. +# Unreferenced parameters are just ignored. +$(warning $(greeting Hello,John,ignored,ignored)) + +# It is also allowed to give fewer arguments. $(2) will be blank in this case. +$(warning $(greeting Hello)) + +# Passing zero argument is OK. In fact, a user-defined function +# is handle in the same way as a recursively expanded variable +$(warning $(greeting)) + +# However, if 1, 2 are defined as a global scope variable, +# user-defined function will use them where arguments are missing +1 = Hi +2 = Tom +$(warning $(greeting)) diff --git a/scripts/kconfig/tests/preprocess/user_func/__init__.py b/scripts/kconfig/tests/preprocess/user_func/__init__.py new file mode 100644 index 0000000..8da60f6 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/__init__.py @@ -0,0 +1,7 @@ +""" +User-defined function tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/user_func/expected_stderr b/scripts/kconfig/tests/preprocess/user_func/expected_stderr new file mode 100644 index 0000000..1dd6684 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/user_func/expected_stderr @@ -0,0 +1,5 @@ +Kconfig:2: Hello, my name is John. +Kconfig:6: Hello, my name is John. +Kconfig:9: Hello, my name is . +Kconfig:13: , my name is . +Kconfig:19: Hi, my name is Tom. diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig new file mode 100644 index 0000000..df4446b --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/Kconfig @@ -0,0 +1,39 @@ +# Simply expanded variable. +X := 1 +SIMPLE := $(X) +X := 2 +$(warning SIMPLE = $(SIMPLE)) + +# Recursively expanded variable. +X := 1 +RECURSIVE = $(X) +X := 2 +$(warning RECURSIVE = $(RECURSIVE)) + +# Append something to a simply expanded variable. +Y := 3 +SIMPLE += $(Y) +Y := 4 +$(warning SIMPLE = $(SIMPLE)) + +# Append something to a recursively expanded variable. +Y := 3 +RECURSIVE += $(Y) +Y := 4 +$(warning RECURSIVE = $(RECURSIVE)) + +# Use += operator to an undefined variable. +# This works as a recursively expanded variable. +Y := 3 +UNDEFINED_VARIABLE += $(Y) +Y := 4 +$(warning UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE)) + +# You can use variable references for the lefthand side of assignment statement. +X := A +Y := B +$(X)$(Y) := 5 +$(warning AB = $(AB)) + +# By the way, you can omit the parentheses for a single-letter variable +$(warning X = $X) diff --git a/scripts/kconfig/tests/preprocess/variable/__init__.py b/scripts/kconfig/tests/preprocess/variable/__init__.py new file mode 100644 index 0000000..e087698 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/__init__.py @@ -0,0 +1,7 @@ +""" +Variable tests. +""" + +def test(conf): + assert conf.oldaskconfig() == 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/variable/expected_stderr b/scripts/kconfig/tests/preprocess/variable/expected_stderr new file mode 100644 index 0000000..61b06e1 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr @@ -0,0 +1,7 @@ +Kconfig:5: SIMPLE = 1 +Kconfig:11: RECURSIVE = 2 +Kconfig:17: SIMPLE = 1 3 +Kconfig:23: RECURSIVE = 2 4 +Kconfig:30: UNDEFINED_VARIABLE = 4 +Kconfig:36: AB = 5 +Kconfig:39: X = A From patchwork Fri Apr 13 05:06:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133335 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347760ljb; Thu, 12 Apr 2018 22:13:54 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+BOtSWneF3V36FgNIfx7vC/R+946AdjL7K7SnTEVs4mZXD7Uv5StnHxM+3pCs3abZ7jkxT X-Received: by 10.99.95.13 with SMTP id t13mr2984665pgb.145.1523596434280; Thu, 12 Apr 2018 22:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596434; cv=none; d=google.com; s=arc-20160816; b=lGccPFzxMQMI25zbUjFnROvy0P5r3RAICxJ3REE8cxL7lAvkgzvZSfrIjWxNZoi/3q ITA1BUwhw2RkyBZtOkSJeHOBrO0YfzrJG+RyvBLVSUDowNOw2cAH2Ie61JzD8l15fFWc j1k313Trj1tJF95D/HK5MWFZ6QP2sOQpO5g0saX9ocephIYK7yDg8sFg2y9DBf2DbhHF Ltq/k1NNGgdApu/Eegl70yzljoV4Ro5eDC0NgqZ9V+94j+gRSnc2waTdZ/TQsut2lVVQ MfN29mBK58Cr9DpWAMG9LgpSO5MkROi1sd90zvNbHAW735PnG4JyVfEBCG1ztp+uF+Th QS8A== 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=ZNByCSmGPck73uN+2FHd9g+O3865D2r6m1y0qc7q6eU=; b=aIhm9rv6+J68ONaWvJ0Zi2bWR+Mw3v7MdxIxQ0jx/FCNG/jHEjONN+oxwQG0jsbGFP kKhSOnH2MmxwwfOlsBN2JayOpFIywIfPaVZRKOIptZBPbVvZ8P+frgrn5iZdYlQEfvai KPo38eAjcAr4a38FDac6yq/p9Rv2zWgN5DR1Gp2Dkft6aqY63vIEOvGhuLeD3icgfcDi x7K8iHVwZdEcCiWcAJjfHBOJ+Z+H11qWL1nPUi9JbkUcweecVnFwN1EDLkW4ykcE6uKF zTtqLZcwAMiu0Fk0pPira/lN3cTbeKpUEeUlbTzBOq20Jna0U5azRLiv6eZXxWBv+pHH KQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=vLpQvsfs; 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 3-v6si4828759plv.323.2018.04.12.22.13.54; Thu, 12 Apr 2018 22:13:54 -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=vLpQvsfs; 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 S1753682AbeDMFNs (ORCPT + 29 others); Fri, 13 Apr 2018 01:13:48 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54503 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751041AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lgD029209; Fri, 13 Apr 2018 14:07:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgD029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596025; bh=ZNByCSmGPck73uN+2FHd9g+O3865D2r6m1y0qc7q6eU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vLpQvsfsq54XOiizbt1WszTE/bvobN4+z0YTo3kxYYvzl8VkOzgJb9kp77X0p3ng6 G0cPTFTyBbr0+DtrSqcAxkHD3uN2dY+f7OjpMLOqDYExhzerU9cayoZW8GMCEbSsUx XViYdckNuu6Vhfq4k0m5EJ7jUWILzLms0cKTqft7xQkOU0bD7c72iEc0hlMwdEpsVF bS5ZYNAx7dz3k7p9W7bYSjqL9cp3GGW8JKzhnWnlI8OgF+kLZmXkWwQIJTpP1mWJDZ 5sXMBheU8qnt9M3g/AOuKaVkfusi/0EMP1DDOHhrUmo2fVHgrGA9vSiR+h5myUvZYl nO/yO8J1ZGdWA== 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 19/30] kconfig: show compiler version text in the top comment Date: Fri, 13 Apr 2018 14:06:28 +0900 Message-Id: <1523595999-27433-20-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 The kernel configuration phase is now tightly coupled with the compiler in use. It will be nice to show the compiler information in Kconfig. The compiler information will be displayed like this: $ make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- config scripts/kconfig/conf --oldaskconfig Kconfig * * Linux/arm64 4.16.0-rc1 Kernel Configuration * * * Compiler: aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011 * * * General setup * Compile also drivers which will not load (COMPILE_TEST) [N/y/?] If you use GUI methods such as menuconfig, it will be displayed in the top menu. This is simply implemented by using the 'comment' statement. So, it will be saved into the .config file as well. This commit has a very important meaning. If the compiler is upgraded, Kconfig must be re-run since different compilers have different sets of supported options. All referenced environments are written to include/config/auto.conf.cmd so that any environment change triggers syncconfig, and prompt the user to input new values if needed. With this commit, something like follows will be added to include/config/auto.conf.cmd ifneq "$(CC_VERSION_TEXT)" "aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011" include/config/auto.conf: FORCE endif Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None Kconfig | 2 ++ Makefile | 2 ++ 2 files changed, 4 insertions(+) -- 2.7.4 diff --git a/Kconfig b/Kconfig index 4af1b42..5b55d87 100644 --- a/Kconfig +++ b/Kconfig @@ -5,4 +5,6 @@ # mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration" +comment "Compiler: $(CC_VERSION_TEXT)" + source "arch/$(SRCARCH)/Kconfig" diff --git a/Makefile b/Makefile index ca3e3e8..4b36329 100644 --- a/Makefile +++ b/Makefile @@ -442,6 +442,8 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL export KBUILD_ARFLAGS +export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1) + # When compiling out-of-tree modules, put MODVERDIR in the module # tree rather than in the kernel tree. The kernel tree might # even be read-only. From patchwork Fri Apr 13 05:06:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133338 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp348200ljb; Thu, 12 Apr 2018 22:14:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+EKf0hONPW9qMjMkX5MhMuyQJQG8ZmGEs+2wJ/aLCV0ayfv6jTx61tmmSNLwtmXL68JoNk X-Received: by 2002:a17:902:e5:: with SMTP id a92-v6mr3860439pla.26.1523596473467; Thu, 12 Apr 2018 22:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596473; cv=none; d=google.com; s=arc-20160816; b=jBW/eVMjhaW1pMgu1yC26rYNDhFfdTYZec+cPxGbyaKiTWtoHG6k+lEI1gh9afAH5q pwPiGtpfUUE7OPr6bElec0rRt3y4n2i4et3h0qS0+EAJwwlnBYH3KAvBWZ26xrQ/6jzl oA7WqQJTCtmslcvSqgirCjpmzUWBBIcRKvpvBWCGmEuNyOu7DLtiBxF0UVAPTuDe5QLg IAXofCSU+jZ0ohJ8kHr8dkhiKtVry8k3nRSM90wee5D8aYGk8lF9ozuGaw28nmnbSC/J C9K5PVhcvgu8c07eGC/UKU6+19oyznCK35+LodrbpfO+/Lcie+2U9UYGBmraQGGbnid6 ZwRQ== 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=lwfyJVwMZs6q+YvqxKJT8CiT1MHim80CvXV5gKwCRMg=; b=nIKZkODsqge/dvrX1k2Z1A2+qCs/MkgW++xA3QlvixJcbOF4y4BQq1vubPXJSNoFTN 9AFpHiKfRmJ40Kp+T7uuoPr57xifIgvfmxkVYx+IeRy3/1w7hzxV99o6EvNewVDLLL47 GZI6ti7C9IFnDAULPPsYwZ24VvQs+oe2Dw00m+ZalWpN6pUf8fIdNmKTaH/7ce3w49oL oGgJjwqTjhRkcjJKzfTBRJPT6CLWquH8utOMFb/o15b5AZBsmg7tAl5uM0Phnd3as26l PO/Ar3NkcPbe1HiBuehgdN4/T3I2f0tED5kwR+sRXZfMrqSDQeDqLJVo8OJF9d4yIY3w rMpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=He2cCuzv; 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 30-v6si4922707plb.316.2018.04.12.22.14.33; Thu, 12 Apr 2018 22:14:33 -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=He2cCuzv; 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 S1753672AbeDMFOD (ORCPT + 29 others); Fri, 13 Apr 2018 01:14:03 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54460 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751035AbeDMFIP (ORCPT ); Fri, 13 Apr 2018 01:08:15 -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 w3D56lgE029209; Fri, 13 Apr 2018 14:07:05 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgE029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596026; bh=lwfyJVwMZs6q+YvqxKJT8CiT1MHim80CvXV5gKwCRMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=He2cCuzvMsuywPlYi7vUttS/+7BCi2yfRDrpiClRnPzay6O4cBPR0Gpiftk5MoFfK 8O1jyvbchEQ0uivxQOjZYzF42Zq0V7zUV7emkSZG0pUgSkjSDE64ski55pzU48lcSj OSDb9ZfpFl6A/3hr3Or3ntSpthn4EqIzZ+letJ65ZdIkKfu9IwMBug5g/HLQaIBVjn NwIy+sP8zgcJsUCg0xC6PDqarmi1ojXcNpSuLSft4OZspepxJ9lr6vGOK7UePQq5GD Ve0n0zCelgFbjYYyDekAZr2nex278ZCZsbNKppIj1Q9olcqplM62bOsHP4aQsEA2LY 9Yl0z/GYDL+1Q== 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 20/30] kconfig: add basic helper macros to scripts/Kconfig.include Date: Fri, 13 Apr 2018 14:06:29 +0900 Message-Id: <1523595999-27433-21-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 Kconfig got text processing tools like we see in Make. Add Kconfig helper macros to scripts/Kconfig.include like we collect Makefile macros in scripts/Kbuild.include. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson --- Changes in v3: - Move helpers to scripts/Kconfig.include Changes in v2: None Kconfig | 2 ++ MAINTAINERS | 1 + scripts/Kconfig.include | 17 +++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 scripts/Kconfig.include -- 2.7.4 diff --git a/Kconfig b/Kconfig index 5b55d87..a90d9f9 100644 --- a/Kconfig +++ b/Kconfig @@ -7,4 +7,6 @@ mainmenu "Linux/$(ARCH) $(KERNELVERSION) Kernel Configuration" comment "Compiler: $(CC_VERSION_TEXT)" +source "scripts/Kconfig.include" + source "arch/$(SRCARCH)/Kconfig" diff --git a/MAINTAINERS b/MAINTAINERS index b9dab38..d962f4a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7624,6 +7624,7 @@ L: linux-kbuild@vger.kernel.org S: Maintained F: Documentation/kbuild/kconfig* F: scripts/kconfig/ +F: scripts/Kconfig.include KDUMP M: Dave Young diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include new file mode 100644 index 0000000..cac7a81 --- /dev/null +++ b/scripts/Kconfig.include @@ -0,0 +1,17 @@ +# Kconfig helper macros + +# Convenient variables +comma := , +quote := " +squote := ' +empty := +space := $(empty) $(empty) + +# y if the command exits with 0, n otherwise +success = $(shell ($(1)) >/dev/null 2>&1 && echo y || echo n) + +# y if the given compiler flag is supported, n otherwise +cc-option = $(success $(CC) -Werror $(1) -c -x c /dev/null -o /dev/null) + +# y if the given linker flag is supported, n otherwise +ld-option = $(success $(LD) -v $(1)) From patchwork Fri Apr 13 05:06:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133329 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346809ljb; Thu, 12 Apr 2018 22:12:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx49IEQ7GH3nkWbt3y/IllX8VgtYg0vfMHj63gVzZ5v8Qaj/JJlOII76LS34HgiGmoW6AlWm7 X-Received: by 10.101.93.82 with SMTP id e18mr2984552pgt.123.1523596342527; Thu, 12 Apr 2018 22:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596342; cv=none; d=google.com; s=arc-20160816; b=yRfcF4OmdPY1Q3Hex95lDsMcRv+dTSDv3aIIEtxCvvKnYU0Pfjx/t+vFpX9bjDGOxa GDNO6iu5zgwsNpILQrWcMAzOdik/4PNtNISaX+fogbC8i4SBBVhYwr58dw0/GVv6sNZh OPohIiFlaXsCAgMZC9lJ+60FH/YLcMV19V1zYrWAwXNQkTRLaQweaE8RTwqq718ODFDR apWbgFljXgdmZnrmr1AdJrd2GMdZhKy48pwD6at6heJcJUpikVb3ktmAY2N1uCWJBhs3 HlsPNOpRp56OWcCEm9qK2E/mQus4wkaFzfpW6ChPyzTF8fPJIPA8lVHvuc1d9u+ufysl a7lQ== 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=GivVj9DitLIm1hqxuFu7LefSIweV1RK8tO9uBtIfk8M=; b=zbbXfCGfmcLPAeVu8YNivPX3bdOzFtdRucucCHTf0k06nOxxLnlpIGpwLXoQvA0fj8 cUogstjEFdwBAK2feoNmwK5iHZGTTPYvFokidEWgNv4o2peLCljlYDfogQjmr3vLXAwM SIGQKhQyCVRrek50GkOiOvEWKSxPAReSG7lJD2ITyqtdBEFIY2Z1KMH4noa0wAreL++7 FHCrNjpn0ACGKEMM5Visph4gJEXWiEjiYmMOjSOCtQ4pkjSUKMK6e3JZHhHFMNRJyBnD rqi4RDiFr6WOHOi+O7YdIJ3CyC0yFi/7UT4KVmShUE/3jAG/1lTZNcjg1rEVBVR0NG78 Ps2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=dRrM36F4; 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 135si3889273pfc.21.2018.04.12.22.12.22; Thu, 12 Apr 2018 22:12:22 -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=dRrM36F4; 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 S1753525AbeDMFMH (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:07 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54557 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbeDMFIR (ORCPT ); Fri, 13 Apr 2018 01:08:17 -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 w3D56lgF029209; Fri, 13 Apr 2018 14:07:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgF029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596027; bh=GivVj9DitLIm1hqxuFu7LefSIweV1RK8tO9uBtIfk8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dRrM36F4HSz9xYUjKNs8eXKyauK/MWHtMnK0/iXEtWVD7LXXKGsX+I7sqZZDdd4J2 JdqA2iTwsQVtABbIRg4k/mK7gEtksozUfiH2sW/jtRv5GZUnSauy6kWSWSA8N5dQFV v8k4KajZ2a6x+5rqen8qCfrlFR3f+iQgDp6ot6XQpkpN2raOPnF1/66EbwCs4mjU4T sSij/cckeeX7jf7360RB4K4/vR0XPKRKoqo8CslNCzPXmB+QQ4IaXWaqWzZ2JQ12Y9 gzk8w2NWKx2ZxKatVOSog92s398TyhNnEWLZe88r4yxct3pAI+jWukSm6yIJ8GIuhD nIEs7J1BTaBPw== 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 21/30] stack-protector: test compiler capability in Kconfig and drop AUTO mode Date: Fri, 13 Apr 2018 14:06:30 +0900 Message-Id: <1523595999-27433-22-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 Move the test for -fstack-protector(-strong) option to Kconfig. If the compiler does not support the option, the corresponding menu is automatically hidden. If STRONG is not supported, it will fall back to REGULAR. If REGULAR is not supported, it will be disabled. This means, AUTO is implicitly handled by the dependency solver of Kconfig, hence removed. I also turned the 'choice' into only two boolean symbols. The use of 'choice' is not a good idea here, because all of all{yes,mod,no}config would choose the first visible value, while we want allnoconfig to disable as many features as possible. X86 has additional shell scripts in case the compiler supports those options, but generates broken code. I added CC_HAS_SANE_STACKPROTECTOR to test this. I had to add -m32 to gcc-x86_32-has-stack-protector.sh to make it work correctly. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None Makefile | 93 ++----------------------------- arch/Kconfig | 32 ++++------- arch/x86/Kconfig | 11 +++- scripts/gcc-x86_32-has-stack-protector.sh | 7 +-- scripts/gcc-x86_64-has-stack-protector.sh | 5 -- 5 files changed, 28 insertions(+), 120 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 4b36329..889d002 100644 --- a/Makefile +++ b/Makefile @@ -672,55 +672,11 @@ ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) endif -# This selects the stack protector compiler flag. Testing it is delayed -# until after .config has been reprocessed, in the prepare-compiler-check -# target. -ifdef CONFIG_CC_STACKPROTECTOR_AUTO - stackp-flag := $(call cc-option,-fstack-protector-strong,$(call cc-option,-fstack-protector)) - stackp-name := AUTO -else -ifdef CONFIG_CC_STACKPROTECTOR_REGULAR - stackp-flag := -fstack-protector - stackp-name := REGULAR -else -ifdef CONFIG_CC_STACKPROTECTOR_STRONG - stackp-flag := -fstack-protector-strong - stackp-name := STRONG -else - # If either there is no stack protector for this architecture or - # CONFIG_CC_STACKPROTECTOR_NONE is selected, we're done, and $(stackp-name) - # is empty, skipping all remaining stack protector tests. - # - # Force off for distro compilers that enable stack protector by default. - KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) -endif -endif -endif -# Find arch-specific stack protector compiler sanity-checking script. -ifdef stackp-name -ifneq ($(stackp-flag),) - stackp-path := $(srctree)/scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh - stackp-check := $(wildcard $(stackp-path)) - # If the wildcard test matches a test script, run it to check functionality. - ifdef stackp-check - ifneq ($(shell $(CONFIG_SHELL) $(stackp-check) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y) - stackp-broken := y - endif - endif - ifndef stackp-broken - # If the stack protector is functional, enable code that depends on it. - KBUILD_CPPFLAGS += -DCONFIG_CC_STACKPROTECTOR - # Either we've already detected the flag (for AUTO) or we'll fail the - # build in the prepare-compiler-check rule (for specific flag). - KBUILD_CFLAGS += $(stackp-flag) - else - # We have to make sure stack protector is unconditionally disabled if - # the compiler is broken (in case we're going to continue the build in - # AUTO mode). - KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector) - endif -endif -endif +stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector +stackp-flags-$(CONFIG_CC_STACKPROTECTOR) := -fstack-protector +stackp-flags-$(CONFIG_CC_STACKPROTECTOR_STRONG) := -fstack-protector-strong + +KBUILD_CFLAGS += $(stackp-flags-y) ifeq ($(cc-name),clang) KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) @@ -1096,7 +1052,7 @@ endif # prepare2 creates a makefile if using a separate output directory. # From this point forward, .config has been reprocessed, so any rules # that need to depend on updated CONFIG_* values can be checked here. -prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic +prepare2: prepare3 outputmakefile asm-generic prepare1: prepare2 $(version_h) $(autoksyms_h) include/generated/utsrelease.h \ include/config/auto.conf @@ -1122,43 +1078,6 @@ uapi-asm-generic: PHONY += prepare-objtool prepare-objtool: $(objtool_target) -# Check for CONFIG flags that require compiler support. Abort the build -# after .config has been processed, but before the kernel build starts. -# -# For security-sensitive CONFIG options, we don't want to fallback and/or -# silently change which compiler flags will be used, since that leads to -# producing kernels with different security feature characteristics -# depending on the compiler used. (For example, "But I selected -# CC_STACKPROTECTOR_STRONG! Why did it build with _REGULAR?!") -PHONY += prepare-compiler-check -prepare-compiler-check: FORCE -# Make sure compiler supports requested stack protector flag. -ifdef stackp-name - # Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option. - ifeq ($(stackp-flag),) - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - Compiler does not support any known stack-protector >&2 - else - # Fail if specifically requested stack protector is missing. - ifeq ($(call cc-option, $(stackp-flag)),) - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) not supported by compiler >&2 && exit 1 - endif - endif -endif -# Make sure compiler does not have buggy stack-protector support. If a -# specific stack-protector was requested, fail the build, otherwise warn. -ifdef stackp-broken - ifeq ($(stackp-name),AUTO) - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) available but compiler is broken: disabling >&2 - else - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) available but compiler is broken >&2 && exit 1 - endif -endif - @: - # Generate some files # --------------------------------------------------------------------------- diff --git a/arch/Kconfig b/arch/Kconfig index 8e0d665..b0582f2 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -535,13 +535,16 @@ config HAVE_CC_STACKPROTECTOR bool help An arch should select this symbol if: - - its compiler supports the -fstack-protector option - it has implemented a stack canary (e.g. __stack_chk_guard) -choice - prompt "Stack Protector buffer overflow detection" +config CC_HAS_STACKPROTECTOR_NONE + def_bool $(cc-option -fno-stack-protector) + +config CC_STACKPROTECTOR + bool "Stack Protector buffer overflow detection" depends on HAVE_CC_STACKPROTECTOR - default CC_STACKPROTECTOR_AUTO + depends on $(cc-option -fstack-protector) + default y help This option turns on the "stack-protector" GCC feature. This feature puts, at the beginning of functions, a canary value on @@ -551,14 +554,6 @@ choice overwrite the canary, which gets detected and the attack is then neutralized via a kernel panic. -config CC_STACKPROTECTOR_NONE - bool "None" - help - Disable "stack-protector" GCC feature. - -config CC_STACKPROTECTOR_REGULAR - bool "Regular" - help Functions will have the stack-protector canary logic added if they have an 8-byte or larger character array on the stack. @@ -570,7 +565,10 @@ config CC_STACKPROTECTOR_REGULAR by about 0.3%. config CC_STACKPROTECTOR_STRONG - bool "Strong" + bool "Strong Stack Protector" + depends on CC_STACKPROTECTOR + depends on $(cc-option -fstack-protector-strong) + default y help Functions will have the stack-protector canary logic added in any of the following conditions: @@ -588,14 +586,6 @@ config CC_STACKPROTECTOR_STRONG about 20% of all kernel functions, which increases the kernel code size by about 2%. -config CC_STACKPROTECTOR_AUTO - bool "Automatic" - help - If the compiler supports it, the best available stack-protector - option will be chosen. - -endchoice - config LD_DEAD_CODE_DATA_ELIMINATION bool help diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 72350d5..6f65146 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -124,7 +124,7 @@ config X86 select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64 select HAVE_ARCH_VMAP_STACK if X86_64 select HAVE_ARCH_WITHIN_STACK_FRAMES - select HAVE_CC_STACKPROTECTOR + select HAVE_CC_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL select HAVE_CONTEXT_TRACKING if X86_64 @@ -340,6 +340,15 @@ config PGTABLE_LEVELS default 2 source "init/Kconfig" + +config CC_HAS_SANE_STACKPROTECTOR + bool + default $(success $(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(CC)) if 64BIT + default $(success $(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(CC)) + help + We have to make sure stack protector is unconditionally disabled if + the compiler produces broken code. + source "kernel/Kconfig.freezer" menu "Processor type and features" diff --git a/scripts/gcc-x86_32-has-stack-protector.sh b/scripts/gcc-x86_32-has-stack-protector.sh index 6b2aeef..f5c1194 100755 --- a/scripts/gcc-x86_32-has-stack-protector.sh +++ b/scripts/gcc-x86_32-has-stack-protector.sh @@ -1,9 +1,4 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs" -if [ "$?" -eq "0" ] ; then - echo y -else - echo n -fi +echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -fstack-protector - -o - 2> /dev/null | grep -q "%gs" diff --git a/scripts/gcc-x86_64-has-stack-protector.sh b/scripts/gcc-x86_64-has-stack-protector.sh index 4a48bdc..3755af0 100755 --- a/scripts/gcc-x86_64-has-stack-protector.sh +++ b/scripts/gcc-x86_64-has-stack-protector.sh @@ -2,8 +2,3 @@ # SPDX-License-Identifier: GPL-2.0 echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" -if [ "$?" -eq "0" ] ; then - echo y -else - echo n -fi From patchwork Fri Apr 13 05:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133334 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347572ljb; Thu, 12 Apr 2018 22:13:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx490LbjNUEdgO5GWND/hB1fyPjvWFbfw0/TJ58PSrl93Ml9bOZDX4p9YXBGCyxtQcEmn01mq X-Received: by 10.99.174.6 with SMTP id q6mr2912465pgf.179.1523596419139; Thu, 12 Apr 2018 22:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596419; cv=none; d=google.com; s=arc-20160816; b=YhLdd8VSPAlle0Ihqa/iD6zUY8sDekne+xiiHq4KdrAxgK9VXV6gxih/Zis3dg2xuO ZhD1tSFa9UJLupJW9nYrJHASrvcIRUW9mqJ9/OHmonq0Hm0U0UJwctah0q8DiNfcVhGM kNedC4AD3HkV5uO+BeexCnK1wp2jLtPPsidsjWE/IIyuINJWIFk2Xse1HT6IOMoWg1s2 /ZrVVPh9hjMv6jYCiQR3E9Dq5wOKb44zrl2fcj0lrMiI6kL4Gjqadzdvm1QiKFmdBD8z QNkrX5RItcVeFHP0y7K9g55zEc5dzADXlKQw2Z+qZtlbZAiCN2dfRZPi4sG3lQLs83aU Tdhg== 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=jg3lVjZel2Yf7OtQxyanll2wk0Bf1Z/iSQBNf+EWzY8=; b=r1nasQYP1cH+F+XPnlx5+RTFHxbIYkukuc52z+hZc53NYGOg0GcbhJNMJf+RuVtiFs NNtsAck0msVy880I1UW/FragBE+qbkVN9ODRTSMqq1zp9+LfWDU2BldtunFEHmTp5yTu V1o15HqHL5O2UGiWuD0NB31yjAKuS5JfWtetiazOjBWztuIWs3zREZzk6n8gRQff6nGg 73Yd9TOEE1sURXTliSJPwqzwHdJj8gZz076V7OVllmAx951HHA3J7k4PuTIlHNeZW25x McZzWw1LK7Pvl8PIPS9RK8vVGWZSyS4vs0pB+3Not5jCk3Fl1P12gArUbq4D5XIYZCY0 PfZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=JNTrERy8; 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 f16si3313507pgt.800.2018.04.12.22.13.38; Thu, 12 Apr 2018 22:13:39 -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=JNTrERy8; 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 S1753126AbeDMFMm (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:42 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54532 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lgG029209; Fri, 13 Apr 2018 14:07:07 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgG029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596028; bh=jg3lVjZel2Yf7OtQxyanll2wk0Bf1Z/iSQBNf+EWzY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNTrERy8/DRBsxMZo1tCyUPCVUErl3Rdxj9lZ4kWlATSLwdkNb2Aq7jWRy1eKGP6F JDwSMfUX5cxFUve1sxo/FNv9tnQr+AXe7f7rvwfVFCYGEc01cozjf+0jWvQEJwnezP gZcxw8VM4NmP/9t14dz+GzX15FPZDzAahmqoPlU/c783iqLlTx/3ao+apXiwxFIxjS d9FL76RSbNsLu8aAwgIDrmi7zv2xQjt3rY1oTQhyPRRAbWFWtuhbv2UxyqWBV47tNL SdqBBLIF7C+FlK0bsfjitatkNtsNQ8DWxikMCynoSQFGmFJ4A/f4ZTYFy8orWskZXK rgB3H50CDggEg== 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 22/30] kconfig: add CC_IS_GCC and GCC_VERSION Date: Fri, 13 Apr 2018 14:06:31 +0900 Message-Id: <1523595999-27433-23-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 This will be useful to specify the required compiler version, like this: config FOO bool "Use Foo" depends on GCC_VERSION >= 408000 help This feature requires GCC 4.8 or newer. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None init/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 diff --git a/init/Kconfig b/init/Kconfig index 4b0b636..145a534 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -8,6 +8,14 @@ config DEFCONFIG_LIST default ARCH_DEFCONFIG default "arch/$(ARCH)/defconfig" +config CC_IS_GCC + def_bool $(success $(CC) --version | grep -q gcc) + +config GCC_VERSION + int + default $(shell $(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') if CC_IS_GCC + default 0 + config CONSTRUCTORS bool depends on !UML From patchwork Fri Apr 13 05:06:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133330 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347038ljb; Thu, 12 Apr 2018 22:12:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/6sgnlBubtZBxt6FWH6WdaH9BqSGgFQCmwR0I/b6gv39Om4U3nhA9pPKz6sARewLkLZaLO X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr3811615plr.154.1523596366737; Thu, 12 Apr 2018 22:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596366; cv=none; d=google.com; s=arc-20160816; b=hLAx5aIx21v4CpNP1tlfD5wzUGLrcZ0VVLtxyox5vFc3z7uW2ofl2Fw+0jIaikUYyY wANWhwfkccjO98X7iJR9w2VCT6pcrQ3ZKYb6KMx9TH9h3Feta8yhOVQx7NcfpVcKMVzQ 18RGlz3u7RqMDvzfKR7weKCCLnCuW9DHgJnYIq/hegT60cPAYYoyF2mD/ZplCIcS3aE4 LS5ckOLy87u7uvqDXjrBS+0JJ4zuZ5RugAEhxwh/QBujldTY+P4d7jQkZqeiu95ITnrc WzLXEnRVtgm3EkO+iICI7eKOme2NHASoYtdDC//MKjY4HXJkiwVpGvQjahnWxz5VGdfT 5rIA== 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=WWDrBCy6F8kVf33juHWFSmV9WNxTCZSXI//PoN2+R4Q=; b=s0rF8Su8IusFZai0q5RSqo6oijrtf/M+iXA1uBZaUw4zxaV7pY1C5wNRVd9DT99whJ t1aeq2aXkLCmi/9Ej2m+tKqECy98+/49UHkp3h5np4Q9dmvzKd7AL4KxdNDh8MOCy1lv 1eUAdQtY2WVilLney9NHHjrfs1Obzb92o0dD30R9MOqSbedluVDqDX7ruVEaAS7c1dXe X1nqOGEswPyLgzJTyMeDX5db9HO9O1t9xC3llekmo8apqKJvC5YqqeESA1UwhWtCXB94 0qtfw8hUmBjGEcJALseQ7CCmZxPKg2agCHP1iXedVFHZnT+0cqBO7zZ8RfnSQ5LhmZUc p6jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=c+W9tTX9; 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 t2si3411527pgb.209.2018.04.12.22.12.46; Thu, 12 Apr 2018 22:12:46 -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=c+W9tTX9; 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 S1753680AbeDMFMn (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:43 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54529 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751076AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -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 w3D56lgH029209; Fri, 13 Apr 2018 14:07:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgH029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596029; bh=WWDrBCy6F8kVf33juHWFSmV9WNxTCZSXI//PoN2+R4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c+W9tTX9BvzbhJ+IYBOhIesGy2bz/kcZ4QbcmfBjcGj4JFHRoy0wDFbXey6pY/2is xCKA++/0h8z6TBPubQBp5CPe/fqqzIm4+dnu2ZqtT4tEiU4Pfc9C6jP4DggDIxYuIX w4D4lz8oHYIW27qLEGVC4rSPaKeXhAv1zEOP/Zpf4tGQv4k5hacfSFJ5F0JUXsGMfy 7NmArRJfUzCg8nTYJrg86VGs/E6RfP5KsN9m1G90xzPTsHMiPT9s6tTpnLW/zwrI3N H+cfowMot3pU81F38r/Ia8X21aTKOs5K8WHcaxWsKlRrVOD8VC67CyPJSNs5p6WoKs y2x+AGh0LVH8w== 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 23/30] kconfig: add CC_IS_CLANG and CLANG_VERSION Date: Fri, 13 Apr 2018 14:06:32 +0900 Message-Id: <1523595999-27433-24-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 This will be useful to describe the clang version dependency. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None init/Kconfig | 7 +++++++ scripts/clang-version.sh | 18 ++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/init/Kconfig b/init/Kconfig index 145a534..c8f4ba3 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -16,6 +16,13 @@ config GCC_VERSION default $(shell $(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') if CC_IS_GCC default 0 +config CC_IS_CLANG + def_bool $(success $(CC) --version | grep -q clang) + +config CLANG_VERSION + int + default $(shell $(srctree)/scripts/clang-version.sh $(CC)) + config CONSTRUCTORS bool depends on !UML diff --git a/scripts/clang-version.sh b/scripts/clang-version.sh index 9780efa..dbf0a31 100755 --- a/scripts/clang-version.sh +++ b/scripts/clang-version.sh @@ -10,24 +10,14 @@ # clang-5.0.1 etc. # -if [ "$1" = "-p" ] ; then - with_patchlevel=1; - shift; -fi - compiler="$*" -if [ ${#compiler} -eq 0 ]; then - echo "Error: No compiler specified." - printf "Usage:\n\t$0 \n" +if !( $compiler --version | grep -q clang) ; then + echo 0 exit 1 fi MAJOR=$(echo __clang_major__ | $compiler -E -x c - | tail -n 1) MINOR=$(echo __clang_minor__ | $compiler -E -x c - | tail -n 1) -if [ "x$with_patchlevel" != "x" ] ; then - PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) - printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL -else - printf "%02d%02d\\n" $MAJOR $MINOR -fi +PATCHLEVEL=$(echo __clang_patchlevel__ | $compiler -E -x c - | tail -n 1) +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL From patchwork Fri Apr 13 05:06:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133316 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344674ljb; Thu, 12 Apr 2018 22:09:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/tudrVifkaNZIkQEGnoSK6uWgBF5YD2l9umb6XD6ESJfQ58x6PUueac5S4lO3YhBgn9Zz3 X-Received: by 2002:a17:902:74c3:: with SMTP id f3-v6mr3804143plt.7.1523596145944; Thu, 12 Apr 2018 22:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596145; cv=none; d=google.com; s=arc-20160816; b=1CYoxMWcirMiSipIoDXJxf0ZAwOlxmjGNkEOSTGEAmlWoifSHtDdyUfqw3YaBX7ETV vwU3aze5tgRP9SWsRgREcW47Yvexo7VTty68KDyr/pRNrPc7QU+kyG4tXC7dmXpwEK61 WMi9Z7RpZpze1dEBYlYyG9BsJcqpRnm882pC9aovpOihO8CYpxT1jWaKvRRQvJ14cvFs mxfPQ0foczGi9k7bfdepoF1oNojxnFJDW3eLkpWxQcKhldzLtK0NzVe3mDBHwxIqIu23 W5rN1wZYW4dQ1DS8DI4Tvleh5orfhc47IRAvwJ+aoZpGbpbtXpNAQ046WdR6c2clkgKq SGPA== 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=eF3nICI6HHjEYvPOol4CqwbYkKB2xRWzW4BAhvRa9Yc=; b=w0GrXkq6BKtyF7QVaVMvCY0yIW91r1/jKkaG0lmZ108HwlGzFsirbr1vlfCzBu+z3y lOTtZQdF0XiNdwxQAqPtmqi0P60bQD239Xw3ZhPTC+YxzF1bY3xxul4jjXJjmwUlA/Zx KCOqZMh+lWVW0pj+OICaXjN8E6rZ4Xw6mE0psyVqQpcJvMaDvsStiqROmoHtFTbRt4Kt zxxfEVIQqRQC1r4AJkpdA9T2Qx4Op6rZ1k1Up6/0PTHWVo4+S2YekIU7ZHJTXlUpS3z5 6Py19egi+Iowdtj/GZkLBOPAIb0KsPTHLOFg2TOG84d1sFx/EHioXghkWd8Zc66djAFL bPtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ekvVjdnn; 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 62si3949126pfs.45.2018.04.12.22.09.05; Thu, 12 Apr 2018 22:09: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=ekvVjdnn; 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 S1753443AbeDMFJB (ORCPT + 29 others); Fri, 13 Apr 2018 01:09:01 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55808 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753244AbeDMFI7 (ORCPT ); Fri, 13 Apr 2018 01:08:59 -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 w3D56lgI029209; Fri, 13 Apr 2018 14:07:09 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgI029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596030; bh=eF3nICI6HHjEYvPOol4CqwbYkKB2xRWzW4BAhvRa9Yc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ekvVjdnnDigEi5O/F9e9pMZ/TCF3qxWc1tZ1PA/otaZ3AiZzoS0v4xbztfuVotGwr 03nlEcfWf/JtxFLOKeGRjnE8FdLyQZGHyakHE6eZ+g7ysonlVziBHQsvaR2i6cQdAe XpnbI6hXvSMrX68cg6ISTrCDqYZzEtRmYE981H32e1sRDONN+Ni/3qdN9T0W8xMbUL JlpGPdUfQGg1kFdV8N/zw57e0gzskTPnrRTusL+kXlp23mCfH3Qqiauzrtsq4UF/aL kpLVb86uv7CzrulWOUgz3WlNY9NZ26gen9xdf1oMxYnLOrpgRTi0RgZR/blaB55IWp pvPFwvVDT/7oA== 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 24/30] gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT Date: Fri, 13 Apr 2018 14:06:33 +0900 Message-Id: <1523595999-27433-25-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 CONFIG_GCOV_FORMAT_AUTODETECT compiles either gcc_3_4.c or gcc_4_7.c according to your GCC version. We can achieve the equivalent behavior by setting reasonable dependency with the knowledge of the compiler version. If GCC older than 4.7 is used, GCOV_FORMAT_3_4 is the default, but users are still allowed to select GCOV_FORMAT_4_7 in case the newer format is back-ported. On the other hand, If GCC 4.7 or newer is used, there is no reason to use GCOV_FORMAT_3_4, so it should be hidden. If you downgrade the compiler to GCC 4.7 or older, oldconfig/syncconfig will display a prompt for the choice because GCOV_FORMAT_3_4 becomes visible as a new symbol. Signed-off-by: Masahiro Yamada Acked-by: Peter Oberparleiter Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None kernel/gcov/Kconfig | 17 +++++------------ kernel/gcov/Makefile | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) -- 2.7.4 diff --git a/kernel/gcov/Kconfig b/kernel/gcov/Kconfig index 1276aab..1e3823f 100644 --- a/kernel/gcov/Kconfig +++ b/kernel/gcov/Kconfig @@ -53,23 +53,16 @@ config GCOV_PROFILE_ALL choice prompt "Specify GCOV format" depends on GCOV_KERNEL - default GCOV_FORMAT_AUTODETECT ---help--- - The gcov format is usually determined by the GCC version, but there are + The gcov format is usually determined by the GCC version, and the + default is chosen according to your GCC version. However, there are exceptions where format changes are integrated in lower-version GCCs. - In such a case use this option to adjust the format used in the kernel - accordingly. - - If unsure, choose "Autodetect". - -config GCOV_FORMAT_AUTODETECT - bool "Autodetect" - ---help--- - Select this option to use the format that corresponds to your GCC - version. + In such a case, change this option to adjust the format used in the + kernel accordingly. config GCOV_FORMAT_3_4 bool "GCC 3.4 format" + depends on CC_IS_GCC && GCC_VERSION < 40700 ---help--- Select this option to use the format defined by GCC 3.4. diff --git a/kernel/gcov/Makefile b/kernel/gcov/Makefile index c6c50e5..ff06d64 100644 --- a/kernel/gcov/Makefile +++ b/kernel/gcov/Makefile @@ -4,5 +4,3 @@ ccflags-y := -DSRCTREE='"$(srctree)"' -DOBJTREE='"$(objtree)"' obj-y := base.o fs.o obj-$(CONFIG_GCOV_FORMAT_3_4) += gcc_3_4.o obj-$(CONFIG_GCOV_FORMAT_4_7) += gcc_4_7.o -obj-$(CONFIG_GCOV_FORMAT_AUTODETECT) += $(call cc-ifversion, -lt, 0407, \ - gcc_3_4.o, gcc_4_7.o) 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 From patchwork Fri Apr 13 05:06:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133322 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp345788ljb; Thu, 12 Apr 2018 22:10:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx48T5+3w3wLfz8C/UB81d69wSEKzEFu+1KgRuJCPNST4cel2kx/+WdkMXBG6PU7y3d4XPMwN X-Received: by 10.98.71.211 with SMTP id p80mr10102140pfi.136.1523596242771; Thu, 12 Apr 2018 22:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596242; cv=none; d=google.com; s=arc-20160816; b=nqP40Jgijw7cDV1q8xKicQnd/blI37r38curRbAIL6MfL88HGPdIn5Ede+bmp9Fauc 2zAsKDutmrMHRqSxHLTgT4sCeDPF2Tq9bE7wZkU/xZ/10Hw0XOR3R35u7PhAkNUKTsBn 51u8LhE9zRAqrGTC8mpogGDQ0f2KM9i8DSImaCmwke0KEPFHgQ0Wvfpo2pvV7unEwZJu Z+rfLgaw4BFEWAVDIhi/jLUXIzzqkpqFKweZikScuIiUwpIjDVLo6gFmYJXQp3DEpiM+ bOF4MYpjoLaOsfRx0sD8Ys4R/cvSTX92BhfSzLFwk42BNQM10+NzA79NxLlE+6NHDxIR RDjA== 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=qvSYT0Qsd4fODSL3H0Lyt/6V1ex5OeWERViDeMImAb8=; b=H5fpICkzRJkqTSyqqyNKzODK2d9hxhQNSbE0GwTn5hWjFpMxcViLKgvVBXLEt2WIwK aWBHOTmZ8JNArrnDIJQcSO+bFZokRttJhG2Ykhqd8Un0K/D9LDim6ALiFXzXL6bU34jQ fs25mFibfq8uEshrCEgn7GF0mGLRHpybOFRn+YwelsTqd7Ssf++rneFkUSQ6a5+Lnd/p 5AiaQRsM9GiHKtpFIRzNVPnXhlhy61AZdLLIHTE0sO9cB6cXpfk9mk2sNjZqKgnyg/hn 56/8pcQ79okEGrwFVf6I7VSW4xPx3wxu1LCFn2sX1XBaUnzCEAs2OHZofuERdPOJbxd9 iYlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=BNzj4G6D; 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 k9si3443994pgr.146.2018.04.12.22.10.42; Thu, 12 Apr 2018 22:10:42 -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=BNzj4G6D; 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 S1753874AbeDMFKi (ORCPT + 29 others); Fri, 13 Apr 2018 01:10:38 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55144 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752849AbeDMFIh (ORCPT ); Fri, 13 Apr 2018 01:08:37 -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 w3D56lgK029209; Fri, 13 Apr 2018 14:07:11 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgK029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596031; bh=qvSYT0Qsd4fODSL3H0Lyt/6V1ex5OeWERViDeMImAb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNzj4G6DUtOYet7x9nw7TbMeRn3TMzkwkL30k4fSh3EXMc28/UWQiD3jElNyHUxGz 5XtmKbpql1uN+whlt48YOiREvPtOsUfc2ZjT4JMWI2k3IlejyVygXQI80NwbGUjZTT M1jrrYUzAT56Nel1njHhCGI3S4YoGTOvj+l9g1ZU3NDU6r6z6pgf5KmZIE64KOVTtd VtO3qFYoMmTMXf3RmHRvk2yydo8I/jCLvKgFW/GrkVQQJltewaFgGyv8Imr4Kuwerj yoX6dt15VPLgNvWg2sKDY1Vtt1TOsy0QOWUnDJ8mxVR5qwNbGXHeSnCywve5jhg5Ha R1v1Cb6+aT12g== 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 26/30] gcc-plugins: move GCC version check for PowerPC to Kconfig Date: Fri, 13 Apr 2018 14:06:35 +0900 Message-Id: <1523595999-27433-27-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 For PowerPC, GCC 5.2 is the requirement for GCC plugins. Move the version check to Kconfig so that the GCC plugin menus will be hidden if an older compiler is in use. Signed-off-by: Masahiro Yamada Acked-by: Andrew Donnellan --- Changes in v3: - Move comment to Kconfig as well Changes in v2: None arch/powerpc/Kconfig | 2 +- scripts/Makefile.gcc-plugins | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) -- 2.7.4 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 73ce5dd..512fcc1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -195,7 +195,7 @@ config PPC select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER - select HAVE_GCC_PLUGINS + select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC select HAVE_GENERIC_GUP select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) select HAVE_IDE diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 0ce3802..1e92353 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -53,14 +53,6 @@ gcc-plugins-check: FORCE ifdef CONFIG_GCC_PLUGINS ifeq ($(PLUGINCC),) ifneq ($(GCC_PLUGINS_CFLAGS),) - # Various gccs between 4.5 and 5.1 have bugs on powerpc due to missing - # header files. gcc <= 4.6 doesn't work at all, gccs from 4.8 to 5.1 have - # issues with 64-bit targets. - ifeq ($(ARCH),powerpc) - ifeq ($(call cc-ifversion, -le, 0501, y), y) - @echo "Cannot use CONFIG_GCC_PLUGINS: plugin support on gcc <= 5.1 is buggy on powerpc, please upgrade to gcc 5.2 or newer" >&2 && exit 1 - endif - endif ifeq ($(call cc-ifversion, -ge, 0405, y), y) $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1 From patchwork Fri Apr 13 05:06:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133328 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp346695ljb; Thu, 12 Apr 2018 22:12:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+L4v1IGcyjzr1Ev6UwTW6xAOSkobAV4XDCjXXEdFkva7YIyayYrcqgEKRgndqoJ7w3ARRz X-Received: by 2002:a17:902:b40d:: with SMTP id x13-v6mr3768484plr.167.1523596332129; Thu, 12 Apr 2018 22:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596332; cv=none; d=google.com; s=arc-20160816; b=u8gR6qgpeWEPoKKxoPXonSRHTzNZJSkw/1MzRbbdZodbHUpRwIH84956cEIl5oCVl5 pHtfQ4MZhFHkYYRgHEzydxu+YRtVJpQ7jfwwC5ryS7sycF/z88Kspqck33FxFyR/kBGU gl0hS+EmZub7g+M+B//mklgdKGt0rqJKcyvhr3a995LemyvDh8G6Fh4n6YTqgjKAAAlZ yyRLOg+Zpanxoe2rughbKtxvZ+RjlYavdqm+2HAVSP3cpZiMg5a7748O1gktKX4b4EqT Cl0nxDTAPi2TgjQFa1P/jSNTvYx3/5zOqXXwSGKJppmbMsMl0PuCrEwNMnwSDeZSEXF4 +A6A== 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=mhnGoZgVdJChwug4AaG0gCRSaAvC02O2uUAXnqXFGH4=; b=zVbBCmqIxCRfQbfj26Qut8iMC2YVGbzL1Azd4mhKJ+eRc8vek8cMdEgWeCYPkJtAoc 46SgNVa6B6HL+Xv2TL75p1rv/mwm0uQ04vVlGf4oL+jsFgw0v67WzLcXqONrKo39Yldl yao2FMGCzU2H83SyPGqvsW9mJmGIk6+UhXh9JrT8/3ub4t4eksKhHlxoM8gfMj1VUlHl 6zcfZMuhTKDTw2m12GN/cb5nWxZ0SpsfQcGIARSfQtU55YaBiQQcpFhX0PGeE+5S+i5f JWwcDw5EhP07G5FJps6ZZEYnSXDh1DLGeScyHaYausECNUL7DJyJwscXK9mmMd1ejzbl GwaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=WQmtkhPU; 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 135si3889273pfc.21.2018.04.12.22.12.11; Thu, 12 Apr 2018 22:12:12 -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=WQmtkhPU; 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 S1753805AbeDMFMJ (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:09 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54534 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751087AbeDMFIR (ORCPT ); Fri, 13 Apr 2018 01:08:17 -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 w3D56lgL029209; Fri, 13 Apr 2018 14:07:12 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgL029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596032; bh=mhnGoZgVdJChwug4AaG0gCRSaAvC02O2uUAXnqXFGH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WQmtkhPUCQHur8JEg+UI2XeWj07xGWyxFgZhEBzN1sdPiDGKHqSHG6lOykyw9va6i 7qNLv9Sj4l2raMp/Vs/98TWAaJLayxoaU3Sd8Q6HxMCWS/5WaYsB/Z5tcXWXeC4pNt +2DLUdZ/bo7DgJJ9ljVPabTJNWgNEFtYdmtpe7AtAW6DS1uKSfFM6hoH9b2ixADAdR 0puveiRP5arKxjNNV3+sOLU/RiZo7cE2TMZoJIr54kAFNEc/Cb28WvVhXqH8L0dVeN fl0ToIzmcPygaEseRRBYeNGLY8MASrD8rAGUv+s6mKXWf1nhx307lIzHvOQaSNSdD7 Gr+/Hn1MN7XSA== 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 27/30] gcc-plugins: test plugin support in Kconfig and clean up Makefile Date: Fri, 13 Apr 2018 14:06:36 +0900 Message-Id: <1523595999-27433-28-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 Run scripts/gcc-plugin.sh from Kconfig so that users can enable GCC_PLUGINS only when the compiler supports building plugins. Kconfig defines a new symbol, PLUGIN_HOSTCC. This will contain the compiler (g++ or gcc) used for building plugins, or empty if the plugin can not be supported at all. This allows us to remove all ugly testing in Makefile.gcc-plugins. Signed-off-by: Masahiro Yamada --- Changes in v3: - Respin to keep scripts/gcc-plugin.sh as-is. Changes in v2: None arch/Kconfig | 10 ++++++ scripts/Kconfig.include | 3 ++ scripts/Makefile.gcc-plugins | 79 ++++++++++++-------------------------------- scripts/gcc-plugins/Makefile | 1 + 4 files changed, 36 insertions(+), 57 deletions(-) -- 2.7.4 diff --git a/arch/Kconfig b/arch/Kconfig index b0582f2..9166157 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -401,6 +401,15 @@ config SECCOMP_FILTER See Documentation/prctl/seccomp_filter.txt for details. +preferred-plugin-hostcc := $(shell [ $(gcc-version) -ge 40800 ] && echo $(HOSTCXX) || echo $(HOSTCC)) + +config PLUGIN_HOSTCC + string + default "$(shell $(srctree)/scripts/gcc-plugin.sh $(preferred-plugin-hostcc) $(HOSTCXX) $(CC))" + help + Host compiler used to build GCC plugins. This can be $(HOSTCXX), + $(HOSTCC), or a null string if GCC plugin is unsupported. + config HAVE_GCC_PLUGINS bool help @@ -410,6 +419,7 @@ config HAVE_GCC_PLUGINS menuconfig GCC_PLUGINS bool "GCC plugins" depends on HAVE_GCC_PLUGINS + depends on PLUGIN_HOSTCC != "" depends on !COMPILE_TEST help GCC plugins are loadable modules that provide extra features to the diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index cac7a81..0864a19 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -15,3 +15,6 @@ cc-option = $(success $(CC) -Werror $(1) -c -x c /dev/null -o /dev/null) # y if the given linker flag is supported, n otherwise ld-option = $(success $(LD) -v $(1)) + +# gcc version including patch level +gcc-version := $(shell $(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//') diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 1e92353..da5d38d 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -1,72 +1,37 @@ # SPDX-License-Identifier: GPL-2.0 -ifdef CONFIG_GCC_PLUGINS - __PLUGINCC := $(call cc-ifversion, -ge, 0408, $(HOSTCXX), $(HOSTCC)) - PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)") - - SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so - - gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so +gcc-plugin-$(CONFIG_GCC_PLUGIN_CYC_COMPLEXITY) += cyc_complexity_plugin.so - gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN - ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY +gcc-plugin-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += latent_entropy_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_LATENT_ENTROPY) += -DLATENT_ENTROPY_PLUGIN +ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable - endif - - ifdef CONFIG_GCC_PLUGIN_SANCOV - # It is needed because of the gcc-plugin.sh and gcc version checks. - gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so - - ifeq ($(PLUGINCC),) - $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) - endif - endif - - gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN +endif - gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN - gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode +gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so +gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += structleak_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE) += -fplugin-arg-structleak_plugin-verbose +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL) += -fplugin-arg-structleak_plugin-byref-all +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK) += -DSTRUCTLEAK_PLUGIN - GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) +gcc-plugin-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += randomize_layout_plugin.so +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT) += -DRANDSTRUCT_PLUGIN +gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_RANDSTRUCT_PERFORMANCE) += -fplugin-arg-randomize_layout_plugin-performance-mode - export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR - export SANCOV_PLUGIN DISABLE_LATENT_ENTROPY_PLUGIN +GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y)) - ifneq ($(PLUGINCC),) - # SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. - GCC_PLUGINS_CFLAGS := $(filter-out $(SANCOV_PLUGIN), $(GCC_PLUGINS_CFLAGS)) - endif +export GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR +export DISABLE_LATENT_ENTROPY_PLUGIN - KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) - GCC_PLUGIN := $(gcc-plugin-y) - GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) -endif +# SANCOV_PLUGIN can be only in CFLAGS_KCOV because avoid duplication. +GCC_PLUGINS_CFLAGS := $(filter-out %/sancov_plugin.so, $(GCC_PLUGINS_CFLAGS)) -# If plugins aren't supported, abort the build before hard-to-read compiler -# errors start getting spewed by the main build. -PHONY += gcc-plugins-check -gcc-plugins-check: FORCE -ifdef CONFIG_GCC_PLUGINS - ifeq ($(PLUGINCC),) - ifneq ($(GCC_PLUGINS_CFLAGS),) - ifeq ($(call cc-ifversion, -ge, 0405, y), y) - $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error "$(__PLUGINCC)" "$(HOSTCXX)" "$(CC)" || true - @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc installation does not support plugins, perhaps the necessary headers are missing?" >&2 && exit 1 - else - @echo "Cannot use CONFIG_GCC_PLUGINS: your gcc version does not support plugins, you should upgrade it to at least gcc 4.5" >&2 && exit 1 - endif - endif - endif -endif - @: +KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS) +GCC_PLUGIN := $(gcc-plugin-y) +GCC_PLUGIN_SUBDIR := $(gcc-plugin-subdir-y) # Actually do the build, if requested. PHONY += gcc-plugins -gcc-plugins: scripts_basic gcc-plugins-check +gcc-plugins: scripts_basic ifdef CONFIG_GCC_PLUGINS $(Q)$(MAKE) $(build)=scripts/gcc-plugins endif diff --git a/scripts/gcc-plugins/Makefile b/scripts/gcc-plugins/Makefile index e2ff425..c47198c 100644 --- a/scripts/gcc-plugins/Makefile +++ b/scripts/gcc-plugins/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 +PLUGINCC := $(CONFIG_PLUGIN_HOSTCC:"%"=%) GCC_PLUGINS_DIR := $(shell $(CC) -print-file-name=plugin) ifeq ($(PLUGINCC),$(HOSTCC)) From patchwork Fri Apr 13 05:06:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133317 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344888ljb; Thu, 12 Apr 2018 22:09:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx49qyPt1DX+CmI7mX1MoiJ8njEjdsF/RkN+g72bWeda6vG+MxIrKupd15kLEZg0XWehFUz7J X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr3857479pli.121.1523596162258; Thu, 12 Apr 2018 22:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596162; cv=none; d=google.com; s=arc-20160816; b=CyStO62dfVgTo7lrZmo0MuBG0Qe57UbmfXaN6VHv0tqUjkPJtNM3yCaXW80In+lgeC jlriNJ+/MBczz9IMtRFmxAs060ZaaOqgGu3S/3HxC4GdIYJkkHHMsQ5P+p5vSxlVg4mw qsr0W79ZysCgcmzd/vOtcS1f5M3gsmnkxHDSPBVw2eQhBKUZk8GlFYF0gQu18Hidu6Jt oe/mvXSBdlwSsR0jAO04Cjcx64ZanS6zMYBxGG6juvNWRmgU4TXz/GxaIY8wjY3JBjdj vjdRiuvXe7w5K/3eaXkCPPPXE/TPkjwc5anj/qI4xNU0YkGNMGgkuHEkAUf7TXfanXPV PZuQ== 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=40eD89Qr4HTIkp8rtOyarGmYd/X+MxgPXbcGP5lC9sA=; b=aFPYL5+EEtu2/3XfXgqsUcQfRWOr4lb4W5FJytG4wGCbEwRusIC8Y7gtf5Oi3EtI2k C9s9WMiqPastl3abl69QvYKdayfGRejvy0VlOZJgK3W6CKK6E4bQwwWvabaGzAkdZ7sZ 4AEo9JkHL9FJ4SuKJzrQX1fd7sMFXpOjR3CDLYWv4VCRPBT8CcRVFWyJNV4yNSOLizSB PVSokdkzeJ5MsdfIOu3FfVj4AZGL6WjpAQlNvQWiCCXKJArn4m0DOxPgPds2z8+Xo7XF oxSMNSKKLbNMsTt57kT9+0skwPlXZKUGXbjoE7rT5oNHygFwmirPxQLhkAEovARQuNl5 5qMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=yzdm+o7b; 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 r11-v6si4903304plo.278.2018.04.12.22.09.21; Thu, 12 Apr 2018 22:09:22 -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=yzdm+o7b; 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 S1753507AbeDMFJR (ORCPT + 29 others); Fri, 13 Apr 2018 01:09:17 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:55853 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbeDMFJA (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 w3D56lgM029209; Fri, 13 Apr 2018 14:07:13 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgM029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596033; bh=40eD89Qr4HTIkp8rtOyarGmYd/X+MxgPXbcGP5lC9sA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yzdm+o7bLu+hSc/QZHX19qlA5kqA7KShzI2LGI8h5sDNJ3I7O21fMVPhltYAWjAN7 PS9p23YrnQrnUcvNMyx+w+++c5V/h3IjAt30C0hWCZQviM4qT+aY6xU+Zc+WT6fYG5 B07YmGz+2MFkMnoyrU3XTkYyjCstFA2E3vXcBVyZH6IKTmIKNZ1Pop2gMv4eStICVu qAllrE1+rlEhey/JnN0zuXCCxY4ssUVW0stOSQuMEULfy+Mr8GUt6Xe9STvh3lNIBI WuBGWXiYCcTzGTHRuAVt6OIFj5NJXVjzQLi2hfLHYl8tmRziqkf9koIVxsKWh2xSMB mgF9g6NvSO6eA== 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 28/30] gcc-plugins: allow to enable GCC_PLUGINS for COMPILE_TEST Date: Fri, 13 Apr 2018 14:06:37 +0900 Message-Id: <1523595999-27433-29-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 Now that the compiler's plugin support is checked in Kconfig, all{yes,mod}config will not be bothered. Remove 'depends on !COMPILE_TEST' for GCC_PLUGINS. 'depends on !COMPILE_TEST' for the following three are still kept: GCC_PLUGIN_CYC_COMPLEXITY GCC_PLUGIN_STRUCTLEAK_VERBOSE GCC_PLUGIN_RANDSTRUCT_PERFORMANCE Kees said to do so because the first two are too noisy, and the last one would reduce the compile test coverage. I commented the reasons in arch/Kconfig. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None arch/Kconfig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/arch/Kconfig b/arch/Kconfig index 9166157..95b9b2e 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -420,7 +420,6 @@ menuconfig GCC_PLUGINS bool "GCC plugins" depends on HAVE_GCC_PLUGINS depends on PLUGIN_HOSTCC != "" - depends on !COMPILE_TEST help GCC plugins are loadable modules that provide extra features to the compiler. They are useful for runtime instrumentation and static analysis. @@ -430,7 +429,7 @@ menuconfig GCC_PLUGINS config GCC_PLUGIN_CYC_COMPLEXITY bool "Compute the cyclomatic complexity of a function" if EXPERT depends on GCC_PLUGINS - depends on !COMPILE_TEST + depends on !COMPILE_TEST # too noisy help The complexity M of a function's control flow graph is defined as: M = E - N + 2P @@ -493,7 +492,7 @@ config GCC_PLUGIN_STRUCTLEAK_BYREF_ALL config GCC_PLUGIN_STRUCTLEAK_VERBOSE bool "Report forcefully initialized variables" depends on GCC_PLUGIN_STRUCTLEAK - depends on !COMPILE_TEST + depends on !COMPILE_TEST # too noisy help This option will cause a warning to be printed each time the structleak plugin finds a variable it thinks needs to be @@ -533,7 +532,7 @@ config GCC_PLUGIN_RANDSTRUCT config GCC_PLUGIN_RANDSTRUCT_PERFORMANCE bool "Use cacheline-aware structure randomization" depends on GCC_PLUGIN_RANDSTRUCT - depends on !COMPILE_TEST + depends on !COMPILE_TEST # do not reduce test coverage help If you say Y here, the RANDSTRUCT randomization will make a best effort at restricting randomization to cacheline-sized From patchwork Fri Apr 13 05:06:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133319 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp345021ljb; Thu, 12 Apr 2018 22:09:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ARHM6bIr2is9SfOzVZgvbhPr4BJ1C5glbltnK8l5xnS5wHkTGKLSdU7wnLyW2sYTaW66J X-Received: by 10.99.190.8 with SMTP id l8mr2912244pgf.243.1523596173215; Thu, 12 Apr 2018 22:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596173; cv=none; d=google.com; s=arc-20160816; b=mK/V+KJaeHCfrhPy5gp/psGyUNQ3WQmIJ8UYK45rlUhnU8aFr4tZlDnVWgR5snePMZ hxh4K3OzbDfYA3Klen8fe8dLDFR9B0/vSu+qWD8q4PlPg5MT1K4YHU6dF4Y6r7pRsoUC uXeYLiKNCP6vrh8gJLh0Rb+U1vmYKZaAMh5D34V+hFlFkNUxPCQj/GQXITCMcrRFMk5p buEqiLaXJjv9qw3Av2Fr+jQ8EJCKYk8N6hD21lW/BB+M4Y0IFSrJaVzps0Bc2xjj63hw OQ8Z1YYprAZzHW8MyECjZC57BWqX20bxO3fNlASzPxnNmz+ReYuI69Ozs+MvrnmPGCSt GQZA== 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=7sJDH5Q944gs3+u0RysOMXljT/ETJe7meiTIO3uGZ/4=; b=YMg4zXwFdhuiuu9C1xmu3a3U/aeIhLyZax1Cyv1sft8YOesBAKHk8x7tBupwZk+QHC U4it0faWJn754bqUNYonFz3/EoQ4aGfQdZ0/Zd4qQS+F/rjJLK9k7H64/2bpvXh5LjXE rPCgf3pMH5D6SDDbqJ1Otp51+jB1zgqgMC37QpltTH0v54bWjzgDhpbZPIJHcmNKt9IQ ahrkmlSBV1fmOzTTcwfRaWc9S1d0cCvR/HsdLugzN0YM4W8huEazKHBocHn0F12WmfsJ MQ7UpQTNYxiRSnntogaHNDqV4I20oQ1W03XrTyKJsrxTRdyVmtwYKiDFIXZl9kHlpVzY 6fDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Kbztf5W0; 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 e6si3441833pfg.305.2018.04.12.22.09.32; Thu, 12 Apr 2018 22:09:33 -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=Kbztf5W0; 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 S1753644AbeDMFJ3 (ORCPT + 29 others); Fri, 13 Apr 2018 01:09:29 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:56645 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753510AbeDMFJ1 (ORCPT ); Fri, 13 Apr 2018 01:09:27 -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 w3D56lgN029209; Fri, 13 Apr 2018 14:07:14 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgN029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596034; bh=7sJDH5Q944gs3+u0RysOMXljT/ETJe7meiTIO3uGZ/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kbztf5W04YKFC2zjkHmUKyXYhMcAKG4t4DA/jl9hIguidwulN5lnklkSeufAEvh7X YIddo81DGrEEp5KjxqMVGFx6CUbN9tZTXv8PNr0ONbJkQKTXKlTqFcdI3beWmLg8t0 OkNu2O7xRwHvmpc8qoTFJsPRkg6XLilNUq2xR614BEAEEmH1YwyOsjNsOBAAFfeLBq dZQtlBY2cfQ+3bqDqHa9ASD0mBOoHUnAsNHvylAaQjur0WiD8UCOnABKrWjjxIWHy8 1eCEGWOOQJNf2wICIb36+aICA1aOPpm6NMd3CQnHaOVw261qpjPDQU5q90ctL9LCk/ 51AqJ+w3CG0Bg== 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 29/30] arm64: move GCC version check for ARCH_SUPPORTS_INT128 to Kconfig Date: Fri, 13 Apr 2018 14:06:38 +0900 Message-Id: <1523595999-27433-30-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 This becomes much neater in Kconfig. Signed-off-by: Masahiro Yamada Acked-by: Will Deacon Reviewed-by: Kees Cook --- Changes in v3: None Changes in v2: None arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) -- 2.7.4 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index eb2cf49..09d1aee 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -43,6 +43,7 @@ config ARM64 select ARCH_USE_QUEUED_RWLOCKS select ARCH_SUPPORTS_MEMORY_FAILURE select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_COMPAT_IPC_PARSE_VERSION select ARCH_WANT_FRAME_POINTERS diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 1540286..cefd1e9 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -56,8 +56,6 @@ KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128) - ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__AARCH64EB__ From patchwork Fri Apr 13 05:06:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133318 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp344996ljb; Thu, 12 Apr 2018 22:09:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/WcQTbmSDqT+zPsiN9AzXJPoXag5LzsDpqicOgbBGsnM5ypMLhL+Es2ajZec5kCj6z0i0U X-Received: by 10.101.88.11 with SMTP id g11mr2942153pgr.201.1523596170938; Thu, 12 Apr 2018 22:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596170; cv=none; d=google.com; s=arc-20160816; b=CvymFQeoh0FdepZo67h1IGbr5ervx1xOZpy/9gV0QQkBLqpfWv4kffq/fq+B+Ep6bV giFRcvpdC9doTdsZ+UaHr7RA0O1gYvxGtZhxtem4Czd1ZAHRZQs7cl8m5IEd5uKiR4ww hSvrQhcFjfHjw+zGogDss4am73BLaVzASr54lNFXeF9VXsfPMdXw95xgDbvAFYTODPoA 6dieMkasJhZ5uNVN5D1E7NESop0xfQ8SvAG6IrS9vQlyLb5Pcq657LsCGdKBma4QDb0H h9uvBmFnTGmfZ25A567twE/9vy1LgrMCuuGKho7R3MltmXQLIgDTChg3ppq+hNUa+pI1 ojvw== 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=4M6pCC9EPgYj0SwcHSwqfnESE7wdZuu3VHrr/fdPj9Y=; b=MMlvhP/IucQJVErDODpVxdbbOAQAWonTnzlEBwL9pFBWxoYGe7ddIpdoX2Nd03VWGT boSoHSN3kG1B4KLKnVjpBRAiARU5k9dofYQGIzZE3QuXynfg2SAF6vZQRCohNVfVN2qT Aa9pc8fH9peNucIxcAaeU9dw+oI7jpWLnqjxeYce6tZtu9XUUW0gmZPMC4cd4sP/nysn fbylua+ZPiFsPu/Ijj09As936SiVqXf3H+KnUqoWtuXrjGlq6FsMoZUQH5iERqKjf+YD voGD+r4UOFizs23tcxYNcDQcEnCDzXVUS3PGVpLGQBoHn9+ltP3YQ6z4IClapahhe+q6 PhKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=u8cP+SA4; 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 e6si3441833pfg.305.2018.04.12.22.09.30; Thu, 12 Apr 2018 22:09:30 -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=u8cP+SA4; 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 S1753588AbeDMFJ1 (ORCPT + 29 others); Fri, 13 Apr 2018 01:09:27 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:56558 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753296AbeDMFJY (ORCPT ); Fri, 13 Apr 2018 01:09:24 -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 w3D56lgO029209; Fri, 13 Apr 2018 14:07:14 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lgO029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596035; bh=4M6pCC9EPgYj0SwcHSwqfnESE7wdZuu3VHrr/fdPj9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8cP+SA4BEqnRMXp4k5kXgv5tiiE/2uB8iKGUCbmjo67ysFKyKJZ4niNCisd/ZyGC ZXqe3IFqhIRXUzRtMf6SUdo11nECoJDAbZ6Qw1LaN2nD4PYAqshiXix47MY9mtciUw j9zfOlFpFCYqJ66bSTWsmlzbjaQBdHfR0XESZhTCPJC0B66Op7X4em1eZg+SvFZIVH N9mX69dg8fNj/DKphAz9UdF2t28gG0XTREwPYw4AweKvtKpaDk8WjnFrF5MNTzgBtd N6mVsBDFeLVTSHp0vBeIHFxqslVoy1ymG0nHakit08FUKklXAJvFBHboof3QSP5nEs C/MZCd8ulmttA== 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 30/30] kbuild: test dead code/data elimination support in Kconfig Date: Fri, 13 Apr 2018 14:06:39 +0900 Message-Id: <1523595999-27433-31-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 This config option should be enabled only when both the compiler and the linker support necessary flags. Add proper dependencies to Kconfig. Unlike 'select', 'imply' is modest enough to observe those dependencies. I suggested this in the help message. Signed-off-by: Masahiro Yamada --- Changes in v3: None Changes in v2: None Makefile | 8 ++------ arch/Kconfig | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 88733b7..92db767 100644 --- a/Makefile +++ b/Makefile @@ -754,8 +754,8 @@ KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once) endif ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION -KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) -KBUILD_CFLAGS += $(call cc-option,-fdata-sections,) +KBUILD_CFLAGS += -ffunction-sections -fdata-sections +LDFLAGS_vmlinux += --gc-sections endif # arch Makefile may override CC so keep this after arch Makefile is included @@ -819,10 +819,6 @@ LDFLAGS_BUILD_ID := $(call ld-option, --build-id) KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) -ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION -LDFLAGS_vmlinux += $(call ld-option, --gc-sections,) -endif - ifeq ($(CONFIG_STRIP_ASM_SYMS),y) LDFLAGS_vmlinux += $(call ld-option, -X,) endif diff --git a/arch/Kconfig b/arch/Kconfig index 95b9b2e..e88f1ba 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -597,8 +597,10 @@ config CC_STACKPROTECTOR_STRONG config LD_DEAD_CODE_DATA_ELIMINATION bool + depends on $(cc-option -ffunction-sections -fdata-sections) + depends on $(ld-option --gc-sections) help - Select this if the architecture wants to do dead code and + Imply this if the architecture wants to do dead code and data elimination with the linker by compiling with -ffunction-sections -fdata-sections and linking with --gc-sections.