From patchwork Thu May 17 06:16:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136112 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1883717lji; Wed, 16 May 2018 23:26:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqCtnojH0IKuWSgoKScInQScdnCuJ4FZsU/+WFtMPBp6QcJ1uXIwn0cC16a1DVcKiQS04GZ X-Received: by 2002:a17:902:2c83:: with SMTP id n3-v6mr3907631plb.211.1526538412872; Wed, 16 May 2018 23:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538412; cv=none; d=google.com; s=arc-20160816; b=gMaUg22c3fIzlkBL3y6CAJ9tNCH3mHjlnyyie0Fuua1X447ite/vyFq3QMBo3MuOLd XBnoFO99Sm3yW2nlLt2JJ/T/H00t6H4E9VTYR/BjH22LLPpebThUYXtr4fSEfMAoo6HJ QwRa11n3y54i+M4npvu2XddpE5HAUb6uvgjcd5M+zK/eH0QJXwsJvazGqpT1rFyU1KwL dUGEFrCq7EImK+X6Ty4dC9LgZ+UT3BkpyHwHSsgXWsgKlx7tAcIoc3+WCNGMkcEtbuw5 PYt31gCmz3N853NWnnn1n7Y4MjcqVs/FBx6T2BWuRcoCX3Fz4fQuclqrw+zm4UPSJcFi XiMw== 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=7Ua2Z40VZ7a3Ao5qUbAsjZkvTXfqnUUJQpG8OomRlu8=; b=o71op5d4k7sd7fU3zTYRCpwX2uOFEav6InGjPgWrMgJzQJrNbg8UIHN7/Oh79ju2DB K65Gfbz/71C6du9r7+F7x1M6Cn9wr4hAJ/Zhmk4LxHxcO3af9NrQwnosUWNys/lJZlhN UoeakbibX+LYYvnDdUqfm3sViWFuTSOvaQPWjK5x5MqCrnmnQz1jUHuciyo4vTBDDWlF Kw/8pNafRMkA030HMXT4O4CjGliY0mfUFNQA67cqTWl1G68kxmOWFxRJ7mBM1mtS1oNu BtluZe0iDdmZ4GYdg1F667Tg3yQiZyscp7WJe3BUff6OoKuD0V49oCW3gAylrHT9Vs/o IFCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=c5WPI5pj; 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 s88-v6si4511404pfe.290.2018.05.16.23.26.52; Wed, 16 May 2018 23:26:52 -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=c5WPI5pj; 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 S1751844AbeEQGSz (ORCPT + 29 others); Thu, 17 May 2018 02:18:55 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24134 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750825AbeEQGSu (ORCPT ); Thu, 17 May 2018 02:18:50 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbTx002841; Thu, 17 May 2018 15:17:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbTx002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537859; bh=7Ua2Z40VZ7a3Ao5qUbAsjZkvTXfqnUUJQpG8OomRlu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c5WPI5pjDcUpffRgoSJU7hq2dKB3InTlwFAU+0khpNn1WwNKVz5bQwTN1I4G/Eg4f pWaDgrkcQ4qkfOH78Fpvh8bwsv1GAo7uyMeFTnGOJE9vyJcssN6XgaIW0UrpIdgoeO Tx6FVxB3Vfpdnay5SYI8AOs4EkqDMH74XkCN1DIZuNu4AoLs96HEnPDXejCk9e5CDV H/6mr0KjG4lITcnPHTK13EJXhtq0Y7PdcAGP19XYJOOAyN2J+KGbivoRk769WOdi56 a/TjuVT78t5orRna9SmTphdlwIptvAomv1XGqeoTOrrVBC08xiKOepIiN2iVty11xl +bOnvDTJgWotQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 01/31] kbuild: remove kbuild cache Date: Thu, 17 May 2018 15:16:40 +0900 Message-Id: <1526537830-22606-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 ba3106b..e78f73f 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 @@ -1622,7 +1622,6 @@ clean: $(clean-dirs) -o -name '*.asn1.[ch]' \ -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 50cee53..925a851 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 := ( pound := \# ### @@ -83,71 +81,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))/) @@ -155,36 +88,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. @@ -204,23 +131,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 @@ -233,21 +160,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 Thu May 17 06:16:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136086 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877081lji; Wed, 16 May 2018 23:18:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrYyKSwc2dNSnq9JskunZCsSj84Ghuh9Ud91/MPK2UdRC5NhP10FKwS3xV8AVcVQ0X/akWv X-Received: by 2002:a63:41c4:: with SMTP id o187-v6mr3042862pga.7.1526537936048; Wed, 16 May 2018 23:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537936; cv=none; d=google.com; s=arc-20160816; b=vYFSizlHusmuTW30FA5QK794k0FpfDEtw3wEl2bkVWIOa2nZNQWqjwMUY9SQ7Q6ThJ /wNEQBk5XvvNiWBdDvDB1G55N1NkVzUJTrzu3fParENRQPL1hng1ss+DV6AbGYFIiOde znuos1zPcyFUP6G/GV7IzAZ3kqGfCAsxAOcl6tXjZgfIjlZk0FPkku6peE9U9lou2NrL k6VOWpifTSswnXQYT30jRYksiCdFom6YjBLX9lZ6GR/2K598ut75DFOK+sXUxbsjLIbv 05JcTZOt0XBPTNmzyCSvNfHSuJPm0z5lQZxBWgD7ieuybKXOrei062flo+6p/tBr21EX NV2A== 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=aSQS3FUJ5e9EiNCD8cynkA8thqQ6GIhoa7wXOMABLyU=; b=sQy7izNblKoIRvBDyBnhT+vr6GDi9y1ZaMrXFCX9RGSI4FEclOplnsCPmHZQJNorbq 9t4VLVUOx8t6iqCnYRupf4vuf4Q+87w6ZjKJB3W4z3FtRYUJ3mRPbeGa1Qx17B3SHsKP 6J6yqssYzFDf3kSOs4ZlgzcM0j4gW9YCV6FAYi/6EF2BW+UZEQ4U/hxYQQQTKIQMAvWb 9kCJxfLV24OUhBYwlPrNjqO1sTj534VgVXx2QdHRpZ+p/B3U2LZIoopHIJDJ9QI+hhAl QInoo7OFrbCqvg6ECpBETZ9idc7ABuG6vbW4cVc8Lfg/2cjqiBBBqxPCmVLM/PDIc+D0 Y6YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=sq5USuqo; 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 l63-v6si4243754plb.49.2018.05.16.23.18.55; Wed, 16 May 2018 23:18:56 -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=sq5USuqo; 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 S1751664AbeEQGSx (ORCPT + 29 others); Thu, 17 May 2018 02:18:53 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24132 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750815AbeEQGSu (ORCPT ); Thu, 17 May 2018 02:18:50 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU0002841; Thu, 17 May 2018 15:17:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU0002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537860; bh=aSQS3FUJ5e9EiNCD8cynkA8thqQ6GIhoa7wXOMABLyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sq5USuqomOD497a1nNm2pZIPl3t1VK1mHZUTJT8GoaZz6ctG2PAAsTXrMLMW3vN57 3IvX1w5fYhTal9suKCG4Y6MKZhjCOLrnj3131/aqNqoclTDg8DTtr/56XYc2bQ213U xljVFR9z1Awrkcy8PSGU0JtDHYJQcEgyMsmPRW3JvPvhvN8daC1FKd/pZDjPL2FPKW VTt5BtAMuDyTyTALSlsmKczLCQNUvRhYb3f7QwqDDFnxBO00BCVdL4ag1yy9dkXh55 NC7Q963oH8j76A3I1YFnlmeZRXptOqbfY35OXLLawLXgg1HgdUCxXFlVXmXri8NVTV cwdQGPyh+z7dw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 02/31] kbuild: remove CONFIG_CROSS_COMPILE support Date: Thu, 17 May 2018 15:16:41 +0900 Message-Id: <1526537830-22606-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 e78f73f..01b2211 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 f013afc..4537962 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 Thu May 17 06:16:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136111 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1883108lji; Wed, 16 May 2018 23:26:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrDXd2I9qf5vBqYxGAX+RoCXghxx+/y8XY/DSArFH+DWj6qeWB0OM89O5Sweifid6gNhvbe X-Received: by 2002:a62:6642:: with SMTP id a63-v6mr3990571pfc.162.1526538368677; Wed, 16 May 2018 23:26:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538368; cv=none; d=google.com; s=arc-20160816; b=SWOzwVhfDDVP+4JQFJ4bMnZMC6rlGeiQq3zrKxNVBw2Bt8LSx3qtI9kKnmBMLn4QMj w/GiQf6SaGA7EQfNZJA3EuD4+6PlYcLXOmQ02JPaNHTXw4l0WjrfiLMiQ9ZCpqmJhDCv qUTtik2SAXea7NMYn2fNClnPuSQNHe52pS2J1RXEcIxu52spMwQ5cv94fuiHnoJPWxQE 4r/i40+nILGZ3CKQS/U7GjdHKkQQQJ13J29iGBI7G/4eJmoalkrDUjsTcpSJawrt5nDv xrcYRenkuDRRRXHZM+M0DmaMixCXphbbZf7yzF6dMcvfEXFZq7vQZvhBovHwi9ny5jak zSCg== 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=7ACp8+hpT37EmggHMoxsN3yq7iJL4c9XGttPy8aXWfA=; b=FqEfrJckz6YZr5NuK17zo8XR3J7mSkid0oUA8OJBIrDuLRaNxv7tx2LC5yQjudIiQL UOP5n2xZymxIdpnlxgk79cfN9LCEc60uR5SUU9LUVIIwQtj7o9s7hAGFYK460pCZjDtc 6CEAYl9ruJxFo5+dVZT2OYvLgPTePiZc0QjxmsHt9x4N+UbwZMVHrk30FuVd6rIO8PdX pXrXy5JIsxDE2q2iyq/W48i/Zml6rj61hoPorja+JvkUel8p6GBMwiQbnfrscjuL2yHP hTkLvC2meOQ/xB5MAvtfIoDjlfKKbDpgWttQFrKXbmNPbczWBXQJHHCgedNYCD8daR7P kuqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=cCtEY8kI; 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 w68-v6si4611690pfb.325.2018.05.16.23.26.08; Wed, 16 May 2018 23:26: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=cCtEY8kI; 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 S1752059AbeEQGTH (ORCPT + 29 others); Thu, 17 May 2018 02:19:07 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24372 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751858AbeEQGS4 (ORCPT ); Thu, 17 May 2018 02:18:56 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU1002841; Thu, 17 May 2018 15:17:41 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU1002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537862; bh=7ACp8+hpT37EmggHMoxsN3yq7iJL4c9XGttPy8aXWfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCtEY8kInBtqn08XZY68esCyVFIJgHkTUXVe6pUw9cHFhhN9I8vfvvGp7YiWblk02 CK+NnVA/nKzYGJCv5M75DDNtRkE0KpW5+VknM+bzLQrL8oySvGZENiBnjlV2pcafEr x1ZdrP86DyAXWFDl+tET4ivzDWrR3cmpeZvZUqXyNqKhILBXtl35hLvjBfp0r+HsxW N2R2jOeDkELx9WBSKe5E0K08VCH5Pu24ov2iyvPHQ8p+/4fW/BJmUxxcCEKhQzOIdg G5o7Q4DBOy07jXyfIAxwoBLKFh2l7XlIAis4RF+2QRhRvkVJCUr2ScOA7zB6SFzrml OA0/bKMBWKpYA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 03/31] kconfig: reference environment variables directly and remove 'option env=' Date: Thu, 17 May 2018 15:16:42 +0900 Message-Id: <1526537830-22606-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 inconsistent. 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 v4: - Enclose ARCH in conf_defname - Drop single-letter support 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 | 33 +--- 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 | 247 ++++++++++++++++++++++++++++++ scripts/kconfig/symbol.c | 56 ------- scripts/kconfig/util.c | 18 +-- scripts/kconfig/zconf.l | 67 +++++++- scripts/kconfig/zconf.y | 2 +- 19 files changed, 340 insertions(+), 154 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 01b2211..c6278e6 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 1851eae..c8400e3 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -58,7 +58,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 @@ -77,7 +77,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 c07f492..2236505 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 4537962..752816b 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..f72587c 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -30,7 +30,7 @@ static void conf_message(const char *fmt, ...) static const char *conf_filename; static int conf_lineno, conf_warnings; -const char conf_defname[] = "arch/$ARCH/defconfig"; +const char conf_defname[] = "arch/$(ARCH)/defconfig"; static void conf_warning(const char *fmt, ...) { @@ -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..1bf506c --- /dev/null +++ b/scripts/kconfig/preprocess.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 Masahiro Yamada + +#include +#include +#include +#include + +#include "list.h" + +static void __attribute__((noreturn)) pperror(const char *format, ...) +{ + va_list ap; + + fprintf(stderr, "%s:%d: ", current_file->name, yylineno); + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); + fprintf(stderr, "\n"); + + exit(1); +} + +/* + * 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) + */ +char *expand_dollar(const char **str) +{ + const char *p = *str; + const char *q; + char *tmp, *out; + int nest = 0; + + /* '$$' represents an escaped '$' */ + if (*p == '$') { + *str = p + 1; + return xstrdup("$"); + } + + /* + * Kconfig does not support single-letter variable as in $A + * or curly braces as in ${CC}. + */ + if (*p != '(') + pperror("syntax error: '$' not followed by '('", p); + + p++; + q = p; + while (*q) { + if (*q == '(') { + nest++; + } else if (*q == ')') { + if (nest-- == 0) + break; + } + q++; + } + + if (!*q) + pperror("unterminated reference to '%s': missing ')'", p); + + 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; +} + +/* + * 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 Thu May 17 06:16:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136117 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1884985lji; Wed, 16 May 2018 23:28:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoH2asnHCq17lNwyMlJhkcl+GqOAVQJ0NKuLstn/9jIIHNpDEQFCzEcE5sqVHymD4JSN7CN X-Received: by 2002:a65:46c1:: with SMTP id n1-v6mr3205338pgr.62.1526538509967; Wed, 16 May 2018 23:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538509; cv=none; d=google.com; s=arc-20160816; b=sk2m3PEhAGMqsR2WP8E+KJRlAf7BN8SsI1SKrMqLJCjVpIIrKkL65E4eVmkvOWwAWe U+LcQndM8lOxykOe9XDYSwVwXYUQN0m4E0AaApk33hMs1Lj5zNcNNyBiCWn6O65zKolB 0dmA2xFrSjtmw4juxPtrboBINvpc7Kv9ARU0g1wxSa8uZp8w3n+wZyNuofWFj603KVFB K9NsH2YYroRiRKXha2yt2e/F8Ddy1IDFRfG7fDzRQM2Isv3j7bATUEajP8AnfQybhmBp 5/DSa9Ctdkme1p/Bqy53h0DFbQTBUtBzMu81sFAJH2apHA27PxMpj4D6jwmFrOn2xGYa SOCA== 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=W1m5Kr1L3BQFUW2WdW84BiwWbl8nKG77TmQ2wdZLdqs=; b=alOagBIeJDV0tLbs8oyHMUBe0Xxw3HAGhJz7mBGCqkEqsE+jr2xZLmya9W32Nd2Edw hbaB5NRaTbFuGThjSvFd5L88AAk3m8DYogSmVNPfXU6xqaLASfNiy2AfWNuh0WRCi6cR pJRuo29o+H5v+ucwpOE4hy45vB9/IYax52d/hRpjrxsrmFI370EkzWnyA70crXDVVnKj 68WKZiVF+h0wXC92lOHIlYV6EZk3+tdoi+ZttA9J3KXe5A9hwayJUzKjDQm9dmM6ABcn jAtZ6XQNgdZJfNwNPlFBkVdTUlMzPnf4SWv6EplM/83ymAKQsgjlflKUQeKOSGx1GWyQ N9Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=OUBS9ew3; 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 n127-v6si3444768pga.523.2018.05.16.23.28.29; Wed, 16 May 2018 23:28:29 -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=OUBS9ew3; 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 S1751984AbeEQG2Z (ORCPT + 29 others); Thu, 17 May 2018 02:28:25 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24167 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbeEQGSv (ORCPT ); Thu, 17 May 2018 02:18:51 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU2002841; Thu, 17 May 2018 15:17:42 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU2002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537863; bh=W1m5Kr1L3BQFUW2WdW84BiwWbl8nKG77TmQ2wdZLdqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OUBS9ew3DqPQDA5bOeDUmGMpvlP6M3HucOkG66bD1T95/CTVMJYT50GsVGleijMgs 7rF/ZH7FW8wOsesEtTrOyMkpZJA+BflZcZcgMjEWT1AZdSR9gvxr82hUVI2yqrDeYE wJKeEjijF+EohvxQYCN579B7WaWs10BbKisQMRfDsoumNgaBjbG2frtMqqPivxXxuZ SEFI5x9iUE4AMTE7coBb9xDjl1K8rcdaLu6uiYJgrjzQbQ6o7pzJftJf3M7Rw+UcyS G9Ow2pGWpWZqyQ2aPZVL6zN/43yowPQWTsS0hrwmIOdcaJmIPusb2ZJYxTwTwdTDR2 FWRsPYrkrVRdg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 04/31] kconfig: remove string expansion in file_lookup() Date: Thu, 17 May 2018 15:16:43 +0900 Message-Id: <1526537830-22606-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Thu May 17 06:16:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136088 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877318lji; Wed, 16 May 2018 23:19:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpAbkEdwQFlFVt4HJ4/XCHSvmLyn85fkynRKqvWma4IqJqF+Hgj/rPQURkHNKT6nCOeGgNN X-Received: by 2002:a17:902:8a8c:: with SMTP id p12-v6mr3883106plo.94.1526537953150; Wed, 16 May 2018 23:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537953; cv=none; d=google.com; s=arc-20160816; b=FGsqS1KeqaPeE0e/d66h5ZPs/9QtKmP/zl0tCX4sY7W9f6mstTD5xPa3wSviYC6i1p bwxwAOMr3PQ1txoQVaFAGgP0O+iod/EoNs2mlJqcS5Bv4/srEc8IBebI4ilUXuoXNNJl N+TKFWSs70ofscjuw/gxEitJXyxsEAMMh2P66GNxL8jRtlc09lXbQ3ZO/4w4Fyo6u6bY kRspZN/WONnCKixfncUo/ClVu1FDAtbjNFvAJqPTNavSS9vGSVhGyXS1nqQ/biyQZZOG ngfmaeNljUIDRyug0lsat2r++IVjTncW+EKCR8Imlu3uuCDMlxOAmGOOhc23lrY/VXXc J1Kw== 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=I+o8yLfAxCl7jvK1vvUhdCXw/bHSIBQ/d1Sk8reh1yA=; b=gIPOiXPjrk8tatI4KarMDLXC0wAwNnyJwtMgENNFaxm5LlIxigWMvdRW6EV7f7YBSR W72i2hrwwZ/++Lwx7NgoX+vC8C3cctbg/V9m5VrPEUjo50AGNyMZ64xcnl4d2C+kgx50 Zp12IEi6PzAle3RXEu6PI7dPM0vmwcOHDsVW1JoHCdF6Ycz2GHfEzwcSWXGSv/KAaKtZ fyZlS5U41HAHTVc2LL1bv5tS04mQHU8FURIZlMZgzxMTJwMcvvh9OjsQhFI1IdS59y+k gcwQiScNkPu6I77LS3XPAjpNGe81qgd65vB9FyQ6241/ZPk3HwhykaDZ8PO8KWYPDuk5 G5qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=DDv9Sh22; 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 f28-v6si4952932plj.255.2018.05.16.23.19.12; Wed, 16 May 2018 23:19: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=DDv9Sh22; 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 S1752141AbeEQGTK (ORCPT + 29 others); Thu, 17 May 2018 02:19:10 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24362 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750825AbeEQGS4 (ORCPT ); Thu, 17 May 2018 02:18:56 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU3002841; Thu, 17 May 2018 15:17:43 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU3002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537863; bh=I+o8yLfAxCl7jvK1vvUhdCXw/bHSIBQ/d1Sk8reh1yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DDv9Sh22vlARVGc8MP3HF8ozBpVH8/3vduR9Ri/fkF/VtkcV+hpG/ztQ1vUQ0jNTx Z115Ojg2g2DJOUInt2kU2o4pD6uwLRZhyQfAB/fpGgDw2AKjgcmEaZ59l3paOMAxEq /C6eLKTGODkrY91+srwkh7WXcpQa9rOBePioEHrBUe5csa2zY8SybAJgftQB/iRbZh ea8jRVehOXJriMJW9nhH3LUSborPMPqnzA61aRY1ysDE9zkBZCWvBy6whhzFmTUFHV 2jyu6sHORG2Br+gMHrDA+s/WTVSoknnmPI81k6glbdWZiMytoNe34xsjUwkOR6sK+k xLCiKR9k9Q0/w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 05/31] kconfig: remove string expansion for mainmenu after yyparse() Date: Thu, 17 May 2018 15:16:44 +0900 Message-Id: <1526537830-22606-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Thu May 17 06:16:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136116 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1884937lji; Wed, 16 May 2018 23:28:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp6I6+UjMxFXNhpZLE6LdEhTvxwrgtUw9hTGjhn32ok2xERYbhDC1pMUEN5XUjlrOem8mPn X-Received: by 2002:a17:902:9a4c:: with SMTP id x12-v6mr3901258plv.213.1526538506886; Wed, 16 May 2018 23:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538506; cv=none; d=google.com; s=arc-20160816; b=N38QX6J1RTp0Ii9iLo1Vq87Oq4lU5ujIy7+CRgYOfdCU+U7jzfDanShPryTTIoaBoP WhWEKCnyQTpNYPBbxXrDU6SjRPXrHv6aM/RVrrM1MMeaKSk5vrxgA2RhW519pcv76A4O vdB9NW0SNx+G2WyDhDTzv+ycR2gXbap8YHzQKl3jr5wBtpo9UCVdiI0+zeTGjisCeeDz v4wh84DvXelLv81h9GOxBAXFGvpDVWXPdVpMa++k/8OUZw2cvxas/CaDd0u0ODyjTsqA 4/TYt1Y9eMoFsrxogkAxKTMbvG049QC6JcmqFhvXd8t0nuTi4KgptCxmoamSi4auBb5F pyxw== 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=zsrI7avFRHVJOVAyOUShxZMujly4akMfTew9t6oN0lQ=; b=U0PBR6oZwx8LM5+WoLFD/lywDf1AOnRSMLNxKd2B5fR0cDLpYKYJjZbBNmsRkyD49c DvmLwo8YDPhu5ttEmw6lwo3gxap164cQOCWU10x017d80F2KtO15F1afgk5lwpMViBrv 1KRfhcWE716Re0GaW6Hb0i7jKhqk26RAY3aqmJV8GTvPqPKPPjcsgvwn1lMlUyz+1wqQ dMcHseQ6++Gs3b2oRGgyXrMwoGh2+kO9/FXpUIjaXnD0lzsOMuYaGdDimQYDe40DZXHw VecWY92yY8Hd9sFPmAzpFNQoe15gJKDMpZiia4cpAtcet4q89FAScBRrWb/ypGcmywPN wo4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=vRy7qFvu; 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 o5-v6si3369458pgn.134.2018.05.16.23.28.26; Wed, 16 May 2018 23:28: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=vRy7qFvu; 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 S1752587AbeEQG2X (ORCPT + 29 others); Thu, 17 May 2018 02:28:23 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24197 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbeEQGSv (ORCPT ); Thu, 17 May 2018 02:18:51 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU4002841; Thu, 17 May 2018 15:17:44 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU4002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537864; bh=zsrI7avFRHVJOVAyOUShxZMujly4akMfTew9t6oN0lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vRy7qFvuBLTFVJM4yeeZgJO9XncWhYOOhmWcQpIzKEeM+0HlMIJ0SEUnCI+ksyLrf tyc9WmVuxB2M+8qUE6z9MjVuSkTQexf7EocaLQzWEpn0t0LOLWf5I+nd6wWs6DtAUf bO2u9FXdDCwfs2rfj7o6a6lcyhlUQbXC3BlpQJia2y5Xv4f4oFTDSD2ty5XfDGie1X JQLqsn7SHGcN53wCLVuTkIQLLTF75BSqXzlVNhh5hMgsFiFdK+EdLGqxHOOThTc13m saXFoVgMyAGm8jlMLOaeicpLR2envUoPATvkKFdz4jIWh0aYFGM/EAXiPnaLMqIB81 y6pmSGjWuBxuw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 06/31] kconfig: remove sym_expand_string_value() Date: Thu, 17 May 2018 15:16:45 +0900 Message-Id: <1526537830-22606-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Reviewed-by: Kees Cook 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 Thu May 17 06:16:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136113 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1884041lji; Wed, 16 May 2018 23:27:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo5QD7wwVDCMYS8Udp219M7XxA018fdbNMePbpybAbFzN94EaxgNtjWQGpD5KosLn9W0dts X-Received: by 2002:a17:902:be0e:: with SMTP id r14-v6mr4002717pls.158.1526538439160; Wed, 16 May 2018 23:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538439; cv=none; d=google.com; s=arc-20160816; b=n8tfwRoNunSwnNEPmdR1Nkh5rglYv5E2+Ci8Il/gjwE1+G3UeUoJls9EJfrbhaqIqA 3YyJEMfTqo8m5mraPKTZqMKDE57Nu20BE+7vjTiNHmC8QYFU4YP0IyyJ4g5dJMjL1QMz rjp76tuleeZmDnyQJ3OCc+zJFeySpmavJeX3DqdS9/JaIYEvzWPyMnkn5gEkORTgh6dH ZD/x73L+YDhlJbMMGLiqkhOFOlVjemow4xIYxHz6VDOwdgO0I0ZFd/Y0/lNGTU9Gud+s pK7MWUdU+3BMZBEGl7UeC3l7Yq4rX3/Pmr/1L3KWojw+35xf8i7I4ngQNNx5dngfBPPh LlsA== 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=m5uJPkqVvXahe6M39G+cOl2E2fdMoEDinmtwuR3Z3M8=; b=jSI7vFHaXY6674MTD24p25onZ/eFZWzJa6KbGZ4fJPdIrbu9L2ZDYg6X6NDpL9jx8r 3Tr4m4BdEXkigs7bAl8aABZdGLJ9ks1l/murCGfzfdkmq9Yqub7uP9q41Tc/D2JaoBWl 4YkcMciewZ+MVFJw2V05L4RBBTHD/qTyd3ba32g5xxwyohg/3Axb8B2fYudt9ZhYHjVv 3mOOr92j+qVUgxnzx3GJMmLKYqKcdMDGNskFDYec9MhL3h+VElmPZ6YeHy9UGPPeOsrI kgiKHdC3yJYsH5eB5/KEqmrIWS/1n6V1+Oe7oJWNVpHuyAvRCeKduf3AV45Yh7V8WIYw 9ZlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=XtsoCMS/; 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 b5-v6si4012328pli.129.2018.05.16.23.27.18; Wed, 16 May 2018 23:27:19 -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=XtsoCMS/; 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 S1752495AbeEQG1O (ORCPT + 29 others); Thu, 17 May 2018 02:27:14 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24208 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751155AbeEQGSv (ORCPT ); Thu, 17 May 2018 02:18:51 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU5002841; Thu, 17 May 2018 15:17:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU5002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537865; bh=m5uJPkqVvXahe6M39G+cOl2E2fdMoEDinmtwuR3Z3M8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XtsoCMS/f9DpL94DPt3v8LMZ8iA91XJk6dUt1kVJ3eJAmC5uU5AlyPH0FEzbTTc+u wTqD/u1ZYL2K2Da8uboO2MW9lWpvJqsDPWp6XEFSurdOaZTqTfuvUU4roCZIRyppGm +FPN05mbefe8km424gPB7QvJs+owlRpOiwdyM4jCNJ4+lRYFeIxiKUusBpXxT/s++d i3R8PEY8y9/saMjSsPM8PY9upnSrhUh3GWHA7V2Yq3D4lwyfR8OiOAVQonBdpSY6YP SmGDPR8SqN2VUXaIOI3Y67Ys/jnIuJk9S7TvQRNGosksrk7CqWV/eXst1Sbl1otZvG O+HYgdAkf0kbg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 07/31] kconfig: add built-in function support Date: Thu, 17 May 2018 15:16:46 +0900 Message-Id: <1526537830-22606-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - Error out if arguments more than FUNCTION_MAX_ARGS are passed - Use a comma as a delimiter between the function name and the first argument - Check the number of arguments accepted by each function - Support delayed expansion of arguments. This will be needed to implement 'if' function 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. - Simplify the implementation since the expansion has been moved to lexer. scripts/kconfig/preprocess.c | 168 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 159 insertions(+), 9 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 1bf506c..5be28ec 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -3,12 +3,17 @@ // Copyright (C) 2018 Masahiro Yamada #include +#include #include #include #include #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[]); + static void __attribute__((noreturn)) pperror(const char *format, ...) { va_list ap; @@ -88,9 +93,85 @@ void env_write_dep(FILE *f, const char *autoconfig_name) } } -static char *eval_clause(const char *in) +/* + * Built-in functions + */ +struct function { + const char *name; + unsigned int min_args; + unsigned int max_args; + bool expand_args; + char *(*func)(int argc, char *argv[], int old_argc, char *old_argv[]); +}; + +static const struct function function_table[] = { + /* Name MIN MAX EXP? Function */ +}; + +#define FUNCTION_MAX_ARGS 16 + +static char *function_expand_arg_and_call(char *(*func)(int argc, char *argv[], + int old_argc, + char *old_argv[]), + int argc, char *argv[], + int old_argc, char *old_argv[]) +{ + char *expanded_argv[FUNCTION_MAX_ARGS], *res; + int i; + + for (i = 0; i < argc; i++) + expanded_argv[i] = expand_string_with_args(argv[i], + old_argc, old_argv); + + res = func(argc, expanded_argv, 0, NULL); + + for (i = 0; i < argc; i++) + free(expanded_argv[i]); + + return res; +} + +static char *function_call(const char *name, int argc, char *argv[], + int old_argc, char *old_argv[]) +{ + const struct function *f; + int i; + + for (i = 0; i < ARRAY_SIZE(function_table); i++) { + f = &function_table[i]; + if (strcmp(f->name, name)) + continue; + + if (argc < f->min_args) + pperror("too few function arguments passed to '%s'", + name); + + if (argc > f->max_args) + pperror("too many function arguments passed to '%s'", + name); + + if (f->expand_args) + return function_expand_arg_and_call(f->func, argc, argv, + old_argc, old_argv); + return f->func(argc, argv, old_argc, old_argv); + } + + return NULL; +} + +/* + * 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 *res, *name; + char *tmp, *prev, *p, *res, *name; + int new_argc = 0; + char *new_argv[FUNCTION_MAX_ARGS]; + int nest = 0; + int i; /* * Returns an empty string because '$()' should be evaluated @@ -99,10 +180,69 @@ static char *eval_clause(const char *in) if (!*in) return xstrdup(""); - name = expand_string(in); + tmp = xstrdup(in); + + prev = p = tmp; + + /* + * Split into tokens + * The function name and 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 == ',') { + *p = 0; + if (new_argc >= FUNCTION_MAX_ARGS) + pperror("too many function arguments"); + new_argv[new_argc++] = prev; + prev = p + 1; + } else if (*p == '(') { + nest++; + } else if (*p == ')') { + nest--; + } + + p++; + } + new_argv[new_argc++] = prev; - res = env_expand(name); + /* + * 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] = new_argv[i + 1]; + + /* Look for built-in functions */ + res = function_call(name, new_argc, new_argv, argc, 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); + free(tmp); return res; } @@ -119,7 +259,7 @@ static char *eval_clause(const char *in) * will be * $(BAR) */ -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; @@ -158,18 +298,18 @@ 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; } /* - * 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; @@ -181,7 +321,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); @@ -196,6 +336,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 Thu May 17 06:16:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136115 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1884922lji; Wed, 16 May 2018 23:28:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoDP6NVLPC+0lqO4BEicY7HRXhS4wVZVOnOd52hxYRG9p30C4JUvmaw/5ajEqwCijiQSzUX X-Received: by 2002:a62:4544:: with SMTP id s65-v6mr4034374pfa.150.1526538506105; Wed, 16 May 2018 23:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538506; cv=none; d=google.com; s=arc-20160816; b=RKtjuBe5EAw7Nm0u9pUZ6s3C13E/qRRgfdJl2c+2BXzu/V4MLd+1VcdJe/gSGAVzCR HFyp/yfWMw4KdMRKkHM2+VAwPc96un0Mq0WuF8MjS1cm0Nx62/2kaOPB+QGXennGb4eq qEhd4FHcNFB6gDd/Z/CVCA17P13LxqwvJ748W2YOSHL0TbqHhqU4W/49ozG3IRGY+NXU Es7m4RxCIa3gjKRvDmx2MF5sjiz4GjmMZfMze0F6pV7gw3ovfp9hRZNxr9dPU2uUFWMO vhkTikh5pAKHI1K7Jwm2150LEJgRgo3HAj4n7bd0rpGaxgdf71S0fNiKYgeHuafBAoRf tBfQ== 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=QV2ke3u7Gh2sqXLcu7CAM0IRxu2ux/+jy1skkNhYDBo=; b=owrhz7E3q8LZbwFOkVUof6mMovhwSnJ4kRYjXwdpc+81YHgOOB2sKTIlUyhZ+zHcY5 alNg5oQM8NXmyDUFe2kFpKhgfuHQSX9YnY6sNY/1h8zgInhMfqm/B5w2L/jhXpWHzj/X NyHVSCEpa5wCX4FQPOBX1N7DkHSkQg6dTA4jgUOnEPiT3SHIDL8Dz64jCRvGRqFVkxEC XVjN5ry65YTYoAW2r8QJ9J25JYhv7ym0NUoZqpqFBk+zzC4/HnMdqZI+stALijD0aBvx DS3ifOoMLYL5MsdaikSjQJ9IjriSKh+FJeAFLxc+c7wgx1LxquaU6BZNYCA6P/spcKXG mGiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hOTe2hgG; 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 o5-v6si3369458pgn.134.2018.05.16.23.28.25; Wed, 16 May 2018 23:28: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=hOTe2hgG; 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 S1752467AbeEQG2V (ORCPT + 29 others); Thu, 17 May 2018 02:28:21 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24196 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751061AbeEQGSv (ORCPT ); Thu, 17 May 2018 02:18:51 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU6002841; Thu, 17 May 2018 15:17:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU6002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537866; bh=QV2ke3u7Gh2sqXLcu7CAM0IRxu2ux/+jy1skkNhYDBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOTe2hgGUbWrwLw00MVSAbBUU0ZrD2HfHUDCU1vC7EUWc29b3RtWFleUNj4LySnuT mNDVKXcTObZ5qt8ngmKMG309raaaP8sI/78x1M7+8pTLIFnC71BbTKVhtum7rWGclU OJIOwZbyc6K2h02zUwGQQSDjgFSccuD+Wuaii1jljQLdG0/OoRJXk7abnZZTwO9U0W t74pHuors+I+QDxRC/JhmLH5TTzO4xpcY6poJ9Yj2kyrRESXxulil67se4mjbt0rZO wJB1DN9xSu/6ccv4IEFhZkKI+yHkyYHkQS0mq4YbSJ0ZX/lnaUHcrfY2rMht2hyYIg vVx2dd2j5Fj6Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 08/31] kconfig: add 'shell' built-in function Date: Thu, 17 May 2018 15:16:47 +0900 Message-Id: <1526537830-22606-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - Accept only one argument to simplify the implementation Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 5be28ec..d8c5f60 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -104,8 +104,49 @@ struct function { char *(*func)(int argc, char *argv[], int old_argc, char *old_argv[]); }; +static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + FILE *p; + char buf[256]; + char *cmd; + size_t nread; + int i; + + cmd = argv[0]; + + p = popen(cmd, "r"); + if (!p) { + perror(cmd); + exit(1); + } + + 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); + exit(1); + } + + return xstrdup(buf); +} + static const struct function function_table[] = { /* Name MIN MAX EXP? Function */ + { "shell", 1, 1, true, do_shell }, }; #define FUNCTION_MAX_ARGS 16 From patchwork Thu May 17 06:16:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136110 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1882950lji; Wed, 16 May 2018 23:25:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpv8GkJ+lXAG+Wo6gX9WNi26kTx4tARDyQflMu+s7PUm/288F0SefcGEp99zS+OerDt50N2 X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr3979473pla.52.1526538356771; Wed, 16 May 2018 23:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538356; cv=none; d=google.com; s=arc-20160816; b=VcXl9MT2UlWTSU+k7LPTQIfzNidpd4pByOVQKMzlIHVjeLqSpbx8Ai0OBxeVTOtIT/ lTmIVBKrhn5+DIhJf4IJvkuieHx8QrPo2UO8+gk3OBH9634ej5kukHAhLN/dTqdWD5nE IoYhtOcBSBMWVhC1QWK0QtPIvI9Pz7CytXVEDHOR37jFRTlenHZZd6BCQhlyfYFwfLC5 guu97XW9X45CbD66w6QC1IbX4yAlXKztRzllxdo/rzRWhc126sCQFtj12qw6CNz3u/rd tDYxV1Ays9FJ0WEAxpArWIVNPZcGQhVMVZsLqnnWb1BSyVsCy7iz3ZsHe4dQuQGGExHJ vsDQ== 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=v8EKEXrkHLNulLEGAKsvHmqv+vu2knhxmGZZax3Ioac=; b=F3yQszw2ukEcB6sjfEj/KUjdhxfMvUTwhlXPC8jOGicPLeOopSDAbBe/nZcOLTEuQ4 HC+G1TafV0+fFsAN2TEG/TDfsU4e4Qy0slnmFdJiSTol3YZGZ8Zvos5ZW7GPzstwwH9E bymnG/FTHSO5OtRjS5JMZHzqRmYAJKBFEl/lgfUZZqwujYjBxrX8c7HeXUXt6PnY/MH9 L+OuufrOlM9hUmJuo5IFnKgzLq18BCQcQqSgx/JCuzyKFVocD4GgUS/j9XRUn1N0DLAp LFpbbn9t9Wpp3fUO/Ke05HyYQcpDAQ13p3G3ASkjIjMjslz2YuGjgz0RNjwtOgOoVIRI flhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=WpkNSsKj; 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 j17-v6si3509005pgv.395.2018.05.16.23.25.56; Wed, 16 May 2018 23:25:56 -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=WpkNSsKj; 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 S1752089AbeEQGTJ (ORCPT + 29 others); Thu, 17 May 2018 02:19:09 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24366 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751850AbeEQGS4 (ORCPT ); Thu, 17 May 2018 02:18:56 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU7002841; Thu, 17 May 2018 15:17:47 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU7002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537867; bh=v8EKEXrkHLNulLEGAKsvHmqv+vu2knhxmGZZax3Ioac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpkNSsKjvhiwoC9k5UsCyZoy+CgGS4uk9UZ0F8i3GZb2JIxPQ+3fHIPQDkypBR6+t S0oI3Mbncgfd72TIffFETeQdFNkI+HnLDR3ojEwIJreMtpmzzeCwDZVAANTtR1fztj sd8X9o7h+eF+QWcQUzgSvJQ8pQkaFAkl0f7QdtfwsI/tXc0e7WhsDrV7nccLmARVju HZXsYeuAt2bcILuO4KAIpQIA2EZ3TLFCU/84dpDmB1N4bwJNncCh4uyVFzbvRXpVkW lAPLgyzRqWQpCSwpPyaduilN/X7cvm8eakmm9ca2NwhdbhvB8KemF9ehpPPkHZE84T 2dqdJDflfZn8g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 09/31] kconfig: replace $(UNAME_RELEASE) with function call Date: Thu, 17 May 2018 15:16:48 +0900 Message-Id: <1526537830-22606-10-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 c6278e6..01b2211 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 752816b..66f0463 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 Thu May 17 06:16:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136114 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1884198lji; Wed, 16 May 2018 23:27:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrSTPx1nEd63WiMkSJrx4z/ky0k5JlMOUf8wtTgTTQnHMATGMlbD2NpkzW5UQSB46Pa6c2O X-Received: by 2002:a62:6e88:: with SMTP id j130-v6mr3952893pfc.111.1526538449937; Wed, 16 May 2018 23:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538449; cv=none; d=google.com; s=arc-20160816; b=Pljfw+7rMvBKtCDPQbWNMicVtcbFoedZ3uKJK30at3fO+MoSjap4TedbcK/KxuwuyU G3FIMmM0HAlhbJPjowLkyUIrm56tmdJlMSSYZ2LIGaLyj3yg7ix9afrmwhpUsQdmAvrt d0kFl7Xkk1STPUSnybn0KbyqTMtvJZWVhO5LGPC6FlokEH/c1NUqKiBMIAzsyO6Fdtgo I/RPfCZvOq7JX1aL/PgeHMz4wLeWB0BXjQ33s8MAVwRrlhbaoz8aaANKC/vkJsLBzQPC IWZSMPp5vQyTMIv322o4xoZW/L8JfsklpIxfYWk+5f00B1/Iya3gL1tOMVMiPwKLWOEQ DKpA== 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=ev13EQg+Fb21HkwbjGskqndoCB7FTTawPLIFXDlwNXg=; b=UaJPV963Fl6JhV6TjnkuZPyql2H0L7mUyCtojg/654cEBfD3mJCq5MLmMOrTgM2t5Z KoHmvo4wbW0mED/n4obZC9W/c+QHrpxsGk5U0YYrDZfn9evuknstydC7sqFYteglXG4j +ikISqYQVcgPbM+E9iDr3zYoBvEh/eIdLbSA8Re68b6/YUsXc74E3q3guJrXbIdxMEOQ 8y2mmvuFmpi1oSkJPD/ZyOsS/ZUJHPjWnvEPOZytu7DnKxrVU+HWdfgbjorX4HCdS3Lg qCBXAXZM8PuRnl2V+eIiPcucdNNGq/6Y9A06Q1tnhl8rIXJsba0mwvqPJdY3RNHNR/H4 KCMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VUqMlFWj; 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 u9-v6si4496922plk.516.2018.05.16.23.27.29; Wed, 16 May 2018 23:27:29 -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=VUqMlFWj; 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 S1752358AbeEQG1N (ORCPT + 29 others); Thu, 17 May 2018 02:27:13 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24212 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179AbeEQGSv (ORCPT ); Thu, 17 May 2018 02:18:51 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU8002841; Thu, 17 May 2018 15:17:48 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU8002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537868; bh=ev13EQg+Fb21HkwbjGskqndoCB7FTTawPLIFXDlwNXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VUqMlFWjgJs71TamqgFKrU462ZOQ6hm4M5D2+fAr6GWCm7niTfBEw+TqjlN9MENck TbuKk5Y8GuVTc0r+A+1shVS87qC8WwGdt6kzElxlYwWPYOJcNHGfHH1BX4V0BdFqEU 84KQNhLhmBWKx1QSlzheXEf6nnfrGbMD6upbKkdO+nEtokE0bt2m0fkespWlUPR6J3 F/Ll60drFi5ixykMpjpS/tusgmiGmvuwctTaU6aCRx/GTsBgD0P6I7n/YtkleLw4SL CGWIA+VIlcCssQiuP3U/Az8KFcD5Q2YbhenLlMH/+a8bOQ0nTFIiV/5wFLmm0dhGwe cbIlJI1f0FZAA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 10/31] kconfig: begin PARAM state only when seeing a command keyword Date: Thu, 17 May 2018 15:16:49 +0900 Message-Id: <1526537830-22606-11-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None Changes in v3: - Newly added 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 Thu May 17 06:16:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136107 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881863lji; Wed, 16 May 2018 23:24:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUT3E3+asEf7Bp0zF8LOwiwSVQHeWve1LK6UEF+RnluRu3NwmShwskHYJfImGa9Bo3LuiS X-Received: by 2002:a63:a34d:: with SMTP id v13-v6mr3169093pgn.224.1526538275679; Wed, 16 May 2018 23:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538275; cv=none; d=google.com; s=arc-20160816; b=k4ava0Hfb+jmyMtYkD5Gz2k9BxGt45qaEypuUxvPNrN/+hLVSyqOAr24g/5SFSQCFw VuiCXst05FPNM9ED8L524u4eniIcdZvljTTR8nvLtrKXRKeRdiJhPyVudBLXf8JUANs2 ir7x4qCggHfFqZ6k+fjsc42S9PtWdPaQVwxdLUbANvWtTzLOJ8tPfE+5JxOLMgx4p7y3 VuIXaleMl1D5i8rhKXwCuU+BC3wG89VhszM+jwmkqiStPkaMveCdirHQTUjaAe32umhl tpShA7sB1rn34o9p8nFrBouUUTQj3f/ySK2N2LH9oy0xyX+Slz60+W9fupzlF/QMwFYz yMQA== 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=FkP6Vun1l+0HiVi/qsVyUkusqaOKn/bTRV8SibPPmds=; b=i9TnRIs1FbJA0UX1pr2YBVaWUGsMdtHO/ri8AugsucC/O8jGhPvBosqaQbfpzlu+jF Jh6VlW/iMdtsZ9CC7ZBPlqkrFVOlVrcpJdcOYtNoxQLc6OQwleoPTIaEB4q7cEFbUs5M 3L8+YELc4kSAgrEsdEx7tiKHgIHisg6xbNMTEm5TDPwUiHRU+yYMaKx1D00SwO/5qVwW 9YYk3exuY0J6kmv/ja9senS2VMRRXLgKf4IcJfdOrn5hiKebLftmpuEv549v8qlk2HUr PrW1DghPqTNnHUupQvg9FVbyy9xA9rMX/Np2eQT67XfTft46y+eCuSDJvpmjbMDHZL1T 2dTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=g3l96x/r; 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 32-v6si3998931plc.252.2018.05.16.23.24.35; Wed, 16 May 2018 23:24: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=g3l96x/r; 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 S1752621AbeEQGYU (ORCPT + 29 others); Thu, 17 May 2018 02:24:20 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25008 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752149AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbU9002841; Thu, 17 May 2018 15:17:49 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbU9002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537869; bh=FkP6Vun1l+0HiVi/qsVyUkusqaOKn/bTRV8SibPPmds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3l96x/rwu1lfAjBeAuXUu6Njs13yyx9PX/ToDYS5GRcq+7vt0PEDQpxFh3WiqYxm pBG2OTYoX69CxDmb0j/+DDDwKASLr+sm59HV3mJiGQco5l1q8ufl1V6JDJ+pRIjknD 2GYQ31ljV4p5hssfAS7CXTo4qBjZGMl9bCnHBT/t3yGdCHPe5ApX7/k71LGhRnc2Ff 8/X7whHX2UKcKdfnZyS18bcB3xjwdJfRiO9TdS3Kh2bbmPthRr8B3r0R5HF/g/Fu9r wASX45IrGgtv6A2x6PGlv/2f4C/CdV65oHYRKQZb4/rNBjNmFHnN+GJELkWN4YHdNu y0/BqcHpAqt0w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 11/31] kconfig: support user-defined function and recursively expanded variable Date: Thu, 17 May 2018 15:16:50 +0900 Message-Id: <1526537830-22606-12-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 -E -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 that. 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 my-func,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 as 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 in the next commit. 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 v4: None 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 | 108 ++++++++++++++++++++++++++++++++++++++++++- scripts/kconfig/zconf.l | 17 ++++++- scripts/kconfig/zconf.y | 19 +++++++- 4 files changed, 142 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 d8c5f60..88580c4 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -201,18 +201,110 @@ static char *function_call(const char *name, int argc, char *argv[], } /* + * 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[], + int old_argc, char *old_argv[]) +{ + struct variable *v; + char *expanded_argv[FUNCTION_MAX_ARGS], *res; + int i; + + v = variable_lookup(name); + if (!v) + return NULL; + + for (i = 0; i < argc; i++) + expanded_argv[i] = expand_string_with_args(argv[i], + old_argc, old_argv); + + res = expand_string_with_args(v->value, argc, expanded_argv); + + for (i = 0; i < argc; i++) + free(expanded_argv[i]); + + return res; +} + +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); +} + +/* * 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; 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 @@ -221,6 +313,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; @@ -268,6 +369,11 @@ static char *eval_clause(const char *in, int argc, char *argv[]) for (i = 0; i < new_argc; i++) new_argv[i] = new_argv[i + 1]; + /* Search for variables */ + res = variable_expand(name, new_argc, new_argv, argc, argv); + if (res) + goto out; + /* Look for built-in functions */ res = function_call(name, new_argc, new_argv, argc, argv); if (res) 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..6201119 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,10 @@ 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 Thu May 17 06:16:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136094 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1878007lji; Wed, 16 May 2018 23:20:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrtSzMKeRHvmHiUNdRWmijIUnOm9woFwVMEPpbgnZr6jp3KoLwHNazPXWRsasz9Vf8h1oBU X-Received: by 2002:a65:6354:: with SMTP id p20-v6mr3141431pgv.437.1526538004416; Wed, 16 May 2018 23:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538004; cv=none; d=google.com; s=arc-20160816; b=Ji3yqrYV3+858ctXyqzB1DSd79W6S9BWOx9aNpql8PyxDRu2ulpFwb9s90mgQhWVCf I3Gwh3A5xkmKxluBdYFuZslBLLgWe/JV7EAINacr/g8ZwblFEJoTMPjsqABRrOwGWdEc nhVRZ2yrflImDEwBn3jEpY8GELv4UDXXNN2SPO3dHpYURNRhRdPfRSGD+0/cKnU+EsTT WpF7026fyPQRvHZQt8DzfzvZx39Q27sKR4UPmSrwaMJ4e+8IhXOnLIxno5g2zhy2OG2/ w68yV1NX9cCVzhBLavnWumLebJJCnlOwYjxINodgiDy38teoXAyHXF6naFQph33uUq12 CMFA== 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=eN63OgcqlXUVueYHzqXoXiKxpHd+JOkDs4lPMTTlXFY=; b=cM7leE01OETcYoAkbrzLDcivV/M/c184cN7J6UvzB0ZuG6I+h7J88NM6F9/RS9WFSB MapWTFf8B47XyMxSXjqq3IS4feJMN64HsvRXjRMVwKhFC85tUUFXu9aVcgtVzhozIwrC B3I8jO2wiX2q2OKGnuO05T+sb6Lm3zBdl6V20lBjK4t+W/XmR/Fg8pi1oqkeLFXGOKJ+ SA7/oATHAj9mecFCKlvmiZirDhAemYY6tp13sMZpe1U1n5eQAhByFSq3xlzVZzs7HCfi fQJdLjiyIgqH39WLOTW7eLhpy3yOXc/siskymvFORMiQmkUFgukbD6ekHX9SaTujyWh+ M+4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VWtzxIqy; 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 i6-v6si4676984pfc.186.2018.05.16.23.20.04; Wed, 16 May 2018 23:20: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=VWtzxIqy; 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 S1752425AbeEQGUC (ORCPT + 29 others); Thu, 17 May 2018 02:20:02 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26319 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752383AbeEQGUA (ORCPT ); Thu, 17 May 2018 02:20:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUA002841; Thu, 17 May 2018 15:17:50 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUA002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537870; bh=eN63OgcqlXUVueYHzqXoXiKxpHd+JOkDs4lPMTTlXFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWtzxIqyqdo7l0Yo9hFGlfSPqNnKbQkLSs0RmrrdDmTtri9ccmHiCmnLUkokc7Q/s VqBWUtELNJwBPyhORvjzDmNX0PHqHMlU5CmkWYsgFMNuC3JRdOpQX4xK/fYxW8T+uc XmlcbzISaKHWl8iASVdnNX+TQ2vE1H4k/eaGdln0/zHMEcl36CKxtHpHmWKLRpGB6S V1H6hvQFTVvDTPcebVrjPoPIDbRKAaxRp2yOZuMWkpOsemKuTdhjFhLwDN8Ua0OrAj EyOB4z8SEVbEMOzwYbIz0jzFYBP5UQaD5nl4ur3AjegwcvfxhRU5bCgq9quhWpG5KU 4aJasR8eKV8rw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 12/31] kconfig: support simply expanded variable Date: Thu, 17 May 2018 15:16:51 +0900 Message-Id: <1526537830-22606-13-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 88580c4..5d7bd9d 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -246,7 +246,8 @@ static char *variable_expand(const char *name, int argc, char *argv[], return res; } -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; @@ -259,7 +260,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 6201119..16432d0 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 Thu May 17 06:16:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136103 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881248lji; Wed, 16 May 2018 23:23:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdvHXI6tS3JE9BcO8PNzZfcDEGipPBXXBlrOegJHMbNm/FlPk4FF6+D7DG6T8C0qjINo67 X-Received: by 2002:a17:902:f83:: with SMTP id 3-v6mr3970405plz.336.1526538228588; Wed, 16 May 2018 23:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538228; cv=none; d=google.com; s=arc-20160816; b=Zbg6W3Jm6Nub0JED2nrqhJzM4rEhdJ9s+gY3jRRbLGRE0ZYrd0gAoTRZoZtyDXVEfi puQhg+XLe93E+PdeiPFh8b0IRUl9uLYgjn79HXBqqdaHUhadk+nmbsVrODs58yaMhvvU TRAWRP5AWcRsA2FO0+cgamei0l1iWD1+g/5O5FNM9D/jFWGpT8JUxbh+t8z5EsCdE4kh MtwtVbURm/oFWK8PtkkjFXa0lODmE632cZMwZWCKE3Y/qX6zE3lncDFbT+mRK6o/hQez UQIAvdTQ//Dt6LFsG8ywFHnzYr4BSgImgZD/OxIdpEDFedk70YKW3WbeeTQPxz1QnCRI KD9w== 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=AhHOPEC5Ia8wokTIBaVdLUk6EnhwEj+yWpUTa9SDN/A=; b=v8WmXEm2ZcAG37/aglBe70AAVo5MMujB6fwpdfjJfKzON/TAT+LiBTrKn+z4tT8Ump CO/2zRPCKVj3ldooojlTCE7V3z3WUW46o5Hdl25d/E1h0YK6gbrOoIvCHkMCQd4leWCD N3DTJewNHMevl6aO8zobREq/dxpW18nMg+U9c564WJXu8dUL4ddoccr3lq26S/AXyLlj yLuxGYrNhDm/4SdTqac27AT18qoQ4ATzSNkxhUe+q/ojmarydJ6QaPJncU9UpTXyfntF fNpcz5ClCa8Fp7UqJO/xeEL0YtjYyCKvp4r5MXnA8s2LzWXrSfqAtiu8KpOVeac2yiFu xZiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qRkzpYU8; 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 y8-v6si4575709pli.242.2018.05.16.23.23.48; Wed, 16 May 2018 23:23: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=qRkzpYU8; 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 S1752174AbeEQGTS (ORCPT + 29 others); Thu, 17 May 2018 02:19:18 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24995 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUB002841; Thu, 17 May 2018 15:17:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUB002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537871; bh=AhHOPEC5Ia8wokTIBaVdLUk6EnhwEj+yWpUTa9SDN/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRkzpYU8zJx+iOuI1p42YNqJNx2XkXzs4qvtGNVmPWh8mppWDvtoqRJ+YR/z9JuWB /yEYnDc0AGdapjo2vdsKp+YlWHjwERER7VDmI7kKCp1+Gca3u+wG6jrqbMuQ4X9Sl/ 9491W/HzXS1QlB01nKdUPIF5FdnUi8j7d7GyxcIyS4pvUwFjZ2rOD76g7Hfd31u34v 2nORY0ZJEp/Vb1k06TqCdwLxpUAh7BWEb47yv2wMX1EbuHuvxPWTWAY2XkcTL/bPVZ KQvNS5P5GDpM9PCCR1wc10JwEOMjMZJAUsjusccPCnPhFHA3KNB2uD7hfA9IEhAxF7 zcGLJa4xFtWIA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 13/31] kconfig: support append assignment operator Date: Thu, 17 May 2018 15:16:52 +0900 Message-Id: <1526537830-22606-14-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 5d7bd9d..47b32dc 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -208,6 +208,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -250,18 +251,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 Thu May 17 06:16:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136092 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877699lji; Wed, 16 May 2018 23:19:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrVAOlNoMtXiGgtK/sXp0ooCXbx+0cRMsozTvtJxVPAYNDRcSOYndj8z+QMKA0aX7Vxo5Is X-Received: by 2002:a65:5003:: with SMTP id f3-v6mr3094445pgo.433.1526537982632; Wed, 16 May 2018 23:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537982; cv=none; d=google.com; s=arc-20160816; b=OzWhJre+rGV+9uL0hAt3ULqooNCQATK9eZ4v19hJQXUocceDZqHgFBcX8dPo5tffQZ Nh9Pj3cdc3Q5colu543wmCAQUIACZ1zs/k9Z95K1pfsyrBJ/f80HCWkQ124cmhULPp1f R388czx4TFTpwbgBjtG1AiTn/8KZqTBq1g2CJ4lXB0z/Lep4NT8Az5vp+g5Io2wYNYWk MZq7RcjMNaxciGFf9S16NQwenwnJ7uJlQQ1oj+L8mfpKYhDRvZ9yya5iBjTotrXOu3TQ Xckafh/b8p7cmFNQDgC+teKzgU7/PHof05OYeJoJkvGWI6T0EyAsxD9d5naxBW6Hi1rJ 4AJQ== 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=+5C5BFghK8bNbBruQh4ridmWGCySFXtqLkuilcFvcew=; b=FGsBPXAv8rbSQVSIfmuCXUhw3UXTjV64D+f1Smect2a9jhrF/hOkAhyfnFFex7so1M xuYlqKL23hVgQarbm0PimMaOK4OY7NrS7MoivBTZRM5dx74N7fQoDnADZ/X0X5nJwrkT YZx513SYkgIPMQTOW2NE5sBxrpkOb5NrzV3GRUDucHwVMoXGw3Deg8tSfXNUa6UCs3t2 D+z+n8b2eWWprowpBe6cdV3RvgbpBkA0AYoF52B/jCcIeoRml8gUM9agdj/XsgrA0zVP XlXTJ5QfOiYAKlUVfN8tMGQcRUxJ+axJ8I+LDxXRUwdseGEEf1t7i6rQMem271uYsEoD ld6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=MT2MrnTO; 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 g11-v6si4561765pfk.187.2018.05.16.23.19.42; Wed, 16 May 2018 23:19: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=MT2MrnTO; 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 S1752309AbeEQGTk (ORCPT + 29 others); Thu, 17 May 2018 02:19:40 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25643 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752276AbeEQGTh (ORCPT ); Thu, 17 May 2018 02:19:37 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUC002841; Thu, 17 May 2018 15:17:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUC002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537872; bh=+5C5BFghK8bNbBruQh4ridmWGCySFXtqLkuilcFvcew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MT2MrnTO8WL69sW6/9er0RNt7gzuoy4H2HRq+N7+GvsG53PcKtTOfk6jXQo0YB2G+ epZd4VFAJ1BuyDXYx2Xxv/DqTl5HJkK0DmHx4KK2vbjqAOz9RqonFrpm2KIrpVY4D7 IbqQznYeebY+UMKd4V7ChmmKPy6usH+SvScP8Oh4SWq7YqiERCb7ru4jlQ4AWTfCTf tD/AigfshL1IWGW6t+FzR7oZStSsD9MCPppda7AiVGwHDB5aK1AFaKqkCwUQ5btaPZ WgcwUUnz2YC+NV31bYvZV57tFHNHyZqJWsUCypt07s3qtzGFVcDhlcWNQnCEVzjhqk 5QIaT8QRqFOLA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 14/31] kconfig: expand lefthand side of assignment statement Date: Thu, 17 May 2018 15:16:53 +0900 Message-Id: <1526537830-22606-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 expands the lefthand side of assignment statements. In fact, Kbuild relies on it since kernel makefiles mostly look like follows: obj-$(CONFIG_FOO) += foo.o Do likewise in Kconfig. Signed-off-by: Masahiro Yamada --- Changes in v4: None 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 Thu May 17 06:16:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136108 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1882573lji; Wed, 16 May 2018 23:25:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqIk78kDkcrduxCvaKFLQg9LanQv4L6NjV/3xmdvgr2P6uYe85yY3LyaH/vjeCfybCtLcoG X-Received: by 2002:a63:8f43:: with SMTP id r3-v6mr3151811pgn.10.1526538326829; Wed, 16 May 2018 23:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538326; cv=none; d=google.com; s=arc-20160816; b=p49TBHj9SAYaqQPvwH3QkGEDdi+6N2mMCnxAhVDvc+uKUaWnVZs8UMG/dvLA8pK5DP Sa+T0COzf4BgWmVrMnk/5G/CRnUAxcz7GAXY3JfQQr9RE5IxfwbfVp8WaJnj2JOsD9b5 M9DgCmFsDiIX6EmckHQVGXbevcOyAmaWNiMd+4rik8CEK3x+10Ci7Vo9MCXqtJ7VExfE CoN81PxvPmvbQldab0AkS2yS+qw7U2FNrMVvNPA6AbGIPjSqc7niibFmRJPTWRAxnw/X inLXe0tlGwIlufkOYj1ltziAkNKbatZ7DRf1IkC8dMc2sNy9i6VQII4QarrBdFiBiQGu ivaQ== 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=yrK8GY4+P2IJbTBqsVTyeFFdhZXMfHSUMP/1U/DDuq4=; b=h9FzHfgFRiWVg1XZ2cCNfsXvA1vSORRTtMxkzKFWmshXGiU+wk+Cnf+CFFHgCK0J7Y ltaHZ90UyR1yRgbUYmCXOjM+Po3u4bFkIrWarcD9p8VDpin5kNjrOZfxTYNQ9iGlKmRb IxJMR3U0a241/lULlwqbluabxKQmImQc/8+NLHmXVFuSe2sD0+GeltZm/z0C7x/P28Q1 QjTRBPtsGUpmcvqchyvi4Yo68TFgt8o76WXuBNY77s+qRyClqT4JHOlSKatt0NsXteyL 77XpaCOiApF1GBrtf+mA2h/3naVxJmTh3YI2DTegcx202TNnuhw4A9SZ29wmGGDQ8gjh esFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=SLKRNtQw; 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 g11-v6si4571991pfk.187.2018.05.16.23.25.26; Wed, 16 May 2018 23:25: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=SLKRNtQw; 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 S1752518AbeEQGYN (ORCPT + 29 others); Thu, 17 May 2018 02:24:13 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25000 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752153AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUD002841; Thu, 17 May 2018 15:17:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUD002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537873; bh=yrK8GY4+P2IJbTBqsVTyeFFdhZXMfHSUMP/1U/DDuq4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLKRNtQw6K/SRUL+rk0jclIZGxF7Hc96WTj17K+ZUQgQGXaUvX33d1X028flTYba7 8tdFNsSMawYb7ln0SslEmpLHPCqSUIQJeQTRNdbEefj5X0YpHqnKijJKdFFqaSQpEU XYh8S67rw9UwQG5bVZ/rnSIrmkKFq6JW8kBePc1KE2baS8LO7N8m+GXbhne95zFzBp /QPn1wcRIfcf5hN4LsF4GDf3PlUncjQ9swUYknkjzxwGywCFKLtwGGYbQb2CdsEbdY 3/nk10BI72qjI6pQffLxPJYuYzMCzjCKeLQayPHmH+WIciOmEsi2XAjIJRm+IbYBrM HamtUDk22VY+w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 15/31] kconfig: add 'info', 'warning', and 'error' built-in functions Date: Thu, 17 May 2018 15:16:54 +0900 Message-Id: <1526537830-22606-16-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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', 'warning', and 'error' functions as in Make. They print messages during parsing Kconfig files. 'error' will be useful to terminate the parsing immediately in fatal cases. Signed-off-by: Masahiro Yamada --- Changes in v4: - Add 'error' function Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 47b32dc..591bcf7 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -104,6 +104,20 @@ struct function { char *(*func)(int argc, char *argv[], int old_argc, char *old_argv[]); }; +static char *do_error(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + pperror("%s", argv[0]); + + return NULL; +} + +static char *do_info(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + printf("%s\n", argv[0]); + + return xstrdup(""); +} + static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[]) { FILE *p; @@ -144,9 +158,19 @@ static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[]) return xstrdup(buf); } +static char *do_warning(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + fprintf(stderr, "%s:%d: %s\n", current_file->name, yylineno, argv[0]); + + return xstrdup(""); +} + static const struct function function_table[] = { /* Name MIN MAX EXP? Function */ + { "error", 1, 1, true, do_error }, + { "info", 1, 1, true, do_info }, { "shell", 1, 1, true, do_shell }, + { "warning", 1, 1, true, do_warning }, }; #define FUNCTION_MAX_ARGS 16 From patchwork Thu May 17 06:16:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136090 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877502lji; Wed, 16 May 2018 23:19:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpp7quANa6Thfo3u2YqltrFNp2ecAihoXzE8d8aPO0ECr0ODMKAeNz9aV/ubZtfxJDchuUE X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr4052852pln.114.1526537966032; Wed, 16 May 2018 23:19:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537966; cv=none; d=google.com; s=arc-20160816; b=CcpQuDLTtMIEGdPoheBt3OtN9tni4M8MDtn7vVA7PhmgcUCPPhpM9C0z7VySehuXhs o5N4k4BT4tRYAddggeBQR9k2idv4pqocgNVc5mNoTZ6a6mFvu+iX9wpooPMKtbuEVINT Fn9WI1Ps0tcQW38lrGaKS06PrLXn7285tt0Bqn2xhItibs1TXhBogfX5+r/CIk/RGGuq rcaPLKzd3hM7ZCLeexWN0Rsx0cfK8YympqFcQ6oqqIDZd7ce1qTO1Iq8BzJ7UkzyJHTg jpF/jVn0pHlRR6A8srPKMHOxr7o5o7qeg8YmGs30FguaPMsXZP9gT0HWj5D4aiPg+rlu m5ow== 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=eENoMDFY0PNYPD2jYFeMGggW47xsAzSKITeObRHmmlQ=; b=YP12q/B7eIBSjfMain70K34jO51qiYrDuGH2EnYz3pfDWNj6aavuQjlTB620ISNm5b 5I2ROWZe8s1AO8hcJvLlExnIkNkQtPJYSqrvEg7qpa+bknHBfCHkA9/Jy+gYAvyTWJfV q+AYe6oRB8V9LunLDgKgVR6lTIYE2EZeCtvtp6zk51ghhzK3NJYTTuoZLzVNynrk4LI3 oydqcleWzg8Bdfdkl1K5xP2buHw1gTsZJcWedFegeMoP6ZsoxuI1hWMncB9SgLj/HWR0 ZAJIGfpAekDh4/ZUewz6LzzoRosI8Cg+vR+clc2DuqJPFsfb0liPB1SdBTac5v9pzpoj gSGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=MadLPkbE; 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 f28-v6si4952932plj.255.2018.05.16.23.19.25; Wed, 16 May 2018 23:19: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=MadLPkbE; 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 S1752245AbeEQGTX (ORCPT + 29 others); Thu, 17 May 2018 02:19:23 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24996 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751379AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUE002841; Thu, 17 May 2018 15:17:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUE002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537874; bh=eENoMDFY0PNYPD2jYFeMGggW47xsAzSKITeObRHmmlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MadLPkbEtZupeCBXt6gen2ZONMJQ3NsYYWhDLY48P/HfRMJcJoQA28m+A5CCXRctP P+MpJAv8EJwC6kPgBMq2eT+0C8KWTOr1TpWH6i53VTtVg360COfwFl4F4lOziOUcPB JhX/h9WyYpQTh/xcfGxWoZI4C9IyQR8NeD2TTtXmogvMErTZo/eg/9liPa8Ot02ofe OgBifI9yrUOfz2cXpn3cqQ5rem59sH+8DKLGq21AexU1NetufrzIt7FeIt0WL7pJBh +xqcWvFxAhd9vkaLlaSgSfI+loB+LUiMpTDzy1F4skTf7z1if4bRsRnxatyFd6sKOR yeJZOw4qT19/w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 16/31] kconfig: add 'if' built-in function Date: Thu, 17 May 2018 15:16:55 +0900 Message-Id: <1526537830-22606-17-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 'if' function is invoked in the form: $(if,condition,then-part,else-part) The behavior is slightly different from that of Make. In Make, the condition is true if the expansion contains any characters (even space). That is why we sometimes need $(strip ...) in the condition part. I thought it was a nasty part in Make, so I changed it for Kconfig; the condition is true if the expansion contains any characters except whitespaces. Unlike the other functions, the parameters passed to 'if' are lazily expanded. The then-part is expanded only when the condition true, and the else-part when false. If the parameters were evaluated before passed to the 'if' function, $(if,$(cond),$(error,...)) would terminate the parsing regardless of $(cond). Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 591bcf7..88844a7 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -111,6 +111,32 @@ static char *do_error(int argc, char *argv[], int old_argc, char *old_argv[]) return NULL; } +static char *do_if(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + char *cond, *p, *res; + const char *sel; + + cond = expand_string_with_args(argv[0], old_argc, old_argv); + p = cond; + + /* condition is true if any character except whitespaces is contained */ + while (*p == ' ' || *p == '\t') + p++; + + if (*p) + sel = argv[1]; + else if (argc >= 3) + sel = argv[2]; + else + sel = ""; + + res = expand_string_with_args(sel, old_argc, old_argv); + + free(cond); + + return res; +} + static char *do_info(int argc, char *argv[], int old_argc, char *old_argv[]) { printf("%s\n", argv[0]); @@ -168,6 +194,7 @@ static char *do_warning(int argc, char *argv[], int old_argc, char *old_argv[]) static const struct function function_table[] = { /* Name MIN MAX EXP? Function */ { "error", 1, 1, true, do_error }, + { "if", 2, 3, false, do_if }, { "info", 1, 1, true, do_info }, { "shell", 1, 1, true, do_shell }, { "warning", 1, 1, true, do_warning }, From patchwork Thu May 17 06:16:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136104 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881642lji; Wed, 16 May 2018 23:24:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpmpgITlsHeZKco7xGzXI2GpW1FyrbC4o6xecqEzANjX9i8Je6rIK/sFQyWqiQWjzmZTidK X-Received: by 2002:a62:449c:: with SMTP id m28-v6mr3966727pfi.145.1526538258821; Wed, 16 May 2018 23:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538258; cv=none; d=google.com; s=arc-20160816; b=eCZBwADSuMevrUHbOpxsTNCAVEO5XZa7VW2HB/Q0HUjjyw1Xv1fJT6asRQACFMhq+m RCvu7O+qPCYnTwo+0wmFhlbPg5e+8bhRU0nmfqgp4HE9z4Cmy1Cxdn80zqkroR4Bjmnq K9qBL2CZT5/ynj8PJMOWK8P+g/VyPs4SVSh/2i5GD1QsBJgH8Eoa98zGhDh88PVHMGAg E9KwS/b0D/E9tUXVfegIchwyWlTrormIcARbLhWhL8XYF7zi/tsjkJbHx4WI+y3JqvhH mkcZlpAmTJKU9Knf6TrL8zz0D8gKq+BhtmsFjYQ/FQmm4uKt1oS11Ej3u/lrRAMyey7L 3JWQ== 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=5S53LhpTS+CxEf8CrW5uwWBe7fNb1Rso9Yw0oFdAG38=; b=R9dylc9M65u6HR77uiA4ce/0SOOMdrWQTvwDkIUPajBu83Qszxm+C6oNWAFXNejl6W B1+YvxZ6Rg2M+bXzQytQKZ/mQ3ZdFktPWFwE/QvSZoGA8K7gQqfcaHB0GPKBO1hImsbX O4C8uUvq4cr65bnfdxxXGAkXwVcZqbvtUP96T62ap3JodZnHoJveIKafuqLDW04/wmdp lo/70zDJLx05Yx5ILMneolYb4yC6qvaMlbdFvJdfVL5kH0NJgP7hbgRsJr3M1jEJ4FfJ cMFpZhZNBftTSORSbypILs510TSzHx2ZKoVIK5PvM3+2Rh0VqwvFyLD542kXtLL9cluR meNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=EFK1kqNp; 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 r14-v6si5070543plj.341.2018.05.16.23.24.18; Wed, 16 May 2018 23:24:18 -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=EFK1kqNp; 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 S1752594AbeEQGYP (ORCPT + 29 others); Thu, 17 May 2018 02:24:15 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24993 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751396AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUF002841; Thu, 17 May 2018 15:17:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUF002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537875; bh=5S53LhpTS+CxEf8CrW5uwWBe7fNb1Rso9Yw0oFdAG38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EFK1kqNp6OM/1N28g/jZU04YBB8b8z5gl7Vd53ded7lwvaYprL7wqKY5ut45v/AvV L6dIGv42aOIKSl2ioK93jNzpul8Zb918q/kyUwvOYOfTe/YlCuatkNQg9W5qZfSpdG 88/q8T0aSikwRO+Z1g0yXtNCZVgnBxkAWlwMAUrFXOZ5A7RazAESVBmPK35s6mnaBF u4+GNvpxoY+ackQK8txOrXKX3K1QygVivXuQwfbyG8pGVEAS+pYnldoW53u/WjfoJU h82PJLORwTqNWUgDi8gIijNw67gtjiAh/XbVzXFuUW61C26ZVniB2Ybc0Dqq9nwgQt dOmnidIj5VCgw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 17/31] kconfig: add 'filename' and 'lineno' built-in variables Date: Thu, 17 May 2018 15:16:56 +0900 Message-Id: <1526537830-22606-18-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 special variables, $(filename) and $(lineno), are expanded to a file name and its line number being parsed, respectively. Suggested-by: Randy Dunlap Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 88844a7..c39e30e 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -111,6 +111,11 @@ static char *do_error(int argc, char *argv[], int old_argc, char *old_argv[]) return NULL; } +static char *do_filename(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + return xstrdup(current_file->name); +} + static char *do_if(int argc, char *argv[], int old_argc, char *old_argv[]) { char *cond, *p, *res; @@ -144,6 +149,15 @@ static char *do_info(int argc, char *argv[], int old_argc, char *old_argv[]) return xstrdup(""); } +static char *do_lineno(int argc, char *argv[], int old_argc, char *old_argv[]) +{ + char buf[16]; + + sprintf(buf, "%d", yylineno); + + return xstrdup(buf); +} + static char *do_shell(int argc, char *argv[], int old_argc, char *old_argv[]) { FILE *p; @@ -194,8 +208,10 @@ static char *do_warning(int argc, char *argv[], int old_argc, char *old_argv[]) static const struct function function_table[] = { /* Name MIN MAX EXP? Function */ { "error", 1, 1, true, do_error }, + { "filename", 0, 0, false, do_filename }, { "if", 2, 3, false, do_if }, { "info", 1, 1, true, do_info }, + { "lineno", 0, 0, false, do_lineno }, { "shell", 1, 1, true, do_shell }, { "warning", 1, 1, true, do_warning }, }; From patchwork Thu May 17 06:16:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136089 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877432lji; Wed, 16 May 2018 23:19:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqqUtv4eBZNmGn26IbAXLp0kDfEdPsTkXDoq/6oB7BPP9AfPdgtAYzNgfovxru+ycdddARG X-Received: by 2002:a17:902:b184:: with SMTP id s4-v6mr3850281plr.359.1526537962908; Wed, 16 May 2018 23:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537962; cv=none; d=google.com; s=arc-20160816; b=HW23opiodZVz6ViJv0CkNRUjoOgtofDcoITZNEleRMOjuiMhLcRxCBSaRW9ptvbf51 WGikvNZI1PIR/5Jw7d899SgGOHJw3xh8PI/FQZyDIQ2Wz6R5TbGpdPRYmYo3MdtZPFOg iRwbxVHVOsSbCdbSg14JdN1lKtk/bfROwNla9r+z2PcjyGzRyjUHKTIADey4d6VQhXae vY4Qe6PFEhdVUvUB97Tmn2Ib3WDIKRvvBOuFGQ9Eb1GrqFY1E4M4BTVfEu3xWppTXwBq 3qAVB8FFxU6WwB+q+3qiUuxtQpG5GWtpnnUaJZmsH0MIwOjrnFbVfmEPhUVIDmuVMY54 tolw== 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=d7ZznbAHzAPLPzbAa1AFz4lYEkTkrvR+7XrpYn4RaN0=; b=X2jWrFPmud6+me8umL4rWn5qSfPCLclzlQ6znlg1tUtQYg5v1gde/YUOnAVy1oY+n8 iieF9CYkM03bzw8LzpeXO7gdrHGWbZ7jJyIIi5sdbBn32sGGh/xhx21AZzau7zxgkR3O MX4brBSNs/hIIjpRBCgbR1p42oQU8GY9RgelAlccMdkfdO1b0YyKuuFE7AV/Yp/Bv59X BN3f0zl907xQBDFjoGxlCzRc6WyYq0QiICkzTXT7ba48wQBj80DJiakvpbYWYNfHVXiW QeT1WhqO2xkSNVQnKQ7ypuUnFeV5i9okLkYPXvrT/WETuNaUQitY7ogPpUJQsNGi9RQ9 K0qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=26Uk5R3R; 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 f28-v6si4952932plj.255.2018.05.16.23.19.22; Wed, 16 May 2018 23:19: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=26Uk5R3R; 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 S1752205AbeEQGTU (ORCPT + 29 others); Thu, 17 May 2018 02:19:20 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24994 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751231AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUG002841; Thu, 17 May 2018 15:17:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUG002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537876; bh=d7ZznbAHzAPLPzbAa1AFz4lYEkTkrvR+7XrpYn4RaN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=26Uk5R3RU3i0LczZaoWgBjpC0lNAyl8pdXK+W/K76Mqq583ndnUnO5yMjEkf5lqbO U9wDNT1UOJRs7C2k2gQPCtUMQ9QgKapRue/W0L9e92sxxDVfCC6+BqeP+KFc3Jg43e Y+qNoyBiRSzfW71TqVLXvVhc1OcVaEIgVYzQ1NjSm/qPv66KeaNbMVSOK5p1MSaUvH r+6WjgAnlNXGY+uauiArJ2idyw60/wmG24RS8s3UtlEhiVpeGwme8zmQsDDiRCxiRi EQAPuw9oPaDMpt3hOFkZ1jIjLPokX3lqrRPftJn3kb7MtXuE12q1xdgp1RnOkxx1oH WLjN/yf/Q+cnw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 18/31] kconfig: error out if a recursive variable references itself Date: Thu, 17 May 2018 15:16:57 +0900 Message-Id: <1526537830-22606-19-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 When using a recursively expanded variable, it is a common mistake to make circular reference. For example, Make terminates the following code: X = $(X) Y := $(X) Let's detect the circular expansion in Kconfig, too. On the other hand, a function that recurses itself is a commonly-used programming technique. So, Make does not check recursion in the reference with 'call'. For example, the following code continues running eternally: X = $(call X) Y := $(X) Kconfig allows circular expansion if one or more arguments are given, but terminates when the same function is recursively invoked 1000 times, assuming it is a programming mistake. Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index c39e30e..246f879 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -276,6 +276,7 @@ struct variable { char *name; char *value; enum variable_flavor flavor; + int exp_count; struct list_head node; }; @@ -306,8 +307,19 @@ static char *variable_expand(const char *name, int argc, char *argv[], expanded_argv[i] = expand_string_with_args(argv[i], old_argc, old_argv); + if (argc == 0 && v->exp_count) + pperror("Recursive variable '%s' references itself (eventually)", + name); + + if (v->exp_count > 1000) + pperror("Too deep recursive expansion"); + + v->exp_count++; + res = expand_string_with_args(v->value, argc, expanded_argv); + v->exp_count--; + for (i = 0; i < argc; i++) free(expanded_argv[i]); @@ -337,6 +349,7 @@ void variable_add(const char *name, const char *value, v = xmalloc(sizeof(*v)); v->name = xstrdup(name); + v->exp_count = 0; list_add_tail(&v->node, &variable_list); } From patchwork Thu May 17 06:16:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136105 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881682lji; Wed, 16 May 2018 23:24:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrwgg98Hu5pJJ5iGZHsyIVMJKb0JmLrE5dWzA22KqBZgnIAga6doaC1fSX4Zvc2WRe6pIID X-Received: by 2002:a63:b307:: with SMTP id i7-v6mr3122058pgf.28.1526538260563; Wed, 16 May 2018 23:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538260; cv=none; d=google.com; s=arc-20160816; b=GL3F36RXbFLW4Qt2Tuav45GLA+a83d6g/cCnbs34xopd32wy73ub7rLy6ezbRTr3Ly 86djbVnWonKX8AvNgFw9/AQIHj0jYia9jq8abwVDbmtOt1j1hvMH/SQKnQAvVONN84Bw PwIMO6lPWmuosFL5OPrdZyUsmBGaFeCCqjiPedbjX1bsZPRPgV5XaSSxdlilWwg3qXic lpy6jJfR+9NJsdAJq9D8U3kR83OThhyOqfasXSeGGSlPjOLhYBhzY81OtO5Axxcu0nOs QF7cG5fXsfZppnrJk++6mI8XVJ1tYQjiV9vZVqyAWy3IbiLPTzDXDtGXgGytyXSibGRp at0g== 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=kqCto/9pipqMvElkXHZMq7kbs6LJ18/e0PuvfjWCwVo=; b=VabpuPcVthX6sTamAiPgBZ76ztbwuozr5hUh6iho+qv/zdmc4CNwKMeCWJ1CDcejYV Y/CxdSWTJr1jG41InigvBiZlUZg+E/nOxh6XgkhQdSbz6xmN8DmOh8iwSamALQ+M9Bi+ voGqYksJoKSJnxgSMJVXB2xiIqQbqmviQ8/3me4Y03VKoS2TK9cAVeQZGL+6P29VwonV uw/w1X6jP/FwQu/k1hmvmyvaYMTxykrc3XZE3rA6zOzGxTRlWUBnZ+NDPLm7Gf/yoL+2 Ap7GAastWC/IOeehN/dVN5hY5gfJDa8onz7Hxoxc+bAzyEvURbEA7jKElu8b+NEP8fWf MYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=KZTIwnk9; 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 z1-v6si2663043pgz.575.2018.05.16.23.24.20; Wed, 16 May 2018 23:24:20 -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=KZTIwnk9; 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 S1752612AbeEQGYR (ORCPT + 29 others); Thu, 17 May 2018 02:24:17 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25010 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752154AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUH002841; Thu, 17 May 2018 15:17:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUH002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537877; bh=kqCto/9pipqMvElkXHZMq7kbs6LJ18/e0PuvfjWCwVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KZTIwnk99dS/YS0HI2iUNRj6Yqd2bQrf/Q4QHneP848+tzBixzC6CPHSag9b1zK8r AkbKSqY8KMcaAx/C+xomwAqbaOzWebJt8W7OhhI34wiElBuhoor03nu/3GQeOczcSB fKFA8MClU94+NlNLN9x3WTxumZFaBrqs09Ug/63FCY9FKD/K9s4Y7oETpK4Mj0ty/w P3oolPSJ3kjHzy5QsTKep4aPDik4KeytQD56qior/k1JNFPZzdOagm7p0E72wX+++M 9Xz4G4jHCjZ92HxRwrmM6q5ahlNeFf6JqGjSwEiI7wSEWztP+TTah9eGQwOjd2XMUA 8PTZFm8Fg9ijA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 19/31] Documentation: kconfig: document a new Kconfig macro language Date: Thu, 17 May 2018 15:16:58 +0900 Message-Id: <1526537830-22606-20-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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. By moving the compiler capability tests to Kconfig, features unsupported by the compiler will be hidden automatically. 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 attribute with 'option shell=...', but I found more generalized text expansion would make Kconfig more powerful and lovely. The basic ideas are from Make, but there are some differences. [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 v4: - Update according to the syntax change Changes in v3: - Newly added Changes in v2: None Documentation/kbuild/kconfig-macro-language.txt | 252 ++++++++++++++++++++++++ MAINTAINERS | 2 +- 2 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 Documentation/kbuild/kconfig-macro-language.txt -- 2.7.4 Reviewed-by: Kees Cook Reviewed-by: Randy Dunlap diff --git a/Documentation/kbuild/kconfig-macro-language.txt b/Documentation/kbuild/kconfig-macro-language.txt new file mode 100644 index 0000000..a8dc792 --- /dev/null +++ b/Documentation/kbuild/kconfig-macro-language.txt @@ -0,0 +1,252 @@ +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 as 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 be +expanded further. To get the value of a variable, enclose the variable name in +$( ). The parentheses are required even for single-letter variable names; $X is +a syntax error. The curly brace form as in ${CC} is not supported either. + +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. + +The variable reference can take parameters, in the following form: + + $(name,arg1,arg2,arg3) + +You can consider the parameterized reference as a function. (more precisely, +"user-defined function" in the contrast to "built-in function" listed below). + +Useful functions must be expanded when they are used since the same function is +expanded differently if different parameters are passed. Hence, a user-defined +function is defined using the = assignment operator. The parameters are +referenced within the body definition with $(1), $(2), etc. + +In fact, recursively expanded variables and user-defined functions are the same +internally. (In other words, "variable" is "function with zero argument".) +When we say "variable" in a broad sense, it includes "user-defined function". + + +Built-in functions +------------------ + +Like Make, Kconfig provides several built-in functions. Every function takes a +particular number of arguments. + +In Make, every built-in function takes at least one argument. Kconfig allows +zero argument for built-in functions, such as $(fileno), $(lineno). You could +consider those as "built-in variable", but it is just a matter of how we call +it after all. Let's say "built-in function" here to refer to natively supported +functionality. + +Kconfig currently supports the following built-in functions. + + - $(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. + + - $(info,text) + + The "info" function takes a single argument and prints it to stdout. + It evaluates to an empty string. + + - $(warning,text) + + The "warning" function is similar to "info" except that it sends its argument + to stderr and prefixes the output with the name of the current Kconfig file + and the current line number. + + - $(error,text) + + The "error" function is similar to "warning", but it terminates the parsing + immediately. + + - $(if,condition,then-part[,else-part]) + + The "if" function takes two or three arguments ('else-part' is optional). + Depending on the value of the condition part, the argument to be expanded + is selected. The condition is true if its expansion contains any characters + except whitespaces. In this case, the then-part is expanded. Otherwise, the + else-part is expanded. + + Note: + In Make, the condition is true if it contains any characters including + whitespaces, which is why $(strip ...) is sometimes necessary in the + condition part. Kconfig changed the behavior to make it handier. + + - $(filename) + + The 'filename' takes no argument, and $(filename) is expanded to a file name + being parsed. + + - $(lineno) + + The 'lineno' takes no argument, and $(lineno) is expanded to a line number + being parsed. + + +Difference of function call syntax +---------------------------------- + +Kconfig adopts Make-like macro language, but the function call syntax is +slightly different. + +A function call in Make looks like follows: + + $(func-name arg1,arg2,arg3) + +The function name and the first argument are separated by at least one +whitespace. Then, leading whitespaces are trimmed from the first argument, +but whitespaces in the other arguments are kept. You need to use a kind of +trick to start the first parameter with spaces. For example, if you want +to make "info" function print " hello", you can write like follows: + + $(info $(space)$(space)hello) + +Kconfig uses only commas for delimiters, and keeps all whitespaces in the +function call. Some people prefer putting a space after each comma delimiter: + + $(func-name, arg1, arg2, arg3) + +In this case, "func-name" will receive " arg1", " arg2", " arg3". The presence +of leading spaces may really matter depending on the function. The same applies +to Make - for example, $(subst .c, .o, $(sources)) is a typical mistake. + +In Make, a user-defined function is referenced by using a built-in function, +'call', like this: + + $(call my-func,arg1,arg2,arg3) + +Kconfig invokes user-defined functions and built-in functions in the same way. +The omission of 'call' makes the syntax shorter. + +In Make, some functions exceptionally treat commas verbatim instead of argument +separators. For example, $(shell echo hello, world) evaluates to "hello, world". +Likewise, $(info hello, world) prints "hello, world" to stdout. You could say +this is _useful_ inconsistency. + +For simpler implementation and grammatical consistency, Kconfig always treats +commas that appear in the $( ) form as delimiters. It means + + $(shell, echo hello, world) + +is an error because it is passing two parameters where the 'shell' function +accepts only one. To pass commas in arguments, you can use the following trick: + + comma := , + $(shell, echo hello$(comma) world) + + +Caveats +------- + +A variable (or function) cannot be expanded across tokens. So, you cannot 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 cannot 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 cannot pass symbols to the 'shell' function. +The following does not work as expected. + + config ENDIAN_FLAG + string + default "-mbig-endian" if CPU_BIG_ENDIAN + default "-mlittle-endian" if CPU_LITTLE_ENDIAN + + config CC_HAS_ENDIAN_FLAG + def_bool $(shell $(srctree)/scripts/gcc-check-flag ENDIAN_FLAG) + +Instead, you can do like follows so that any function call is statically +expanded. + + config CC_HAS_ENDIAN_FLAG + bool + default $(shell $(srctree)/scripts/gcc-check-flag -mbig-endian) if CPU_BIG_ENDIAN + default $(shell $(srctree)/scripts/gcc-check-flag -mlittle-endian) if CPU_LITTLE_ENDIAN diff --git a/MAINTAINERS b/MAINTAINERS index 58b9861..b7d7ae61 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7632,7 +7632,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 Thu May 17 06:16:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136095 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1878118lji; Wed, 16 May 2018 23:20:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdpoSP53YkHOkFt/qbgdT/SgWql71jk2sBt6fIfRQ8JeBg3HW6SzLuiifB2uChDehpyT2U X-Received: by 2002:a65:4ed1:: with SMTP id w17-v6mr3062459pgq.83.1526538012044; Wed, 16 May 2018 23:20:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538012; cv=none; d=google.com; s=arc-20160816; b=iw43goliTq8/dryqBMgiEyilIP9ejVVE04OG/n+yAfWsCJJCCPpDzdBjlT5+a8d0J5 QBkM9t56KUa8bPZOAmQhApu0q+E7gTQrIyFQGlY9dOBtNogcfndwAruxPnJ/VwmFmVxs Ewfx67dcyOPcOY1hqUsEfinzus4pyUBCzB02s/4IjFDYSHm0PVje9CAU7wVhFhzubIr/ T2weU/SNYSkf6STXfJChirCWZWC78scFU2JKOMC8/DiUVDjI2CCOkDszN9xkFyLUJ5cO u8CFOxEHXMPBw6vAdFs2kiBi7VOEMBbDPfK8oJTNbjOxoJ9gJ+409lpn3dyerH8ZVAVI xm2A== 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=mUciHQ+Au4DF3BlhBvH1p8KIkW0zCpLQ8c13MZb2/3o=; b=SuKu3lY7YXzC8b4poPM+XJWTn6bu4E944VKB60ykovpJUqwKFk0XLdEYGN1qhabZcW WxyqRhmheD/H5/iV2a03nTIAcLHSJceAo16ZaEcGmF59qrlqzUFWvtJA9KqsptD6Ok9q xSvg4EShH0X9JVxJrlOAF+RrQ/MOe2HKXQQHSxWnlCoBp2sT8tSUvKQDSk5EaQY0Vi6P WxTdJJhhR9P/BYixAD+U7Lo9Hu0/6y5TFdiRSFXhoHZyRaLeb96e0iVLbHu1Ug+ZVIRb HVfhcmlz8t6/44yJjsTD33E/aUPFhfSyExkP7O9Oj2sDJ1XU76SFV+Gc7sWztFBpnpFK ztcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pDCoDtni; 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 o9-v6si4672778pfk.276.2018.05.16.23.20.11; Wed, 16 May 2018 23:20: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=pDCoDtni; 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 S1752454AbeEQGUJ (ORCPT + 29 others); Thu, 17 May 2018 02:20:09 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26525 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752404AbeEQGUG (ORCPT ); Thu, 17 May 2018 02:20:06 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUI002841; Thu, 17 May 2018 15:17:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUI002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537878; bh=mUciHQ+Au4DF3BlhBvH1p8KIkW0zCpLQ8c13MZb2/3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pDCoDtniC1vQLfVhS7kQOB5jkkvV1r7wJx8XGWUKn8RHL1FdVBP5qkPRkPDxLdrG8 KPAfACldmcig5uqbE5R9+5uQrjVIXNu9uL/L8k/lHb6mWSsPgS2BXErewXHMcKJFUB DSHERNCP1UFBQzmu6zbLuJhu13xCN0zzGeSPJjqJP9iniobVa6qr2Z+Gfa6f1EZi8j L/64xfxHQ7CQheudfo5iAzm8t0R3u0jVxZVpdIZ8UqD8G55VBi++u8DpEUBro1nAQ3 q9DLA8WnF0B+KhGAPKwiJTh2nvWuEBpWZCHT3ddr66IydGxFgcly4PHksJhPpGXq+W 28MgQtBYJ8V8g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 20/31] kconfig: test: add Kconfig macro language tests Date: Thu, 17 May 2018 15:16:59 +0900 Message-Id: <1526537830-22606-21-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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. Signed-off-by: Masahiro Yamada --- Changes in v4: - Adjust for the change in function call syntax. - Remove unnecessarily tricky tests. Changes in v3: - newly added Changes in v2: None .../kconfig/tests/preprocess/builtin_func/Kconfig | 29 +++++++++++++ .../tests/preprocess/builtin_func/__init__.py | 8 ++++ .../tests/preprocess/builtin_func/expected_stderr | 7 ++++ .../tests/preprocess/builtin_func/expected_stdout | 1 + .../tests/preprocess/circular_expansion/Kconfig | 3 ++ .../preprocess/circular_expansion/__init__.py | 10 +++++ .../preprocess/circular_expansion/expected_stderr | 1 + scripts/kconfig/tests/preprocess/escape/Kconfig | 21 ++++++++++ .../kconfig/tests/preprocess/escape/__init__.py | 7 ++++ .../tests/preprocess/escape/expected_stderr | 5 +++ scripts/kconfig/tests/preprocess/variable/Kconfig | 48 ++++++++++++++++++++++ .../kconfig/tests/preprocess/variable/__init__.py | 7 ++++ .../tests/preprocess/variable/expected_stderr | 9 ++++ 13 files changed, 156 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/circular_expansion/Kconfig create mode 100644 scripts/kconfig/tests/preprocess/circular_expansion/__init__.py create mode 100644 scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr 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/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..5f51135 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig @@ -0,0 +1,29 @@ +# 'info' prints the argument to stdout. +$(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) + +# 'shell' executes a command, and returns its stdout. +$(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')) + +# 'filename' is expanded to the currently parsed file name, +# 'lineno' to the line number. +$(warning,filename=$(filename)) +$(warning,lineno=$(lineno)) + +# 'if' selects which argument to expand +# depending on the condition part. +cond := 1 +$(warning,$(if,$(cond),y,n)) +cond := +$(warning,$(if,$(cond),y,n)) + +# 'if' delays the expansion of arguments. +# In the following, the 'error' function should not be evaluated. +$(if,,$(error,this should not be expanded)) 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..a4f27a6 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr @@ -0,0 +1,7 @@ +Kconfig:6: hello world 1 +Kconfig:9: hello world 3 +Kconfig:13: hello world 4 +Kconfig:17: filename=Kconfig +Kconfig:18: lineno=18 +Kconfig:23: y +Kconfig:25: n 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..82de3a7 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stdout @@ -0,0 +1 @@ +hello world 0 diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig b/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig new file mode 100644 index 0000000..54debf1 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig @@ -0,0 +1,3 @@ +X = $(Y) +Y = $(X) +$(info $(X)) diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py b/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py new file mode 100644 index 0000000..21413d9 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py @@ -0,0 +1,10 @@ +""" +Detect circular variable expansion. + +If a recursively expanded variable references itself (eventually), +it should fail with an error message. +""" + +def test(conf): + assert conf.oldaskconfig() != 0 + assert conf.stderr_matches('expected_stderr') diff --git a/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr b/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr new file mode 100644 index 0000000..c638a8c --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr @@ -0,0 +1 @@ +Kconfig:3: Recursive variable 'X' references itself (eventually) diff --git a/scripts/kconfig/tests/preprocess/escape/Kconfig b/scripts/kconfig/tests/preprocess/escape/Kconfig new file mode 100644 index 0000000..b38c897 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/Kconfig @@ -0,0 +1,21 @@ +# You can not pass commas directly to a function since they are treated as +# delimiters. You can use the following trick to do so. +comma := , +$(warning,hello$(comma) world) + +# 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,$($$)) diff --git a/scripts/kconfig/tests/preprocess/escape/__init__.py b/scripts/kconfig/tests/preprocess/escape/__init__.py new file mode 100644 index 0000000..602861e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/__init__.py @@ -0,0 +1,7 @@ +""" +Escape sequence tests. +""" + +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..6a80134 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/expected_stderr @@ -0,0 +1,5 @@ +Kconfig:4: hello, world +Kconfig:8: ' " '" ' ''' "'" +Kconfig:11: $ +Kconfig:15: $(X) +Kconfig:21: nasty diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig new file mode 100644 index 0000000..271834e --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/Kconfig @@ -0,0 +1,48 @@ +# 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)) + +# User-defined function. +greeting = $(1), my name is $(2). +$(warning,$(greeting,Hello,John)) + +# The number of arguments is not checked for user-defined functions. +# If some arguments are optional, it is useful to pass fewer parameters. +# $(2) will be blank in this case. +$(warning,$(greeting,Hello)) + +# Unreferenced parameters are just ignored. +$(warning,$(greeting,Hello,John,ignored,ignored)) diff --git a/scripts/kconfig/tests/preprocess/variable/__init__.py b/scripts/kconfig/tests/preprocess/variable/__init__.py new file mode 100644 index 0000000..5b2c1be --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/__init__.py @@ -0,0 +1,7 @@ +""" +Variable and user-defined function 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..bddfa3b --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr @@ -0,0 +1,9 @@ +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:40: Hello, my name is John. +Kconfig:45: Hello, my name is . +Kconfig:48: Hello, my name is John. From patchwork Thu May 17 06:17:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136102 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1879931lji; Wed, 16 May 2018 23:22:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo1q4oEgbTabCw0GOQV+3IeXvMQnRj31Je0flPGpLkM1Ga611a9rltnFlWs6nDZe7mCbBO8 X-Received: by 2002:a17:902:7046:: with SMTP id h6-v6mr3974724plt.249.1526538133996; Wed, 16 May 2018 23:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538133; cv=none; d=google.com; s=arc-20160816; b=GStueEo1QSaK8B6jsntzCzTC3aH706DDZMVJirTJC4iV6sgVLiBtzafBoLY6y5Rlvx OZhmd7t9VvYGeUwBdoRCSeXAXpC1BmFLYvPVni1aJUYjb4OaXagdpZygLztVm+D5YcZV g7gKOesD/HX3P8HTEEIcQor2PItdFly30qGhULWQYWHslfwwLuFKFwrlO0zUA1X7KXho 76edDq5OOPEDOGrDF1M+VqrlGGVlZC+GEp4+1eTutYhBhjR4SgqvweR/SuHTSz5I4RbF +688rninsq+h2DNnuEPjfQo63AO6maiYvHO/s3Nuku6FilOnL4cmvDtHoqViQZt3OAop ojog== 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=wtmluTE6253pNxx3As88qgTQx0hPxMcrVOSGHz81Wv0=; b=Io/d3As5rqXFSaHvHHTvQ5FktCr/ecFjh67KBFCh5QYCxz+b5K9kA1xVZui+nCFcRr wk3xZEgPC8nk4GedHpbIY0UPu8eLIvkfkvalxOS8TaOZnuWUiOz+d97m6MsL8hDRkPnN 2H+fwShOT8sxxmnmca4WvEfe3dQxbVgg5jGJrjbCoNCxSDZS5FFLsgxAPDRrUNHa40m9 vfn4JXzfX71P7npIyzYRPp+Q+QPSjgfpFw0pA2KDp8JPJzY3ay5bTblb13kCcXlxaTKg +0IFloySs5TtgJEz3EAvD33Rh356ZWgYDTgzXWCI69gHCmyI0Trq6NBAmgG1Tu+qa91+ UVaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=oSCsRszv; 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 u62-v6si3402108pgc.180.2018.05.16.23.22.13; Wed, 16 May 2018 23:22: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=oSCsRszv; 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 S1752547AbeEQGWL (ORCPT + 29 others); Thu, 17 May 2018 02:22:11 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25143 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752175AbeEQGTU (ORCPT ); Thu, 17 May 2018 02:19:20 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUJ002841; Thu, 17 May 2018 15:17:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUJ002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537879; bh=wtmluTE6253pNxx3As88qgTQx0hPxMcrVOSGHz81Wv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oSCsRszvYz++jwG0bqqQUsJ8pDndpa0B305XNY5jnE9RMc1cS0RV+GEtM2GNtXyoA nMWJabZfTiUsaYLeIHmNebTUrlbhJurY/JN+yBh95wZ8QlfFjkobzf1GvmkQ0N9qTi bgBOnnPTZJhmUByy96/6zZcT9ddi6vk46h4KadyE4JDz3rEi7KzB7fWcuCn3HAeGSm uUzzkrCbmbQS8qa6RJy0JlM2JfUBz9u7K6nbBcBatvX+qUofgQAijN//lg2M1LOTlg MS67EuIUqgSTVoLSrVRK+VK4ciYMTtLd54aOqP5Er/8ysmcLsN/pTMqH7E5dZEp2AS wO0Xd1Cwd0HZg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 21/31] kconfig: show compiler version text in the top comment Date: Thu, 17 May 2018 15:17:00 +0900 Message-Id: <1526537830-22606-22-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - Add comment to arch/x86/um/Kconfig as well Changes in v3: None Changes in v2: None Kconfig | 2 ++ Makefile | 2 ++ arch/x86/um/Kconfig | 2 ++ 3 files changed, 6 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 01b2211..7529825 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. diff --git a/arch/x86/um/Kconfig b/arch/x86/um/Kconfig index 6a15c4d..a992f8e 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 mainmenu "User Mode Linux/$(SUBARCH) $(KERNELVERSION) Kernel Configuration" +comment "Compiler: $(CC_VERSION_TEXT)" + source "arch/um/Kconfig.common" menu "UML-specific options" From patchwork Thu May 17 06:17:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136098 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1878800lji; Wed, 16 May 2018 23:21:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGINkatwxQLogtYzdaXuEFnQV5+/BvHfVADa37W8bQitRBPs7mpLrXxfDw7Qj89G/p3xuk X-Received: by 2002:a63:6fc3:: with SMTP id k186-v6mr3135950pgc.111.1526538062089; Wed, 16 May 2018 23:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538062; cv=none; d=google.com; s=arc-20160816; b=IgNxdNGPX+Z/hAjmRz9Jjm5Lfe9IbKWlSI/Zhg7l3WhT+qYQKvSyAQpPUL8ChPL9yF G64kuQoNFNmcXwTmKCBoACQctxfMj4Bhpg+YoGVgfjFUO0E8bQPHdrP67YA+E8kuGeoK 6NQtf5arCezvaRNT0j2cFf25KyDsupH3wk7A3FTjfUJkAe0bH/QeXb3OjRopZXGAu8l2 nViJQ2BpyoFv8j0cv0VZ0Rs7SnLkj57qJgruUK8hdunwK1Se6dSwFw49uHVgsEAhepjG 4NiDJzQfj2gtf2JbDbJaLIWDzBpjQgHOB8z1NmV6LxHv6de5t15hRn2CVPLkKoIhkrFg s1LQ== 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=5mJlL/t+ozUtBhJCFdxYpng+Ff1pUYw/yo8QejCackc=; b=SJWf05Jfj0xj3yz0fyn+SfNwQuorg+qAa3LrJvczK+xW/+K/OAw8712PUZzKaLb373 gAQ69WonO4nGTE3rn3wuVZhJ8oCi5ua7f9HuR4q24Q4MOOFCN/VUbRQIEZP6jwcdxcd3 QC7UNxFbX4/0UxC1paYhv+UGjGTVJLHk7P8jo1Go2Q593M+VZayHNSM6HVUMxxSduVaJ ajdP2djK4Co3+wnMn5a2qcsFB5SkXahFk7OlSoFegMIDllbP4FAL7Dcw5ffYn9/ZqXRR 0oO5+EdtehMtSzfPEj51qykr1NjPVoHv/8O6zUTLSteh0wJQCn5gICBClSiVCHjcMVZx 63rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=K3urevTc; 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 ay5-v6si4227649plb.459.2018.05.16.23.21.01; Wed, 16 May 2018 23:21:02 -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=K3urevTc; 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 S1752485AbeEQGUf (ORCPT + 29 others); Thu, 17 May 2018 02:20:35 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26311 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752380AbeEQGT7 (ORCPT ); Thu, 17 May 2018 02:19:59 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUK002841; Thu, 17 May 2018 15:17:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUK002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537880; bh=5mJlL/t+ozUtBhJCFdxYpng+Ff1pUYw/yo8QejCackc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K3urevTckZmHPz7VU07K3hYm0IQtc4UP/5dPvXZ15UJWOEIVx1KItFvDvgCR/3/Pz +clIgiJEMXPg+uDTaOxwvxBVwgskKyfFBa7ChjhCmq+hS4FhCleXP5Y8/CH9jwlJnJ 3PzGycX/w83+CjNkMGFOul1NwRmNShk9PhdeR0IziM3k1OAmD/WfwFr9W0g0kuHiPA 8e8/NZ0PMNRcP4myKCnTkiy5VZKswtU2tlhayB9h850eQoGW8axeI7tbSz31gk/HkK VxkJoyNEhMcJQoBuZpxLUqTQ7nDxGEnzMeDnNtZXmGB9XmIawEVf0b4u2AAfDN2YPa cVG6SPfaHbI+g== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 22/31] kconfig: add basic helper macros to scripts/Kconfig.include Date: Thu, 17 May 2018 15:17:01 +0900 Message-Id: <1526537830-22606-23-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - source scripts/Kconfig.include from arch/x86/um/Kconfig since UML is special - Use { $(1); } for 'success' macro for better performance - Use -E instead of -c for 'cc-option' macro for better performance - Add 'if-success' macro Changes in v3: - Move helpers to scripts/Kconfig.include Changes in v2: None Kconfig | 2 ++ MAINTAINERS | 1 + arch/x86/um/Kconfig | 2 ++ scripts/Kconfig.include | 24 ++++++++++++++++++++++++ 4 files changed, 29 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 b7d7ae61..1667cee 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7634,6 +7634,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/arch/x86/um/Kconfig b/arch/x86/um/Kconfig index a992f8e..9d529f2 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -3,6 +3,8 @@ mainmenu "User Mode Linux/$(SUBARCH) $(KERNELVERSION) Kernel Configuration" comment "Compiler: $(CC_VERSION_TEXT)" +source "scripts/Kconfig.include" + source "arch/um/Kconfig.common" menu "UML-specific options" diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include new file mode 100644 index 0000000..b1502f4 --- /dev/null +++ b/scripts/Kconfig.include @@ -0,0 +1,24 @@ +# Kconfig helper macros + +# Convenient variables +comma := , +quote := " +squote := ' +empty := +space := $(empty) $(empty) + +# $(if-success,,,) +# if exits with 0, otherwise. +if-success = $(shell, { $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") + +# $(success,) +# y if exits with 0, n otherwise +success = $(if-success, $(1),y,n) + +# $(cc-option,) +# y if the compiler supports , n otherwise +cc-option = $(success, $(CC) -Werror $(1) -E -x c /dev/null -o /dev/null) + +# $(ld-option,) +# y if the linker supports , n otherwise +ld-option = $(success, $(LD) -v $(1)) From patchwork Thu May 17 06:17:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136100 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1879439lji; Wed, 16 May 2018 23:21:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpqARWyrgj9UWbWYbdIcP6Xvx3QkQAaUn27BN62IYjTQ0zu0s/lAK53sBfmhLlgbZ4DodGt X-Received: by 2002:a17:902:9689:: with SMTP id n9-v6mr3863382plp.363.1526538094712; Wed, 16 May 2018 23:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538094; cv=none; d=google.com; s=arc-20160816; b=PltK0KzkRSG54F7Hp5fFOVOWCN0gZoa/UVVSXlPra5lpSLyEJUXnXCyepeZceWQ/pR tQlwBsAT4uqWQrs6IeK/BXN7VShfUrI6n1LactCSUvICDMQNeEVlg+0AJVHOodawpO5/ BO109fc11iQZ7200ZIr9sJgJSDI4izbrpLUKDrw+F/pEp0LL06GkI/PajYrfYLlTtu4/ 1GChuYm9FlOFFT/3TNyesAKWCMF6nVeikhPhPVDkzl/f9dMsN9MiFFSiDre5oARAdd7P cq00paD6QA/FwXDkORHWr/MiqzqUh518napw3xsJYyRijRzdjEet/ZNb7NuM0ryMHaCO fjPw== 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=0Vp4I9imvjnl+StrNfLDlk/JuTyrsJ9hJ/yxXgHqcEM=; b=Ns+Hs1XCiBpHyzXUCOwc9SAiCuLFEnVqjGnaagr3wV3KLJbfie0eKqfGCb/uroPzTf ojp7LyTX7xadhIG+mbhtGvszl1aZxmAiigOl6sMjcM6h2u8zDxHTEITl3bP2L5vNlDFu OZjFNruSxcW5kjzaKh38TPtB5EyO65X7POVyYjSLKGLD8FqQAAos1GxPEV1D4tmlaFbp aG4Z9f9X7btH7fFbV4X2Wt+5wGlzNJwePrpAvXX8l6vEJF+c6el2Tw01mKHI29mLsBWq nXshetV8bpMQMAxkSjPyHmbRBiLFp6mVopm2vti9Zyklj78o5ugTTi6QyJMPl2APDAyg o2KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=xllhKAt3; 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 j5-v6si3592110pgt.449.2018.05.16.23.21.34; Wed, 16 May 2018 23:21:34 -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=xllhKAt3; 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 S1752529AbeEQGVb (ORCPT + 29 others); Thu, 17 May 2018 02:21:31 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26234 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbeEQGT5 (ORCPT ); Thu, 17 May 2018 02:19:57 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUL002841; Thu, 17 May 2018 15:18:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUL002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537881; bh=0Vp4I9imvjnl+StrNfLDlk/JuTyrsJ9hJ/yxXgHqcEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xllhKAt33R97+u4Gl2PPZUWNT4ut7unk188wiW/LiAFpTwCTu01HxPGsgwLPve0rv Xhu2d0OOBze6IZGG/vjeMi2SgWVtz6MrSKFhLAnghHKzLiuBu6Psp9JAoZYhPxkhgN Y/25wxJsIjtX+f45T1UzhidvuMzlwYBi8EuYbZfhrPBJZJ2s1wSHFPuF3AWjLJCDw1 Wi4q7NaX3fKWnyWXyyzt+Szj3oMjRrz3uKuHGcXAY+1kZ1jPWFPX0yWLEsOlkL+nto I9VU+APSnoELukpaYn9Odr2czGnmopZljAXsRg2GR7wNYWXZdkCyTna2A9QEL+ZQQo Cl53UukyDN7VA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 23/31] stack-protector: test compiler capability in Kconfig and drop AUTO mode Date: Thu, 17 May 2018 15:17:02 +0900 Message-Id: <1526537830-22606-24-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Acked-by: Kees Cook diff --git a/Makefile b/Makefile index 7529825..12c222d 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,) @@ -1099,7 +1055,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 @@ -1125,43 +1081,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 75dd23a..ca32950 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -539,13 +539,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 @@ -555,14 +558,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. @@ -574,7 +569,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: @@ -592,14 +590,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 2236505..8e9eb75 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -126,7 +126,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 @@ -345,6 +345,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 Thu May 17 06:17:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136096 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1878509lji; Wed, 16 May 2018 23:20:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqRcUFz9acN6zXEDCk0Qvgbup2Dr3Yw+nj//KIvEkMn+10z+hrlx2osSDHVAn8kor//MKFY X-Received: by 2002:a63:2b46:: with SMTP id r67-v6mr3074741pgr.89.1526538041500; Wed, 16 May 2018 23:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538041; cv=none; d=google.com; s=arc-20160816; b=ZKtXzax73lg8+MFOVj5X8gTi6UpwQX4v/hIqFQFJXHXID65PSI7EjZ2c1DAUDuBjPV ai7tzQ9YrCToaj2Erusp/gZVy98+M9B2Qno3AnYUvVyHj1UIubQxvG0hrrzGGpwG4QgG J5FT4h1pwuJUH4pAhe9TaTYZTxjYlXTPSChfwqtYcW2g4LZf7rksMQv/p/dI02eLX1pS 9rkOY8++mxcxyT2l25ZFboa+4AkK66x8/rVOG7JnnvkZV0fzhCCvPw5caSyu41/7CsEe 6OtJUb10EmJm81bpHWs6SLhq6sJRTvyXps6BS6BTdmYRiw76qB4ERu7UDDCZKsQ2s7D8 LcpA== 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=svCMWd1eJifwrbrp8GDwRGkS3dcb1kFY41kde3D/Hv0=; b=WWhpNiaKZVJ1qk3V53Dxfx5qMrlur1CgA87yFRZKxSbcrwfXJhMazJ3d67FgYEJ3JN vKZt5KUGA8X98sQZiGqutUS/w0AFJUXyqGXzdRQ3o6tojI5JshC5ZQUYD4O81f+kw1Qu xolquJjND885bCbBTDw0lfnDMuu2X9F5RSm2d+750Ax/9zIWyNsM36l4vcCX0aPZaAgJ JmB/QVRyk0Hm1h6U+yVYYqr0NnkMCwexU2nB5wfDpt+oawJ82VZXHBqDQbyBjj1dSSLR rc4MwtrygSXf7vSq0XT1+4rB2IqO7AwFb3cnwjXVyK/vyK5DNeElEJbhc47TyDJ9GIE0 YsfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=nZ8kZdMR; 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 b10-v6si4433280pla.282.2018.05.16.23.20.41; Wed, 16 May 2018 23:20:41 -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=nZ8kZdMR; 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 S1752516AbeEQGUh (ORCPT + 29 others); Thu, 17 May 2018 02:20:37 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26308 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbeEQGT7 (ORCPT ); Thu, 17 May 2018 02:19:59 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUM002841; Thu, 17 May 2018 15:18:01 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUM002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537882; bh=svCMWd1eJifwrbrp8GDwRGkS3dcb1kFY41kde3D/Hv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZ8kZdMR1THYVzfecX++ogKUrJ+L5SDWTYbLDwLjnwkxk5MPoe3U3VWFEk+HulCrr M9tz+e3jl5B9l6osU9JikhZS9BlzTC9+8NTvrD+QX0x8Ta2AMxw3UxhDOjvF/t0Ats UOs10Nn2IVuLVKki8l5pKGXDed7GnC3TpBB+cXFs7UqEIzNLlO9b9CANoo+Erdnwmi XIGulccpsD/QQLr1yqBDQvptEyMRQTWonW38Nm+92ZPffP+ufHD/qXxnLcGgLQJJSo ygIYLroY6N3/Ow5zrmrYr1uQCUeCp3+oAc2MJf+PYQ8MZeaa+sNUmbhUK0oexEkC2R PmgEg/EAiI31Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 24/31] kconfig: add CC_IS_GCC and GCC_VERSION Date: Thu, 17 May 2018 15:17:03 +0900 Message-Id: <1526537830-22606-25-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 >= 40800 help This feature requires GCC 4.8 or newer. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v4: None 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 66f0463..c6ac856 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 Thu May 17 06:17:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136101 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1879811lji; Wed, 16 May 2018 23:22:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqON38GBSXzye73A51NSEV+CeOVons/9jnXSrRa/SK/q9V7X0LVTLtsUlkBiOWCjc4QQTqD X-Received: by 2002:a17:902:bd84:: with SMTP id q4-v6mr4066576pls.254.1526538122285; Wed, 16 May 2018 23:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538122; cv=none; d=google.com; s=arc-20160816; b=AEc04UVVBvZcuxXQeavD0qoPt1oHoupqcEyNUuvmf6R53xCD9OKxTruKyEIbaraTLm 00lguqAgshXgsGifzQqoHfsI6TiVcVmG7H9lxXWNEJDql6s7SG619Yf4nU+ydGWplTzX X6li4eDNDs1S8FKalQMlZ3s3kjGwHAKl7+caIXEBk0Ee06FcyctijnTAwmAUxVmP4OaO DQSU67VfP3qrnvhw9GKrBMfvh+52U0op/4f7T2fvSODXRBMbPnAWkd/cl6PX0AFwuZFN b7WfS3PXWjPcM5J43oQSxPjLV060rAvvKnzWGNnf7rieYrndJ3RmDF2IvaeOrYXvhW5G 0E6A== 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=pS+3Y6tL7lsg15LY3hyDjKNMmofohNoh9cls+dafNuI=; b=NdjQQ1f0iDOo+FPYslQXwLpG2ZxwRQjWBK2Oi43/a6RDnzsf3zbuHbSz0J5gjCAnz9 YDrT3iVRJMC3VHjOiUI4sghi/iqUvn8T1eqwUX743sL9dwKhlrxl9kO7xXV7f12nrAKr oY9jHKTVijOIhXyPFsDY7lfP43JzBUGxj/ThC9DqbyYd0m9K8UL548636GjICTuy8Msm KyjUSgHy1ZmHBfPA6ICgNWep9SI4L48tdfGmMkQZiQhtXZVzYqG+J2+pE3XqlvNcm79w m7zkW+N9AszAgSTDU9SQhk4L1XOJDKxMnzd9ogMPfbmdLfLp5fBgx6qlHKQRe/70SWQn BYyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=2sOKnPuD; 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 u62-v6si3402108pgc.180.2018.05.16.23.22.01; Wed, 16 May 2018 23:22:02 -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=2sOKnPuD; 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 S1752400AbeEQGVa (ORCPT + 29 others); Thu, 17 May 2018 02:21:30 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26235 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752348AbeEQGT5 (ORCPT ); Thu, 17 May 2018 02:19:57 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUN002841; Thu, 17 May 2018 15:18:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUN002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537883; bh=pS+3Y6tL7lsg15LY3hyDjKNMmofohNoh9cls+dafNuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2sOKnPuDchlf3BngORWQN5PBCnoFsahgibarF/6RPZPQSGnuK7iIBltCkWrrTyZtb 4SStrqrfzHOBmZvfKtdRSmnbEaVDPcPIKAmzMCKp49F1QvBaI2nwvTYOE3Kk5FQ79h MFEFYjk8bRbTMC6OAHZ9a7k4sADqpYvI19gSaJ49dHT9+jM4SeSwik22kJ4hxEzWQs l/iTYFyya29G0HYDohBNq07iRvMm/CQXVIu4sAmMAsP/+MXiBqvTQbx/UlN9OQD0S4 Etan2Lllq++AmANhqyGfMhKrxrCm/PQNwBwspbvcsuQjBrj6oLZHi2r0K3jSvGxhSM 8y3s5wF6iR4NQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 25/31] kconfig: add CC_IS_CLANG and CLANG_VERSION Date: Thu, 17 May 2018 15:17:04 +0900 Message-Id: <1526537830-22606-26-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 c6ac856..3aeb37a 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 Thu May 17 06:17:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136109 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1882766lji; Wed, 16 May 2018 23:25:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq+rlwCGDmKMGMrx2rYKmcvV979peEk1H34obb3E9Ei4u5ZOjHfJTsZcmQe4a3kUj7PMnfT X-Received: by 2002:a17:902:a4:: with SMTP id a33-v6mr3936334pla.346.1526538340756; Wed, 16 May 2018 23:25:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538340; cv=none; d=google.com; s=arc-20160816; b=ktkPzQ/MqtIiZVM7hYTD8TH9aiAWZG0RfY37M8Esbvn2MJUR2ltiHVyjK8TTseRx3w FUzV5BeqaYsDH2q90U4nzz5/TxqmCEtaw0JWik0MhUNcLTtGDHuTCli2heY5TdBeBGR7 YLGerrE5tuLSbbiQgKh59zm6Ks/p6akOZRvLhzqX49rNA9ZaSHNDEGvbZHewd9ZP6/oQ m/7LlBt6P7C8JvyshtR0+SbkfgqmM5LU5TKHgrwfumGtjTUVDAPAmP/d0KVgNSiVTeFl ClbBSg1DQgJFyzuVW+cZjx+pxdjhNEtm7fKj0KXRQUFrqw3MGIM2pQVyBRH+5/Rlb4NM 8jDA== 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=ehbSBriZlrpst+Z7nyiIz+ZrCm8J63ZOc5Y+RuSZkoc=; b=qLjLoQVuyfnCbIsZpsbOF+7sjVOskLTjC0V/Urp9/WmcWO2RQVEyHcTc8QQ6nzkIF1 XjKgF49CXEeLHyjVmTUP3fzhEJVJkGKsBTGsbfzKQO7AUiie/u+7Xy65n6FvkqmUSIhW IfGiZptOKcusBEByQslLf2eaLYG8VR8SYxzJJm+Rsz7ctkYn6VjqKB4T7OlsZi2ZW0dr jBquUQ4LNFW5WCxM8dF1sthoXnlWGiG2boEkVjqZy8/4fWzHDgo0MJ4MzkXcx3CLMufO JqItMvFVPbeUvXdohPf+t6k2pVuV1olXj/Q8JL4SYLpAfVvBFUJRnEZr/s1hUvPwQl3+ F0zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=wtKUkMQ0; 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 g11-v6si4571991pfk.187.2018.05.16.23.25.40; Wed, 16 May 2018 23:25: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=wtKUkMQ0; 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 S1752438AbeEQGZi (ORCPT + 29 others); Thu, 17 May 2018 02:25:38 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24998 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751698AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUO002841; Thu, 17 May 2018 15:18:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUO002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537884; bh=ehbSBriZlrpst+Z7nyiIz+ZrCm8J63ZOc5Y+RuSZkoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wtKUkMQ0heHWH2opm6x7jy0dMEzvN3WnSN6nPtv9fnXcqNJjmjIhx5giAbE5jhw+P NvN5+e0OQ/VLkezUxgGnVHjLxk8gRG16prXcoVTf9Njg5/5CPSHMaHARMS5hZIL2ME H7EeS/vGAVq5P7pjSPSn2pPzuXoqPLnkraXoiBiajR7Uf78xBUnuIoFe852eHngXP9 XKN8S91Lzxmo3IRicg0T3CafOASRg8qVM8p7tnmsvM/kgaaEbS0ioOQZmDhhhXOfyn bbyynVLFnbcC107sGP3cnOG0to/qhHnLGNqUzb4ZQlALFrYPg1/b6s8iEx36w7ID2Z yk+Jx2aZdCVmg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 26/31] gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT Date: Thu, 17 May 2018 15:17:05 +0900 Message-Id: <1526537830-22606-27-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Thu May 17 06:17:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136091 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877608lji; Wed, 16 May 2018 23:19:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrwa0htIKFnXHROL0JGmvMGAoh6Q3JbORMA0kO7OabYKgIPaIlRbaM9w96OMALb1xSPiRBS X-Received: by 2002:a62:c103:: with SMTP id i3-v6mr3988390pfg.148.1526537975768; Wed, 16 May 2018 23:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526537975; cv=none; d=google.com; s=arc-20160816; b=g/Byh3Hcs0vf70R95/hAjYFkXo7+/1YCsrmah7zWwkMUIfaUF91CYDlYFRq9AX+YkS JDb21Ia6wlSSaEUu1m6FMYmH7r26OErLImQpcOX72gBR8VVC80/yQRhgWr2TL0neF31J 0embD9L/wUo3txKGW30gxZOVy9972Opryj5W108xObVE+gwCvdYDH6B9yWduCbQQNiDe Riy8nCuV1XIb9kvzb2zccCCD8eUrMdBREHnqX0ZDTeuDgpTGWWPEFR01eVEb9ZhQr9Fc 8ggyi4H80y8zl2r0uNGzkCXWcq4vAlCNC8t4FnF5G/qEFDB2TIPrzJXA+8DFswnUyuY8 0QYA== 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=7pABYw1WB6Eb6gh2Lj5g9j7I8sOuxtbCdlbgkCPCzx4=; b=mufEonGLmkTR7Uixl1Ea33ikhh+WWjZiYsdWxbewAlCAf+z4EViprRHKUc6Ccv4ye9 4g5JgOmVTByWe+8q2chITc0zXStMEf9r2/oYIuw+xxRiysMXYczZjC6hIt6qIfy6N9MY 3NUMDI2q3vAo+ryTBBEZ89Y8ym+DLWCnv7N0dMR8tOY78zhDvQPhgEhhKbnksO66741Y L1tx5DJjCBYR1PhyoOFojU+MEZ/zatOEAi/tnltZpNTqDzpVBl6WFpJ95qNdFp9j1AUp HkGyp2LhxRus25KyyZjZM2XPw357kVjWqIR4TwXOXvpdtRgKcvTQ8BrWQlsaDzy9rJTn 0sCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=1oSSsjAS; 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 g11-v6si4561765pfk.187.2018.05.16.23.19.35; Wed, 16 May 2018 23:19: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=1oSSsjAS; 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 S1752226AbeEQGTV (ORCPT + 29 others); Thu, 17 May 2018 02:19:21 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24992 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750825AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUP002841; Thu, 17 May 2018 15:18:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUP002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537885; bh=7pABYw1WB6Eb6gh2Lj5g9j7I8sOuxtbCdlbgkCPCzx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1oSSsjAShI+FWyjrWF8sV4YJbe3V7GWXy1HcVJiRmCNrl6cGwJst1lYd+2LlDfn/U piZ+YJWYMBOyN48Hhc2Lx02JQTNzXSX14GwA7q7jyjq8wG/nfLswpmj7soJaQtNW1k jekdFX5dz5B3FMxiDndwxVR6JRrJq1v1idELTHoJRKpZBYF+JERlaM0iB3V0Jm2GH/ RB5tD5Y0+/bgQBSVHT42qXjkb9pDzMt+WkzS4feQ4Rxbd4tVvNCY35RLQIcaYvCSrv L02YXC45eCpX/dyQyySG2cX8CZSTYGTVK3fm1LLy59J4ds5u1KvuQkEmc4SljAUvFZ mxbIBPkh1cj2w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 27/31] kcov: test compiler capability in Kconfig and correct dependency Date: Thu, 17 May 2018 15:17:06 +0900 Message-Id: <1526537830-22606-28-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Reviewed-by: Kees Cook diff --git a/Makefile b/Makefile index 12c222d..b5c1301 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..bba2298 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 Thu May 17 06:17:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136093 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1877988lji; Wed, 16 May 2018 23:20:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoY4f3+pbl/L8gGjXs32qWzKtUcip+nqsoXMmEfVGuRfNAHUcPW3BH1eslFtF4BxpISqseK X-Received: by 2002:a63:ae0b:: with SMTP id q11-v6mr3200483pgf.109.1526538003283; Wed, 16 May 2018 23:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538003; cv=none; d=google.com; s=arc-20160816; b=AoEqfF35ZzTuYABK9q491ejI2PU0SZa18qwo7ib1T2PoLiYv7RZ34bJNgXAL79DvLD o3wMo+d6v7RiqdTvtkyvorhQLU8kv3hTduBRR4gJOz+anBan8il++3jT+/dk3sRx/hqE JUknnH0QuKQOpbjSirwEaQBBCdGbiXjKrqB6PhDgngvPBPdIW4EaNgF0ZqU3S15Xh5AI thPAi86UQxs9FJTfCBTQk/EqzMBG9PWevzRmOm0wp5XqEilefUmQfpa1u2k4d85Fa+CT 3OOAExw2dq8+Z2FkYjd7TTzDN4fKbJ7SSb0c9N1qS6TEZTIR4dWWaU/LYKXX8mfPwLTb nDDw== 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=IuhIJa9blMCnxxz36aY4jxSrQFLyzf42D25Bc+qOlGc=; b=qy6rfgE5FvlNgCgtIPl8bbcCUPY3h8rsjbMUZvDsr41+x8yOYBWvC2gK8oWEiPzsE7 SFGZdlE8cTBlBMRZfyIxrM/kdKFG/SER7T7MhBYhRaXKjdCO1rkzrRNW/Rj6jS07K3zu l3ufkDVq4Yqmz6FGCM4UujBIjTY1P39nVZwgkAj9IGWKyvhnlZKw9Leo2xvfXT+yQnyp JynyhAsgm0COILJbRIltjj1r2seYwvn01HS0EDpBPc3XSP/SLK2fx7hWSTrdrVxLbyjq 8ghJnVyNQF3VCovWuiteq1pSeDHgFuBDshbWqkx1otTUdKC2tOts/5n6WdmPdIr6a7Bu vsfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=IM/la3o+; 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 z8-v6si3433208pgc.693.2018.05.16.23.20.03; Wed, 16 May 2018 23:20: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=IM/la3o+; 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 S1752403AbeEQGUA (ORCPT + 29 others); Thu, 17 May 2018 02:20:00 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26250 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752349AbeEQGT5 (ORCPT ); Thu, 17 May 2018 02:19:57 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUQ002841; Thu, 17 May 2018 15:18:05 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUQ002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537886; bh=IuhIJa9blMCnxxz36aY4jxSrQFLyzf42D25Bc+qOlGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IM/la3o+GzAJD3G/jhCTOYBSD8AXtOOOdNu0ohti+YfYJNejSc9Lv7I1hPZ9kikXz DhbOZvsNnczXUlqO1zgkRTvJmuAofr4ar4w04UZO20IajxUyGCbehcH6ajK8Zx2NiG 7GPnt3B5iS9g/KRgj6829vMl9idtQKKSMfoZyvES8y8LpmsJDUKMfMJmD9UfjUeQwz baOLoj8B0PXtfC+clvMMPA11FyFdcA4UfSSo1YDUl785C3OBBKNVRYtDv+xuVLjwXj 9aognsbswE6ZUVA2UIPZ50hSCTB7l54EtD2/76mJinEt3A44Gw7Hn05DF1tB/GgjMl RQfxqUClsJzzA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 28/31] gcc-plugins: move GCC version check for PowerPC to Kconfig Date: Thu, 17 May 2018 15:17:07 +0900 Message-Id: <1526537830-22606-29-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 Reviewed-by: Kees Cook diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index c32a181..17e53e6 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 Thu May 17 06:17:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136106 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881716lji; Wed, 16 May 2018 23:24:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpPSJi9+LVqbPAfKNNB+kyYbv/MhdrTvezpoYXBJPJcYRwg8ncGtVf9hpOdY1Qzbv/aF8sU X-Received: by 2002:a62:1a4e:: with SMTP id a75-v6mr3998747pfa.84.1526538264124; Wed, 16 May 2018 23:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538264; cv=none; d=google.com; s=arc-20160816; b=0I+qbY1o9O5SRkVhAcSWmZSeF/VJ76P5Z03wuCmjoTBNOWBPqtI3y8qTcZkZWSZT7u qTqL9q+bGb1hADVXbEFeWgYylbowMbJvl1I2QcVuYIfNnh0YYOH47lGXZ7qpYAsMP4Vq 7YaldqiLrEheONRr3otmA1DM1fB+XaznE1msMPblE5zNgejx0QdaVl9RuriG6AK8B/oy A+yn6YE1TqVcinlaizJW+hqIVeLm7FTRJf/Fs5APY3fRDVOBjRQat+WgELGJ/wqm8a1t j2I9/FvfdhJQdLcrvbanRqTaO1+t+gpiqfr6K8wgmuw16+HctTUjWWx+XfKgtlHn5oSb IQeA== 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=wNFW1Z+0klFAUFJPj7yJ+J4PFfA0+0tObFRZxXspDLs=; b=z8IzU7ahkdbQMFoQ/1aiSdmzOTDTVw1YQLu93NuSAj1cgapWJ7B8sEjI/IgqYrkY9A t6chaYlIwP/9Uniz7Fjv1fj/tFcz1eGiFzHOqPhPu2n9w4KOYzjpVyvBYsug0UPNJx8j TqvOOnE113KEShPMqcBPR4AzWq70v/3eDi8Q3D+d7Dgnl6EUHjSgH+SaKdu7Nff9hWau yB2VaW5HlzIJvjLebCRv8N24+xjvgZzZOKnMZVQ9NV2MyEJGEn0nRW0pV9gdTCBMWoEy O0qHFudYXKs4HWYJAjbA7XHVDeV1AH0GRqckcZghHzm1tLqtsNmISFidC+MKTlNOlPtA mplQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=tatComYI; 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 32-v6si3998931plc.252.2018.05.16.23.24.23; Wed, 16 May 2018 23:24:24 -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=tatComYI; 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 S1752636AbeEQGYW (ORCPT + 29 others); Thu, 17 May 2018 02:24:22 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24999 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752146AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUR002841; Thu, 17 May 2018 15:18:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUR002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537887; bh=wNFW1Z+0klFAUFJPj7yJ+J4PFfA0+0tObFRZxXspDLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tatComYIsIrAXiTeUZ7X61ktn3e+1N0cnHX89Pu4Url+1VhiOqDja8BYuASnKNmYM asGDcDFm3uusKQhpTABIHnk6yng06ksHTO810RstZXkczGIgcU+uIizlbEbvsGUNpm WCOnLMlLSJEJxuyO5ac65u9pG68/tbBgGpMJSV4JjlheHooKZAX92sWwAeThFfhnIF ERz3Fp0XexWqg1LjA3/f1vSjCmJb2yCWgShCiRZnknw4aQBJX4w8FUK5y3uo2PY5+r qHYAvKg8xn6BYrsu8t9PpCy8aLC2ov4kEInGaNUvkG6kbXr+JtI4DgD5zGnp11TmGU 9mXCVAfGnaYFw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 29/31] gcc-plugins: test plugin support in Kconfig and clean up Makefile Date: Thu, 17 May 2018 15:17:08 +0900 Message-Id: <1526537830-22606-30-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - Use if-success macro for clean-up 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 Acked-by: Kees Cook diff --git a/arch/Kconfig b/arch/Kconfig index ca32950..70f585f 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 := $(if-success, [ $(gcc-version) -ge 40800 ],$(HOSTCXX),$(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 b1502f4..bfecf61 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -22,3 +22,6 @@ cc-option = $(success, $(CC) -Werror $(1) -E -x c /dev/null -o /dev/null) # $(ld-option,) # y if the linker supports , 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 Thu May 17 06:17:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136099 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1879217lji; Wed, 16 May 2018 23:21:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrGtH/tYrBLH5jSKCuYQluyPKhaf/+YCNWAcaCnrFRsKiY+MOdEk4bwKJ0ljy0Y9f1sKhFe X-Received: by 2002:a17:902:1023:: with SMTP id b32-v6mr3945833pla.145.1526538077734; Wed, 16 May 2018 23:21:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538077; cv=none; d=google.com; s=arc-20160816; b=ig5ANIUDR5NXzN5GAsqAk8NEUR+hqEECVCZ+u5bBCBc3k+ED+uSrz/+EV2vda0hG5+ SJ8VHuGIc2AeCez2XNr+dHTsSH/m4OjED71jC/cGaLwjtRYB2dM2vmcAYyTSWcJgzkDs WOMU8txbzETJxBgdexbjgOr/Iepy1QAZg8Xoci9h1DeRU6kUqqqRx8osEPN6u4e8LkUt vnV33jL3O5YDwW+MUK/FBgKw5NIXAsrOehexvRZfdcR+T/0xXTP0ngebDHAXCp8m7FE7 Ap3EamU3wzD1fO3tgugNnzsa/cu+E2ODRzwPnusdmcxsPf0m4YwxStqioDWxqEygA/lD TNVg== 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=SHaC8/sgCayhpXeqxZOvoeMYH8fcS4tPhIe4qhRh/l8=; b=Dxp/K0HHnm7k83xtWYxbgr5vEVZT5iSHH1fDUyGAnwRhYniQTpRPwl9tbddV9wPiqw NxKGOehBnDq05+LMqSw7avQ922GlC/wDqgcUlrO3nlQ0QD4dErF8MdFD+mCPYFavgQVp yrhd2xpc0C34VUUuHohW9CBNlPprN+IO6OGKRA5EE9Rg1cmMAguvzUcvmjscqcjeZo1X cL/ouqtRiB8iTUTcUmuz8EvXxgCtQvmuBMjNlFPcyJ7k5Iw7EKLT50Ij95OfEnhiVLLp LiV5w5VXPOB8flfh6gTCrG9vJ+SYbKOt/s7j5XgK9R41Ga9L3Ct2/WThZw3R0EK+KQ98 4ouA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=YbkvCOZi; 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 ay5-v6si4227649plb.459.2018.05.16.23.21.17; Wed, 16 May 2018 23:21:17 -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=YbkvCOZi; 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 S1752377AbeEQGT6 (ORCPT + 29 others); Thu, 17 May 2018 02:19:58 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25144 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176AbeEQGTU (ORCPT ); Thu, 17 May 2018 02:19:20 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUS002841; Thu, 17 May 2018 15:18:07 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUS002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537888; bh=SHaC8/sgCayhpXeqxZOvoeMYH8fcS4tPhIe4qhRh/l8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YbkvCOZircSAu2cBNE/aUsSaXzXHBhWkeo4tKWDY+TnJDRQGAj5SBO+elc8KfHm+4 gHSXbIrMmcSxEjkIlHUBOtwVJ2rCLgnx2PGE7SaHE4JW/Z7c6F2pxX10lg7j0/qYJs OsZPj2jU2hqmfOfaT7sBYrOufZMuuwhJHkbnePee1hL/Mv0kQMAh2pXt9umzgDah6N yZ69GeUCDJ6x4Dgle1JB8unTaxHPutOA4HunHGDulZNLgUvtqFVohOR7+dxb3ChY8M 2Y03uo/OUboXt3NoTCv/5Y8JNEOZ2GJx/ete6Ff2G8hXHnVLTe6wucmnLgiK88tuqQ MbY6XiG+FtReg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 30/31] gcc-plugins: allow to enable GCC_PLUGINS for COMPILE_TEST Date: Thu, 17 May 2018 15:17:09 +0900 Message-Id: <1526537830-22606-31-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None Changes in v3: - Add comment about reason Changes in v2: None arch/Kconfig | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 Acked-by: Kees Cook diff --git a/arch/Kconfig b/arch/Kconfig index 70f585f..6e8f0cf 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 @@ -497,7 +496,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 @@ -537,7 +536,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 Thu May 17 06:17: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: 136097 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1878652lji; Wed, 16 May 2018 23:20:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoEuThy6mNi0XZfdv5PfUvqAkavhzNhUXIN51Agg43lKDEWaQNC5IgW287YISsY+Iox7jCV X-Received: by 2002:a62:4c53:: with SMTP id z80-v6mr4005367pfa.181.1526538049815; Wed, 16 May 2018 23:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538049; cv=none; d=google.com; s=arc-20160816; b=TNEVEAZViOQpis6SgQRVdq7LZ9NkhgsOk01hO/LJd+SD8YH7kv92kSI6l6nVAFWq9n wgJVFoLpVvAupynacy8u9EfHjp9q2xbkBJ+QTAOmlpVYwQtIv2U0Ytt7dkIm6x1DXkGx 48ZRbNIqNwzSBafq5hP3irrW+CI8l8nwZ3+D/Z/dwpdG3FZ2/k8muPel5Ore83Wqh9hG zYBDNClTWRNJUNBaJem+hHx/uk4bfveF/fSs8beA00Hz8Cm8N3wt2gK9lKqY1428u7Wg puI7JZBmc1mwA1NpHDZK2thuiw6UBCwRUqDC+1H5Sox0WsK4DrDh4VuM85srRXLI9rwt hZrA== 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=2cFpIapoLIq5b2QBiH0yJANk6wpAo4imNZSnLqFfnnw=; b=tfhK+Kf6vssvQAM6DpnjUl61n/x2WBjnov9d+lWu4oSRfPtJXx/Qu6Zyfq6tbDIYko Vb3Ns9GpvO7GSwRjMLbRza1RpdulpLlDuWDcUH2OSzzKR+dk0Sz9FT6P7M6WeWWrFIiH cvfQxDSA1LVa6ADEGQEbT86YwXm2Okf6iKvrFzYswm32Z8z/DF/MFmb0sKHgQ0pxyhZD vX7YEAmUe+vK0M+QpmeNCRlOzs/CLRCxFdZEzcIvQsbQ5JXmUPYWl33RbLpNICLen/+W OXMsBszMKM68agNNr/m3NxGN9JM6sVkYegCs/hMj8zDg7Ce/1hg9yq4c64hZqqMI7YxS gW/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VWH6MmGT; 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 b10-v6si4433280pla.282.2018.05.16.23.20.49; Wed, 16 May 2018 23:20:49 -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=VWH6MmGT; 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 S1752505AbeEQGUg (ORCPT + 29 others); Thu, 17 May 2018 02:20:36 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:26312 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752378AbeEQGT7 (ORCPT ); Thu, 17 May 2018 02:19:59 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUT002841; Thu, 17 May 2018 15:18:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUT002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537889; bh=2cFpIapoLIq5b2QBiH0yJANk6wpAo4imNZSnLqFfnnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VWH6MmGTP2po+dAeb00pV+djM2LUiPWC8iyLQQsZAEPyOQCTKS6PUJ3vACoGCYjU5 JM2nnFgPKwBsWkTzwsFuztAYbzJ/oNYIfpqHB/R1IzzvIzoUcs7C8FOldqb7dKc4aF 270/P2t5FxUAxU521NFk8dKe3dP5pEWYEcKBx6SYheC+GWswCkQELBVFbCA6LBbS2u +YF+Qq+WFSKMOt5Qf3nxkCzq15nv6t8B4qpacTLegTuVoFy3l2ukLzU0qKco4DoB8o mJAPSCWhMZ8ZnRdoy/gkdntABMAaS2BGhuRz5Vjs+EDhfRfJYYs8HxPvfYQAKT1ovX xXA4nb9BVFh7A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 31/31] arm64: move GCC version check for ARCH_SUPPORTS_INT128 to Kconfig Date: Thu, 17 May 2018 15:17:10 +0900 Message-Id: <1526537830-22606-32-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: - Rebase Changes in v3: - Newly added Changes in v2: None arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) -- 2.7.4 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index eb2cf49..119b18e 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 || CC_IS_CLANG 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 87f7d2f..cefd1e9 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -56,12 +56,6 @@ KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) -ifeq ($(cc-name),clang) -KBUILD_CFLAGS += -DCONFIG_ARCH_SUPPORTS_INT128 -else -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128) -endif - ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__AARCH64EB__