From patchwork Mon May 28 09:21:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 137065 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2596774lji; Mon, 28 May 2018 02:30:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNYausoUniSWz/VE8gJiH03sZ4USjyl7L0sApgvHaVneD5Kc9qk9BYU4Vr2Jxo3xMNUyrF X-Received: by 2002:a17:902:20c9:: with SMTP id v9-v6mr12931808plg.206.1527499830151; Mon, 28 May 2018 02:30:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499830; cv=none; d=google.com; s=arc-20160816; b=u3jRf3qRQUPTUnOWmPpzmKiRpCdga/oWKvh6c4bQGp/2mpt9AY1+Zx6nNN8g8QI0d6 rpdbk7MPtTdLWyWyugVZaMO+Ar083m+ZaA3kARnRJWA75beAVqGUlzYMIbhWpqg5vaf7 CPIU64cdEzyNfJRLZXkojZy6t3ZNn/u/wxoYnnzjucPLAQBdrVzZ15MLKIn04KEf0o0D Iyob5jHwLL2x7Aj01zEI1ID5YC/eY7cfyaZ3LIOlRgs3K+5vEl3otyO2MeouJoLYc0Rm x/BHxzRCoUZRrcL40g2SalXzUrIM8u/+Cb8THBTptQhGuTRbS0ELP+moW0SHNlCPw6An mAJw== 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=uID5QwVz8O5eC4qs7omIna/BbDyuws8qjBNDHia+jKc=; b=z3Rbf/JwPlkKCjPuUSrR23G70008kYdr49mXD5Ip/gyx4tLhEJjoTHLzlHaIxSFbi/ Fhgk3MTdl9MgJbWzPQkTLPD6lx/GDchKGvqmSyp2bfz/sfZmgD3WHFRuPvKMQJdT2QCs WzuJ857A74+PsNnSb6fEprSTw0ttuLlfVb0wGqVateVDed5vuurnu8QCxu6060DhCnDO oimusLVPHFkzG2QB+xeT95cGmrQSKH2ajzrO+c5jxaOtjb9sBYT58Q7bz2PpyQ29zPV+ wcn6VV5NMzO90p2pIwnFj5mhiHbrn9ww4b4lBQDntprpMvo3mFhRLq5HXZEmfHU3ALei cSFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Z35n73Ux; 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 136-v6si5492350pgf.604.2018.05.28.02.30.29; Mon, 28 May 2018 02:30:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Z35n73Ux; 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 S932179AbeE1Ja1 (ORCPT + 30 others); Mon, 28 May 2018 05:30:27 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21545 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754278AbeE1JYO (ORCPT ); Mon, 28 May 2018 05:24:14 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInI027506; Mon, 28 May 2018 18:22:20 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInI027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499340; bh=uID5QwVz8O5eC4qs7omIna/BbDyuws8qjBNDHia+jKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z35n73UxDVdFdIMdWsyIs7/RRDNRLzToReHh/Hln5dJxq3v+z7KyBVFK6nCCdWVBo VJn2ACJqTv5/jHyrouQYL8gu5YEu5kPLveJ/I26DqLgYCWIi6lpDnukXWhDqLsxMcp tirHM8U+UwQI9vbfufsPl8S5n7ICm1K/FCWSLkPA5su2I8JX2o9693Uxj/Jc+9H2A3 BZCLv+ROi1glWk90PbXr1OqONM5OIMPAzY/pcdr88gcVGvCPPPDMKl9ja92ewy5s/F ry2m1qhIDS/BB+vWEy5lAMQbgs6ra1ZKkeG4G0PHWY15Ad7WX3mbxwGHpkfc8Czy/h HDc7WWEtUwmaA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 01/31] kbuild: remove kbuild cache Date: Mon, 28 May 2018 18:21:38 +0900 Message-Id: <1527499328-13213-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 56ba070..02202d3 100644 --- a/Makefile +++ b/Makefile @@ -504,7 +504,7 @@ KBUILD_CFLAGS += $(call cc-option,-fno-PIE) KBUILD_AFLAGS += $(call cc-option,-fno-PIE) # 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 @@ -807,7 +807,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 @@ -1625,7 +1625,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 Mon May 28 09:21:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 137067 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2597416lji; Mon, 28 May 2018 02:31:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq35rCeYYGMMdlEKiRyvI2aMiZwsYAgOJsMkYq18GhF10FVmIFOB7+CrDvL8skoC60joyit X-Received: by 2002:a17:902:7896:: with SMTP id q22-v6mr13046833pll.243.1527499872878; Mon, 28 May 2018 02:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499872; cv=none; d=google.com; s=arc-20160816; b=u0WPCv7OLr2x5DHpjlZ6w5qSLFXTHRAUxaIO4P1smExHv2XvKEJwVK0rwlZYVJ+Lc9 SVS5m0RC/lO/TgItdq3PWeR6wY8I3ZVwtWYgw/kEjQHm57SdgZgnR+sVGTJsBVIKH/bo iXC88DOMJ8DHrk6nisieC0dxs7zozpxfRDyDfH+xxbBRhpL360rtKTVAiUMKDYLbIccM DaDYVzJqE7gc84fvvWYjA2A9RPYzujo4gfSThOkWfyQt9RGoLabATfvBERAm3kXne95P EEICfl5hG9ZjAQ5k3kPYUbPn1OfDPSXpb31s5zRK4d0zTAQAxzXuB+6MvoBswAWn4Swc BpaA== 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=+mERXWOaTOmV7BBi3Br812M4paeN+QQdqw/nLvrJLJA=; b=Cpu/H+Jj0zfW5A8jfvseYwx4n9GHn3ED88/aK47uo2GyahhpNSMKGgVxT/a/9BCOcg Wa6Z6cV+Oi59u/IWUFgS9Ow2Hsa5AmHMizQpxlBEkHmKRMbwJdlJ+0GjWAT2HnBlCyd6 Nzm1pq/5l0fMegjPWqUEY/tUr9JqwmrgwBQ+nh5m49yyqbKQ3NpeDMBvGJaQoe0EEZyn zV6ftxM7phHBpfmGoJ6U0jy/AvsCM54Ea4ytTDTA/13oAhRtLo+DrpHYDcWisQiURMIu LZZ2wSTU0kFh6z9u1nHCPIXZfh30PBrAShG8jEJ4FLUxZqhkS8nkuUwRkRpxFwhSou7v DaWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=zBFiC56o; 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 f2-v6si30732615pli.569.2018.05.28.02.31.12; Mon, 28 May 2018 02:31: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=zBFiC56o; 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 S1754563AbeE1JbK (ORCPT + 30 others); Mon, 28 May 2018 05:31:10 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21486 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754216AbeE1JYN (ORCPT ); Mon, 28 May 2018 05:24:13 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInJ027506; Mon, 28 May 2018 18:22:20 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInJ027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499341; bh=+mERXWOaTOmV7BBi3Br812M4paeN+QQdqw/nLvrJLJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zBFiC56ot9GXFpPYqu21vSQ2e1140t5x84vKwpxg0qG/wAmVnBL76p1UCYQ5dtDtN 4p8rkUuScN4fw8JSPiCUJTJuVm45XE3YwCrmoRmIP0rk9+kV11Nb0AsubEkEeg4rfn DXiVcrSQdtnHJ/NNSz5MJuKeYBUbfPfdeZDvYM1ug6VUBg7CyfDpygiO7l3LEeDxWq Nw01KH2kFkNK5crLz+Cp/TtC7VTmEVMecC5wu4k9jP04HbNnmP7IJH1jOfufDB4S3u wOX0yU6rfDyWjvr4+jvJV4UsLWhPVREt7VLThRvsudrT7N4rMRFieBocH0DEudsxCZ lZncN+m+FJxjg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 02/31] kbuild: remove CONFIG_CROSS_COMPILE support Date: Mon, 28 May 2018 18:21:39 +0900 Message-Id: <1527499328-13213-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 02202d3..58afa07 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 18b151f..15aae32 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 Mon May 28 09:21: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: 137055 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2594768lji; Mon, 28 May 2018 02:28:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp6Z1MOplIGxr9pwskIbfqrdnjVruwpMmW5moRf6yZCFOZkq+/n9I19trAwxt9VbIz07juG X-Received: by 2002:a62:6a0a:: with SMTP id f10-v6mr12554449pfc.99.1527499694225; Mon, 28 May 2018 02:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499694; cv=none; d=google.com; s=arc-20160816; b=gYxlW8cPh2x94YeZz1gnrDWwJ15P4eq/nVhhl2opjulbeKJBJAu93Py78hCJw8SPaW SdaYcALHd96zd6G/uaN007aAJE4/D9ewIZb/fsLgZWLOFV1HJCr3m2kHwpeLc8B6oEuG 5/W3uH+Do0kF0TtEJdWxPhEJ2W8j9DuSExIP2XmdizybXsxKe9Du9KvQ1UjROd2KB7oq gGQ6kMyKGcUYrPJC/vSa6IC+k6hTzzDxaqhHJBvVKvoYaWH/iDfzdRB6201aUpuJj5As 3Zq+WIDsAHlmjumpVL4dbl3utYXZaop9D0dwCCS+mjC84JQWpaZe8G4jLkwvf5Lg6me7 uuyQ== 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=vktjGzrJiahds0B8NaVZIZ4ZYIREgvWantKmmhYHRlw=; b=UohPRjP54lng8HoYVDJkiiteDPYpp4Mo6fA14QAQKGc6lLx9SdOFHkUSW+kICvXROt 1IoxDnU60YcWo+p0Xe6JEVhcZyZ9pm4H/ULVj783V0C6o0LAmbC6qlFxTtz9FPrVPFiJ ThOki3alC/ASkpPjfsnXbhuNMddodt4PVr3+oiDri19vZcP6xHr/TrUwtQqbcRoDxYZB V7fasorQmZnKiwmuc+5UyYXWLInLhc1jGFSizx3y602zopNTFe9AQFNC8fRkAQWGM0Xt jc23mpBbRa3URAwIMAE4Yf9g/2gdwuySkb5dnj96td0Mn5wdS9s3z0KrfICMAL3q5HHR U+3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=PTDsI4SC; 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 e129-v6si30316187pfa.217.2018.05.28.02.28.13; Mon, 28 May 2018 02:28:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=PTDsI4SC; 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 S933855AbeE1J2L (ORCPT + 30 others); Mon, 28 May 2018 05:28:11 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21663 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754335AbeE1JYR (ORCPT ); Mon, 28 May 2018 05:24:17 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInK027506; Mon, 28 May 2018 18:22:21 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInK027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499342; bh=vktjGzrJiahds0B8NaVZIZ4ZYIREgvWantKmmhYHRlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PTDsI4SCY6h3imiKiN3pS+Jy8G/C2Om80WF9dnGibz1LM5SNjTONJ3equydBewbt3 gpj0It7/BAO412nbNU34EgwlOM2AF0V2O2JE8vC14BzE4gKL6moTaNeMWp+cnuCI/S EPvLYG6ABQuqJv94pp4zgdzxTJupoVlnGuHR2oM07+IGD5Uh4CgRDXG1qLvw7N8ejY WcRPFPJI4Zcn1GFmyJ96a9ny239gcIffLHuIlmtAqW2p8jFrIvx6dShLvmFwUtWIKj KT1/gKCbJNeYG2qA9wkcEXvN1NzhhDRrpk7iisFyKWtZkKj2a6rDXu0DKNlYR8jFxV obRnRr/CkKT/Q== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 03/31] kconfig: reference environment variables directly and remove 'option env=' Date: Mon, 28 May 2018 18:21:40 +0900 Message-Id: <1527499328-13213-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: - More comments like "advance pointer to ..." - Factor out the duplicated code into __expand_string() - Move the empty name check to env_expand(). - Remove escape sequence of '$' 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 | 5 +- scripts/kconfig/lkc_proto.h | 6 + scripts/kconfig/menu.c | 3 - scripts/kconfig/preprocess.c | 238 ++++++++++++++++++++++++++++++ scripts/kconfig/symbol.c | 56 ------- scripts/kconfig/util.c | 29 ++-- scripts/kconfig/zconf.l | 67 ++++++++- scripts/kconfig/zconf.y | 2 +- 19 files changed, 343 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 58afa07..59b8654 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 15aae32..1217fc6 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..658efb0 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 { @@ -117,6 +116,7 @@ void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); void *xrealloc(void *p, size_t size); char *xstrdup(const char *s); +char *xstrndup(const char *s, size_t n); struct gstr { size_t len; @@ -134,9 +134,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..a2eb2eb --- /dev/null +++ b/scripts/kconfig/preprocess.c @@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 Masahiro Yamada + +#include +#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; + + if (!*name) + return NULL; + + list_for_each_entry(e, &env_list, node) { + if (!strcmp(name, e->name)) + return xstrdup(e->value); + } + + value = getenv(name); + if (!value) + return NULL; + + /* + * We need to remember all referenced environment variables. + * 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 *str, size_t len) +{ + char *tmp, *name, *res; + + tmp = xstrndup(str, len); + + name = expand_string(tmp); + + res = env_expand(name); + if (res) + goto free; + + res = xstrdup(""); +free: + free(name); + free(tmp); + + return res; +} + +/* + * Expand a string that follows '$' + * + * For example, if the input string is + * ($(FOO)$($(BAR)))$(BAZ) + * this helper evaluates + * $($(FOO)$($(BAR))) + * and returns a new string containing the expansion (note that the string is + * recursively expanded), also advancing '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; + int nest = 0; + + /* + * In Kconfig, variable references always start with "$(". + * Neither single-letter variables as in $A nor curly braces as in ${CC} + * are supported. '$' not followed by '(' loses its special meaning. + */ + if (*p != '(') { + *str = p; + return xstrdup("$"); + } + + 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); + + /* Advance 'str' to after the expanded initial portion of the string */ + *str = q + 1; + + return eval_clause(p, q - p); +} + +static char *__expand_string(const char **str, bool (*is_end)(char c)) +{ + const char *in, *p; + char *expansion, *out; + size_t in_len, out_len; + + out = xmalloc(1); + *out = 0; + out_len = 1; + + p = in = *str; + + while (1) { + if (*p == '$') { + in_len = p - in; + p++; + expansion = expand_dollar(&p); + out_len += in_len + strlen(expansion); + out = xrealloc(out, out_len); + strncat(out, in, in_len); + strcat(out, expansion); + free(expansion); + in = p; + continue; + } + + if (is_end(*p)) + break; + + p++; + } + + in_len = p - in; + out_len += in_len; + out = xrealloc(out, out_len); + strncat(out, in, in_len); + + /* Advance 'str' to the end character */ + *str = p; + + return out; +} + +static bool is_end_of_str(char c) +{ + return !c; +} + +/* + * 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) +{ + return __expand_string(&in, is_end_of_str); +} + +static bool is_end_of_token(char c) +{ + /* Why are '.' and '/' valid characters for symbols? */ + return !(isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/'); +} + +/* + * 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) +{ + return __expand_string(str, is_end_of_token); +} 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..703ee49 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); @@ -165,3 +149,14 @@ char *xstrdup(const char *s) fprintf(stderr, "Out of memory.\n"); exit(1); } + +char *xstrndup(const char *s, size_t n) +{ + char *p; + + p = strndup(s, n); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 045093d..b385590 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 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 Mon May 28 09:21: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: 137039 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2591897lji; Mon, 28 May 2018 02:24:29 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr/kRZhB5W0QYcS/KMVUnpc4WzO0C5X9CswrizT487OzMFTyc9cpkInHcAXR164dVjmePE5 X-Received: by 2002:a17:902:5c6:: with SMTP id f64-v6mr12814434plf.50.1527499469169; Mon, 28 May 2018 02:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499469; cv=none; d=google.com; s=arc-20160816; b=c1Jj84ldecQbUeN1UlgFCrHTNz/unVPaY+KMPmtJnjPYW3bivmnSi1wETdZU/KWsnX ReCFHSjQC4DPtoXRMWOIlWXYnhNWjJLJwQGVa0rRoQVtMlHkWS5RC4TxF/AifYgdnt2F wQJT1gMVxoLbCqhJdMpaX+tufnkgaa+vJep6ls5YAIRo4gZp81cFJxDgCsl+nHmDsVbz 8F4N3xE95+YghbCMd9LbGaU0P0BUSw41nEgFBJcyiSb9jU+uv4r8A4gh01MRgMsT2xEH wexuSWT+GNOyZSx4Qi/brfRHAkWGtnWTs7dhcY8FPORU/cSW/Ik8DH+wZLNrwCNPywo6 1ZfA== 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=hnIoSO7D1B5Ka5B/TDr8jeVdLbfoSN4957XMK3FjJzs=; b=NRrelqiDxWHNOXyjmQ9IlvqBePiMmFzWDsoez9DyTiBFxMLNA9emjuD97MqiQNAdpL XnGBdQmvEPPSrSjKsRKW2HX5a2OWxXuydnfNr6SuhvsyO5yUiTUG0ROECeofHbE7shAf icGAhYhuwk8a2PpJjbgnAwAcKuns9zHcYYdu0gOJpK4UqVbm1PN3rgMrIgpcW4Uul3cI GSaf+VyJNHCSO/AgRpoT3N2jKssBIrwO0LcIp/yjQgqjEM0HgFuVHT3I1j89Z5wH0uFI fzNSST88tbjqVMz/5KnEz4mRXkeRCTBjBe/MeGL2Ut0PSm/YJzU3j6qdiSSew/GT0PMW 2sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=okKxtupT; 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 t1-v6si13250726plq.341.2018.05.28.02.24.28; Mon, 28 May 2018 02:24: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=okKxtupT; 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 S932145AbeE1JY0 (ORCPT + 30 others); Mon, 28 May 2018 05:24:26 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21481 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754207AbeE1JYN (ORCPT ); Mon, 28 May 2018 05:24:13 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInL027506; Mon, 28 May 2018 18:22:22 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInL027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499343; bh=hnIoSO7D1B5Ka5B/TDr8jeVdLbfoSN4957XMK3FjJzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=okKxtupTwSJZnwZ+edd3dgoiU8la0VrRGrk2tro7s9lZTS/rGOAvM7StiFYsGJoc+ ootTiy99iGxlgDD4QaY69rjVriHQvKSKwhrIziEN6HwWVx7px4H0qr8J1WeH8wJQQQ 38tYc36yEHU2mQrmpgq8glTiAKESbZApQCA/HWmTfQYgowl4oiFssRaiBA/pPPMOL3 JEVciya7i+J9uULeFz4GY9aArYYK1eOC+3GzNh7zCxGXnIBreisg/qaIpgGBj3yWn3 taCLeBywMZJ0caDxZbnLlnMWXH+7pUMnESsD0AY+uK38WHCJyDIehYJdq+IiejuS5a z9q7yDSL80Mbg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 04/31] kconfig: remove string expansion in file_lookup() Date: Mon, 28 May 2018 18:21:41 +0900 Message-Id: <1527499328-13213-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 703ee49..a365594 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 Mon May 28 09:21: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: 137037 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2591811lji; Mon, 28 May 2018 02:24:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqN0kJoUmZifMysil+DmZ54IOtXLmK3dbdwAc2BAzxeXsxYh4dWTrarSVAD4hF8klD5FQVO X-Received: by 2002:a62:a21e:: with SMTP id m30-v6mr12825889pff.251.1527499462446; Mon, 28 May 2018 02:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499462; cv=none; d=google.com; s=arc-20160816; b=iCq4i57Kc9BwECXFd9CZ5XwHiNWAmcAYlmSwCxQgGOGKYNpk8yFYabPl4+oc8/gyuk dxj0zm7JcnupzBSXCWoQQd3wOtJhOylz2oz3YLwap1vo5P6XxkDWE8kATsjNPGhy3uvN z9RxnTgLWEYcj7yuWWUxeO6iWSaEgfFqcYX4ubqjT7BcuK7+a2KlgnCq1OI9fe5BhWRE dRVRjLDpsH6ns2gQKcEXJda7vMd1Sq6TcYNQOcickJHd+sA8TQDVL1x2E1hcFmEDO7Wx VA5ezv+fdpemzWeGvO6GSdiHJamgc9BeO/zlyT50e+vlpKQuIgdH00CG3y+n99cgk1Xo kPUg== 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=a+sJfDvaiOW0y1ISbFPnFjGs0NB0UxI35ML1XjhPaaQ=; b=zSUlxwyTQN8HhQP+vXXfFWBi1toLnVV1wHFI6+xNZ6nghZdRyKKt2a/TO2+KGOXv41 +gGumJhNWWpT6+HQx+Q65sB/E+b6aa6+fnNYN/a8Xurz/drMCc5KK6cTppkBgou4LwEd mZOzVuuNjWhaV4eXQEn/7hO1I1skrBOJAFisOmc/KLwVvK8MSqSMjibK4D9xAL7i7PYG nInCMdGIQ18wcBOQlWYoEugzHpVZUCZkxUai9oxq81/YZgs4Y8Ss9xD9QSqp9TOxvK2f ikmVfDyJLjaQRQcRqEF9Gb3OLFroC4ZQZ8bnyc/ZDSwvc0wha0gOAxFPcVoXvgKIH+fZ 4ByA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=kzyXtNNG; 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 w10-v6si2388144ply.482.2018.05.28.02.24.22; Mon, 28 May 2018 02:24: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=kzyXtNNG; 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 S1754364AbeE1JYS (ORCPT + 30 others); Mon, 28 May 2018 05:24:18 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21452 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754090AbeE1JYM (ORCPT ); Mon, 28 May 2018 05:24:12 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInM027506; Mon, 28 May 2018 18:22:23 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInM027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499343; bh=a+sJfDvaiOW0y1ISbFPnFjGs0NB0UxI35ML1XjhPaaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzyXtNNGhs+6RWZLFYwdKvSsujbn2hn4jxKOCs+RvM/NgQkpD/8K52GL06W2SO8J4 HDTkGUE4bRhvTo/RAdhZFUc3s+NlmijRdiyNxw45OtbBlemWbx0sYWbVQgrD1MM/z1 GsNEAzrwkFsU3slOL3u3U3g3JVVdI3ZiFeuC1SZO9YZntNSfkqVkuhzxvNXkGDVvnC 372xOBpJDXl9KrK2tngCsF7Kl70rhsVTW7dj7aCFDbWCoMxQxnaEjNcp3+9FkQo+bJ ElgQHU7QaZBZh5A11D8ETrca6u1sbyyXc9GwgmpVgnIywU7i69EPYBZuO6JJoF+0Wq kCaMsKYze1QTw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 05/31] kconfig: remove string expansion for mainmenu after yyparse() Date: Mon, 28 May 2018 18:21:42 +0900 Message-Id: <1527499328-13213-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 Mon May 28 09:21: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: 137056 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2594835lji; Mon, 28 May 2018 02:28:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoyYxNk1cM0J+Iqv8lv6xM5mZTWoMEIB89Rd2408AV3/5b33CZpkuqibJwlgM9DKA0w17J6 X-Received: by 2002:a62:d653:: with SMTP id r80-v6mr11581002pfg.54.1527499698712; Mon, 28 May 2018 02:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499698; cv=none; d=google.com; s=arc-20160816; b=XhyrEf2KBrqH3obHsRqubLiQH5uncnydtD9ecd6fPL3R4RMuHfWb/pCKTmT4L9b0ZD d6wFLzODD4Bt1Rb3yRMDznnQ04/rzt89YmLpVIQu0F56bHozMj8tmGlLHJvdSdFWcoPx OTulN/w8rL8IMzbOrfZMGbxpDgPCuBQh0QuYYH9ltinCWJQSvTdthYm/UgdodnDnSE+P fGO+oRkXsYJAecgaukiqZXh0X4r0EZJWO29AzI/qUCP+YpewsLKXX70KsPhCR2x7nSkF xcK0GjM/aOpAo5pS0zA6Zjhmn//Et8bS+BmFX9qdiepQzwK1sHnMR0NnJkZZGZAuulTD hZwA== 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=V7aT5q12Mz8VRqDnP3delQOQnBaFgtyqn3U4iSjRNGo=; b=0ILxAY34cc03LQTCash1IHUhKnqSK1JnSk73AjYyvIO7RqgGHNgwJqsZkQn5f2Ej00 DBrCG++HUxGWySIKZjwmeP9rLzdvj6ROXjAC1RMuRDl178pQtiqR3k88zBvQReWixcKa yEGZtKE/LR5tN+F1fnHpLxVr+q6ur78trexlwZVV/Z/SfKaLCmbfVrAwgOyS0JZ6yPbB 63wSNG7VmS4RNFUSvc2eJxCwwAo17/zUAzVBLHJywo9fMgmXNFLDk3OSV4aiCG4eJd7D hDiz7zAd0q0IKUfjnNRth2ISRMaz72aWnwEHdlZm786Q9VFwQ2T2Nbpm12Z34zA0Kxoi HRIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=h8Uvu++x; 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 88-v6si29308679pla.315.2018.05.28.02.28.18; Mon, 28 May 2018 02:28: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=h8Uvu++x; 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 S933913AbeE1J2P (ORCPT + 30 others); Mon, 28 May 2018 05:28:15 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21666 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754337AbeE1JYR (ORCPT ); Mon, 28 May 2018 05:24:17 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInN027506; Mon, 28 May 2018 18:22:24 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInN027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499344; bh=V7aT5q12Mz8VRqDnP3delQOQnBaFgtyqn3U4iSjRNGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h8Uvu++xk2B3VFteKCfJPZkjFoj9hgbb0jl5a2rT/efVbPbgLWjcuArE3Ky3h1VEL 0z6bh/WuBxg5Em34sy+s8XH54omqnZny+03TuXzQuYmdVcUepU4nPFsFaBH2V30Nai ezrlKztVCCdIKBIbfXFLx2t0MHTiC2Wsxp7H989Vfp/LzjfrhkAOZvkInSxKVZyWaL 9du3I0r38DL5DU0hmUiYMeObWcbBaIYuUtZRbx3APiV/+s7Taw62NiYrObNMiM1tIc KiMGNncapRiRc70+Vss3q9oc2UM8NuiK36BLSKxdlG0OxMGh8UdE03UhCVROJeHQJS h3jxgjcsgHYsg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 06/31] kconfig: remove sym_expand_string_value() Date: Mon, 28 May 2018 18:21:43 +0900 Message-Id: <1527499328-13213-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Reviewed-by: Kees Cook --- Changes in v5: None 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 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 Mon May 28 09:21: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: 137038 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2591852lji; Mon, 28 May 2018 02:24:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqZmhdAJd3d7UGrch31TuVN3Ib5mPW9kGcwl3B/fip7yl4hWKMdGB/DPIIHEVTJiCKUF5cu X-Received: by 2002:a63:42c6:: with SMTP id p189-v6mr10010570pga.48.1527499465676; Mon, 28 May 2018 02:24:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499465; cv=none; d=google.com; s=arc-20160816; b=EwVeLABztYMZxSUb2HOJMsMN0XE1kqVh+BfBqvdipp5VUOLXhhh8sxoLeNVksuljS/ 9Wv7FOHmU2WbClxruJQGN8Afp+0QdXscsl8XSStwBgMxW+PCGdYmTmmzvnVYay5SkQUB fYVVjsP0JVhjC/j1E+w0xjPTmTeQjy8wXTk8+7gIjNjOf+SfRX9YzTFQhCO3MAaZHQpq OXzKRf8wCKTZpfa6UgVZpfdBeO9QPfWV7CJb4pcDF4hrC6J8cpHCOGy0IQ30UXCjGPOF /2LyPQfu9nuyy9nVXiI4ApsP1Yj1Hs+Fbl8IcZyXr5mk1u6sPAS8uWuBvdIR2WYyUVBz +kDA== 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=Kgeq1MM66zDDMwXPcmtGMcgMZJdpHYBq5ld73j/V1DE=; b=Qv0OCAkh+ZK1sRfh/Lxe2iAWQyE9A9dYBR5GJYi6qpkA/+rGC1GenRfKsRc/lj8/M0 T9e8pQIuXcfdJW/KW+0YZa9YPlFTs+o68+juMWuSSH1hl+wDwZU25Kh2pVN2wQJIE3Y5 Ifn9T4E0EuXLso4SbOj7QEcHoAIAQ6l1VTbmIzokKztgwbY2mMhzG9+MoTzLFIxMKCya xjRhq+uvb4zXp7KSZ6AzxCHCZkK6rsaLUnElsdVAJ3KQ3bBTUq+TU+tIcvBmYx8ZKtH6 HsdNV8bEPVt3Hjg/lGWSM/57peGAlYXxb154mNSAu24/LjuDq+6iARyN+Vy9J6VOe9GR Jo3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=mivVBaV6; 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 w10-v6si2388144ply.482.2018.05.28.02.24.25; Mon, 28 May 2018 02:24:25 -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=mivVBaV6; 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 S932097AbeE1JYX (ORCPT + 30 others); Mon, 28 May 2018 05:24:23 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21477 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754138AbeE1JYN (ORCPT ); Mon, 28 May 2018 05:24:13 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInO027506; Mon, 28 May 2018 18:22:24 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInO027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499345; bh=Kgeq1MM66zDDMwXPcmtGMcgMZJdpHYBq5ld73j/V1DE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mivVBaV6ScCkQ1TwliDpOyjpeXz0IGfaInv+h/3IUvgyyYKJRELldSK+BjXyY0Prf 6lVnkNuDSn6WRlTntX0hBuRb/0EdzDJJB4cv+39mQshAQEK2JBAAv7Thr1tOEQMAkb kGnnuJXrmasPPvIfNqw5grQivog10nJDwksG7u7IGIQYNbj54pCXb15fCWWv8QGfAU Ba/r25Dph6Q4zj8vRyjFHymQsQ6D70XhKhxV/LQmPIulz0g4Ob7Clj0CxohtDr05K2 mvpG6Q21QPs5Btq6/mtbDxSmZc1iuR0z2Is1DhXF6P0qxCvJrdDG0IOGp3iKQ8EaLo 2ch6j3nby3sYA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 07/31] kconfig: make default prompt of mainmenu less specific Date: Mon, 28 May 2018 18:21:44 +0900 Message-Id: <1527499328-13213-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 If "mainmenu" is not specified, "Linux Kernel Configuration" is used as a default prompt. Given that Kconfig is used in other projects than Linux, let's use a more generic prompt, "Main menu". Suggested-by: Sam Ravnborg Signed-off-by: Masahiro Yamada --- Changes in v5: - Newly added Changes in v4: None Changes in v3: None Changes in v2: None scripts/kconfig/tests/no_write_if_dep_unmet/expected_config | 2 +- scripts/kconfig/zconf.y | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/tests/no_write_if_dep_unmet/expected_config b/scripts/kconfig/tests/no_write_if_dep_unmet/expected_config index 0d15e41..4732288 100644 --- a/scripts/kconfig/tests/no_write_if_dep_unmet/expected_config +++ b/scripts/kconfig/tests/no_write_if_dep_unmet/expected_config @@ -1,5 +1,5 @@ # # Automatically generated file; DO NOT EDIT. -# Linux Kernel Configuration +# Main menu # # CONFIG_A is not set diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 22e318c..8a82aaf 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -532,7 +532,7 @@ void conf_parse(const char *name) if (!menu_has_prompt(&rootmenu)) { current_entry = &rootmenu; - menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); + menu_add_prompt(P_MENU, "Main menu", NULL); } menu_finalize(&rootmenu); From patchwork Mon May 28 09:21: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: 137060 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2595736lji; Mon, 28 May 2018 02:29:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoCkJN3f1OTGeE1okX5JmlAH6BVWr5PumiBKJg4z6HdsSBewDW7N/DglWc3s8IZKA1H2Z8P X-Received: by 2002:aa7:8386:: with SMTP id u6-v6mr12680222pfm.253.1527499767299; Mon, 28 May 2018 02:29:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499767; cv=none; d=google.com; s=arc-20160816; b=ocbac2pyS+eHfp+EirV27K6Db66hOGfbcmLHOrKoeQRJVIKJX2JjcbgllmBGZEWnqt cK+6q68zgjo0M5f7HVUtJwPwGvYRxyRNZvJFVi89UJdfdMPwanXwTUcPiQ5b8ygh5fLC sbnJXERQlRlZRkjvvjWrPKBQ8r+Fb8P6h9NDmYajZMXb4y0/TjwaeoaSlH3uGNk6ryVd r+gug1i4DLb1bHHAeDcHL6fin3mIfXSCur+OZB71WNrDaedYqz3MQQIZSYiAfV0Bam8N NIf2c8i6ciYq0sN1vxzBDbjjMdTXYP+O7m/gQWtIUpICucvQnViVMkbJhj+BG8cbvvkq hoRA== 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=omPhLk5Dv/gC6/y3aSKFdKnRIeqwivubnuVdhcAi+dg=; b=PtWbuOoeEq1RPnZ6W9r4sa4jifecYXY+k0MfqcaeP6tpxrUwkjNu1Dhmh5J+8RcEiE 5fJBN3rj7H/9ViQvFVGQp1YiaKDPG1aBlqZxkoO3iA0hI2Vqv9JoBeSC7c9/KMiRHzk9 N1/V6A65IsdmPYIHOBiR6lLGDNxo1aNopHSvEoxCFtahqrlo8PYEfKyqpZS12EL/HzUS bP8syxm7FFHPVBh5+k+5uI7jEpGoeCtl4R8N/ehgJj3ZRod6D3jtpg2kemRCGB2Tn609 XofDGfNPijUml6iD1P6Afk0OxVbDltPrH47V1dC0PDCxyeF1qaXXgPwESmf01o+9grtC wKkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=p8D00j54; 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 v34-v6si1641930plg.524.2018.05.28.02.29.27; Mon, 28 May 2018 02:29:27 -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=p8D00j54; 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 S1754367AbeE1J3Z (ORCPT + 30 others); Mon, 28 May 2018 05:29:25 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21624 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754331AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInP027506; Mon, 28 May 2018 18:22:25 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInP027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499346; bh=omPhLk5Dv/gC6/y3aSKFdKnRIeqwivubnuVdhcAi+dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p8D00j54I6h9tKJ6LJKh+yoxpOJJ/Q/WRZlw98uAQu8Cd5IduRYjxl74X1h0NXQZz aTDsgCHs5b6Daq9qLN36Tyai2VEPhL72xYYF4rEvLglJYPpOMo9ruqsAy4z691SqPz UNjS+FuwsT+/VqvdtzX7ovk0Z0n+HqtASbC40lmK5Tyw0i2kPZJEp7zvpwxJl+57pg X1ZiDaVLg4+E/ahX7UGbfrSjrFd5uMxe0965P48f+DbeLQkhRsY+ASHYIk0YfxodPC pzxbKxPejhOAWr6AM3qO/VnY2ur1LcLBlnhDe7LI0Q9sxTBKMamAgMbtEHsQleN7JX ZIAokh15j2eDQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 08/31] kconfig: add built-in function support Date: Mon, 28 May 2018 18:21:45 +0900 Message-Id: <1527499328-13213-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: - Drop delayed expansion of arguments. 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 | 142 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 130 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index a2eb2eb..f32a496 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -10,6 +10,10 @@ #include "list.h" +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +static char *expand_string_with_args(const char *in, int argc, char *argv[]); + static void __attribute__((noreturn)) pperror(const char *format, ...) { va_list ap; @@ -92,20 +96,123 @@ void env_write_dep(FILE *f, const char *autoconfig_name) } } -static char *eval_clause(const char *str, size_t len) +/* + * Built-in functions + */ +struct function { + const char *name; + unsigned int min_args; + unsigned int max_args; + char *(*func)(int argc, char *argv[]); +}; + +static const struct function function_table[] = { + /* Name MIN MAX Function */ +}; + +#define FUNCTION_MAX_ARGS 16 + +static char *function_expand(const char *name, int argc, char *argv[]) { - char *tmp, *name, *res; + 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); + + return f->func(argc, 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 *str, size_t len, int argc, char *argv[]) +{ + char *tmp, *name, *res, *prev, *p; + int new_argc = 0; + char *new_argv[FUNCTION_MAX_ARGS]; + int nest = 0; + int i; tmp = xstrndup(str, len); - name = expand_string(tmp); + 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,$(x),$(y)) + * + * The input string for this helper should be: + * foo,$(x),$(y) + * + * and split into: + * new_argv[0] = 'foo' + * new_argv[1] = '$(x)' + * new_argv[2] = '$(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--; + } - res = env_expand(name); + p++; + } + new_argv[new_argc++] = prev; + + /* + * Shift arguments + * new_argv[0] represents a function name or a variable name. Put it + * into 'name', then shift the rest of the arguments. This simplifies + * 'const' handling. + */ + name = expand_string_with_args(new_argv[0], argc, argv); + new_argc--; + for (i = 0; i < new_argc; i++) + new_argv[i] = expand_string_with_args(new_argv[i + 1], + argc, argv); + + /* Look for built-in functions */ + res = function_expand(name, new_argc, new_argv); if (res) goto free; + /* Last, try environment variable */ + if (new_argc == 0) { + res = env_expand(name); + if (res) + goto free; + } + res = xstrdup(""); free: + for (i = 0; i < new_argc; i++) + free(new_argv[i]); free(name); free(tmp); @@ -124,14 +231,14 @@ static char *eval_clause(const char *str, size_t len) * after the corresponding closing parenthesis, in this case, *str 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; int nest = 0; /* - * In Kconfig, variable references always start with "$(". + * In Kconfig, variable/function references always start with "$(". * Neither single-letter variables as in $A nor curly braces as in ${CC} * are supported. '$' not followed by '(' loses its special meaning. */ @@ -158,10 +265,16 @@ char *expand_dollar(const char **str) /* Advance 'str' to after the expanded initial portion of the string */ *str = q + 1; - return eval_clause(p, q - p); + return eval_clause(p, q - p, argc, argv); +} + +char *expand_dollar(const char **str) +{ + return expand_dollar_with_args(str, 0, NULL); } -static char *__expand_string(const char **str, bool (*is_end)(char c)) +static char *__expand_string(const char **str, bool (*is_end)(char c), + int argc, char *argv[]) { const char *in, *p; char *expansion, *out; @@ -177,7 +290,7 @@ static char *__expand_string(const char **str, bool (*is_end)(char c)) if (*p == '$') { in_len = p - in; p++; - expansion = expand_dollar(&p); + expansion = expand_dollar_with_args(&p, argc, argv); out_len += in_len + strlen(expansion); out = xrealloc(out, out_len); strncat(out, in, in_len); @@ -210,13 +323,18 @@ static bool is_end_of_str(char c) } /* - * Expand variables in the given string. Undefined variables + * Expand variables and functions in the given string. Undefined variables * expand to an empty string. * The returned string must be freed when done. */ +static char *expand_string_with_args(const char *in, int argc, char *argv[]) +{ + return __expand_string(&in, is_end_of_str, argc, argv); +} + char *expand_string(const char *in) { - return __expand_string(&in, is_end_of_str); + return expand_string_with_args(in, 0, NULL); } static bool is_end_of_token(char c) @@ -234,5 +352,5 @@ static bool is_end_of_token(char c) */ char *expand_one_token(const char **str) { - return __expand_string(str, is_end_of_token); + return __expand_string(str, is_end_of_token, 0, NULL); } From patchwork Mon May 28 09:21: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: 137059 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2595675lji; Mon, 28 May 2018 02:29:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLjvFTOPQTC2zz7EEORlZccPWNkrO58sy6UbbdqsqDe0WGcMu5haKjgJ/oDQWajhv0mSvXH X-Received: by 2002:a17:902:7105:: with SMTP id a5-v6mr4651366pll.171.1527499762712; Mon, 28 May 2018 02:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499762; cv=none; d=google.com; s=arc-20160816; b=AJVIrwme5UY/vxW5ueY4BpkNLW0+L1adysJHJclCJ7ExAplBg/gnA/rBEd6W+ROohM nk9T9BeBrP0/iuXi4vYI+E3iw5Jer3jwICxsNAA63bRrHCwoSViMkPZYfkK7ava9md/o 3/8yuqzUtX+ICjERHain83kyRG5Hg3QhXGidwzKQK6MONc1ftUEBy8hbK6NNbP1Fgh2i qietZL7WGA8hsvU6/0dEcDRPobjbHXtn5fb5vMJnPxtRR3oWTsf+WAegOatm8K/AEMKy jarH9yHXgifrxSW1g/NJwhcX9wG1Z5yp+UIY8gHrSOn5EYKS3D93HK9ZibRTw9yMzeXe 3jZA== 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=Ya/ZQhKy1YAggohbHXRbgTgfcGxUazykAPfdK9IVmIk=; b=j0ccEtsXvdWERBN3IrEqDvn6IupT43FdgzDGZXMGlJvMqrwuWur+JijkwtVwXVaxW2 IyMneZ3rDkLtHYOWtRtAP4kBSD+87d8PYPSrRLpmaSJiLQhsTamYr5CqCePtLHttW6fu 8dub5Fp5PNOrfl5XUuFdQ7GcGhwcqdU1DgA0AOhp0qrQSL4jVeZpvN0R7JVm3t+BRflJ +pf958Ro4EsUeHzGtYmEfRv50IPJX7gu/KTH3VE9BwrtEVPYS/8lLVxhBkli3eVdlujF xFbD7tT65WOX+n05jxPlRPg+yEJQbaceCfz1d4F5v8kx/Nn7nfwn1nGATEgSWGghzIsU TmrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qzy0I94i; 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 v34-v6si1641930plg.524.2018.05.28.02.29.22; Mon, 28 May 2018 02:29: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=qzy0I94i; 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 S1754271AbeE1J3U (ORCPT + 30 others); Mon, 28 May 2018 05:29:20 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21621 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754326AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInQ027506; Mon, 28 May 2018 18:22:26 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInQ027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499347; bh=Ya/ZQhKy1YAggohbHXRbgTgfcGxUazykAPfdK9IVmIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qzy0I94igBSBLc9C9py76RvAvxU+F1XH82NfMz1Sfz8c0nP7FtTdo8q5SDBBIvrN1 DqIUms4vLXQ0lRFBZ/20NTtxiLr642LCFY7Joi1piymxnsHaS8rjLjQ8pJX7+paFiq Ih+52aWMkmTkNtMhYn3dYUEKt5HFKJtSQK3wrSixaI3JicX7dAxKtcJyG4DHXGQCaV eMJ3iJa7hL7n3gGW3wCBZn3a4ce2mm9i69MjoLXL+KI9DEDj7fLW+8k4smTsr4Z3c2 5U5Y9MhT7W/bQ5LJM2dHODEVKArCvluC3iA3REPODh7aqi/H/rU2L/i16pYLiX0Py2 yqN1jmFv946BA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 09/31] kconfig: add 'shell' built-in function Date: Mon, 28 May 2018 18:21:46 +0900 Message-Id: <1527499328-13213-10-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 f32a496..528be59 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -106,8 +106,49 @@ struct function { char *(*func)(int argc, char *argv[]); }; +static char *do_shell(int argc, char *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 Function */ + { "shell", 1, 1, do_shell }, }; #define FUNCTION_MAX_ARGS 16 From patchwork Mon May 28 09:21: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: 137063 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2596160lji; Mon, 28 May 2018 02:29:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrzeJqOIHx7GFSgPaPw7TJs3N17IYp0a8txyukGUw4TcRpY0AUShggTK1zXnA8AU+QgxEFo X-Received: by 2002:a62:cf43:: with SMTP id b64-v6mr12649729pfg.248.1527499795974; Mon, 28 May 2018 02:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499795; cv=none; d=google.com; s=arc-20160816; b=gKTxERmCdW50WtTEvauMY4qlnyivNEPqC6Ghjn93t/bJqmtDWZyo9RkeKrcS3Wmidp /4MaDI9wtvugZSZ4ZmdDZMYH1hKfWRgJGcziIGRWlZJzJbIdH7CKFFEQc1Wdtx37Ra77 GUbGE6Hob8LxJZ6Lbb3G39/lMIBT0WehbzVlQgwfZHK3m+3XYS0oQIuJ7uG6JhXOT82e 7ArTYunghiW+dapNZZ2Z/VNo+JSK5Fkdha8S9IczGzLjZDo+x7G8T+vANOlkL2X81jyJ XJ7tIPBs5i18wLVJS97IVGNrKjt/cACYDmD+etVWKXEJKfesFyL8+4fP4TF663TXgBSc YVeQ== 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=vYpPTJhorXn/ORx73YlODbDL6sHt3PicU6+i4bEs6rA=; b=nlAkFm5FlwC1Hgtwmd8SYmHEnUwgoPeBuHvdvqt1w0LXFwFa0UQOvSBAmiyQ/kMKb4 mVZev235Dcs5MC+sEoxoEk8+08/N8aCNO3KD8zhXP9r+n52JR1zWmnmB/YRJMu0LSek6 4HODrPj/duIsI7YE1UChYwLbfz+QFE6KCghVV097Y6KymZA3KtbTLa4ay5/2Y3DPTztG cuBOYdkpRaYUgELLyigQAbgz4lrZ9s+sWaA0InAPf1o3YC5+nw/MSD0UuYudrK5eoGjo RpgAxLPw+3DWy6ceXqWC8DFLdy0d7ChGFu/amEVdxC7ccNbgAAX8E6ApHehz54i1Y/km AWdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=12XxOej3; 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 h66-v6si7945061pgc.53.2018.05.28.02.29.55; Mon, 28 May 2018 02:29:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=12XxOej3; 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 S1754496AbeE1J3x (ORCPT + 30 others); Mon, 28 May 2018 05:29:53 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21616 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754321AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInR027506; Mon, 28 May 2018 18:22:27 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInR027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499347; bh=vYpPTJhorXn/ORx73YlODbDL6sHt3PicU6+i4bEs6rA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=12XxOej3dbTj3agnHnvUM1rg7MXqScTGkJrrgJh7mtrZvVVgIMhEF524/HqLgtw6R zF7ewfl6qtdmIdvyIQHEGuqaZuAX1G//erY+4GdYSjTVlYVOFXsMwgQ+xyf46vxTr4 hzKVnauMbYhOj0+gWv+Bsj06l4L1+xnVY6tjg4TbQWTzcNK19Vd6KRJRogdorlKZzQ ifyOabUtSrnlspgcCw+0VXg8XnS5WzTx18htaYTrdOD/4uTjlQm5s4ND5tZt+mBWWe 4e/AuQNHuzYxBomwy3ohdxyZOzp5fATQlPyVdQFZ+OQyeZvSMr/2Ym1XqBhUAeGguj ba7E4N1rS+aiQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 10/31] kconfig: replace $(UNAME_RELEASE) with function call Date: Mon, 28 May 2018 18:21:47 +0900 Message-Id: <1527499328-13213-11-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 59b8654..58afa07 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 1217fc6..f1b0cfb 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 Mon May 28 09:21: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: 137062 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2596112lji; Mon, 28 May 2018 02:29:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqpOwOvCr3S+82jK0KEduhtLalew7C2c3P2YthupovCi20RNdA2R2nXzjmXc8NSWkD/+YM+ X-Received: by 2002:a63:7804:: with SMTP id t4-v6mr10218445pgc.323.1527499792162; Mon, 28 May 2018 02:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499792; cv=none; d=google.com; s=arc-20160816; b=lZ0OSXxMHbe/oFOKn5Q9suqrCmyzRnM9avwU64bwbrnt6AwOSKGpKVHbyrz1xBalPQ 82GmKWgWrC4KMbBI9uaEerLF++W5OegIId1H1JbYsdNrxyqstEvigRceBc/BpCgeJ/wY 3NG3O4CzQXufHbGchhRxp4gk4uAGLZwaGhePhObuX8gCE4BdvCXc5VG56smUJYI2B19K FxlieX7zq/5YZIR9BXP7R9AtWAJEELOpCo4xUMvahonxJuXsmoi4yOD7E0CHcTev+1oO l5ZKAb3LgAx40/Ol4wlD4XD1ZL7DvturJTXY14TFnoP8Oqd+IYLblukNpWMJPADEqB0b Kmww== 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=vAy22p2EOlKxrkyyKFQXW4coGIYwZi29YzZ3Dr91Q+Q=; b=Jg3WpPu0gWILdMYuCq/yF2i6zbnp6t2GtbZwSVHhZ1htyZcaWhrJgHT90Q8e5GX9fk rqJEE3CSpMG3XEJGbfGvEEjfWdV76pvCWSLs9lkSupawpHumTzypkaRxCob0xnPxe4Tz vW03ez7WTnM4Osuh5kfVI3bfO86BfwUl2sXq4SNxzg1ylGXoRlzlErwc/fZfmIGh5zLH uUB5R09F2CIEp9Z7m/FWKJqeH8q4F1OhjHB4OEz3fDlWcwqyX9sGWKWovYj8xj6QWEFY vifYAKekdl+iD4lsGag8NvJGGeGBqCa+Slssnws4osrkSdX7Sgl+G5NfqvbfuUoY+HYn UXgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Q4hCNZdb; 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 q3-v6si22669389pgp.95.2018.05.28.02.29.51; Mon, 28 May 2018 02:29: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=Q4hCNZdb; 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 S1754457AbeE1J3q (ORCPT + 30 others); Mon, 28 May 2018 05:29:46 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21618 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754324AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInS027506; Mon, 28 May 2018 18:22:28 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInS027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499348; bh=vAy22p2EOlKxrkyyKFQXW4coGIYwZi29YzZ3Dr91Q+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q4hCNZdbjYXxw5MXA3isYTJHKQrSyXuwKKlVGP/zKM/RrxsWnQ6IVU02m9CNx1Q4R kxwA4cFPL8fG87OqA8ieubgGC+77LPyN+v5fgNTIZl858kg1gYJ10KivDJ5bz1qg8d hRrGFT/s3xCooZcr1buySwtfm7bV/ctPcMjGFIotsRfSP/wS9Dy4CNj/Q9tYmw0NxV n9LDxAgUSl3Wry4BtPWOqoHYVCr0xjgvNzXXTJRQl2b6RTKKd0CRPApdj4DKN7XiP1 FCdmC8VKe4Rp14LRKTiLWea7DHcQ5b6K9r8G0OZtTr987qcqvS/w/EkBP1u9KBcC3N QKpR4e9MaXjIA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 11/31] kconfig: begin PARAM state only when seeing a command keyword Date: Mon, 28 May 2018 18:21:48 +0900 Message-Id: <1527499328-13213-12-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 b385590..9a14797 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 Mon May 28 09:21: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: 137064 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2596693lji; Mon, 28 May 2018 02:30:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZombYDdrPUiRogrTUtqxT+qToo918gi9hYWS/ERlTw8+AgHAPvSLZ4hRL4xey3CYExOM+7W X-Received: by 2002:a63:ac57:: with SMTP id z23-v6mr8546292pgn.394.1527499826469; Mon, 28 May 2018 02:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499826; cv=none; d=google.com; s=arc-20160816; b=sjF/XGu1Roai0znWYiW11joPUD7hIZWbY60s78dJVKDyyA+Y3bUcgjFijev+OzU0yu 3hrU7fOt78XArjT3bYA7OBwGQkuyavZRBwxzkJqd9bD9800KEWLFtEJzNtD4TSYcDtNg DGpwdS/QeR1bsiH2zh/GU6LHHGeep10XqiXSy+hLNuARY00gABuEaUOILiF5pma6tw/O ezVivPeju1fT0GwtGVDH/HziL4LvBx8vtFgL/cBG4WrUP10J1QojzbMSfvQTrJqWvlSW s4+zj466tUgXGFVg9cN1YNrfIKpfpMs3kHbDyZskonpzI7I++yz+tvZQANDRoQGnYVbr XYVQ== 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=Lz8oEi9ZSRwrQ6hRlMHpxdGoVFHUa6dhLfqmgm+mxNc=; b=ZxJ1T6u4VQ4EIcCX104bgWhHpzUcVrmPT0TrHdlJTmiMzzC+sBBWGXiUwVklfTu8t3 6mDVCZh4A4fGKZbpAZIHCMWo5HJaeOLdyXVMdaq1WfQYssFX/fhFnQi1VNz7okMxD0mt pJ+qbtKZkEYQHyDweTXgSdgI+jKO4z4dXPzu0sVlPjlJPf1wXz/L9+35ROBteTloFzJF cKMwxNupZb8s2lN1qKn/90/5DeZLKJblPie1/vwThLDlpxL21riUzao4nNy+HvcBJPjt bU3jq+D0sSivKUCWS1ctx+eWUiRMg5IJ9hqbDCDN8SrdQF+lvO9QjZ4iPTsNMPOYMYgT GLIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pzN3qfdP; 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 136-v6si5492350pgf.604.2018.05.28.02.30.26; Mon, 28 May 2018 02:30: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=pzN3qfdP; 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 S1754522AbeE1JaX (ORCPT + 30 others); Mon, 28 May 2018 05:30:23 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21572 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754292AbeE1JYP (ORCPT ); Mon, 28 May 2018 05:24:15 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInT027506; Mon, 28 May 2018 18:22:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInT027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499349; bh=Lz8oEi9ZSRwrQ6hRlMHpxdGoVFHUa6dhLfqmgm+mxNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pzN3qfdPOfC/El/gTKMCX1LzobOjcdOqCsgRxpmutAaKwUeRnYJDiA+EpQIhX8Wxc MRiNHoGHkwDyEhva+zkwMNBCBcd1TQQTOMsC4zWE97K62B2S/kGjcaGAU86q+gPPl7 dDXJvlLLSEOlfOpw8nZAHs1LP1AwDrQ1sw9eNqusI4NkN8eb94v+Dq7yo+SbiDR0TU dajivVFfb/0USACkVUWXHDKk2xdeJ92Jdqe79zF1vvhOpBNOzyWqlm/fPMry+HjM4n Q4kq4tHZ3A15Xvfy1TsiZ42ynmIjbh5vMhDGrvyB/ckN5g+LoXF2NtgNS/OS2tjgGk TJkb21MXiaHnw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 12/31] kconfig: support user-defined function and recursively expanded variable Date: Mon, 28 May 2018 18:21:49 +0900 Message-Id: <1527499328-13213-13-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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) -E -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 v5: - Remove lazy expansion support and simplify the code again 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 | 86 +++++++++++++++++++++++++++++++++++++++++++- scripts/kconfig/zconf.l | 17 +++++++-- scripts/kconfig/zconf.y | 19 +++++++++- 4 files changed, 120 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 528be59..46487fe 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -178,6 +178,72 @@ static char *function_expand(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[]) +{ + struct variable *v; + + v = variable_lookup(name); + if (!v) + return NULL; + + return expand_string_with_args(v->value, argc, argv); +} + +void variable_add(const char *name, const char *value) +{ + struct variable *v; + + v = variable_lookup(name); + if (v) { + free(v->value); + } else { + v = xmalloc(sizeof(*v)); + v->name = xstrdup(name); + list_add_tail(&v->node, &variable_list); + } + + v->value = xstrdup(value); +} + +static void variable_del(struct variable *v) +{ + list_del(&v->node); + free(v->name); + free(v->value); + free(v); +} + +void variable_all_del(void) +{ + struct variable *v, *tmp; + + list_for_each_entry_safe(v, tmp, &variable_list, node) + variable_del(v); +} + +/* * Evaluate a clause with arguments. argc/argv are arguments from the upper * function call. * @@ -185,14 +251,26 @@ static char *function_expand(const char *name, int argc, char *argv[]) */ static char *eval_clause(const char *str, size_t len, int argc, char *argv[]) { - char *tmp, *name, *res, *prev, *p; + char *tmp, *name, *res, *endptr, *prev, *p; int new_argc = 0; char *new_argv[FUNCTION_MAX_ARGS]; int nest = 0; int i; + unsigned long n; tmp = xstrndup(str, len); + /* + * 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(tmp, &endptr, 10); + if (!*endptr && n > 0 && n <= argc) { + res = xstrdup(argv[n - 1]); + goto free_tmp; + } + prev = p = tmp; /* @@ -238,6 +316,11 @@ static char *eval_clause(const char *str, size_t len, int argc, char *argv[]) new_argv[i] = expand_string_with_args(new_argv[i + 1], argc, argv); + /* Search for variables */ + res = variable_expand(name, new_argc, new_argv); + if (res) + goto free; + /* Look for built-in functions */ res = function_expand(name, new_argc, new_argv); if (res) @@ -255,6 +338,7 @@ static char *eval_clause(const char *str, size_t len, int argc, char *argv[]) for (i = 0; i < new_argc; i++) free(new_argv[i]); free(name); +free_tmp: free(tmp); return res; diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 9a14797..dd08f7a 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 8a82aaf..e15e8c7 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 Mon May 28 09:21: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: 137036 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2591759lji; Mon, 28 May 2018 02:24:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdINbZ6/BBArgzxfrTjFTqifA0lkBw3CR0jHsbdu4hZ+8HsIaLjx8UjUqVkYWfrxBrVLTa X-Received: by 2002:a65:50c7:: with SMTP id s7-v6mr9946385pgp.359.1527499459151; Mon, 28 May 2018 02:24:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499459; cv=none; d=google.com; s=arc-20160816; b=FmbDSGe6um17oQGVLTkxEd3aDzxUqUML4EGt/Z6DyY9nqOIKsdFxAv4UL4sLXspxGP UN/gi63iAg+tXboECJ62wR23210JEyqtDVHo9uq9wd1CqvbZsyFwNyLemyMmnMEXpZNn V0pKOFNTjYUFr4H9NYA714ELLtXh9Te10Lk7vNhsOc6TwNG7YePXGUjKAlex/MA+h/dG BqTCHsFSc9tkBkvsjvhr1o9m6nnEWTickvLukVC7vvPveR7I+DOwYqiTKbYP2p9kme9h o819yt3Fb1NfpIDszuBLdafnzLBDKnXgeYG6i2n6d3BZosih33dtnVQ6iPVR7j/Ecqqs m3CQ== 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=eZ7Dn7/LEJcOdurXvi4kEK8PWh0jBitZmbMz5stFI3s=; b=iS+xFhfXtzsMmYvFBwLktafONN/FeLKtd7Lc02GVqO07c1ao9xNG9nm5mIeO2NYK+h SduKP14SHWidK227BXsd/yiohZ3OEjRpyTp74FGV7+l9QpnKHb9usKeAxaTEbBotIgZe YcCMG/LE/RuIKdEmWI6xXYP6LoS/coDgz7fVmkdu7F9FR5e9HgrUiNoaURoZXohMOTt0 HHPV69IGlOID8Zxdt/LEbtAFooyG6cQt+EVnLxGs3nvGGmN5OO8k4si1bEykWDcEH02a jdcltMVY0m9sfnv5JYgG3igUH537A/H5a+KMdMs52Y90zsdJws682O0OWgmzVR83wFB2 QXWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=o9WL31Gd; 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 b63-v6si30038512plb.566.2018.05.28.02.24.18; Mon, 28 May 2018 02:24: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=o9WL31Gd; 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 S1754308AbeE1JYO (ORCPT + 30 others); Mon, 28 May 2018 05:24:14 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21449 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133AbeE1JYM (ORCPT ); Mon, 28 May 2018 05:24:12 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInU027506; Mon, 28 May 2018 18:22:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInU027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499350; bh=eZ7Dn7/LEJcOdurXvi4kEK8PWh0jBitZmbMz5stFI3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o9WL31GdIVXbbhLQbc2bn+fT3GL477ZNVXsohtcil5Yu3yzOhkMaBD9iyTuwAIhUy iU5W4OLWqkHsTLvzL/i+OWucqFx7l1ndTThuZ9YdTZtT+vphVhUIUjt3oilD73WWlp nCmzSDH1sO7kKY/f1kEh1ql28sncWhpfKYa3ywsiFAps66KsjxEtsT8ZuhVFLjQceM 4bU3q2cMwM2PgOda7WT7ATtvqcDnCqTMuyq5D2VPIHtiqraoVtOBpw5HH4vJmFIvPj PZlYC3fJHwW/QGJr6wcCneTY2Urb2hPwgg5RVXrFlf2xb3sZooNKbLwOV1TCxY8sDQ 5RBjsvo6ZzQ1A== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 13/31] kconfig: support simply expanded variable Date: Mon, 28 May 2018 18:21:50 +0900 Message-Id: <1527499328-13213-14-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: - Fix multiple expansion bug of simple variables Changes in v4: None Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 7 ++++++- scripts/kconfig/preprocess.c | 19 ++++++++++++++++--- scripts/kconfig/zconf.l | 3 ++- scripts/kconfig/zconf.y | 5 +++-- 4 files changed, 27 insertions(+), 7 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 46487fe..d103683 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -185,6 +185,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -203,15 +204,22 @@ static struct variable *variable_lookup(const char *name) static char *variable_expand(const char *name, int argc, char *argv[]) { struct variable *v; + char *res; v = variable_lookup(name); if (!v) return NULL; - return expand_string_with_args(v->value, argc, argv); + if (v->flavor == VAR_RECURSIVE) + res = expand_string_with_args(v->value, argc, argv); + else + res = xstrdup(v->value); + + 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; @@ -224,7 +232,12 @@ void variable_add(const char *name, const char *value) list_add_tail(&v->node, &variable_list); } - v->value = xstrdup(value); + v->flavor = flavor; + + if (flavor == VAR_SIMPLE) + v->value = expand_string(value); + else + v->value = xstrdup(value); } static void variable_del(struct variable *v) diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index dd08f7a..376af6c 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 e15e8c7..6f9b0aa 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 Mon May 28 09:21: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: 137066 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2597225lji; Mon, 28 May 2018 02:30:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqc4oCpezBYMXcO7j+ndAr0U+4Dg96jNO4H1IPhUVDNUUgQupuy1AkfMyRdzdf1ydWL9V4H X-Received: by 2002:a63:5f12:: with SMTP id t18-v6mr9733220pgb.81.1527499858441; Mon, 28 May 2018 02:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499858; cv=none; d=google.com; s=arc-20160816; b=CMtDIHhdbK/nzpSwGQdxi/VruEPw1sXoJyw5sPJLKCsqWDtjXqr1B1dGXcVAZJ7I5O ps3tqYdAc1nQKbQw0MdJCPoL6Cw4fA51xEcLMt3gOkE7FRjW77jLPIb/sMBFNI2dc+uG 3HVmzvMOh0o20EONhsX+DRGMPZijze4NazC9sw3Qs2M3n7I/R+eKtqFNlfm9vFu6KNYc EFbHVfWjnJrxhe3w5XRAtzYl/fPKbdbwjs0UgfCVrKTWvvwP01Ln+LQVIrRFYJuMpdsC UuHawOCDZHgy7KFOMbruYERaKDZ74QHOem9l6wTZ32JGmXy0DCsDsKP+KOvXiNhN+dsd HPkg== 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=3oQUZQmz3ZbFWUKPhXIaBpGvdPd2p7aJebc3HxGnsy4=; b=gedxDEr9OskFOIg6CZKiNLstpU6+Ojr89QVTqhR+XoVn1P16mHWR/kL8FIWgXF7zli u2xoQQi/D00NdX60P3kDEkdIQiDGjzAFjRSzqtTMWUrnjBk9ocqvy7hHXZi+vJJVaakT Z8qF+HmmcpzLoxewBG97o1/cU5izBJh6mqobcQMjzPFGRqjgZbORsb1HM1NlWbar+O+w NzJUX4ksuIwtYlRniVb1fU5ug+jXSvIraWFCCDnvoBvYuXHyln9VI3Uwvq67wXeSgWqF jvoDQU8DRtbGKxZWN4RvKqVtUR+lxTEs/DdYCibWcWh3WYX9lIkjv48CXpiMsD0fb5pD oDew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Pkj70tln; 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 o89-v6si4601785pfi.165.2018.05.28.02.30.58; Mon, 28 May 2018 02:30:58 -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=Pkj70tln; 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 S1754546AbeE1Jaz (ORCPT + 30 others); Mon, 28 May 2018 05:30:55 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21512 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754219AbeE1JYO (ORCPT ); Mon, 28 May 2018 05:24:14 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInV027506; Mon, 28 May 2018 18:22:30 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInV027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499351; bh=3oQUZQmz3ZbFWUKPhXIaBpGvdPd2p7aJebc3HxGnsy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pkj70tlnqR8w6Ez0EADseBu0P8neHXTjSeyOaiViIAr6tTsJF8ZrZS2ATU7H74+2l pWsxwW9gcGb2N4FaFU2F/uINE4ZaJ2aVU6pno6sIq+NXTWvYScxIXY8VB3jVMaEai6 sXfEomZuN1L5hJQ0vcFCrYgAfn7D2//BxC6Vm1mY7rdzIaniZrdQZIAi8xTrCD4IDT NNSMaabHMQNTK0zL7NM3p+JGrJHQsAp1A0rjTNqFWGt/54QoV/A77vgA5vpj5LnGML /NUeDkMrlTI7N+aeRB4UGkI9o55u8pKZ9RubFQ+Ebm3XIzAlG5r0td252d2XZJCwuO vDABnsFymCGZg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 14/31] kconfig: support append assignment operator Date: Mon, 28 May 2018 18:21:51 +0900 Message-Id: <1527499328-13213-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None Changes in v4: None Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/preprocess.c | 28 +++++++++++++++++++++++++--- scripts/kconfig/zconf.l | 1 + 3 files changed, 27 insertions(+), 3 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 d103683..56aa1f0 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -222,11 +222,23 @@ 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); @@ -235,9 +247,19 @@ void variable_add(const char *name, const char *value, v->flavor = flavor; if (flavor == VAR_SIMPLE) - v->value = expand_string(value); + new_value = expand_string(value); else - v->value = xstrdup(value); + new_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 376af6c..a6cbe2d 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 Mon May 28 09:21: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: 137048 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592577lji; Mon, 28 May 2018 02:25:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJz74PdfursOFNg7uyhah0YRvcu6MvNVNmOe8lCTyrz9VHEcE+U/bGWBrKt4UWYMPX/v7w9 X-Received: by 2002:a62:bd0:: with SMTP id 77-v6mr8175659pfl.235.1527499524659; Mon, 28 May 2018 02:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499524; cv=none; d=google.com; s=arc-20160816; b=x8BareQf40Axp76esP4LdggVEMUD23mPKBgWvjTAHgK4G08lBw0/CITQi817BIlmVE h0NV195Fwh23PVmB1IxQRjMHtM4XVRhIirZ6v1/smAPhNbdo82t74RWOQbMZQW2B3O8r mUvxisxCxu1Tk85aMw063RM+jBn1U8YF616BaDekpFxm2ZgS9xBwCWxxRym3XuNt6Oz5 k+zTR8rRY8osMMNrtXVx9oN4X4fv+Ho9WCZihYSUskvGs+8cEkld3cx3vijZLUcxWGIq g5/aJ69Hdq9gTPBYLtyq7Chkl49fCkcfHDBynEpYeoSYAfFzaL+Co1WBsIDtjR6HcO4g VTzw== 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=lnlXgpG2yr3gcltd1Tfk1Ic+F5H37kq4DDC7fttMI+M=; b=PevLMx6BAaWvV37xiRF/teKYkowDKvn6m4Eal05akQvPGNe6junAcQ6tzUwlRHjHkr OjJO5Ul9Ts8EhrKmSPTbEFEY/3boRZndU96Vlo8BGu69TRpSDk/LV3NLA17pdmp/Mqbz gX69Fi+JytFnnNHn5bftNA7AdwBk8GdJDQPjLMsjRXmmUDyH749ekG5uEMd1Wg5X30Pi eWAfNH2l4lrSE4SFvq5XNv7VNGJsR2PzKT1eenMAtR7ln1chkItgB+Alo3nLlDtgyFQh EGR+3Tmck5hSv3Fua3iE5FadsCwaL3cy5egi6+mCfhig0ac2WQin0iBjmfwHYnmIBayL aKhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=0SjgHlGG; 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 o73-v6si29905174pfg.327.2018.05.28.02.25.24; Mon, 28 May 2018 02:25: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=0SjgHlGG; 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 S933832AbeE1JZV (ORCPT + 30 others); Mon, 28 May 2018 05:25:21 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:23165 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933652AbeE1JZJ (ORCPT ); Mon, 28 May 2018 05:25:09 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInW027506; Mon, 28 May 2018 18:22:31 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInW027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499352; bh=lnlXgpG2yr3gcltd1Tfk1Ic+F5H37kq4DDC7fttMI+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0SjgHlGGUBYwbKzkRSQbUdD6UfsTXr7xFW07Vkc/xUCpFhiuiw0Y3DJ9X9QytQOyU Sb285tZtIeqBxaBgIICuaRZZbwT8+8caneCScsbYKUImfHAkrjHida3di3UVbs17So NvfhWzeIgxD+urnNnv2hTazWoei6jaoba9IUB2+INz6RFn76gFklZampIRNS85YYqy 9/t06cHo9MdtrACaZ7Ypr3I3k+OPaeLSP4ggS4wPkA9Qvm4r62/MTfQhosT5vwUZDe oCazBHuAqsEYGwa75hB/DbE8RK3sK5KdkeKKyTrR6WeBstoZKnxUWvj4RwPqx4Jact gkj4CkYzJ1GGw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 15/31] kconfig: expand lefthand side of assignment statement Date: Mon, 28 May 2018 18:21:52 +0900 Message-Id: <1527499328-13213-16-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 this: obj-$(CONFIG_FOO) += foo.o Do likewise in Kconfig. Signed-off-by: Masahiro Yamada --- Changes in v5: None 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 a6cbe2d..25bd2b8 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 Mon May 28 09:21: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: 137057 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2594882lji; Mon, 28 May 2018 02:28:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpAp9qjrHs/Ro+Q4epxWg7W9/6VmWQjxRtwEivd9l4uOONvV03iA5kv+PvU6wbfRq/iYKuF X-Received: by 2002:a62:4fd8:: with SMTP id f85-v6mr12832012pfj.77.1527499701952; Mon, 28 May 2018 02:28:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499701; cv=none; d=google.com; s=arc-20160816; b=uzyTfKAq91vpmt685Eu6yLGQm6ROlMGQ2i672XxRRUOgg7/VxzWgrEVsFPJDu0jEKB VV5v6ENVbqGP8yoZUuAfeL3mAglGWHocvHDJlYQxLqqY+4OeIS9KMMWQA62heyYQK2Uz DdEY0XazqVzbNxQwPk8jrKjtuw1rNlr2aKUBL/zx00M5qW0A2MkJH7dif3RxuFKX4OyD rq/F/WGdVgaiIEtU/nBnnqzAsBae0a0IaslzuojVnxR5RknOxbBKBhMiBZluoAMUmq+J Wo7VU0ixP7l3DV71OAvOorGbWkRL3yZd3zFfxk6UsdIOrwngctooT3UDuBnMcD7YiQPT AE2A== 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=JyN+S9qjkCUrUFMgbXUBDGzRIL5odSelzsNe5w8J8TY=; b=ArlZC+HkWgAxup1G/g8p0hfGaA5BdWO5d+tXFeLLMEoSnH9Sy8++b50Pb0RKS+nPmW XNpVS3JKqeXZfarnuXUN5g8HW9X2dNoP+vp94JCPYsA0d5wefWPK6JFBf4IHoEeVd9wD 5M3KjCuj5oXhzyFLmKQOace3tyYlJiGD/bAigae9bLp1rXNI1QTb21c04R5VSzWqo1Nt 65RimBpC5WkMZt/j0bjuYN54kU0TRxkohKV77sWkjnOJiIP1R1Ebth70tr21Ux10ujeH +lsGFJHmX8TEroWIofBFmWdI8X3hp3SHYsotXwVJuDHmwzcp8Sd7jmBKOnbubtxfYTBS d6Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TLxWhGMC; 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 88-v6si29308679pla.315.2018.05.28.02.28.21; Mon, 28 May 2018 02:28:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TLxWhGMC; 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 S933979AbeE1J2R (ORCPT + 30 others); Mon, 28 May 2018 05:28:17 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21625 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754333AbeE1JYR (ORCPT ); Mon, 28 May 2018 05:24:17 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInX027506; Mon, 28 May 2018 18:22:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInX027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499352; bh=JyN+S9qjkCUrUFMgbXUBDGzRIL5odSelzsNe5w8J8TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TLxWhGMCGZuksNAJ2dPT+1KP/EaHtdgrHxvOCbRcWoQOfoHzYQCSzLrLJ5FieyTYX AcTYGcgc1+huttpndXspK8f49iCHIBIx5ko4MnA569sm0SqKEksB7csH9U0DBgKbmY idYHs7A+hkfHkHnE44bWJQH6+GOz7Te4HZji+I5M3O5BY4TQWE2d8XJj3kqij6kmLO +TaqlaPBwPSmP9hUNh+qfOKcOHjYyBdhZvGJXKs/whVGOzsn62G6twW+dYhXLkpNod otiiNn4Y1r7Mjm9XOBPZRBaK4TuUAfgfvYKpgwCS7+NY4p4E9vSZf++reqQPy/SDLb aJPiRO/7w8WlA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 16/31] kconfig: add 'info', 'warning-if', and 'error-if' built-in functions Date: Mon, 28 May 2018 18:21:53 +0900 Message-Id: <1527499328-13213-17-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Syntax: $(info,) $(warning-if,,) $(error-if,, part is y. Kconfig does not implement the lazy expansion as used in the 'if' 'and, 'or' functions in Make. In other words, Kconfig does not support conditional expansion. The unconditional 'error' function would always terminate the parsing, hence would be useless in Kconfig. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook --- Changes in v5: - Replace 'warning', 'error' with 'warning-if', 'error-if' Changes in v4: - Add 'error' function 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 56aa1f0..5ee58ee 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -106,6 +106,21 @@ struct function { char *(*func)(int argc, char *argv[]); }; +static char *do_error_if(int argc, char *argv[]) +{ + if (!strcmp(argv[0], "y")) + pperror("%s", argv[1]); + + return NULL; +} + +static char *do_info(int argc, char *argv[]) +{ + printf("%s\n", argv[0]); + + return xstrdup(""); +} + static char *do_shell(int argc, char *argv[]) { FILE *p; @@ -146,9 +161,21 @@ static char *do_shell(int argc, char *argv[]) return xstrdup(buf); } +static char *do_warning_if(int argc, char *argv[]) +{ + if (!strcmp(argv[0], "y")) + fprintf(stderr, "%s:%d: %s\n", + current_file->name, yylineno, argv[1]); + + return xstrdup(""); +} + static const struct function function_table[] = { /* Name MIN MAX Function */ + { "error-if", 2, 2, do_error_if }, + { "info", 1, 1, do_info }, { "shell", 1, 1, do_shell }, + { "warning-if", 2, 2, do_warning_if }, }; #define FUNCTION_MAX_ARGS 16 From patchwork Mon May 28 09:21: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: 137061 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2596097lji; Mon, 28 May 2018 02:29:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrS7DRhzvfbZ3kf4VtrQ+55DEc7sbDkj2XeIViVVTBXCf9DV3mH6TKjz5U5WrOsOa2M+lDV X-Received: by 2002:a63:87c8:: with SMTP id i191-v6mr10117563pge.124.1527499791563; Mon, 28 May 2018 02:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499791; cv=none; d=google.com; s=arc-20160816; b=xc7c2BcnxSq+WeNpWIkeZjeGjRAlsVANsvOXiAcsPXkTPGPTdo/ZWLgYsEVXXhVUWb IdZdeai+HrhtZBoIwpM7YRocrQKQ5kJJe2qFJ72f1DQlsARHqgGh8YeKQ/9wuqVYsvcS feJRiTeR2dpzkDRefKZlclRhBM/WGw37Md3bsJWsTx+mTzpaLH9dE7DV/wyMqw9OLQwX OWOswLLAcNHMpC+OahZEkCNYgE/E2HdRsZ35X+srqiNKmsf8kYk5p/M0tKMbvgzPiRXl tbVp/ieRIU6DyGSRezeb6e7MYiId307Ef8KPr55Oo+uyDowlXhOL6RVtD59e6VG9h8ey eZPw== 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=yy4siuNzt3oM11IST7ouMxBogD9ZdE8h3kOPZXVnJdI=; b=CCHtzLkVUeNSOj97xMkKcdu7bpCIePPGi00kE+Tw6Xm+p/YmNK18pQU/ZHgU0BTCQ3 +8vtgwqrCmB4Bcr7eqzINPpxZS5EeHN/cI/U6m3rFD58GGIGD+leS2SngJo0WZjaCzEP zulOZZ0s4/bUypF2cZyI3tmzdhiqoUPvETIzV2HvyYcBoXrEGd5LBL2xFRCEAD+yOCDk HvYq3a8qqGm6+VDx129diTWzIx/ow+Drc9zmI9yI6emL07iS/v1zg2MEsNHQAt6OpoeH Lghv69cNw36KX8zaXCBj/tYEGg68mVTftdFBhsUmE+Y2EAyz/DmkN9T/BS21Dlh8goi5 aSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Eq2dVn0h; 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 q3-v6si22669389pgp.95.2018.05.28.02.29.51; Mon, 28 May 2018 02:29:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Eq2dVn0h; 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 S1754479AbeE1J3s (ORCPT + 30 others); Mon, 28 May 2018 05:29:48 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21615 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754319AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInY027506; Mon, 28 May 2018 18:22:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInY027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499353; bh=yy4siuNzt3oM11IST7ouMxBogD9ZdE8h3kOPZXVnJdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eq2dVn0hd24xKOSryq7GVGM70lHNM7bXufgmO7P18Gq3MZ+lsABtanb47Gp98qdBa 08AUYyyVl1BJJus+PqtPx1HdH+XtT2JPjbSsPufG3zO23mdYR7Rt/29+F9CVyFcX1V 1DmGVa+AOyZ4IMmyqpnf6IJslzM06MqTJO6/AW8AJpp8NhKX3AWgwChuiSGIYdgSXH qEWXEdZY4i4QHTE0YQgRWIlgQi9BEb3++oTQbxv9T4MuVLLx6CEY0NKnrhK2Mly+UD q7l9rAo1+VeH9bhBDLGkh9eqNc1mQe1UcS8g1+Nna4iAoxDlbNmc6mvkZ/LlcFwQoE +KWyrWTKRDAYA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 17/31] kconfig: add 'filename' and 'lineno' built-in variables Date: Mon, 28 May 2018 18:21:54 +0900 Message-Id: <1527499328-13213-18-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Reviewed-by: Kees Cook --- Changes in v5: None 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 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 5ee58ee..0574039 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -114,6 +114,11 @@ static char *do_error_if(int argc, char *argv[]) return NULL; } +static char *do_filename(int argc, char *argv[]) +{ + return xstrdup(current_file->name); +} + static char *do_info(int argc, char *argv[]) { printf("%s\n", argv[0]); @@ -121,6 +126,15 @@ static char *do_info(int argc, char *argv[]) return xstrdup(""); } +static char *do_lineno(int argc, char *argv[]) +{ + char buf[16]; + + sprintf(buf, "%d", yylineno); + + return xstrdup(buf); +} + static char *do_shell(int argc, char *argv[]) { FILE *p; @@ -173,7 +187,9 @@ static char *do_warning_if(int argc, char *argv[]) static const struct function function_table[] = { /* Name MIN MAX Function */ { "error-if", 2, 2, do_error_if }, + { "filename", 0, 0, do_filename }, { "info", 1, 1, do_info }, + { "lineno", 0, 0, do_lineno }, { "shell", 1, 1, do_shell }, { "warning-if", 2, 2, do_warning_if }, }; From patchwork Mon May 28 09:21: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: 137058 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2595313lji; Mon, 28 May 2018 02:28:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrIarygQRaff69wM7WKRsxFpHTb0sZwDVtIVSt6a/nGTSOF+Vxid1uobVkYM9Tk/4bjd2rR X-Received: by 2002:a63:ba1c:: with SMTP id k28-v6mr10028570pgf.179.1527499735133; Mon, 28 May 2018 02:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499735; cv=none; d=google.com; s=arc-20160816; b=zW5qTgqfcBAjJQfXIcJi40sH255wwM6XmBNJ1OyNh/O0nJzCiqfM7mV3JNQiyL9ODp APEpjLe6L6cf/ggk46QK7sEvMOJxRxFRSkOyVy+Mq9ZsRVa3gV1uNzwQyFbPX5mYSaW5 FiZ0z+Bv5C2dv6+1G9P1cg4AZpYBKOFwwmwNeCiI+bW32kG8hOqwH7Q01HCs3IznC24R 2ahYLbqJdUIn5AG+GV3yItBS8czOqZAMiZvhAsQmnQ5zYo/Hx51nCOuedjT8xj+ev56W POKhkkWm/Ca534mZ64ZjAHez8BoGwfiY5mnpJhF57x/8z18XZZIdoyu/7rbz0bDeBeny oS0w== 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=LbVKH3YfDdo86RaBlckj7gU3H1+hfktcSEEEz/uGgcY=; b=B5XRtOpGu5R+6ZRXXskLN5vNACDXpDrcEjxJ8wnmnBpB5a9S0hLazLtm5IjyOlHYuN m8j3AVO58o2U330dywmClGscWcNwI3as62ZT9HoKxynNv9nEG2AGRi/4iYIDmvHZRHqb 46VV0DCU9Bfbo+GU8bbEb9tJ5rTj3kUhajLltNKyIMiafB5XtD3uaBqwnN3yyM/icBiP fCVvkCzAQdXWVxWnkW15PDZUgSPI4hPlrkP18d0oTvlgsyImS1cR5WGsid/GVPcmQR5d VW1lwW8PsM6zzuiQzuf6MBhLzRJjDTHkaBGvhvRa4tzR4F8XCFfENTGG9MriomuZMY1f swoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aNSMywPA; 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 g13-v6si23861279pgn.146.2018.05.28.02.28.54; Mon, 28 May 2018 02:28:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aNSMywPA; 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 S933888AbeE1J2w (ORCPT + 30 others); Mon, 28 May 2018 05:28:52 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21628 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754334AbeE1JYR (ORCPT ); Mon, 28 May 2018 05:24:17 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInZ027506; Mon, 28 May 2018 18:22:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInZ027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499354; bh=LbVKH3YfDdo86RaBlckj7gU3H1+hfktcSEEEz/uGgcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aNSMywPAxNtsGreyBwY6U1/dqGrF+LLwtOMpWTN2ZCeDnteSBvqFGMd0oBILUuuZn WNXDteNr0OkKty3mVIQwa6b9PR58IFc85hFfWZaEw00crfRy0Pq0DZibAI2r20DQqZ 1wYWT7kQhSgObelyN8TUjUl/G6+8qDpQN1Y7rhdQtKGBWXNwmEWMNHBvM1//GDLfGF LIe6nWa2yvzeRh+Tu9h3ntyh+BncRLtXrHACCXtu4ARPjp3xF8DPbw4TnIIOitGJWP oWL6RDyCbWwn7athfY/hdi9kSnASEVyuz+5ZY1+bY0fVUjFaJrl0GmO7faLIuVxwSl v6NGf7jS66M5w== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 18/31] kconfig: error out if a recursive variable references itself Date: Mon, 28 May 2018 18:21:55 +0900 Message-Id: <1527499328-13213-19-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 0574039..65da87f 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -229,6 +229,7 @@ struct variable { char *name; char *value; enum variable_flavor flavor; + int exp_count; struct list_head node; }; @@ -253,11 +254,22 @@ static char *variable_expand(const char *name, int argc, char *argv[]) if (!v) return NULL; + 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++; + if (v->flavor == VAR_RECURSIVE) res = expand_string_with_args(v->value, argc, argv); else res = xstrdup(v->value); + v->exp_count--; + return res; } @@ -284,6 +296,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 Mon May 28 09:21: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: 137054 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2594484lji; Mon, 28 May 2018 02:27:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqCy1oQvo71GOkUyNgbYyFa7Ab2/WuwuAlSlfARX+7H8vetVIOPWbyBJyeaW800o6IU1xoL X-Received: by 2002:a17:902:8308:: with SMTP id bd8-v6mr12948418plb.195.1527499672309; Mon, 28 May 2018 02:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499672; cv=none; d=google.com; s=arc-20160816; b=dwXqYjeQ27AUlieikXPyNkr97hAD2rZ8gyRohD5uB6tf2iguP20hrSguEITUPoZcnl 0GOjpVjEhyJdQPNydWRI8OSTu3ASnsMk5XTqrna3XqfK6WpL0le8QHiTyJVbBbxTuf7C XXIG+7B7awfK44edbNzbV7UJOqPDF++JU9c72PSXTP1dIJqU2u2DolNKAXF6S1+iLUxS LwsuerTT5Qmm0P7M6rtceMrNrbnYvbdFcyD5iPiu/FNdlP+k0+AbmTYInw5VrUe3Hbay Xq9AynPizXumjmRd1KLJEpAbbXgoDwM8vg5w86tTo4jd1MQ2Mz6BM0ZGC7RfeLmjMHpI SpeA== 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=j/GROc78f6byteZ6xTJQ/0oJhHGmnBbZ4PRMk+adfZE=; b=Cmx9ZOV0O/ZPGG86fbScZDEjCDuJC8+CDge4bqp45Yvb6iQC5zF6eLyOC3fwqHo+0W C7ojM8DJ8RJLhn0jAA2xscVBVYNE7kUPBy1/CdxIjWSBrkUh3S2BUiBKqFKTkVs2NQXb J1YqM6rTpsKapDvqgKJraYuFit+PkgzqweTRE7mMGaKGHMN0udA9caqdg9TQ2sgjUf71 NY7pYzu8iaz1uaCJMvkBf/DBzRTkRyoau2rPe16hb+ShfmzkTS2XZLdGie4gfTClra/1 gtB+wAuGJlU0rst4iLw4edGT2WKZhgEhJqnV/z2qvV09pAgPvK/6zv2wTdeeTcZaQET8 p2+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=iWtHvgoj; 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 34-v6si30119576plp.409.2018.05.28.02.27.52; Mon, 28 May 2018 02:27: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=iWtHvgoj; 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 S933822AbeE1J1u (ORCPT + 30 others); Mon, 28 May 2018 05:27:50 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21714 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754090AbeE1JYT (ORCPT ); Mon, 28 May 2018 05:24:19 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MIna027506; Mon, 28 May 2018 18:22:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MIna027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499355; bh=j/GROc78f6byteZ6xTJQ/0oJhHGmnBbZ4PRMk+adfZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWtHvgoj/8wGsQib3diuqgWIZDjeEj3wO0goH7oDzbj2n3KXhmK1vZXH2HnuW/4g6 DGl3ljgW1/GMob3WaDvLn71m52C071JlNDv8M39ckLtx5Vhpy0ctSwIbM0LxUQQEWa 84ZCtlx85jS9yNjA+4JTsDbAlkruFF4ZAghCyhMEwn+FihUaZVZyZJcklLPYniky3Q qV0MvbWfNprTYvVPvALqvy3oTzPsc1KxryNX52WY4AMYrgPW5HRYiO94zCDx1lFqqL n0af35r0i/nVAQCwGcRoSu0Wxx9ReS52yT7mNdFtAhSr+cyXAvbedQr2lIngtCV6FA UyUkKI0+PCqpg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 19/31] Documentation: kconfig: document a new Kconfig macro language Date: Mon, 28 May 2018 18:21:56 +0900 Message-Id: <1527499328-13213-20-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Reviewed-by: Kees Cook Reviewed-by: Randy Dunlap --- Changes in v5: None Changes in v4: - Update according to the syntax change Changes in v3: - Newly added Changes in v2: None Documentation/kbuild/kconfig-macro-language.txt | 242 ++++++++++++++++++++++++ MAINTAINERS | 2 +- 2 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 Documentation/kbuild/kconfig-macro-language.txt -- 2.7.4 diff --git a/Documentation/kbuild/kconfig-macro-language.txt b/Documentation/kbuild/kconfig-macro-language.txt new file mode 100644 index 0000000..07da2ea --- /dev/null +++ b/Documentation/kbuild/kconfig-macro-language.txt @@ -0,0 +1,242 @@ +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 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-if,condition,text) + + The "warning-if" function takes two arguments. If the condition part is "y", + the text part is sent to stderr. The text is prefixed with the name of the + current Kconfig file and the current line number. + + - $(error-if,condition,text) + + The "error-if" function is similar to "warning-if", but it terminates the + parsing immediately if the condition part is "y". + + - $(filename) + + The 'filename' takes no argument, and $(filename) is expanded to the file + name being parsed. + + - $(lineno) + + The 'lineno' takes no argument, and $(lineno) is expanded to the line number + being parsed. + + +Make vs Kconfig +--------------- + +Kconfig adopts Make-like macro language, but the function call syntax is +slightly different. + +A function call in Make looks like this: + + $(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, +while 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: + + empty := + space := $(empty) $(empty) + $(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 matter depending on the function. The same applies to +Make - for example, $(subst .c, .o, $(sources)) is a typical mistake; it +replaces ".c" with " .o". + +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 treat commas verbatim instead of argument separators. +For example, $(shell echo hello, world) runs the command "echo hello, world". +Likewise, $(info hello, world) prints "hello, world" to stdout. You could say +this is _useful_ inconsistency. + +In Kconfig, for simpler implementation and grammatical consistency, commas that +appear in the $( ) context are always 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 ca4afd6..b87723a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7637,7 +7637,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 Mon May 28 09:21: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: 137041 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2591992lji; Mon, 28 May 2018 02:24:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoeGD37dRs2TM0kupesDJzhEMbRVxZ70huD0IsY1x2woXZ+IBUNWNkaTyy7+rGjw/dJfWj2 X-Received: by 2002:a63:af13:: with SMTP id w19-v6mr10217290pge.47.1527499477388; Mon, 28 May 2018 02:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499477; cv=none; d=google.com; s=arc-20160816; b=X5UNffCoRpiu1mSZ6N1GDevI00SxdKVHKnRpwGpNivQCwFAhj8v2mPbvyT6a0eErBA 7qTQCnxRAYV9XRFkcgexlOlXyFNj3s8DXNkakne9BHjrsjaR2y5RSwUmKXDV/JFLe14t gfdJHMMrxsFs6i4XdcoeLZh2pEFwOuXmaEbB8U/8CmB6hIa8qse0F75grmVlLFtpyMFV zp83gErnE5lMiICKF77zMb9/pApAEcmh0+g6csbGBc1UadaEqduHC1IIx9DiQMhi1otc HIGx6j/ZoCzcXe7KjRLOcM1buh7B3nsh3orL/bMwiiB/hOJGWhQ+5rvbWx2Wlpep5oUX zouA== 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=0hdLDJRgUGIAi4OY9ovYMG+CduToOpK/lLyOwpYtHOc=; b=pObrj2d9okwyBMraCbYqh+TYw6eL7gUOrKNylDcGe8DwLcdUVkyxKFqwCIHsaKqo+h n6O5YW20aO7f9vVoDcVTB6dgLCNBOvGwBoILn0rEtfcZdX7reXAjvOOJ0SydkGU3NhoF +h8qli+eTCWuRypLa08uj/tUtDiQ4HNKMVfUVUiCzHMTbmF6yvq7xMBa7fU1vy9BMGVm 8mL47bokfCpUJKCHxRntnjBGx/IxoZ0T1Tfh9XhtPS4je+GrR6V+Hrm301Q6a/bNXvPq Bf95Ktne4QujvEh1emDNZe8EmQjOUcOeqnu2rXN1bzwAntn4JZD26iwfqIBEZHfcF/wV +ubQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=JyX3oYS2; 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 a76-v6si6834972pfk.35.2018.05.28.02.24.37; Mon, 28 May 2018 02:24:37 -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=JyX3oYS2; 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 S933221AbeE1JYe (ORCPT + 30 others); Mon, 28 May 2018 05:24:34 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22008 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932170AbeE1JY3 (ORCPT ); Mon, 28 May 2018 05:24:29 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInb027506; Mon, 28 May 2018 18:22:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInb027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499356; bh=0hdLDJRgUGIAi4OY9ovYMG+CduToOpK/lLyOwpYtHOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JyX3oYS2kvW+f7yHKhssjFDfItx2my1MukEsE+NArTYGk/AhuxwqG06eGyYanp8ks pA7aho2ptEhL97JJHHbhuf4YCGiZTLl9ImT6gZsGNq4tqAa9DBRKgLIoBLkfYg3S1e 6/aGcOlS3sORvq9HNWWXQ/yPXqRTmUx+joIxM119U/OODA7mOZ0NDRSu7ZcfyGLDYx 1b/faI/yBlQ+Un8ZiF1tj1PvzCmBSEg3yyd5jI/wQajv34eY+FuscKjsSdDGRpSvRY p8XtCs65paAUNagYKhbU9Ejxo/QRkH+PvF2VcsG1JnhYPh2e38/ryAMEHCSmwsbhcf BtbFV9IxWNFLg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 20/31] kconfig: test: add Kconfig macro language tests Date: Mon, 28 May 2018 18:21:57 +0900 Message-Id: <1527499328-13213-21-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: - Add SPDX License Identifier to test files - Update tests according to the simplification of grammar - Add more escape sequence tricks 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 | 27 +++++++++++ .../tests/preprocess/builtin_func/__init__.py | 9 ++++ .../tests/preprocess/builtin_func/expected_stderr | 5 ++ .../tests/preprocess/builtin_func/expected_stdout | 1 + .../tests/preprocess/circular_expansion/Kconfig | 5 ++ .../preprocess/circular_expansion/__init__.py | 11 +++++ .../preprocess/circular_expansion/expected_stderr | 1 + scripts/kconfig/tests/preprocess/escape/Kconfig | 44 ++++++++++++++++++ .../kconfig/tests/preprocess/escape/__init__.py | 8 ++++ .../tests/preprocess/escape/expected_stderr | 10 ++++ scripts/kconfig/tests/preprocess/variable/Kconfig | 53 ++++++++++++++++++++++ .../kconfig/tests/preprocess/variable/__init__.py | 8 ++++ .../tests/preprocess/variable/expected_stderr | 9 ++++ 13 files changed, 191 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..baa3288 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/Kconfig @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0 + +# 'info' prints the argument to stdout. +$(info,hello world 0) + +# 'warning-if', if the first argument is y, sends the second argument to stderr, +# and the message is prefixed with the current file name and line number. +$(warning-if,y,hello world 1) + +# 'error-if' is similar, but it terminates the parsing immediately. +# The following is just no-op since the first argument is not y. +$(error-if,n,this should not be printed) + +# Shorthand +warning = $(warning-if,y,$(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)) 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..2e53ba0 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/__init__.py @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +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..33ea9ca --- /dev/null +++ b/scripts/kconfig/tests/preprocess/builtin_func/expected_stderr @@ -0,0 +1,5 @@ +Kconfig:8: hello world 1 +Kconfig:18: hello world 3 +Kconfig:22: hello world 4 +Kconfig:26: filename=Kconfig +Kconfig:27: lineno=27 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..6838997 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/Kconfig @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +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..419bda3 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/__init__.py @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +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..cde68fa --- /dev/null +++ b/scripts/kconfig/tests/preprocess/circular_expansion/expected_stderr @@ -0,0 +1 @@ +Kconfig:5: 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..4e3f444 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/Kconfig @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-2.0 + +# Shorthand +warning = $(warning-if,y,$(1)) + +# 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, ' " '" ' ''' "'") + +# Unlike Make, '$' has special meaning only when it is followed by '('. +# No need to escape '$' itself. +$(warning,$) +$(warning,$$) +$ := 1 +$(warning,$($)) + +# You need a trick to escape '$' followed by '(' +# The following should print "$(X)". It should not be expanded further. +dollar := $ +$(warning,$(dollar)(X)) + +# You need a trick to treat unbalanced parentheses. +# The following should print "(". +left_paren := ( +$(warning,$(left_paren)) + +# A simple expanded should not be expanded multiple times. +# The following should print "$(X)". It should not be expanded further. +Y := $(dollar)(X) +$(warning,$(Y)) + +# The following should print "$(X)" as well. +Y = $(dollar)(X) +$(warning,$(Y)) + +# The following should print "$(". +# It should not be emit "unterminated reference" error. +unterminated := $(dollar)( +$(warning,$(unterminated)) diff --git a/scripts/kconfig/tests/preprocess/escape/__init__.py b/scripts/kconfig/tests/preprocess/escape/__init__.py new file mode 100644 index 0000000..7ee8e74 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/__init__.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +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..1c00957 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/escape/expected_stderr @@ -0,0 +1,10 @@ +Kconfig:9: hello, world +Kconfig:13: ' " '" ' ''' "'" +Kconfig:17: $ +Kconfig:18: $$ +Kconfig:20: 1 +Kconfig:25: $(X) +Kconfig:30: ( +Kconfig:35: $(X) +Kconfig:39: $(X) +Kconfig:44: $( diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig new file mode 100644 index 0000000..9ce2f95 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/Kconfig @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: GPL-2.0 + +# Shorthand +warning = $(warning-if,y,$(1)) + +# 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..e88b170 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/__init__.py @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +""" +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..a4841c3 --- /dev/null +++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr @@ -0,0 +1,9 @@ +Kconfig:10: SIMPLE = 1 +Kconfig:16: RECURSIVE = 2 +Kconfig:22: SIMPLE = 1 3 +Kconfig:28: RECURSIVE = 2 4 +Kconfig:35: UNDEFINED_VARIABLE = 4 +Kconfig:41: AB = 5 +Kconfig:45: Hello, my name is John. +Kconfig:50: Hello, my name is . +Kconfig:53: Hello, my name is John. From patchwork Mon May 28 09:21: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: 137042 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592062lji; Mon, 28 May 2018 02:24:44 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrpDI7spsxzWhz5362r3jS85WKbZPDxWu0sLBbj3P4ADsIac55amWej89dn7lCVP5GMAsLW X-Received: by 2002:a17:902:b189:: with SMTP id s9-v6mr12946527plr.352.1527499484443; Mon, 28 May 2018 02:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499484; cv=none; d=google.com; s=arc-20160816; b=LMrTJUSy/WY2Rhl83SPT33yApvw4hW++OGgrc6NdrCLo7uf+IqI5JotL6qKcZj9qWr Jzq7c88mmJSMlNEz+LJpT6A3lygcOZNIzTj75PsIwS8lb+9vVSGHkeM9Jo83AvoTp9+v 0pWo+hIKOFNZ5U+T5a5TQhU/TQg72gix7fZslme9LSwNdK/dvkzJiMGs/gnE2cHtVvux 1jTzoub3Cz+iQMgSW7l7KRfjoq97eBbwY17/ZKuNfrYqx1QkllM6i3oNlM8bwcj9DZGq gZA2Ekj/kKHp4cfMx0UhqxkgepfxDaxJQvVqiyA3JxEsKqIViPPzjDkHuViComom4Q5Z nLew== 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=AxljiM6nQMv29U6TbNmPPbMehnAnc+k5ZzXGvso5DlI=; b=igqRsyiXDFK1OT49WDorSfU+nyxs5ZMXvipeHNPSsvru1XglLaeVDpxuH+5u2dHluY c/EfTxvvprpQMCO6Y0ENOrFZOh9onYG1XiYQkc12xtEc3AygvFD4K0pRdrKI4C96kCiX NevmFzDm7hbo7szlkF2/c/+81n8G9c4EkAL0xXcu1xoitkueiap+aJB+tAVdJXQXckIx Z3Lm7dqSc1Q9u+LbOdxpzLssqiJAtw5uidpgyt98nxOSZDqVzemANqIGIbMVzht8YfkC RlZXfsXci/hD78pPk7WnRDQLazF7+m0/cfczNAJUxpaN8PsfS3mXvWJzQxqjDUHRZ0+Z Wq8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=u+XQu24L; 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 k1-v6si29130099pld.416.2018.05.28.02.24.44; Mon, 28 May 2018 02:24:44 -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=u+XQu24L; 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 S933371AbeE1JYm (ORCPT + 30 others); Mon, 28 May 2018 05:24:42 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22283 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933233AbeE1JYj (ORCPT ); Mon, 28 May 2018 05:24:39 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInc027506; Mon, 28 May 2018 18:22:36 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInc027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499356; bh=AxljiM6nQMv29U6TbNmPPbMehnAnc+k5ZzXGvso5DlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u+XQu24LfQSENN5ArAfPLIgPV16g+n+w7uSQpEnuCImQYXRH/IgqCrqz+FvKa2NVA ZVsiLL0f7F6sJP8SEvr47CCplaCpYYG/3L7Ku4vde8MrxAjb06wJfW9UyaVBa+XDMz 6FHnJPqFpW67N9R9Qrm+LTl9d2XrgNRwDuuimluYtqp5HnpqiC/LPTb+788K9/DJzA J5G4oxJOqyE/1KAgbWkGvSLAs/bwltVQd0EEGU5CRh4sDYtgg8W02KKPKr+wOBZnuf c84rCnXhwBCg4S7h3jFJuNor3CaL1DzP8KOH83+4Kr05uCOtJCL8YYHHuaH97benL4 eogyEE5zOKP8Q== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 21/31] kconfig: show compiler version text in the top comment Date: Mon, 28 May 2018 18:21:58 +0900 Message-Id: <1527499328-13213-22-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 58afa07..defb383 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 Mon May 28 09:21: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: 137044 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592340lji; Mon, 28 May 2018 02:25:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpOwrwwj0EeXiypHgE1TfQCS8UMXwoAcFwV9uBvjsAdUY18EaaAhavdxHa/bdxz4+mNGMMu X-Received: by 2002:a63:b215:: with SMTP id x21-v6mr9541371pge.393.1527499507486; Mon, 28 May 2018 02:25:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499507; cv=none; d=google.com; s=arc-20160816; b=QTAwIV1+7e9/EJTDK84PhtzESwW8VUGAikauosfVCBI+bRTD4D9OP6xHe5MKwx8nrz GNKEik5/mB4ko7st9lw0cvJF6bgRGpDex+1Y778IN6ORlNEFdeHV4dqErHoUPVtMyUSA t8fw+qLHAd0ttp1DR1opl8d9z0hx74QHgGRI+OAi5ITQ68VrgY7hOC9JIfBfyYhiWbUV h1Rl78NDVjxqhdvn+iIdhflkvRLg9nxBQWS+lA8qfgwi9LCM/2/KgIFbZ75edox/RvEW tCo/NiI7eoqGqTrntq2RFjPPIra4dkHSE/Xm6ngQiAbF39LxmDlTFL+Xu9M7jn4c3cGa b8qg== 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=unsFiFi/xtm2oBI/in0Sb3ZGNiZANg5KGMUcVIKyl38=; b=KUZ3WUCLMFFUK7pTdZRW9JFKAZ5oZb4bR7jFUbkgIS95l1VtmUJHfGqc/naD8afgzN g2hQR9pp/iySHE01DrFbEUq48WFnhBTowGx/EzzQGhgtJaDMKJaTfwMKZsxPP/eHdRuL dh07goNjGHUzFCaJO4EsSjiPxVzoBRwPcdOKfi+B6SD69H/MJkWsNc+RIs0DHz9OAQ+J MCh/7dqnH7/KlHzrFqvS1hqpgPqnyjDGUrG0JzaleQYBnbQefACXDE2kBApD1O9V7K1/ scF/HMbPJWM8zdX55BPXAYgwX8iSidWaVEHBOyCLpwEbc3sc7Vi/LEMp96ZBrEk9j6Ci QJrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=U5PeggRi; 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 m11-v6si17795287plt.284.2018.05.28.02.25.07; Mon, 28 May 2018 02:25:07 -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=U5PeggRi; 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 S933585AbeE1JZF (ORCPT + 30 others); Mon, 28 May 2018 05:25:05 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22960 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933509AbeE1JZD (ORCPT ); Mon, 28 May 2018 05:25:03 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInd027506; Mon, 28 May 2018 18:22:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInd027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499357; bh=unsFiFi/xtm2oBI/in0Sb3ZGNiZANg5KGMUcVIKyl38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U5PeggRiwBkNpnTrduk97u9+lwV/7KXV4Pgwt11I52uTQ1oEorfFGldv6ARPf8L0x TxiWNPZlV4t/gHj6j144Zrfwn/zhlOUMfSgmLF1N83bCm4rlGzs+wQ3ZyTfLzoYHaX Eq355Z31PhMRXYRFdPGyBSilpGxcUIoutWhyHtQ+HRXM2f2gDA7KR46mzFsf7d8dij 5BS3vP2XpTAAfCp8ANSyDyVfn4UANKtP08TIuA4LgA4MpP96WWkSkvV4cLiZrujkAO C+rwh7QBRGslm1dirpLdvLVo5kYqTQfhX9jPAPK9h6j4CdNSrMaQPlkE+Jf52MyIib yqtrDC5LZnG6Q== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 22/31] kconfig: add basic helper macros to scripts/Kconfig.include Date: Mon, 28 May 2018 18:21:59 +0900 Message-Id: <1527499328-13213-23-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: - Add dollar, right_paren, left_paren variables 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 | 27 +++++++++++++++++++++++++++ 4 files changed, 32 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 b87723a..79decb1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7639,6 +7639,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..bf7c0c9 --- /dev/null +++ b/scripts/Kconfig.include @@ -0,0 +1,27 @@ +# Kconfig helper macros + +# Convenient variables +comma := , +quote := " +squote := ' +empty := +space := $(empty) $(empty) +dollar := $ +right_paren := ) +left_paren := ( + +# $(if-success,,,) +# Return if exits with 0, otherwise. +if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)") + +# $(success,) +# Return y if exits with 0, n otherwise +success = $(if-success,$(1),y,n) + +# $(cc-option,) +# Return y if the compiler supports , n otherwise +cc-option = $(success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null) + +# $(ld-option,) +# Return y if the linker supports , n otherwise +ld-option = $(success,$(LD) -v $(1)) From patchwork Mon May 28 09:22: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: 137047 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592510lji; Mon, 28 May 2018 02:25:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpyGKk5TMLBUUDJLzqJjtXGZBMZVaf2zTQa69PFL4QVdhXKgtbwEXLbxWeTVY4kBVBCoNvn X-Received: by 2002:a63:61d6:: with SMTP id v205-v6mr9952087pgb.432.1527499520071; Mon, 28 May 2018 02:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499520; cv=none; d=google.com; s=arc-20160816; b=rE3KPrj3p1yXialqmHQSUhaEy3TsFZalKMtytvEEgMiCxzxzKz/25HOx7B/vhcYoqZ 3VPCk6bn0MALeEgtZwfUUfpDVnE1C9od2poccmRud6j0WZzLDyBsIhx31Wri8ctmYwKj DFknRacLJA2D0t/L5TkYat7+bXGZj8e36Yk/gR7SU1Wkui4lhjMFlEy8FudG2kVRQPIv VdyHelmJeR22TOpNWPrcC80coxCzjXM8QEGQEdxm5sGTEuMzZdUg76LjM6/cwF+kGdRG 2RVyH4CuX7WLHvCFHLKl5QgWV/4qzOHOapONLlP+iFe2u178DpZmsIu1hUXw+ZpbtM+q j9HQ== 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=FX+GLIc1RJpIXDbo4uulGbHaEtfASf7SH1eML1aUKdg=; b=T+RvVtYfFP8LGWquEZBBShdnyY1FViwzR0dGqT7oQyWweo+EjLGiZeIgomSefGxMl+ PXZzihwtr8PlivSL/uFih16hBRgWP/q0xbqqogv/tNcavz1PSjbRiw9LPyvvxzb1BvF3 hKbYRIIE3touiXPRV/62kC0W7msnCKvINX9OJ53IP8MW1ueRGWAjttNLjl7ujSorwOuq F0HkCQ1mtmyXSUhh2cDHYo7oihUXYmMfYcvRe2Euz6KNLPv41TOasdLoy5abnU+ugfco E1AyR4USiYCRIuZtwoaWUZTJXdiV+eWFlS7fNlLh4tMAeavHzmhG7JOjxHQGclsj8s0r P8dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=nuIfEecm; 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 q200-v6si11556680pgq.682.2018.05.28.02.25.19; Mon, 28 May 2018 02:25: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=nuIfEecm; 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 S933765AbeE1JZR (ORCPT + 30 others); Mon, 28 May 2018 05:25:17 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:23171 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933656AbeE1JZJ (ORCPT ); Mon, 28 May 2018 05:25:09 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MIne027506; Mon, 28 May 2018 18:22:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MIne027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499358; bh=FX+GLIc1RJpIXDbo4uulGbHaEtfASf7SH1eML1aUKdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nuIfEecmX+hDKrKwcTS0c582r7o0/otWnJVg11pPuQVJLvP8KIIcY32y7Fmg09seI faNosUvu5JvK/UvR2qOnNq/rri9I0DlNl+M46o5v3PxUerOTK3gWGLJfZH+rCxvVRa k0BkX5a7KzkpKW7M3G9AIQ6CuEiUl+iIRNgIlusGyRf4Kx74s0ei9lbLOMOtxCTfcn io+UuLm8fZfKtrZs2Ji45st05geRxhn7Mmh8w/BjbDy1C+WkcdhH45EVL2yGTjdKvj Ce/EL/N7S4/d3qsgEOslxoJadErJDrGVEQ3NCV1nDC16a9zeFGSPbK5lJJ68Y+sKcc sX0EUZppf1dTQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 23/31] stack-protector: test compiler capability in Kconfig and drop AUTO mode Date: Mon, 28 May 2018 18:22:00 +0900 Message-Id: <1527499328-13213-24-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Acked-by: Kees Cook --- Changes in v5: None 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 diff --git a/Makefile b/Makefile index defb383..80e0800 100644 --- a/Makefile +++ b/Makefile @@ -675,55 +675,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,) @@ -1102,7 +1058,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 @@ -1128,43 +1084,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..1556ef4 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..9ab335f 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 Mon May 28 09:22: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: 137053 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2594281lji; Mon, 28 May 2018 02:27:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLSCmuhPHUdfXCHwmz/QEC2bVyPJ8fNcHvxbkaxSe9Hclf+rKAR1+6UGdVFiyRjeR1AKM/s X-Received: by 2002:a17:902:566:: with SMTP id 93-v6mr2550003plf.385.1527499655504; Mon, 28 May 2018 02:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499655; cv=none; d=google.com; s=arc-20160816; b=S0A79zKmOsYfkt3cYxg4LupBRtsBzYdDBzNu4NnCqsWdchwQ2+qUW/rophPLS+mCfg faYIrV8782pqRbWmVdvjgWvJPoFzWz98Y6hdlnChVsX+XACFRZq+d3njuF1RGMxGjLGU vyg/tnqsdjpbkW/oLJtcPVZkIu6VYtkveCvunc1EqRKmSAEDBXJvNrFWTPkg4+Kzf+/8 QjBkK9qe5tW1iTlTEMSdjLdPbztGD4Bdo6ZOYOWd/QCNlF3bibANiU7vYz7hX5jrKbRl Z9+8Ypjt/RUAaehRB1blIV0ERye7h9YTzwwIzYcS3MHJb9h2gRvBqAteluc5joDd3aUE nMiQ== 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=rVhnJfkZ47h7Ex9lsCwIUrEW6C4miI37K3OhJdWZqeE=; b=Wy6YnF2/5Ed42NLOHtLu4AlXkfTM6gvuVSOdeCbhKTF7u1ThYsvbpdPRR0GKlC9S0s caN+gKNw3l+aDZsP/SZXKy2/JmipvFHbSEA0S8AhrQK/Kcj3mj4lQSg0FbTkCZxHAG5y cSm1905pmTPNkdSDZL1ZgJYg8GfEzRLruWY6VmqqtQ2oitXwbiF5IxnLDNXeAXTBnFa0 2ygWhlpQ2uUu8P1QXeBM8xkSgFOfuUU9VH3meeABrLPXinksTkL7gKrXljXSBuJ79Di9 e0go1ncHoGMSXRvem29GuwjOnqTrC29WupncSiXOjD2sq2kOYDkVH9gaIBcTTILFiGoL u0oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=BBo3UJma; 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 k2-v6si1838978pgp.200.2018.05.28.02.27.35; Mon, 28 May 2018 02:27: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=BBo3UJma; 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 S933752AbeE1J1d (ORCPT + 30 others); Mon, 28 May 2018 05:27:33 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21768 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754373AbeE1JYU (ORCPT ); Mon, 28 May 2018 05:24:20 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInf027506; Mon, 28 May 2018 18:22:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInf027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499359; bh=rVhnJfkZ47h7Ex9lsCwIUrEW6C4miI37K3OhJdWZqeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBo3UJmah8PRJRUn3QpX7HCY0+AuiE0Ldsfz7w2mC2yYdpbXdvaQ2z8MNTcrFMLpH uZ3j/mOu17rMnH4hG9hjkqZl80APdvt8n8qkXJmnjrTtCFz5cfa+JuRLXW5gUr3+dG OegCkm1WdRzr/sv12Cewz4APdf35fjP4Gw6B+97rzr/FCESMuziBoYs2rkel53w9Me shA4MV18EltHGo6skFZTWeBsxwNycU5jdqRA/YcinnQl04vOuTU5u3+VQ1PUo01SkC 6UAY1KH5oql+p/b/v4U3UP4BhGd7LijYkeRacIC9rknben3JEbOxnMoQacCGm/F9bn 9yNC2N03M0Lvg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 24/31] kconfig: add CC_IS_GCC and GCC_VERSION Date: Mon, 28 May 2018 18:22:01 +0900 Message-Id: <1527499328-13213-25-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 f1b0cfb..2e33d93 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 Mon May 28 09:22: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: 137045 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592401lji; Mon, 28 May 2018 02:25:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrVGWQFpfAvAsKnbPX2x6683Vx+u8BB114LGYoG0Zbo064VF2gmdRt2yU6fR4Viuye7SaKn X-Received: by 2002:a17:902:9a98:: with SMTP id w24-v6mr13230725plp.9.1527499511618; Mon, 28 May 2018 02:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499511; cv=none; d=google.com; s=arc-20160816; b=o64vYJMaAyIm1GtnyyOPTgx/1415G7pC63av9FoM+V+nLU7sAKjlHrEIXHo2iRTvw3 SDIYv1lR+WOpqovzV66muqnEIsUZ8hAIbUW4bsFY56VrRyeYfRzajJnUrZ/4Th7h8Azi 8K7Yhk2qwspG2TI8tu0IgaLKXPTd21g/UPsSaLndwK0RrQY0SqZ9LyBqR+8EoWvt4gLK S3K52/YzPPj4ehNOBb44LNgpN0cpM6ycvcvf9MabvGdhim7KCg74+rWSjiN1j1PEuHXM LZSCTfBjt097wHQlGLBykEKIS+guud1k6194yPrHvQoZfC18KiP6o8aWx+Wna6RrEU3f 3KQA== 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=0mlkdVUrNIHStmyOwsbiABMg5JGMCZKqWBfmaYib8q0=; b=PaxU8JaruiAN+M0Q4iFmwEomzN7Q9bnCNPJPymHoX7RZAhEr7sJflmASkn+vjgpO3f yqRu3vHUMUB52FYFp4JqqQlccG+5Crn1lDVOr6uJkLQbDkQ7i65Bxlp1EZq6B10NuSVU fGjNAbRmVDmGATCWY1YMz/h/C2RoHfpOeONv2ZDdjR9PghcjAE7NWjyCRixqgDWp2zVL Krpawsi2aDaihsZbGWwL7WqsboKdT8D/OWs5JuIdaxxf4LWnVLZvt00Uwk60wazz1vw7 jIBWZvHJEZyzMVprgc7PzJoK6sm4fBDhJQqFKfFytjwYje6rg6zd9Rhd0YEzk9Yt1bsm tQsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=nEO65nls; 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 o12-v6si23831883pgc.515.2018.05.28.02.25.11; Mon, 28 May 2018 02:25:11 -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=nEO65nls; 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 S933650AbeE1JZH (ORCPT + 30 others); Mon, 28 May 2018 05:25:07 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22951 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933272AbeE1JZC (ORCPT ); Mon, 28 May 2018 05:25:02 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MIng027506; Mon, 28 May 2018 18:22:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MIng027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499360; bh=0mlkdVUrNIHStmyOwsbiABMg5JGMCZKqWBfmaYib8q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nEO65nlsqqxKr4ao159eu9E23yYDfGNST1WYTGCVN+VqGP6u7zXICdnx9ZUWK7n3h ULuZiIMzKDlnWDr5MnvuXPVZxVi6UjFlsaOouz0jZg6VLXgtuZ9EXBcqSVezbiSTJj agLt0IBQq4OMyf95Ro2V23t5RuBazNilbjobUL7iphSJMms+jP3pGi8kPBq/JFZ7cG h77W8/MkXn3dH+yZ7tHwrSZcfolb/n4+9FnehazHuHej0JD1KnNhqXRRlTuwPzIKAu tNSR8G6yHIKzzG7k2J9uSLW1n0yWO6fZf+QiVXZRNbzq4oO6xyr0AY3/l7zgfAm8RF 7+eiH57CoOzKQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 25/31] kconfig: add CC_IS_CLANG and CLANG_VERSION Date: Mon, 28 May 2018 18:22:02 +0900 Message-Id: <1527499328-13213-26-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 2e33d93..22e095d 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 Mon May 28 09:22: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: 137052 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2593987lji; Mon, 28 May 2018 02:27:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoqqJSMueWL7dYo6DvQsD3Re6C2XPYKXLiMCJCI8ZQPrn1YgZlDetw/pxXTsSyDlobXQ1NF X-Received: by 2002:a17:902:748b:: with SMTP id h11-v6mr13124912pll.12.1527499632918; Mon, 28 May 2018 02:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499632; cv=none; d=google.com; s=arc-20160816; b=j2xfiKEg5S6diUakZgeaQqegkk8/8uRApCM1/zFheJCresy0BVioqkZwieIeGPlWs4 pfE16dw7CCBGVQu3V751r7hu7nCnDTSoVAcjm9iz/gPDFYiNEsHfNxbqpYVUpRVEOCVy lLuXxGLL9/00RnkS/JxA4wD3xS6VMdnbMuyRKAiNR6FYS1M1FrYHQGaCfuzxNCHG1lRT oGc1JDBVp3uDDPqpKoGPN25N5qT6zYrYNko6QX0uv9iA8KrzppAI1VpFg/fQxgQckybl MrnVkGbeJS4pfgypAzGMlXVusDj/NDznUM9D6tIG9uvDcEgiD3AHY9Uqv63FP0lN52Cu XFig== 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=IAzcHIS9Fi06hYYNp+wVpi+eD+kV9WOpVbxdQ9nu4p8=; b=bZJlxC4mwOlO400KAPCCcAN7By710ROqT6Q7PpPzvtbKAuBH5J/3mPmqtaImmSXJqn TjNnuyhhEjkGF60JjawsyUy8nskidzBog8C42okAXjsKblc3xoZ/WLkPh5dNthxv0YVu zsTMgX9P1ZwLDHJRtMJ+8zgaEgUBJmP5brfh63OhxXG/dNM4jDOTtS5p5zyhSHJodt2z VldoHMSs71aoLO+/bGCjXsS9fwL2O/qFRLhul+DGVSEijC3dU24ZAkHODWO46ft018Ui OxKcpllZBYn9BPdxu3syMMxgrW08jGO59WYUcE02VdOZjnbFaYk3+K/0ACGPmN04bU0r DZzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hKuP0wu8; 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 k2-v6si1838978pgp.200.2018.05.28.02.27.12; Mon, 28 May 2018 02:27: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=hKuP0wu8; 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 S933639AbeE1J1K (ORCPT + 30 others); Mon, 28 May 2018 05:27:10 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21909 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932110AbeE1JYZ (ORCPT ); Mon, 28 May 2018 05:24:25 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInh027506; Mon, 28 May 2018 18:22:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInh027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499361; bh=IAzcHIS9Fi06hYYNp+wVpi+eD+kV9WOpVbxdQ9nu4p8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hKuP0wu88c7QkHzGoN5HUzwWgN4w3M22w+fkfzGZL5+Y1LLhScd7xn06WlB7GDBEN tybUSNWtmLG9QcgNh8rtjqNa+CSMCJrKpt2TS94x3uhtm0Blcw2ygEAqw8F+OGTPBU Hon24GYKGs+BVRZCxT21jVkxMmDQ12oR9Ub4uCdkYyQHucl0bNfqIbuDMAvZPpIa5m Sz4xlX/iZvYMC4IPfcwnvLZgPCnFGl6+9jncm/XVfTSsKBa9HXLkNuM7Ab+spOhK3J aM7rFnhaao5/0Vo76r2KneU37QUBpMJEiVYN2r9j/AyLwQWd6a2O/qrrGGb9jQTdBB A7RjNalIbiXew== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 26/31] gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT Date: Mon, 28 May 2018 18:22:03 +0900 Message-Id: <1527499328-13213-27-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None 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 Mon May 28 09:22: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: 137050 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2593253lji; Mon, 28 May 2018 02:26:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq2MtV/nucaIYmYnJ5eJz6goY8vfU2PpLr4s1Rysm/mSHuBvftXDNB51Tf2daRH/fQsLE9Z X-Received: by 2002:a62:3b5d:: with SMTP id i90-v6mr12602363pfa.24.1527499575644; Mon, 28 May 2018 02:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499575; cv=none; d=google.com; s=arc-20160816; b=OLRO2wB2jjLo0UHYb+G9hZ0WyDDPQ+ERnUQxEUYy4qIGPCdFvwwFoJXKIQfjcNmhxJ 7jB8PO4QCcjvg0Ks+PyamLvKNdnz4UlqHblTVTqEG4LMSO21Q2I5bIMEE33oX7/jWGu+ 6wPnVBJ8ut9Sd4YkjT++cQWVptEVD35FeWBxBcFT8UoSdfZJoA8nvzEQACCX8DK3CP1Z 6fobNupvDKtZ7rlc/HgAXs+JlsqH5rWdE5FArdG0M8euqN4DbfVtxlddpl847OZcQ0n+ 4ntMb1MLkC+CKfgtnbxnIP2xeeMInILDkfWgJ/LLuUQhJduHiyjkXxeUxgs2RstIZzRA Us6A== 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=OPJmIjNNla4WZnf4QzbMQRQHdJ5YNsNSuOB1/RvnfEA=; b=xptkNx0RKbQeaUTXN7cHFEvFduJSzNstszx8f9Tj/xA56l0KzRCb0BMWYup6QZe9wk gqhD2vSpKOCjEGVEfi0C5ewbskFfZ9Tk9mCPtp51k7lvtYy2u5zfZsCNWLApHE0V2GW0 ix3Peq2uJRw7nM2PicALA/mh/MHNP/46HGkVHeBdW4xtltX14AqNm/cqphL5Vnyo6fQG gIcHSkZN7PoSKglql6S6wRteUHDposY4sat1wcg2fSCnrRHWWC39ukWIfZdyH/lv70Fs RSmTpbZKnoUlSlYBybXmjReSlcyWFLRnVHGHhw1T8PjlZ6YCUa3ZShojnb9EION0VTOd aI9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=sZDy1H3P; 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 b74-v6si4850506pfb.189.2018.05.28.02.26.15; Mon, 28 May 2018 02:26:15 -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=sZDy1H3P; 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 S933925AbeE1J0N (ORCPT + 30 others); Mon, 28 May 2018 05:26:13 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:23137 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933643AbeE1JZI (ORCPT ); Mon, 28 May 2018 05:25:08 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MIni027506; Mon, 28 May 2018 18:22:41 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MIni027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499361; bh=OPJmIjNNla4WZnf4QzbMQRQHdJ5YNsNSuOB1/RvnfEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sZDy1H3PrcE2RxWtc6E1Utf2mxJghVbQSf6wloiv+p4WOvDY0wQ0Fo8BCHT1YGVlb wVS/UCD0pMure0nYw7zmiLlEC/9aw02ML4MgbSKd4aj6nh/NPHJ7b/iqBWV0gtkDB5 sXCEjERP5dT4nJ9HORO0bQKcRs5H90rwsKsrxDfDKLtwWtklrXzefmLg3QH/b7ItJJ mapM2jKUq/jQMTgVTyx4ENZFRRq2odiZpv3n27G95UvxpqKafPQ3XzzHWbKHa7/Kcf rkyKo/IDxsFLomPLHzdYnF4Ti5Jr24ZsVibDlZv47znimRNyNeNfOXE0tLYmvO8YpJ 8RQNaqDIH4LBQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 27/31] kcov: test compiler capability in Kconfig and correct dependency Date: Mon, 28 May 2018 18:22:04 +0900 Message-Id: <1527499328-13213-28-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Reviewed-by: Kees Cook --- Changes in v5: None 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 diff --git a/Makefile b/Makefile index 80e0800..4b5a17a 100644 --- a/Makefile +++ b/Makefile @@ -626,7 +626,7 @@ all: vmlinux CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \ $(call cc-option,-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..b76cab2 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 Mon May 28 09:22: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: 137051 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2593715lji; Mon, 28 May 2018 02:26:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoRTG8CvKT5kEdVHDD2nZhSqoRbtLhCht8FkpbPT0HInPGakeO0RRtNsgT4JV0qUEWUO5WW X-Received: by 2002:a65:50c7:: with SMTP id s7-v6mr9952102pgp.359.1527499612062; Mon, 28 May 2018 02:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499612; cv=none; d=google.com; s=arc-20160816; b=ElWhNCx1P6DPV8NoABCqKTUKBfKZRb4s6ZWgRA8v/fWIDh6PRHrbRV1qsKLfpe+1Lq Z4bZ8wcPQ1URdMbvMBAOw6JWFM9GXeOX/69MGsFzKP5y2SV455K01hMBvuhBhuE+GPbg ILZYzK7OrSFA9ce11EEe5+slDx4n1IbgmfQDa6ftRpHSAW+FFXenNJQrBrgE7rL5F3+F UIpgH1imkfQ2/syw6/ckq+9Qms5B1/D6Uo06/iMW9od7Sf6/D0VYzPhXkv11NLJHFJOk OyzzL1bl1sdOUCF9EWHss2iPxkPB8cocs5TegeV4Sy8F9BkJCgKAEQ9VC1lqRor81rk+ q5Dw== 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=K2pnM9k4Ir5ms5fvVd46T5nd2LcbxCSfCNHsU2G0jPI=; b=SSaEH8yBZ6YxUxvAR9ERMdDXCDqklFMZlG8PiY/zHtU/bpwuUOS+V7tx5w8t8qP8K0 nct+5/JJpuO4cq7ePkSYJCtewQbNXRfkaC3v5ZwNVaQ+qr8ukGapUl/ZUvavwDVO5fMW tAlMLkbX5Uzbop5MsmLxKuBNe4CeirLEZ5u/5OtC8l2LA7zz3ILvjq9e49wwArRQbGO6 8LQ5HN7OAtMjs02CSiMWNENHjz6bEa8+vWoqR2ry8/EnbuUeWS3X2p8qmNEBpjbDb2QI WrPOEb3kWbIp02xsLqPAL9fE70bBZOKuzSJt6XlmVaeOnS7x72iUcGsnqvIRulxmQPUy IpHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=P6DMGZ9/; 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 w3-v6si5640744pgb.588.2018.05.28.02.26.51; Mon, 28 May 2018 02: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=P6DMGZ9/; 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 S933439AbeE1J0u (ORCPT + 30 others); Mon, 28 May 2018 05:26:50 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21964 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932146AbeE1JY2 (ORCPT ); Mon, 28 May 2018 05:24:28 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInj027506; Mon, 28 May 2018 18:22:42 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInj027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499362; bh=K2pnM9k4Ir5ms5fvVd46T5nd2LcbxCSfCNHsU2G0jPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P6DMGZ9/x2WuNVBCp3wwKsVlol9Owg9pp/x89/t4cFxaDC8m8q02stbgW5y1CjzHb sMci2jj68UfRWvErnvdxv0ZLFirlnkDJd2qU3BUkmGkfTIxkmRQFf9Mh9aftMyfgO6 t4IU1ZHW/TKBYr6Zp+E0P41RdnCCvFkmVn5rXtFzl9bJqFEZs2zX1TCR9JZHK8u031 ksldT2Lfrr6G7q70I3+zWD5v7b6ZLOBI4QGK1wXY+Fm/GqvaFMEbO3vo5zNTYjpa1d b77ReBts7qq/pK14j5fou6sWdq46+N9Lc3pPVor8cTgDXMr4jKs7tt0ASu3VTp1RXp DfacytbSLixDg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 28/31] gcc-plugins: move GCC version check for PowerPC to Kconfig Date: Mon, 28 May 2018 18:22:05 +0900 Message-Id: <1527499328-13213-29-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Reviewed-by: Kees Cook --- Changes in v5: None 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 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 Mon May 28 09:22: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: 137049 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592822lji; Mon, 28 May 2018 02:25:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZouv58ocoJi3R8eMkeCeKnY+O6LkBcOSo7hGNVx529luHtHn+yjfnTi03xYCp1MJSopqxSe X-Received: by 2002:a63:755d:: with SMTP id f29-v6mr9888163pgn.278.1527499543184; Mon, 28 May 2018 02:25:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499543; cv=none; d=google.com; s=arc-20160816; b=qX/ZFy7znuwp3xmp3+F6nv2fml9WSFB9qpJn7iyKzCcPlghPJ0tmvGsHddB64yLes6 GeTeaZPrer9u014h4Z5hPT7JKkMyLA+PSsNM0t1dcg6ZA7gaJAMY+TKJjd6EiKeGfYL5 zWc4qYxyuPI8DwP2t8mrmJj35PqBRaggGpy33vkuNsSZt5HKA0q5GOTXHyvpj8PL08gd 1g/RanQnp9qr9Ad/gc/UCzOPSdiLr57fHckIt/bfpqach0xQGbOyfzXyv2RD7asFpmVX 3Vlqx9hfNLshOokNGNrL7kJa4+H5ny4qL/UES1HTGFCL6vZvt3YWtXzKyxufTJnAuE8w 0T2w== 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=qIS42SuooNsMki3XkAY+qEKjS6CCn9zdpYxY2XH8qr8=; b=NuSGOITiVaTbom7V0reRZ0yO50aM0mqxQTAgoVRsC1zIqYyLWeh3deAjY27VRARNMz eOycY1hohVWGuh4CiIzjLs8hSIx2KuI+NSN+tSmKBmilf/n2+367LTAUkJ3cDtAIgq6H uab0yMN/jCH31Dhbs9xTv4IxMpWZYJh7NlAKVOZvGk5Ibp1nJSw+ln8GnNr5SkBwL+Mj +5zqdfvrw4WaWHcxyq9Afh8VedkSD0ARdAUvt7EzkWhs6uqNRs9jqpKHT/nh/JISgOv2 Pj1WmVXgOJsQHNVaO5Qscre2LmrB65zdVgZgwMoh7SdPoXI3SOvQkRdSLUoElY8ukMDM +nZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aC5v7PCV; 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 m13-v6si1276274pgt.554.2018.05.28.02.25.42; Mon, 28 May 2018 02:25:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=aC5v7PCV; 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 S933895AbeE1JZj (ORCPT + 30 others); Mon, 28 May 2018 05:25:39 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:23792 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933366AbeE1JZc (ORCPT ); Mon, 28 May 2018 05:25:32 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInk027506; Mon, 28 May 2018 18:22:42 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInk027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499363; bh=qIS42SuooNsMki3XkAY+qEKjS6CCn9zdpYxY2XH8qr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aC5v7PCVTvKo+YCfZrl/4EM/nQlPmQffbGUEwUqAIqIq0xVZ5Xo+HhSN/IJnikeOV YAIhr4Ly2qUkG929t0dKWNQ7imkc0F3/fhvv1uXGu0IfdfaBbsQkV/3sSSJeu8FQoY 2QCXERJaHGJCiZm7XSIcnt8Nlz6ckTBPwU5iKBJOG1m56KJY7onN9JEfZyCPzOgtRV uFb/GTzGXCy5QTY8TCa34KfPT5/50zObE2H8AA2blJ5GiCZA1FP4/8aQo2yDaWP5mb JyHTMmSpa8vxaC6JkdeMQQ5zybHTo+XFcgCxYwUPP2pCPvFBJ2szCA9lwpUTI6N6QW xlK6lhC00CcbQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 29/31] gcc-plugins: test plugin support in Kconfig and clean up Makefile Date: Mon, 28 May 2018 18:22:06 +0900 Message-Id: <1527499328-13213-30-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 Acked-by: Kees Cook --- Changes in v5: None 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 diff --git a/arch/Kconfig b/arch/Kconfig index 1556ef4..6051386 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 bf7c0c9..dad5583 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -25,3 +25,6 @@ cc-option = $(success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null) # $(ld-option,) # Return 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 Mon May 28 09:22: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: 137046 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592420lji; Mon, 28 May 2018 02:25:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPOqQliNQSnS38NTyx4fgxsaDyv6X668T9m3Ew7TJgFecdqRKvr4/Jkx95Tq+6jPhQGT0K X-Received: by 2002:a63:61d6:: with SMTP id v205-v6mr9951805pgb.432.1527499512838; Mon, 28 May 2018 02:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499512; cv=none; d=google.com; s=arc-20160816; b=uBMhByTbYoBwrEjmtbnsu0A5bbXAtqOVcg9nvPX7yU0hrLh5Vbw8b4eMXlJvxFi3ln Og10n8D3UcWjUlWlY0Jul+xSBLiTlfAaUZ1HtAPpNU2WME5KYA7itlPE5lDaluevHMAB WwQdr4zYM9QTVehmqmY2ixOTyyfNpqOj4cXcuvAF6A/D1WH4f08/OKJ2c0fSbRzUO1gR muY6rugN78kxdxQ6FA1O8ptS844RSpX6Sh9diezbox43aqu0rYnQP0urprR/FQt52eds 5BBtxmBzyldFs+Babgq2yewCXNleP4qnjokM/gwzen4jkr/AkX006C/nZfVfohYbhYoz iyPQ== 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=JoiwlMoDhFMQuLdtUxJL/dDvBCxUTt0wM/d0IzvUjp4=; b=09zNeDCNDfKBxDs/DqxIQTN2+azCGOA8drse0sQQmZro8Mv8uMNxYzKMqcBI8i2pAP m1M2Ns/ltj/RBH/dR0a0aCIytuhM7JncRk6lCIqaYC9wmE5qMA/I92H8Q/BYnqb+fsqm GSIR1eryC4t/O2Eagt5tSKrQt0x9jMTzfdX+cTaMW0kCgpHITBaLNrYwqYzDLR+ptiYP muIDvibvjIsJpOtKRyDTqGn1rR6XN2RCG9aKhwtnQXnF97dj+Udbt1sCQ/FPwQxXSgl4 VKM/bKPdFM2rqtF1klvvR+zT8WYiQyqoHLpJtoDb4io9EurcVFc7sLUlUJq6KKAGNA1K kf+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=TeMeasUC; 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 q200-v6si11556680pgq.682.2018.05.28.02.25.12; Mon, 28 May 2018 02:25: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=TeMeasUC; 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 S933718AbeE1JZK (ORCPT + 30 others); Mon, 28 May 2018 05:25:10 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22994 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933515AbeE1JZD (ORCPT ); Mon, 28 May 2018 05:25:03 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInl027506; Mon, 28 May 2018 18:22:43 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInl027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499364; bh=JoiwlMoDhFMQuLdtUxJL/dDvBCxUTt0wM/d0IzvUjp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeMeasUCtiyLpLwroDrSHh1xoD7bC1FXUmRSuzA1ZI1fa+qzzL9dbPlkLnvBc1gm3 sOpOo2vb/ASRdzssePCBQS+HoobZznPgaYwtQ4JdkBwa8M4hENVeDJjk8YvmxQzS4J f9U9rEj42fZnDVMggucp6B9zoBN1E9PzhUyoE2reL8IZ+fvCsxBzvG2Gtv/0fAfBKA e6M17cXATr5Nxd2v7Hb+BKpD7WePqqSylEmejmuoDvfYo4d4Dqu9vEujLtQd8DP6ek 9EoGZFq5Yd9L210t22xsVFxG3fPKsVb1YQESQNxUSMpAdyCqs2T7IFUw3HX/GoxNNk TSfc8nnsYQ+aQ== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 30/31] gcc-plugins: allow to enable GCC_PLUGINS for COMPILE_TEST Date: Mon, 28 May 2018 18:22:07 +0900 Message-Id: <1527499328-13213-31-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 suggested 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 Acked-by: Kees Cook --- Changes in v5: None 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 diff --git a/arch/Kconfig b/arch/Kconfig index 6051386..e9475d0 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 Mon May 28 09:22: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: 137043 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2592183lji; Mon, 28 May 2018 02:24:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpZGZYvPxEl+5YH4FcFoWm6t/+nHf7uZZop7ASMfDH3FNRZM2ragWwS3e0FV/sP/n62MoGd X-Received: by 2002:a17:902:274a:: with SMTP id j10-v6mr13160444plg.393.1527499496538; Mon, 28 May 2018 02:24:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499496; cv=none; d=google.com; s=arc-20160816; b=SnOqyFX3PC/lTa13YCW9kWyrPLYgQQyfZ191Uopd4bWqGpDeqyDEFs/k7XZK1IxhvG BTOZZ9Dw8BYqDy9Yuvb5TMJxItYsKaqYug1OR7xsK0zC+1TSdgWsAndMl+AS37af+/w2 m9Byovvm5bsJqD5otwC+9YL5ZvoFdz94JBItKr5AmZH+JE4nOYpj8Lim2H9Ozf/e/SHH JvgbsQ7Dp5BXRygUueH1SQszwnLdOFcDtFwZ7cALD40bCWVhGQulg7kwo5fgu8/42TtA 2ccBCOFihAzzBPkwwjvYTQNu/TGmxpcMqzfXGPK29J3ZVkFOyj1/1E/cfbM3R0ySXaQL dv9A== 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=KGWTRxsHzhfYmXXlA+L1qxO2n0s45ic1ueQ8VBleHpw=; b=nr9nSP+rnVD6/m3hpCGYC+EtMwju9THvUR50+dM0mppWtu1LzjVh8572sztiKRzup+ PSeers73OvtOsubM09i00efWbx00zT/d1vKCjvJSr3CfwfhgUSM1gQsyGUglRlWOdR5j VoqAkSm+OQCBblGKs0TS+6iFUKuyDbTwTGAcSDboq9a/F+iVaBihRQH2wUeej1gTLxsi zjLKA7HcjXJUg8i4SZQAQAlRENPegclDUdrd4zfCP8XnAQ8vpS02BqvcJOBt0tbee5zo qkQiCG9c3EpXjdxUetymyWn8u0mHF4SZfdHMKbJmTQhQvUl1Tnk+APwKmexMegs8ylj4 53Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Tjgz7Qy+; 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 m11-v6si17795287plt.284.2018.05.28.02.24.56; Mon, 28 May 2018 02:24: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=Tjgz7Qy+; 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 S933503AbeE1JYy (ORCPT + 30 others); Mon, 28 May 2018 05:24:54 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:22335 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933272AbeE1JYl (ORCPT ); Mon, 28 May 2018 05:24:41 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInm027506; Mon, 28 May 2018 18:22:44 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInm027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499365; bh=KGWTRxsHzhfYmXXlA+L1qxO2n0s45ic1ueQ8VBleHpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tjgz7Qy+K42twdfDruErrrUqpD1QYre98ZJFpnbrzmxBFs87YxLy85SMyAENR+zyz G8wq7JH4kmCNg2cLXXApK+lmoWlMvkaTrn9J6AdMhYosMU/AbD2MPHdWaonOC3y+sA tK5a+M6y3VGrHY5aUN41Xq7H4q8tMSolTLHhQ/cZa1utDLRRTZorVzUQ6ZyGKyrCuR AI+Kp4wI69fENOytrZSweltt6T1CEYuhM4p3dw55CFXTgcknn2Mb3te7sRBRa8r4q9 U3fuKW4B1NNOAxht7Qbd6SxGCQo/G8dV/y7KMau2oSFTPzWgPTZPLXGINjkaAcfMtd ya5M0ThC1k90g== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 31/31] Documentation: kconfig: add recommended way to describe compiler support Date: Mon, 28 May 2018 18:22:08 +0900 Message-Id: <1527499328-13213-32-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 It would be nice if the source code is written in the same style. This proposes the convention for describing the compiler capability in Kconfig. Signed-off-by: Masahiro Yamada --- This is not a technical issue, but it would be nice if everybody follows the same coding style. Without any documemation, people may write the code in their own way. For example, there could be some possibilities for the option naming. CC_HAS_ CC_SUPPORTS_ CC_HAVE_ ... IMHO, CC_HAS_ is short and enough to understand the meaning. CC_SUPPORTS_ is also good, but I personally prefer the shorter one. Comments are appreciated. Changes in v5: - Newly added Changes in v4: None Changes in v3: None Changes in v2: None Documentation/kbuild/kconfig-language.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.7.4 diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt index 0e966e8..a4eb018 100644 --- a/Documentation/kbuild/kconfig-language.txt +++ b/Documentation/kbuild/kconfig-language.txt @@ -473,6 +473,24 @@ config option to 'y' no matter the dependencies. The dependencies are moved to the symbol GENERIC_IOMAP and we avoid the situation where select forces a symbol equals to 'y'. +Adding features that need compiler support +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +There are several features that need compiler support. The recommended way +to describe the dependency on the compiler feature is to use "depends on" +followed by a test macro. + +config CC_STACKPROTECTOR + bool "Stack Protector buffer overflow detection" + depends on $(cc-option,-fstack-protector) + ... + +If you need to expose a compiler capability to makefiles and/or C source files, +CC_HAS_ is the recommended prefix for the config option. + +config CC_HAS_STACKPROTECTOR_NONE + def_bool $(cc-option,-fno-stack-protector) + Build as module only ~~~~~~~~~~~~~~~~~~~~ To restrict a component build to module-only, qualify its config symbol