From patchwork Tue Mar 27 05:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132451 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655405ljb; Mon, 26 Mar 2018 22:35:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx492phpnk6Z6Aq0gW64qduQvUsASxZpdXo5o0J0zXf7pCdjnf49af0M+26WSjmW8R4rm+lFU X-Received: by 2002:a17:902:7c83:: with SMTP id y3-v6mr6314292pll.271.1522128906439; Mon, 26 Mar 2018 22:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128906; cv=none; d=google.com; s=arc-20160816; b=hoPyEQ5GqoXnwM9YrN9VgsiqoaRh8JbBzpjunq/rDUoJGg2Z2q8XN1qqP3BY2Wgzay Km02uVvP103ABZRBPYpMRYjE+2TBl8U4L98HccBK9FR8J+pprTRsiBX/3rd840TcN4ZV 1hgGUZsCmRH04su84xq3m6S7RVtqn9xMGxJF/CGYW5RzX6K6LKiZrH7BlOrL6ZaQjT4n v2PxcSEAaht16FS2m2jYrnQirLdGOtvcjNB6nv5Clm9aEu9DKcqU3sbOEPOIMR+zU4tH y2m0f+Pe1HrEkquQW4jwMvvHhheGIy/qc/UxFkRw6tV3qTITdA/tDk3vHsNXSVnR9jLs +M9w== 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=BEYy2YpsCxousWjhVu3n83TSZ8fZI9tGa32wUXYJQxE=; b=kHd1yQv2Dy5biX3PqbdOUUW8ZOvTqlHJ6zUGTv89wRZ5D2cS4tfpk3NvRLkNVeRiSL W1z42bBJIVGyRxZwNRlotluKXFDWspvJpLsd0DqL4Vs+k/wVjTgCqK/q21dWcLsrAlJA pnOuvXs5nVwE8OA37hgfw8UDJ7KfmVsi+D6HbcD8Qof1xRsj3iUX9Pu91MVD5OOPJnYK 39m3M3zQtEqXC1/75u4ZrQDfYTt8ZVUgKLA9dGaH8iiu/4w8qRIRiA0cdsf6waow6f0n 8BgADOfBVqWSD5Nw3pIMq5NOy637slabXbtVSQEomUnXYTMl/6CnvemYh4Z/V38wdkwp P/xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=oBpSn+rE; 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 g1-v6si507736plk.138.2018.03.26.22.35.06; Mon, 26 Mar 2018 22:35:06 -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=oBpSn+rE; 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 S1752325AbeC0Fet (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:49 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44800 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752044AbeC0FcE (ORCPT ); Tue, 27 Mar 2018 01:32:04 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLk011947; Tue, 27 Mar 2018 14:29:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLk011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128579; bh=BEYy2YpsCxousWjhVu3n83TSZ8fZI9tGa32wUXYJQxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBpSn+rEKGyQyJJhxgBVGGf9BmCRyocdP78SW8sCYUKED821/ZJLS+m4FzsYTpFvD zw7Jsv3t/lsBrOzYnKUkgyofkywSbw4RHHGxUWEWyMdw3CS9BKhpZCmVQ/nM8FPGtk iMUb3gkfdqZxs8OPastFOijcGrDzHefm1mFAk6raysp1E6kETYxbDvNqMPaGHQvnDT 2BgXcoP8gYRtVA5QmSJbVkwQnSPC85F+R7Wl05Y/9zoCOruH6acpDP0kj5kTac7qtU xoe4RilWB+FxLjIJl+VZltSLNF/55+S8UJb1qVCmjF2hzaRJmzrS4p3o0KWYdSOx1+ GQuDHvxNTCdgg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/21] kbuild: remove kbuild cache Date: Tue, 27 Mar 2018 14:29:15 +0900 Message-Id: <1522128575-5326-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 --- Changes in v2: None Makefile | 5 +-- scripts/Kbuild.include | 101 +++++++------------------------------------------ 2 files changed, 16 insertions(+), 90 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/Makefile b/Makefile index ff62b8e..c55cf95 100644 --- a/Makefile +++ b/Makefile @@ -656,7 +656,7 @@ KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \ KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) # 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) KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO endif @@ -811,7 +811,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 @@ -1615,7 +1615,6 @@ clean: $(clean-dirs) -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name modules.builtin -o -name '.tmp_*.o.*' \ - -o -name .cache.mk \ -o -name '*.c.[012]*.*' \ -o -name '*.ll' \ -o -name '*.gcno' \) -type f -print | xargs rm -f diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index cce31ee..9f7eb10 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -8,8 +8,6 @@ squote := ' empty := space := $(empty) $(empty) space_escape := _-_SPACE_-_ -right_paren := ) -left_paren := ( ### # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o @@ -82,71 +80,6 @@ cc-cross-prefix = \ echo $(c); \ fi))) -# Tools for caching Makefile variables that are "expensive" to compute. -# -# Here we want to help deal with variables that take a long time to compute -# by making it easy to store these variables in a cache. -# -# The canonical example here is testing for compiler flags. On a simple system -# each call to the compiler takes 10 ms, but on a system with a compiler that's -# called through various wrappers it can take upwards of 100 ms. If we have -# 100 calls to the compiler this can take 1 second (on a simple system) or 10 -# seconds (on a complicated system). -# -# The "cache" will be in Makefile syntax and can be directly included. -# Any time we try to reference a variable that's not in the cache we'll -# calculate it and store it in the cache for next time. - -# Include values from last time -make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk -$(make-cache): ; --include $(make-cache) - -cached-data := $(filter __cached_%, $(.VARIABLES)) - -# If cache exceeds 1000 lines, shrink it down to 500. -ifneq ($(word 1000,$(cached-data)),) -$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \ - mv $(make-cache).tmp $(make-cache)) -endif - -create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1)) - -# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios) -# -# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_' -__sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$(subst \,_,$(subst =,_,$(subst $(space),_,$(subst $(comma),_,$(subst :,_,$(1))))))))) - -# Usage: $(call shell-cached,shell_command) -# Example: $(call shell-cached,md5sum /usr/bin/gcc) -# -# If we've already seen a call to this exact shell command (even in a -# previous invocation of make!) we'll return the value. If not, we'll -# compute it and store the result for future runs. -# -# This is a bit of voodoo, but basic explanation is that if the variable -# was undefined then we'll evaluate the shell command and store the result -# into the variable. We'll then store that value in the cache and finally -# output the value. -# -# NOTE: The $$(2) here isn't actually a parameter to __run-and-store. We -# happen to know that the caller will have their shell command in $(2) so the -# result of "call"ing this will produce a reference to that $(2). The reason -# for this strangeness is to avoid an extra level of eval (and escaping) of -# $(2). -define __run-and-store -ifeq ($(origin $(1)),undefined) - $$(eval $(1) := $$(shell $$(2))) -ifeq ($(create-cache-dir),1) - $$(shell mkdir -p $(dir $(make-cache))) - $$(eval create-cache-dir :=) -endif - $$(shell echo '$(1) := $$($(1))' >> $(make-cache)) -endif -endef -__shell-cached = $(eval $(call __run-and-store,$(1)))$($(1)) -shell-cached = $(call __shell-cached,__cached_$(call __sanitize-opt,$(1)),$(1)) - # output directory for tests below TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) @@ -154,36 +87,30 @@ TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) # Exit code chooses option. "$$TMP" serves as a temporary file and is # automatically cleaned up. -__try-run = set -e; \ +try-run = $(shell set -e; \ TMP="$(TMPOUT).$$$$.tmp"; \ TMPO="$(TMPOUT).$$$$.o"; \ if ($(1)) >/dev/null 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; \ fi; \ - rm -f "$$TMP" "$$TMPO" - -try-run = $(shell $(__try-run)) - -# try-run-cached -# This works like try-run, but the result is cached. -try-run-cached = $(call shell-cached,$(__try-run)) + rm -f "$$TMP" "$$TMPO") # as-option # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) -as-option = $(call try-run-cached,\ +as-option = $(call try-run,\ $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) # as-instr # Usage: cflags-y += $(call as-instr,instr,option1,option2) -as-instr = $(call try-run-cached,\ +as-instr = $(call try-run,\ printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) # __cc-option # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) -__cc-option = $(call try-run-cached,\ +__cc-option = $(call try-run,\ $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) # Do not attempt to build with gcc plugins during cc-option tests. @@ -203,23 +130,23 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\ # cc-option-yn # Usage: flag := $(call cc-option-yn,-march=winchip-c6) -cc-option-yn = $(call try-run-cached,\ +cc-option-yn = $(call try-run,\ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) # cc-disable-warning # Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) -cc-disable-warning = $(call try-run-cached,\ +cc-disable-warning = $(call try-run,\ $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) # cc-name # Expands to either gcc or clang -cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) +cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) # cc-version -cc-version = $(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) +cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) # cc-fullversion -cc-fullversion = $(call shell-cached,$(CONFIG_SHELL) \ +cc-fullversion = $(shell $(CONFIG_SHELL) \ $(srctree)/scripts/gcc-version.sh -p $(CC)) # cc-ifversion @@ -232,21 +159,21 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo # cc-ldoption # Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) -cc-ldoption = $(call try-run-cached,\ +cc-ldoption = $(call try-run,\ $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) # ld-option # Usage: LDFLAGS += $(call ld-option, -X) -ld-option = $(call try-run-cached, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) +ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D) # Important: no spaces around options -ar-option = $(call try-run-cached, $(AR) rc$(1) "$$TMP",$(1),$(2)) +ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) # ld-version # Note this is mainly for HJ Lu's 3 number binutil versions -ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version.sh) +ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) # ld-ifversion # Usage: $(call ld-ifversion, -ge, 22252, y) From patchwork Tue Mar 27 05:29:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132452 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655523ljb; Mon, 26 Mar 2018 22:35:18 -0700 (PDT) X-Google-Smtp-Source: AG47ELs83esfajf9kJ7DV5IOsUDwAMWeQslcQAlkNbT1j1aIOunnMSMag3xbnskpeVWPM9pfDbYt X-Received: by 2002:a17:902:534f:: with SMTP id b73-v6mr26837917pli.148.1522128918392; Mon, 26 Mar 2018 22:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128918; cv=none; d=google.com; s=arc-20160816; b=MNHe4n7m+gPIhS+OLBqEleC3slk6wXnnNNqZhVDcFEV3BOIghUGcti6gOFYrIc6iaT PbEgkTWNuLK28EVL6o/FTN3BCifXhwjjAJSh0OAG7tsl4KB77kqnUvm8Gcd2p1MevYGY T/yJllLLQHkGDvvJ9+hPSGzRaUgvu7ZlB0BvVwt1i07MODL7KePvukXr/OSJp83gFPCi LbRvp3h+lPENY3TUniIRu6BKgjDBz6M46prfjRR2evgApX8D7hsRqDqCGFmH2BG2Yv38 Xz2dCDwHnEYK60bX+xVQZ6af4jZu8k5DDWzaPXzgt5F2nUp/lDsz2gy4XF0QVPxOjmcT GV7w== 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=RGk+aT9ZGpkRkDLDSt7yEl22MZ2hquI+ZQNQeH0HzbI=; b=S5ZHXuYum59l5SIQFHqfm0/4hP07QOx8dXFFIa6ZWmHd5x7ZWXsfNVWMdjDt9FsYps 5itVyW0WXVXupmoMEx4qVUR/wxpArb6DJ8mkJ/jeK/5kT3HXTZG2Byf30XPu3YzkgTbm tGVfHy26Is22wldaUMSyG9BQVtkd/TKXSZ53R1qMdOul0gjed3L6YopmQYs7JEJOVETK bdS+AXm0xQcDqhOecfAtM79rxYspOPsrh3zsnESgFSYBIBHQk5oHuRLbCD4BYSnNJGfM IjaoklvzPAhh7z2XUOHxX+yZX0Xeuh/NXp5LlZxOHjnhRnxKE+3uFqffTEaWqwjoevvO Cz0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=RICW6Nmi; 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 v2si335548pgo.639.2018.03.26.22.35.18; Mon, 26 Mar 2018 22:35: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=RICW6Nmi; 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 S1752261AbeC0Fer (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:47 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44794 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752048AbeC0FcE (ORCPT ); Tue, 27 Mar 2018 01:32:04 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLl011947; Tue, 27 Mar 2018 14:29:39 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLl011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128580; bh=RGk+aT9ZGpkRkDLDSt7yEl22MZ2hquI+ZQNQeH0HzbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RICW6Nmi235HitZUCPjAM8cBFpplUPBgtCAcqVV2tEks3yUksW6JOVF094Z+PRJko 3cIakIcJwlJJoVckmpYZUY9SbF/Iusm/mxLEYpUEQx4bAn1IReltIuG+lFaU7FXVwt UQYnECXlIXbNnH58QRCimo+fE0O03YzSEceH10ifUh6XEQmwMn98gLmBFQVBZW6r4h GseyWSiJViEnQFbMHUxz2+SQX3sAlk2k8ZhVloHMitsTuOr+qZc4cY2HVM39cPwsv5 pOFUiR4KnbPjCN2NZGJXWzBQ5YktXv8OyxwOPr/vhU2O4ggob2EYQnUxHOiNuvFJ2z RxEzDCQLFKMDQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 02/21] kbuild: remove CONFIG_CROSS_COMPILE support Date: Tue, 27 Mar 2018 14:29:16 +0900 Message-Id: <1522128575-5326-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 4 defconfig files that specify CONFIG_CROSS_COMPILE. arch/arm/configs/lpc18xx_defconfig arch/hexagon/configs/comet_defconfig arch/openrisc/configs/or1ksim_defconfig arch/openrisc/configs/simple_smp_defconfig Signed-off-by: Masahiro Yamada --- Changes in v2: None Makefile | 3 --- init/Kconfig | 9 --------- 2 files changed, 12 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/Makefile b/Makefile index c55cf95..5c395ed 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 e37f4b2..df18492 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 Tue Mar 27 05:29:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132455 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655973ljb; Mon, 26 Mar 2018 22:35:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELvNvhLhDaj7K1nLxzEEpxSJ53wrMrgHoMkzhr+Pkx1CfiHMftmbF8wXdFjg+1kz04D4RBeV X-Received: by 10.99.107.9 with SMTP id g9mr30201354pgc.3.1522128957951; Mon, 26 Mar 2018 22:35:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128957; cv=none; d=google.com; s=arc-20160816; b=XzXxjx2oTqtmKCL6x2BejqQ8BcVacHKQiTFdoS5MksPRqlVAaNQJAFTtxnxL8MsDSP VMZ737u/e+WqIexOBZ69EEUcLDhYHKihMbKD7jZopDo/c23sF31nPO7EbXSq+Izu4ZXV hEfKAgoUswju9fYGfCXFmo+pMhgTMB7TDVLGyzW6ZSPw3YcOfCKSbT7hpRhnzjixEWUw GHPUnQPAJE7hxBIn2jOLREnW4nmPmYe5ZP5c+vEdeihIksfJiojkk1+yGUIHaS38gxTu T5Vsojh3AW+p6TVcnhSLES451vUPv9+BBRFo4TmAo2lUCSJabYjytG/FRA9Q5igmajTX l1EA== 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=yADi40SR8/2ChTwsNSAQd580Q6MNTEbsv8czRHjI84U=; b=vrCBTnvq2hTwSokEpwPJR6B++D0vHxyjCcD4mgNvaEQtV7bnVX2m3LndF/TwKN1/8g vYFNEGzQPIHlgA/ksdgs/D1RNylfyCuUgMD7BBvLodku91nkJ6NzMte7s9fupYySGjYz G4sVmMqfk97NgfT50egshZnuIctFHd5iqYFjvCmAhb4Vp9uGgbXG5dwBMk5N4oCo0Xv0 WnYuhqGHqEEQssbj5S5Ek0Zu+uibbH7/IF3PyJlKx1uMsYXpRKZzVcka5aveVV2HgLOi JXQRao5dldSFF9vvczJNUs4t4ihkkJxYIOGJcE4feDyXvbQ3fXvdzVquDw+R44pbEptZ JfOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=pR+nPa2P; 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 i1si350626pgc.229.2018.03.26.22.35.57; Mon, 26 Mar 2018 22:35:57 -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=pR+nPa2P; 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 S1752489AbeC0Ffw (ORCPT + 28 others); Tue, 27 Mar 2018 01:35:52 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44622 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751897AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLm011947; Tue, 27 Mar 2018 14:29:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLm011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128581; bh=yADi40SR8/2ChTwsNSAQd580Q6MNTEbsv8czRHjI84U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pR+nPa2PtF7veLsn9F+yPSqMVx9GvNm+9GhiGTrgJZu6MOjdICf5R7IchwY8DiS9Z n9j+R0YANnw5IqrqOpogVzfw7WLqhGxRsupuwH82nUCEWXqt6CnrlPTjnQ+2iMCx+e V6UGAZ+/ds0UCTmY6O+IYtG8yp1nn1p0rl53RipSkb+Ll56ht5t7TovkwLEQTIfNDX h8UiQDnqjafPJYUm85UAbsKdZNqrjS/tX5AN9Rt11GUFKghd5qISe6FEBsHVHRPrnA hf1xldzC5pbk+kFD8FJbgQpwsl7DKBGVqWP0QMLGl7Rq/Aei+kJ2TlVln4buMXRgrL ReJGEmVuPoN/A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 03/21] kconfig: move and rename sym_expand_string_value() Date: Tue, 27 Mar 2018 14:29:17 +0900 Message-Id: <1522128575-5326-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 helper expands symbols contained in a string. I am about to change it to expand environments instead of symbols. Also, I will add function expansion later. Rename it to expand_string_value(), and move it to util.c, which is a more suitable place. Signed-off-by: Masahiro Yamada --- Changes in v2: None scripts/kconfig/lkc.h | 1 + scripts/kconfig/lkc_proto.h | 1 - scripts/kconfig/symbol.c | 53 ------------------------------------------- scripts/kconfig/util.c | 55 ++++++++++++++++++++++++++++++++++++++++++++- scripts/kconfig/zconf.y | 2 +- 5 files changed, 56 insertions(+), 56 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index f4394af..c8d9e55 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -111,6 +111,7 @@ void menu_finalize(struct menu *parent); void menu_set_type(int type); /* util.c */ +char *expand_string_value(const char *in); struct file *file_lookup(const char *name); int file_write_dep(const char *name); void *xmalloc(size_t size); diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9dc8abf..9884adc 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 f0b2e3b..03143b2 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -906,59 +906,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; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index c6f6e21..22201a4 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -10,11 +10,64 @@ #include #include "lkc.h" +/* + * 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 *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; +} + /* file already present in list? If not add it */ struct file *file_lookup(const char *name) { struct file *file; - char *file_name = sym_expand_string_value(name); + char *file_name = expand_string_value(name); for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index ad6305b..262c464 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -547,7 +547,7 @@ void conf_parse(const char *name) tmp = rootmenu.prompt->text; rootmenu.prompt->text = _(rootmenu.prompt->text); - rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); + rootmenu.prompt->text = expand_string_value(rootmenu.prompt->text); free((char*)tmp); menu_finalize(&rootmenu); From patchwork Tue Mar 27 05:29:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132443 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654182ljb; Mon, 26 Mar 2018 22:33:17 -0700 (PDT) X-Google-Smtp-Source: AG47ELvZOHiBoGIT4pwjk/OLoY4d4fjS86EQuPcc2rF+XiDTi4BrMiKTTRfDVqnNz7iWo+GmN8HH X-Received: by 10.99.188.9 with SMTP id q9mr27033889pge.381.1522128797310; Mon, 26 Mar 2018 22:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128797; cv=none; d=google.com; s=arc-20160816; b=d5wCNKeGlzDanz15u9fyZt/olzdmaPDA9nwhbouNFNmry2aSb88T45DNAm1tLnDQmN R3iL1jJ7sh5xuTIBXELGzRHdw0t/59xefb5QIB2d7Hu6w/XaT0hvHyrWg5jj3LUbx7Bq YfKbnIlKzbtCLrd4jH57DFbC7qHt6XYRwRgm3AREJuzk8K73UAEPInP8h91quXpD6fnm T8CVJodJMivQV4B7eCyPPmRS0dkby9A7MQkBymqAUdYMfQKxvLqI4LB/ZJbM7kTbIfxC JmB2flkNovCW+OMV9/mzJZRnkc7zIhy61bYMYN4m9Qr9LH6xM0jPXIuR6C3mSvPDtZj4 OwVw== 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=KVtfV40QbB7b1ul5DKergAyEyb2/oQLVpLcCEAFf6Z8=; b=w+QdPv7sYjqtOMyptR9PN5F9AayXEerouCUSRdHJL++Jf1JYWXARyQuw4zIUq+Fu2P 7F9ZeDNd2Yi4076Nh3fLOmf7LzFe6P46sIQIMR3mnuKk0f74nwfOz1dLIvko9TRXNTZE TWVsFbrNCTSePeZkYJ8m7RhTyOhsuguR6rjxo89A860cC2PrXiC2bXhnfu6xkNCq04ze qsoMPT6PcsrkrIF9hAf3vfDfI6xHtJtXTCQli9XBSlH2BqZvrwke73iKmPoghoVatY/Y h8HxIhW6f2mugWkh0kLHjXLnT0ImcOCr6jDYsFgy9y4oArrh8wvcXHPAP00F0ByfPWBn z7dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=sNVGX+6C; 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-v6si499695plo.141.2018.03.26.22.33.16; Mon, 26 Mar 2018 22:33:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=sNVGX+6C; 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 S1752383AbeC0Fc7 (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:59 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:45082 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751202AbeC0FcO (ORCPT ); Tue, 27 Mar 2018 01:32:14 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLn011947; Tue, 27 Mar 2018 14:29:41 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLn011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128582; bh=KVtfV40QbB7b1ul5DKergAyEyb2/oQLVpLcCEAFf6Z8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sNVGX+6Cr9/ym1GYN2/fao5gnk6OBeC74PYovrNi05IalxJvneFVY/FWABdEDL08b v5iOS+z1B1ZVDKg6ey9L4qG0WdxyV7JMzLwzN5f4Z2rWh03MoRJCxKY0jxS2WLP7OW LYDF0Rt2DuMOzQ1Udh/SEehgRvArls0VVrnbyrCMhwEjloANiHYdjk4hd07KzjRliM gx67uP0mXye0cfaUPBAKuCRSNUYYM3XXDP8zI8fp+NQA0GFxKOr1c/ESmsgBHqK/ZQ KqxfuZgJg/KkqgMWrnJutdyVqSKAzL0HX3OaCgIdYGojaHn30uYobgCV4ei7kpB8aL w0iPyfaNnvL3Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org, Ingo Molnar Subject: [PATCH v2 04/21] kconfig: reference environments directly and remove 'option env=' syntax Date: Tue, 27 Mar 2018 14:29:18 +0900 Message-Id: <1522128575-5326-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 an environment value, Kconfig needs to define a symbol using "option env=" syntax. It is tedious to add a config entry for each environment given that we need more environments such as 'CC', 'AS', 'srctree' etc. to evaluate the compiler capability in Kconfig. Adding '$' to symbols is weird. Kconfig can reference symbols directly like this: config FOO string default BAR So, I want to use the following syntax to get environment 'BAR' from the system: config FOO string default $BAR 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' - expand_string_value() This is used to expand strings in 'source' and 'mainmenu' All of them are fixed values independent of user configuration. So, this kind of syntax should be moved to simply take the environment. 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 be given from the environment. ARCH_DEFCONFIG is a normal symbol, so it should be simply referenced by 'default ARCH_DEFCONFIG'. The environments are expanding in the lexer; when '$' is encountered, it is expanded, and resulted strings are pushed back to the input stream. This makes the implementation simpler. For example, the following code works. [Example code] config TOOLCHAIN_LIST string default "My tools: CC=$CC, AS=$AS, CPP=$CPP" [Result] $ make -s alldefconfig && tail -n 1 .config CONFIG_TOOLCHAIN_LIST="My tools: CC=gcc, AS=as, CPP=gcc -E" Signed-off-by: Masahiro Yamada --- I tested all 'make *config' for arch architectures. I confirmed this commit still produced the same result (by my kconfig test tool). Changes in v2: - Move the string expansion to the lexer phase. - Split environment helpers to env.c Documentation/kbuild/kconfig-language.txt | 8 --- Kconfig | 4 -- Makefile | 3 +- arch/sh/Kconfig | 4 +- arch/sparc/Kconfig | 4 +- arch/tile/Kconfig | 2 +- arch/um/Kconfig.common | 4 -- arch/x86/Kconfig | 4 +- arch/x86/um/Kconfig | 4 +- init/Kconfig | 10 +--- scripts/kconfig/confdata.c | 31 +--------- scripts/kconfig/env.c | 95 +++++++++++++++++++++++++++++++ scripts/kconfig/kconf_id.c | 1 - scripts/kconfig/lkc.h | 8 +-- scripts/kconfig/menu.c | 3 - scripts/kconfig/symbol.c | 56 ------------------ scripts/kconfig/util.c | 75 ++++++++---------------- scripts/kconfig/zconf.l | 20 ++++++- scripts/kconfig/zconf.y | 2 +- 19 files changed, 158 insertions(+), 180 deletions(-) create mode 100644 scripts/kconfig/env.c -- 2.7.4 Reviewed-by: Kees Cook 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..e6ece5b 100644 --- a/Kconfig +++ b/Kconfig @@ -5,8 +5,4 @@ # mainmenu "Linux/$ARCH $KERNELVERSION Kernel Configuration" -config SRCARCH - string - option env="SRCARCH" - source "arch/$SRCARCH/Kconfig" diff --git a/Makefile b/Makefile index 5c395ed..4ae1486 100644 --- a/Makefile +++ b/Makefile @@ -284,7 +284,8 @@ include scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) -export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION +UNAME_RELEASE := $(shell uname --release) +export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION UNAME_RELEASE # SUBARCH tells the usermode build what the underlying arch is. That is set # first, and if a usermode build is happening, the "ARCH=um" on the command diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 97fe293..14f3ef1 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -57,7 +57,7 @@ config SUPERH . config SUPERH32 - def_bool ARCH = "sh" + def_bool "$ARCH" = "sh" select HAVE_KPROBES select HAVE_KRETPROBES select HAVE_IOREMAP_PROT if MMU && !X2TLB @@ -76,7 +76,7 @@ config SUPERH32 select HAVE_CC_STACKPROTECTOR config SUPERH64 - def_bool ARCH = "sh64" + def_bool "$ARCH" = "sh64" select HAVE_EXIT_THREAD select KALLSYMS diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 8767e45..86b852e 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/tile/Kconfig b/arch/tile/Kconfig index ef9d403..acc2182 100644 --- a/arch/tile/Kconfig +++ b/arch/tile/Kconfig @@ -119,7 +119,7 @@ config HVC_TILE # Building with ARCH=tilegx (or ARCH=tile) implies using the # 64-bit TILE-Gx toolchain, so force CONFIG_TILEGX on. config TILEGX - def_bool ARCH != "tilepro" + def_bool "$ARCH" != "tilepro" select ARCH_SUPPORTS_ATOMIC_RMW select GENERIC_IRQ_LEGACY_ALLOC_HWIRQ select HAVE_ARCH_JUMP_LABEL 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 0fa71a7..986fb0a 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..d355413 100644 --- a/arch/x86/um/Kconfig +++ b/arch/x86/um/Kconfig @@ -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 df18492..b4814e6 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1,11 +1,3 @@ -config ARCH - string - option env="ARCH" - -config KERNELVERSION - string - option env="KERNELVERSION" - config DEFCONFIG_LIST string depends on !UML @@ -13,7 +5,7 @@ config DEFCONFIG_LIST default "/lib/modules/$UNAME_RELEASE/.config" default "/etc/kernel-config" default "/boot/config-$UNAME_RELEASE" - default "$ARCH_DEFCONFIG" + default ARCH_DEFCONFIG default "arch/$ARCH/defconfig" config CONSTRUCTORS diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index df26c7b..98c2014 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -81,39 +81,13 @@ const char *conf_get_autoconfig_name(void) return name ? name : "include/config/auto.conf"; } -static char *conf_expand_value(const char *in) -{ - struct symbol *sym; - const char *src; - static char res_value[SYMBOL_MAXLENGTH]; - char *dst, name[SYMBOL_MAXLENGTH]; - - res_value[0] = 0; - dst = name; - while ((src = strchr(in, '$'))) { - strncat(res_value, in, src - in); - src++; - dst = name; - while (isalnum(*src) || *src == '_') - *dst++ = *src++; - *dst = 0; - sym = sym_lookup(name, 0); - sym_calc_value(sym); - strcat(res_value, sym_get_string_value(sym)); - in = src; - } - strcat(res_value, in); - - return res_value; -} - char *conf_get_default_confname(void) { struct stat buf; static char fullname[PATH_MAX+1]; char *env, *name; - name = conf_expand_value(conf_defname); + name = expand_string_value(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/env.c b/scripts/kconfig/env.c new file mode 100644 index 0000000..9702f5c --- /dev/null +++ b/scripts/kconfig/env.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 Masahiro Yamada + +static LIST_HEAD(env_list); + +struct env { + char *name; + char *value; + struct list_head node; +}; + +static struct env *env_list_lookup(const char *name) +{ + struct env *e; + + list_for_each_entry(e, &env_list, node) { + if (!strcmp(name, e->name)) + return e; + } + + return NULL; +} + +static void env_list_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_list_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; + + e = env_list_lookup(name); + if (e) + return xstrdup(e->value); + + value = getenv(name); + if (!value) { + fprintf(stderr, "environment variable \"%s\" undefined\n", name); + value = ""; + } + + /* + * we need to remember all referenced environments. + * They will be written out to include/config/auto.conf.cmd + */ + env_list_add(name, value); + + return xstrdup(value); +} + +/* works like env_expand, but 'name' does not need to be null-terminated */ +char *env_expand_n(const char *name, size_t n) +{ + char *tmp, *res; + + tmp = xmalloc(n + 1); + memcpy(tmp, name, n); + *(tmp + n) = '\0'; + + res = env_expand(tmp); + + free(tmp); + + return res; +} + +void env_write_dep(FILE *f, const char *autoconfig_name) +{ + struct env *env, *tmp; + + list_for_each_entry_safe(env, tmp, &env_list, node) { + fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", env->name, env->value); + fprintf(f, "%s: FORCE\n", autoconfig_name); + fprintf(f, "endif\n"); + env_list_del(env); + } +} 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 c8d9e55..03d007f 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 { @@ -95,6 +94,10 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) fprintf(stderr, "Error in writing or end of file.\n"); } +/* env.c */ +char *env_expand_n(const char *name, size_t n); +void env_write_dep(FILE *f, const char *auto_conf_name); + /* menu.c */ void _menu_init(void); void menu_warn(struct menu *menu, const char *fmt, ...); @@ -135,9 +138,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/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/symbol.c b/scripts/kconfig/symbol.c index 03143b2..7c9a88e 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; @@ -1348,32 +1321,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 22201a4..136e497 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -8,16 +8,18 @@ #include #include #include + +#include "list.h" #include "lkc.h" /* - * 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 + * Expand environments embedded in the string given in argument. Environments + * to be expanded shall be prefixed by a '$'. Unknown environment expands to * the empty string. */ char *expand_string_value(const char *in) { - const char *src; + const char *p, *q; char *res; size_t reslen; @@ -25,39 +27,28 @@ char *expand_string_value(const char *in) * 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); - } + res = xmalloc(1); + *res = '\0'; - newlen = strlen(res) + strlen(symval) + strlen(src) + 1; - if (newlen > reslen) { - reslen = newlen; - res = xrealloc(res, reslen); - } + while ((p = strchr(in, '$'))) { + char *new; + + q = p + 1; + while (isalnum(*q) || *q == '_') + q++; - strcat(res, symval); - in = src; + new = env_expand_n(p + 1, q - p - 1); + + reslen = strlen(res) + (p - in) + strlen(new) + 1; + res = xrealloc(res, reslen); + strncat(res, in, p - in); + strcat(res, new); + free(new); + in = q; } + + reslen = strlen(res) + strlen(in) + 1; + res = xrealloc(res, reslen); strcat(res, in); return res; @@ -87,8 +78,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; @@ -107,21 +96,7 @@ int file_write_dep(const char *name) fprintf(out, "\n%s: \\\n" "\t$(deps_config)\n\n", conf_get_autoconfig_name()); - expr_list_for_each_sym(sym_env_list, e, sym) { - struct property *prop; - const char *value; - - prop = sym_get_env_prop(sym); - env_sym = prop_get_symbol(prop); - if (!env_sym) - continue; - value = getenv(env_sym->name); - if (!value) - value = ""; - fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value); - fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name()); - fprintf(out, "endif\n"); - } + env_write_dep(out, conf_get_autoconfig_name()); fprintf(out, "\n$(deps_config): ;\n"); fclose(out); diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 045093d..551ca47 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -35,6 +35,7 @@ struct buffer *current_buf; static int last_ts, first_ts; +static void expand_string(const char *in); static void zconf_endhelp(void); static void zconf_endfile(void); @@ -120,6 +121,7 @@ n [A-Za-z0-9_-] } { + "$".* expand_string(yytext); "&&" return T_AND; "||" return T_OR; "(" return T_OPEN_PAREN; @@ -157,12 +159,13 @@ n [A-Za-z0-9_-] } { - [^'"\\\n]+/\n { + "$".* expand_string(yytext); + [^$'"\\\n]+/\n { append_string(yytext, yyleng); yylval.string = text; return T_WORD_QUOTE; } - [^'"\\\n]+ { + [^$'"\\\n]+ { append_string(yytext, yyleng); } \\.?/\n { @@ -249,6 +252,19 @@ n [A-Za-z0-9_-] } %% +static void expand_string(const char *in) +{ + char *p, *q; + + p = expand_string_value(in); + + q = p + strlen(p); + while (q > p) + unput(*--q); + + free(p); +} + void zconf_starthelp(void) { new_string(); diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 262c464..4ff4ac9 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")) @@ -775,6 +774,7 @@ void zconfdump(FILE *out) } #include "zconf.lex.c" +#include "env.c" #include "util.c" #include "confdata.c" #include "expr.c" From patchwork Tue Mar 27 05:29:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132450 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655296ljb; Mon, 26 Mar 2018 22:34:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELtJ/AbOhZpwvoTFLheD0nMvS4ewHWkBgKmzKifrvnNVx4gc8AZ3jHtNUrQDIR0Mlpoq5C0e X-Received: by 10.98.196.153 with SMTP id h25mr27448349pfk.111.1522128897567; Mon, 26 Mar 2018 22:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128897; cv=none; d=google.com; s=arc-20160816; b=HpFYjRy64IE6LjOLuBnOR+0nW/KcOwizosSaP8BhruIol0jbcN9SM4kROHyaWrWeAg 7N/FjsSY8g8L4E+SQ+/xjJOWGCYtLZSUInwyrtegNQ8lPr6JgFUsIxp4TJrCrKV/F8uV Q2uxSW9dVUCC1rQEy0ffLpgngWUgS5jNCEY+6Wg8o4HDZLAnXkgxV4hXG5lu501jvfW/ 8vY/u6p4CSCXhyodpseZ5KCzAnDRv9+l9BUWhzJoVDk2cSC4MOi0e7PRp5E4qMa92y4E dKI41QpzVkGRD770aDZM+e3gMMNTFApCv90HUBC0QOLl9786M3QC2vAFlpSYD4PvP0pl 9Hjw== 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=3YSzDtX7AAyzV3555aHdl8YmRdjyPFtREyhq2EffcVw=; b=Ygns/N18Oxr10vlu6kZV0+tPj5WllXNkEu4H/jVgTiQiU521sIn4QCd01+/I4hcrhG ou2nnFmy2XvHqVaSuf7C1J/vj3EmsFXNdzqJDrxpmEbHZPNcZbm7D+3Ds9m2+kIfmPcz dVEnNOobuZOZa1dp3oJ0Jyne66s11Bwa8e+82NlkHZU8ey3qcCu80RFd/THquXxTZ6nH TYNqyE7hakL7qFcCx5CmDcANuby4brLWviFaLJJVODtTQ+R1Mns2+ICjFe8r+UV8aaB4 DA1g8wDxC0nT1uoZdQG/o8TwcQl57QT96suMTgoBDegEM/uELzK2xieyx4aJP7RgnzUL bJMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=WO0pecUg; 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 g1-v6si507736plk.138.2018.03.26.22.34.57; Mon, 26 Mar 2018 22:34:57 -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=WO0pecUg; 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 S1752561AbeC0Few (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:52 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44788 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751765AbeC0FcE (ORCPT ); Tue, 27 Mar 2018 01:32:04 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLo011947; Tue, 27 Mar 2018 14:29:43 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLo011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128584; bh=3YSzDtX7AAyzV3555aHdl8YmRdjyPFtREyhq2EffcVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WO0pecUgnoeGRDpww1FardE2UMEFzUiippf+dUzjCFRxXjrHg7Ijzg/JaN7rREDHe +YNeZ4MeMTfwVOoJfHBMjfoC6tWHCCUNVVf1lOOBoVjbzenkihSByQ+GnodqOiCF4g ht9xNJPKUZ75eLPjKJEX29JYc3IA4iU6CS+MGG6sMsPtSvq0FU94hZQoyj2RL8LmA1 lKS69lzV0QkZsKMOF1Dcl5dh8DFZo0k5/2sJTDsd2yi/4PX6AC/9HyTDopx84wYsLD WJSdMZTUdGrnEi+dYdWMRBjJcbYP+sIuWN2Y5/kb8OMwsSUK7UyR2k/qs4FfsanY88 zn06WgftCH8Qw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 05/21] kconfig: remove string expansion in file_lookup() Date: Tue, 27 Mar 2018 14:29:19 +0900 Message-Id: <1522128575-5326-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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(). [1] zconf_initscan() This is used to open the first Kconfig. However, it cannot contain environments in the file path because zconf_fopen() is called before file_lookup(). By swapping the call order, KBUILD_KCONFIG would be able to contain environments, but I do not see practical benefits to support it. [2] zconf_nextfile() This is used to open the next file from 'source' statement like source "arch/$SRCARCH/Kconfig" but this has already been expanded in the lexer phase. So, file_lookup() does not need to expand the given path. 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 --- 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 Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 136e497..3d27c49 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -58,18 +58,16 @@ char *expand_string_value(const char *in) struct file *file_lookup(const char *name) { struct file *file; - char *file_name = 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 Tue Mar 27 05:29:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132458 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4656524ljb; Mon, 26 Mar 2018 22:36:45 -0700 (PDT) X-Google-Smtp-Source: AG47ELvXavtisLcrwYcz6QZ8aDqwgp+IPzV9Hw44XXmNmRbj8ZNyFsGFYoMD4KYNeglhXwPndt5j X-Received: by 10.99.109.203 with SMTP id i194mr31170125pgc.314.1522129005787; Mon, 26 Mar 2018 22:36:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522129005; cv=none; d=google.com; s=arc-20160816; b=JhhegtnMx/InijfSrpBAgYBo8HcqYyQEyS5kcpG5M/j3vTCWUmWpXOCt43r+l0Ewz7 EXTWPF7FLwGww0vA2/s6PuTopMwIpMpadzg/nJBQTrzLh5j5i0oUyLz1pCpKti8JP584 N7cDwtHEf6CS5U85oETxCbevaVo0IPux1Ivo7k9kqdWV9Y+TAaL5gNjCYoCPa7BNQj6J ZngUI9YHiyYPTBGcF9XYO+V2wUc/+9fPVLd2cDvXa4sP8iboz2Qr+GGKZsO1/BTVi+kB ZOuGIB9DLcj8XJQbWydSY//eHqlQAiLn3UPGv7r+FfHjkGDMCkqRALrZ93F0cgP04ko8 GtWA== 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=DJg7hGbemINDwGQx8+jEc01G97qTOgH9soG1HjzbY7o=; b=KbSp0+yAk75vw+Jp/c0dvatHqLVuNRinjIrrCjz29E/Dzev7VBzbGkBn1neaj1Aqg9 izpsJXFdAAOCafwDVwUywQMNXYb6UQkLZYLeI7RJViZZRP5KEsrZHxW0kQ2O9aoWOM55 0Q6VwzfUPjhsaThiHDOoFB1Sc5XIgImD0dbRsJWOthWt1jeoGdLRcZckip+uOvbifG7Y m8sT7n20iLmta80OnlcPs1DO+bzDVOy3jERgnhyscxHDN55IlZfHzZqYdkni1445EWdK jgabSyDqqGL99B1gLqIdOME8lNqHpTTI7YR+S3ycJ4cicCTMiHpKgDmrp7mRSRy2nvua F8DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=HCz6Rh5M; 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 r3si363813pgf.125.2018.03.26.22.36.45; Mon, 26 Mar 2018 22:36:45 -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=HCz6Rh5M; 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 S1752547AbeC0Fga (ORCPT + 28 others); Tue, 27 Mar 2018 01:36:30 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44598 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLp011947; Tue, 27 Mar 2018 14:29:44 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLp011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128585; bh=DJg7hGbemINDwGQx8+jEc01G97qTOgH9soG1HjzbY7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCz6Rh5MUbl5/X4lCrIedMGioG8qXrHxEktq/QinIMlbdbJ7sRuTEW+gvoTRubSXA g2zwFY46hOkEXofC8rbjm8qpqhRpnRUbq+wKF+Uf0F2yh8Cs8dxOxNZvbWx2xgdomR gsAXvJqXpVjmlnXrLSf5U+2J6/TpZLjmiUWv9CkGHwQwHYV2f4niUNO0Sf4I6zJPHr qF84iGodnZGKOevjHwgLA95Kei/WlpBSTcd68Cs/esyTDyuRrFMtyl0kuA6s72dreE 0uu/C3xcSPvl+4lSmrV1wHn6QvGvaGZ3S/GNBSVvLAhDQFKq8eGJsl2RiilarriL8k MJ6gr5RdvJqPg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 06/21] kconfig: remove string expansion for mainmenu after yyparse() Date: Tue, 27 Mar 2018 14:29:20 +0900 Message-Id: <1522128575-5326-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 explicitly expand $ARCH and $KERNELVERSION in the mainmenu. The hack introduced by commit 0724a7c32a54 ("kconfig: Don't leak main menus during parsing") can go away. Signed-off-by: Masahiro Yamada --- 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 Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 4ff4ac9..d8120c7 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 = 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 Tue Mar 27 05:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132453 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655800ljb; Mon, 26 Mar 2018 22:35:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx484rNcjWa2tRnXVn9qyXgTTiFqGXybiDZobIQQAG6jnfS6a2VqaF+kG6Fwr+g/taAPu2RNB X-Received: by 2002:a17:902:7798:: with SMTP id o24-v6mr4868983pll.171.1522128942206; Mon, 26 Mar 2018 22:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128942; cv=none; d=google.com; s=arc-20160816; b=oxmVcfjc+YmZUwMgzenQi/AVJOq/82HdIaAm/BQg+86k4/feGBWOWaPW5XNXvUB+Mt BzBME1+WpWFhfOML87jI8V9R/J0VGtX1+Y8ThIe9YBsRb9jLxPXri6utLFQRjs6ktYXe LagakhMJ7iPxRFw7lkb8E6rff27BFRU0+uS/S3kU2Jlr+OOEQMSZorfVNXVkP7z52VBM f3LUByg3CSVwnuvmC8Tic8lKc3hJdCXQCkET9rxePp212SLTXxMcx4075zzKyGQdKoxk WN5vbMKXH9i/cQrzVnJCJ/e/HlNXqjpOinP/x/+bu4DYqkpgudDyXdPx+NAe2LLL3f0G dFQA== 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=TLBa4Mx3C2xuQQjXVxZRbKbObZE5qbUZMeGEuNW3JYM=; b=ZnirWWz+j4ZsF442rir976c0utB63Ufo/WGK1jai5w4Jx9/dTILku/89eueD7zVElL O8ln0MRn36hk/hp15rzPwCw4i9YbPBgxvUNZ/dazbyzf1n35RbGc2hP/SEBDWpib727L 5ol+nots9dibCI4MDXhmqhY42ablEDrmRFCYHEBQLYqv2uvguiv7dU5kzQFvOO7iswBt FzbMAemjry6EzoGyrxtZSBzPBC/MmAc3uIJouCK5gsT/Q65u6ovS78fTVr1nWvcJ2Ayg kRBkNk9SAZ8GrU+39QxPQAxus571hcuF+ud7GKAxaLyEp2Ay7wCc+MmDgPedVQDeRhzR /nqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Vae+iBeH; 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 k11-v6si503127pln.257.2018.03.26.22.35.41; Mon, 26 Mar 2018 22:35:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Vae+iBeH; 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 S1752027AbeC0FcC (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:02 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44601 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751765AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLq011947; Tue, 27 Mar 2018 14:29:45 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLq011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128586; bh=TLBa4Mx3C2xuQQjXVxZRbKbObZE5qbUZMeGEuNW3JYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vae+iBeH5q+bNBR8hbKlVNSvchZkOW4vbqibYr1B0+PgReAfojGzmTO0Slyoh0Yqu MCUTZHcBjZKQqfBN5ZRY2qRH6TTgDrw5uu2x8mdzMkzzi/W2eCAT7YWTqv3veMk5o5 Svu2l/JRQQi5s0AWkdCp7lBKHb8Pc4XJZNs+ylnnuBbFLwTH7D2OJY7O1V24V4xOrr D2yrt2H69IWQGP/7c35QlfeSAtRFW7tl2a0fHP6YfxkW7I7s7y+1YOa+ZJhbfkPYD0 ty+S1NxB2oLgLbwTedrnnmIwEJ1FaxfAayjInzj0ySqD4V55Pnh2XywWVS4XzgDsnP +5/yl1Ndy5GKA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 07/21] kconfig: add function support and implement 'shell' function Date: Tue, 27 Mar 2018 14:29:21 +0900 Message-Id: <1522128575-5326-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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, ...) (Actually, this syntax was inspired by make.) Real examples will look like this: $(shell echo hello world) $(cc-option -fstackprotector) This commit adds the basic infrastructure to add, delete, evaluate functions, and also the first built-in function $(shell ...). 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 --- Reminder for myself: Update Documentation/kbuild/kconfig-language.txt Changes in v2: - Use 'shell' for getting stdout from the comment. It was 'shell-stdout' in the previous version. - Symplify the implementation since the expansion has been moved to lexer. scripts/kconfig/function.c | 170 ++++++++++++++++++++++++++++++++++++++++++++ scripts/kconfig/lkc_proto.h | 5 ++ scripts/kconfig/util.c | 46 +++++++++--- scripts/kconfig/zconf.y | 9 +++ 4 files changed, 222 insertions(+), 8 deletions(-) create mode 100644 scripts/kconfig/function.c -- 2.7.4 diff --git a/scripts/kconfig/function.c b/scripts/kconfig/function.c new file mode 100644 index 0000000..913685f --- /dev/null +++ b/scripts/kconfig/function.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (C) 2018 Masahiro Yamada + +#include +#include +#include + +#include "list.h" + +#define FUNCTION_MAX_ARGS 10 + +static LIST_HEAD(function_list); + +struct function { + char *name; + char *(*func)(struct function *f, int argc, char *argv[]); + struct list_head node; +}; + +static struct function *func_lookup(const char *name) +{ + struct function *f; + + list_for_each_entry(f, &function_list, node) { + if (!strcmp(name, f->name)) + return f; + } + + return NULL; +} + +static void func_add(const char *name, + char *(*func)(struct function *f, int argc, char *argv[])) +{ + struct function *f; + + f = func_lookup(name); + if (f) { + fprintf(stderr, "%s: function already exists. ignored.\n", name); + return; + } + + f = xmalloc(sizeof(*f)); + f->name = xstrdup(name); + f->func = func; + + list_add_tail(&f->node, &function_list); +} + +static void func_del(struct function *f) +{ + list_del(&f->node); + free(f->name); + free(f); +} + +static char *func_call(int argc, char *argv[]) +{ + struct function *f; + + f = func_lookup(argv[0]); + if (!f) { + fprintf(stderr, "%s: function not found\n", argv[0]); + return NULL; + } + + return f->func(f, argc, argv); +} + +static char *func_eval(const char *func) +{ + char *expanded, *saveptr, *str, *token, *res; + const char *delim; + int argc = 0; + char *argv[FUNCTION_MAX_ARGS]; + + expanded = expand_string_value(func); + + str = expanded; + delim = " "; + + while ((token = strtok_r(str, delim, &saveptr))) { + argv[argc++] = token; + str = NULL; + delim = ","; + } + + res = func_call(argc, argv); + + free(expanded); + + return res ?: xstrdup(""); +} + +char *func_eval_n(const char *func, size_t n) +{ + char *tmp, *res; + + tmp = xmalloc(n + 1); + memcpy(tmp, func, n); + *(tmp + n) = '\0'; + + res = func_eval(tmp); + + free(tmp); + + return res; +} + +/* built-in functions */ +static char *do_shell(struct function *f, int argc, char *argv[]) +{ + static const char *pre = "("; + static const char *post = ") 2>/dev/null"; + FILE *p; + char buf[256]; + char *cmd; + int ret; + + if (argc != 2) + return NULL; + + /* + * Surround the command with ( ) in case it is piped commands. + * Also, redirect stderr to /dev/null. + */ + cmd = xmalloc(strlen(pre) + strlen(argv[1]) + strlen(post) + 1); + strcpy(cmd, pre); + strcat(cmd, argv[1]); + strcat(cmd, post); + + p = popen(cmd, "r"); + if (!p) { + perror(cmd); + goto free; + } + if (fgets(buf, sizeof(buf), p)) { + size_t len = strlen(buf); + + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + } else { + buf[0] = '\0'; + } + + ret = pclose(p); + if (ret == -1) + perror(cmd); + +free: + free(cmd); + + return xstrdup(buf); +} + +void func_init(void) +{ + /* register built-in functions */ + func_add("shell", do_shell); +} + +void func_exit(void) +{ + struct function *f, *tmp; + + /* unregister all functions */ + list_for_each_entry_safe(f, tmp, &function_list, node) + func_del(f); +} diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9884adc..09a4f53 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -48,5 +48,10 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); +/* function.c */ +char *func_eval_n(const char *func, size_t n); +void func_init(void); +void func_exit(void); + /* expr.c */ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 3d27c49..218b051 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -13,9 +13,10 @@ #include "lkc.h" /* - * Expand environments embedded in the string given in argument. Environments - * to be expanded shall be prefixed by a '$'. Unknown environment expands to - * the empty string. + * Expand environments and functions embedded in the string given in argument. + * Environments to be expanded shall be prefixed by a '$'. Functions to be + * evaluated shall be surrounded by $(). Unknown environment/function expands + * to the empty string. */ char *expand_string_value(const char *in) { @@ -33,11 +34,40 @@ char *expand_string_value(const char *in) while ((p = strchr(in, '$'))) { char *new; - q = p + 1; - while (isalnum(*q) || *q == '_') - q++; - - new = env_expand_n(p + 1, q - p - 1); + /* + * If the next character is '(', it is a function. + * Otherwise, environment. + */ + if (*(p + 1) == '(') { + int nest = 0; + + q = p + 2; + while (1) { + if (*q == '\0') { + fprintf(stderr, + "unterminated function: %s\n", + p); + new = xstrdup(""); + break; + } else if (*q == '(') { + nest++; + } else if (*q == ')') { + if (nest-- == 0) { + new = func_eval_n(p + 2, + q - p - 2); + q++; + break; + } + } + q++; + } + } else { + q = p + 1; + while (isalnum(*q) || *q == '_') + q++; + + new = env_expand_n(p + 1, q - p - 1); + } reslen = strlen(res) + (p - in) + strlen(new) + 1; res = xrealloc(res, reslen); diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index d8120c7..feaea18 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -520,11 +520,19 @@ void conf_parse(const char *name) zconf_initscan(name); + func_init(); _menu_init(); if (getenv("ZCONF_DEBUG")) yydebug = 1; yyparse(); + + /* + * Currently, functions are evaluated only when Kconfig files are + * parsed. We can free functions here. + */ + func_exit(); + if (yynerrs) exit(1); if (!modules_sym) @@ -765,4 +773,5 @@ void zconfdump(FILE *out) #include "confdata.c" #include "expr.c" #include "symbol.c" +#include "function.c" #include "menu.c" From patchwork Tue Mar 27 05:29:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132457 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4656389ljb; Mon, 26 Mar 2018 22:36:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELuczegvLzYyBHn6pVPX7wDtNZy83q0v4U0woV8VSaYy7aEUf7uxRww/zMDe11FMFV77+HE+ X-Received: by 10.99.127.9 with SMTP id a9mr12096076pgd.168.1522128995742; Mon, 26 Mar 2018 22:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128995; cv=none; d=google.com; s=arc-20160816; b=sKDSJYwRokzzwx4/8E50jKrr/Zxc6muDTXktCbdhgrOpWT4ripMkC3/OUR8WJ3Y2U9 v0+og994w8FKLi2y6B1d9sc3m47GVf82EUk992dM0mZyKpa1prdRc6LWiblUaRsFXnW3 P6iOd7yyG+g4dp/WQb3hyOZeaMHlWrNnAVaGvbIZEjJOjIgEtg7VwlK9ix2g4LcDdl9y qw5hr1WRT1gjsewvn86tx/JNcU0BR1pBhBZYOTi1H/699CNDqCX5pfD584HK2YTQaU0U eGM419jRUZe2wkvoDc/O+qERX4cgiHpYpNeOt15T22xfnOMP/OXUj6PRgRtajbDTXmEI yZ3g== 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=J2BgIXcZwp3hlOWfk/Pju/0FbwUbeEepiJU9WiBDX5g=; b=dXk0BGI9wOKrbdKVYFpDbIB3+ZAAbFVTTqC/HxnlCPAh2/S020LhdRHjZOQQOrbkn2 Fc38cUBjmtRIVHZgwy3e0wXvgc5drDaQxWLDauRwVCQm6yQuvBWCL33Pblqas4Nip5f4 QQ/rzGI4meyGz/y6etK9GZaLjog+abz0SuHHxjqOsYuANAa7Z0G6dGS3H73JrWuBKgmZ SEmbMybaSRRQam/2cRlFgywW1WIGvpKB/Qk9XuhULfeAO6qZFI892a9ufkQuKqx0lXC7 er+okdzAqXACOERwSMDiiDZUzglZMeRFi9zwCUYxvWc3ezfyyOaTZQNWwa89CoUKiV6f RBCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=yAGX2yST; 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 r3si363813pgf.125.2018.03.26.22.36.35; Mon, 26 Mar 2018 22:36: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=yAGX2yST; 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 S1752580AbeC0Fgb (ORCPT + 28 others); Tue, 27 Mar 2018 01:36:31 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44619 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLr011947; Tue, 27 Mar 2018 14:29:47 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLr011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128587; bh=J2BgIXcZwp3hlOWfk/Pju/0FbwUbeEepiJU9WiBDX5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yAGX2ySTEJZavEU+/sXQsyLR4Ca49lVjQT5FDCKikq3rv3FkvSm4jmiLWpSCTKgFd O8Hlo7efOt9Qa1XIFS5q3x6cZuI0NDaVUiYYSMio1Ulpgj66MoxuFxKDG7gLL/xzQe dvO+0Fx6ewQIJ20pRFURHtIox+zxIhrbCogF74P3P/DzHxn3UBSDYMB263m+H4yaWO 3CImLwl4kTNe0f120F7B238elzhxy1AaMdVEYrRw4iPWeXyk6kLk1UfAJdJ7NRDwA7 CLBbbB+Gn9+mo7zo92uLh1WyQ3PCeeiaL+8GzAUlewtNCX+GWJQHsG5tQtHCOqTXDD xabGpC/SL6XSQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 08/21] kconfig: replace $UNAME_RELEASE with function call Date: Tue, 27 Mar 2018 14:29:22 +0900 Message-Id: <1522128575-5326-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 --- Changes in v2: None Makefile | 3 +-- init/Kconfig | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson diff --git a/Makefile b/Makefile index 4ae1486..5c395ed 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 b4814e6..0d6fe20 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 Tue Mar 27 05:29:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132448 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655042ljb; Mon, 26 Mar 2018 22:34:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELswxuK/c40gEsJKjKsy6EvfXqOjX/rmat1lzdAgy+5Upj5iUmLXUcGrYq4q2AgtcC1YTlNd X-Received: by 10.98.214.218 with SMTP id a87mr27391763pfl.124.1522128873840; Mon, 26 Mar 2018 22:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128873; cv=none; d=google.com; s=arc-20160816; b=BjcGRRXrMxUlD666WaSqMFPniX933FlvO+YUYKu9PXBDalDXh6zQkNByz+L5HTRDy7 a2BsQ2f01rxmB2+baIuzdYtXguEtLXAvx1qR7vG+fb54XXBZs9gUeSJntsPQomJb/fSq /eg1+oBXsIcsRbPrYDBNtBrvmjAg54u9VM5AjMDxzm32DCLBfib+ILshC5XMJldl3Sqi 1QUm36JZmFEVnk3Ta3nt9ceXGaWlVUNj7u2y0+tVsWx8f8Mg5jmJ2zA7u3nBndv168zl alPRswXKTM4znXTYACb9UDE7qQ+kmO6VxrPZ/tl4T3D+6bZ8OWyudX+oth9cKGrX1hT6 NfQg== 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=hfxSFq+yfNF9k+XV5X1In6K3Q3h/kBskgYYt0vXrL38=; b=x+EfUlPJOLuWgizyDFTcAOKMF8FDn0+I/xeRmTMQg28pLS7U6eeL0Q6P+PtQMlwGoC bBjmi1UuiyQVyXlOFgtuuuHqcEuPNrDK8fUECCTM5RZo4eU60RWM4NfarlyAFqRQNjJ8 bCStzM2ukhVJFalKtmF08in8U8kQzYxTIVjoflHyKw08BbJN5FN85RjMZvdoVNS4ZWul acm2ZrP+Q9tssc8EcozrYMkwWVHTvq3kSndBW8kqDOomt5pokaFJ6uHFcJ0w7q1kJBkO ZRMahBGGU+TxcGmaIOoV69WCKhkwRofXuNYeUcrES4pdsi1cKl4jLVCgOpA+8l3CKU4M Z/LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Oy8mxPFr; 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 g1-v6si510327plt.54.2018.03.26.22.34.33; Mon, 26 Mar 2018 22:34:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Oy8mxPFr; 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 S1752503AbeC0FeE (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:04 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44833 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbeC0FcF (ORCPT ); Tue, 27 Mar 2018 01:32:05 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLs011947; Tue, 27 Mar 2018 14:29:48 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLs011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128589; bh=hfxSFq+yfNF9k+XV5X1In6K3Q3h/kBskgYYt0vXrL38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oy8mxPFrwIuszmZOxa/6y0/zQ1vP/db79vbjx2m8E1svGtah16HnA7zrScZKaQt8o PhL2923YUk3GzZjnz29RIM7Lrux7cjLCUHg9cg6xPKXO9Ynz+1XN6PpiowHEElA8Nn 6120k1MYSUjWwiZrb2MZmds3OtGg9L/18L5lYAll5j5Tzbkt0oB8ESK8h0yYxpSSds 5nPsBP/MkoH0hW1rdighPolCQNf5cVIMjpedbLlxdSBQaxRO41d++zADDx86ZRUGsX u3uyreSBxGmHh9eFecG6ZX/hayw7tdj9ygpdpPMPFozi0YqdINAbM7WJozaE330QA8 QPmWIb96FFlvw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 09/21] kconfig: add 'macro' keyword to support user-defined function Date: Tue, 27 Mar 2018 14:29:23 +0900 Message-Id: <1522128575-5326-10-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now, we got a basic ability to test compiler capability in Kconfig. config CC_HAS_STACKPROTECTOR def_bool $(shell (($CC -Werror -fstack-protector -c -x c /dev/null -o /dev/null) && echo y) || echo n) This works, but it is ugly to repeat this long boilerplate. We want to describe like this: config CC_HAS_STACKPROTECTOR bool default $(cc-option -fstack-protector) It is straight-forward to add a new function, but I do not like to hard-code specialized functions like this. Hence, here is another feature to add functions from Kconfig files. A user-defined function is defined with a special keyword 'macro'. It can be referenced in the same way as built-in functions. This feature was also inspired by Makefile where user-defined functions are referenced by $(call func-name, args...), but I omitted the 'call' to makes it shorter. The macro definition can contain $(1), $(2), ... which will be replaced with arguments from the caller. The macro works just as a textual shorthand, which is also expanded in the lexer phase. [Example Code] macro success $(shell ($(1) && echo y) || echo n) config TRUE bool "true" default $(success true) config FALSE bool "false" default $(success false) [Result] $ make -s alldefconfig $ tail -n 2 .config CONFIG_TRUE=y # CONFIG_FALSE is not set [Example Code] macro success $(shell ($(1) && echo y) || echo n) macro cc-option $(success $CC -Werror $(1) -c -x c /dev/null -o /dev/null) config CC_HAS_STACKPROTECTOR def_bool $(cc-option -fstack-protector) [Result] $ make -s alldefconfig $ tail -n 1 .config CONFIG_CC_HAS_STACKPROTECTOR=y Signed-off-by: Masahiro Yamada --- Reminder for myself: Update Documentation/kbuild/kconfig-language.txt Changes in v2: - Use 'macro' directly instead of inside the string type symbol. scripts/kconfig/function.c | 59 +++++++++++++++++++++++++++++++++++++++++++-- scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/zconf.l | 31 ++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/function.c b/scripts/kconfig/function.c index 913685f..389bb44 100644 --- a/scripts/kconfig/function.c +++ b/scripts/kconfig/function.c @@ -15,6 +15,7 @@ static LIST_HEAD(function_list); struct function { char *name; char *(*func)(struct function *f, int argc, char *argv[]); + char *macro; struct list_head node; }; @@ -31,7 +32,8 @@ static struct function *func_lookup(const char *name) } static void func_add(const char *name, - char *(*func)(struct function *f, int argc, char *argv[])) + char *(*func)(struct function *f, int argc, char *argv[]), + const char *macro) { struct function *f; @@ -44,6 +46,7 @@ static void func_add(const char *name, f = xmalloc(sizeof(*f)); f->name = xstrdup(name); f->func = func; + f->macro = macro ? xstrdup(macro) : NULL; list_add_tail(&f->node, &function_list); } @@ -51,6 +54,7 @@ static void func_add(const char *name, static void func_del(struct function *f) { list_del(&f->node); + free(f->macro); free(f->name); free(f); } @@ -108,6 +112,57 @@ char *func_eval_n(const char *func, size_t n) return res; } +/* run user-defined function */ +static char *do_macro(struct function *f, int argc, char *argv[]) +{ + char *new; + char *src, *p, *res; + size_t newlen; + int n; + + new = xmalloc(1); + *new = 0; + + /* + * This is a format string. $(1), $(2), ... must be replaced with + * function arguments. + */ + src = f->macro; + p = src; + + while ((p = strstr(p, "$("))) { + if (isdigit(p[2]) && p[3] == ')') { + n = p[2] - '0'; + if (n < argc) { + newlen = strlen(new) + (p - src) + + strlen(argv[n]) + 1; + new = xrealloc(new, newlen); + strncat(new, src, p - src); + strcat(new, argv[n]); + src = p + 4; + } + p += 2; + } + p += 2; + } + + newlen = strlen(new) + strlen(src) + 1; + new = xrealloc(new, newlen); + strcat(new, src); + + res = expand_string_value(new); + + free(new); + + return res; +} + +/* add user-defined function (macro) */ +void func_add_macro(const char *name, const char *macro) +{ + func_add(name, do_macro, macro); +} + /* built-in functions */ static char *do_shell(struct function *f, int argc, char *argv[]) { @@ -157,7 +212,7 @@ static char *do_shell(struct function *f, int argc, char *argv[]) void func_init(void) { /* register built-in functions */ - func_add("shell", do_shell); + func_add("shell", do_shell, NULL); } void func_exit(void) diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 09a4f53..48699c0 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -50,6 +50,7 @@ const char * prop_get_type_name(enum prop_type type); /* function.c */ char *func_eval_n(const char *func, size_t n); +void func_add_macro(const char *name, const char *macro); void func_init(void); void func_exit(void); diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 551ca47..6a18c68 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -74,6 +74,36 @@ static void warn_ignored_character(char chr) "%s:%d:warning: ignoring unsupported character '%c'\n", zconf_curname(), zconf_lineno(), chr); } + +static void handle_macro(const char *text) +{ + char *p, *q; + + while (isspace(*text)) + text++; + + p = xstrdup(text); + + q = p; + while (isalnum(*q) || *q == '_' || *q == '-') + q++; + + if (q == p || !*q) { + yyerror("invalid\n"); + goto free; + } + + *q = '\0'; + + q++; + while (isspace(*q)) + q++; + + func_add_macro(p, q); +free: + free(p); +} + %} n [A-Za-z0-9_-] @@ -82,6 +112,7 @@ n [A-Za-z0-9_-] int str = 0; int ts, i; +"macro"[ \t].* handle_macro(yytext + 6); [ \t]*#.*\n | [ \t]*\n { return T_EOL; From patchwork Tue Mar 27 05:29:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132437 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4653428ljb; Mon, 26 Mar 2018 22:32:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49v8J8lRjul8+Ie73RSOjjbjx3Ve3fPeGgry8gB4RM6rJO4z+AhnhnK2evLnolQPm6byqXC X-Received: by 10.98.212.67 with SMTP id u3mr915584pfl.58.1522128731088; Mon, 26 Mar 2018 22:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128731; cv=none; d=google.com; s=arc-20160816; b=uoj9KLqX+8pU88W0O3t28PYtCw17PC8y/445CWb/4oB0krutOKayxZGsb1hN9mkx1x rLrEbG//j5cPvgxtt+zCJa1HNaN+b2tVehKlgCp3fA2ghDcy7PfGB4ZKezV3DRDnZKn5 MwBmGRlf2NTfkql6po/RzFvpNgJMgnCjXFHdkLnnndrGrNZulD3GM67al79AAzVV3UR9 qoWlqHHwWYIPao+lMTyaFZKsW4HnBXGDOg85z+xI81hH8NysLWOlb48cKAA7qSKClTxs 6AUhTZ9jSC+Yaf1f4TW7pUu82SjAtDogbpsXKF1ph7zxBL8T0lE1AZtvP8jQ79NMANqB faoA== 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=6WjQL00enGkVi5o0NmgKQEyQtdjD15+bMKSxvKuX21Q=; b=fQnv+UhuXzAQ84Qr2/0wbBckY1c2XNdbg0sKtO9dGTayJODcp+XRcGsXguboZifsHL 61AjT4s5aZmByWGv1lEwCua9u7Pa5HnD/Vkm/lfONHyrR07PpOMByYhIk6bUHf5nGOYl BKEyWmQ2g/34zlwZzxYbUF3G2hlyI6NfCApCv+yWp8dOQQE4GX+LuQww0pKxvYQQJ41i a0F7UNSySQWICRfSuqXqLfrxCbqRvyPhkCKNNBe5tdXBLYgolQ13ZlG6GtGMX+iqOn1I KjdQUox0mbuilWv414NeAzW5Y/6jxGIUxwtdt8qA7ffnpWht9JY+Zf3juulOC1EUAwEu ig8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hWZA5rAg; 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 s15-v6si532544plj.701.2018.03.26.22.32.10; Mon, 26 Mar 2018 22:32: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=hWZA5rAg; 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 S1752138AbeC0FcG (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:06 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44594 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLt011947; Tue, 27 Mar 2018 14:29:49 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLt011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128590; bh=6WjQL00enGkVi5o0NmgKQEyQtdjD15+bMKSxvKuX21Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWZA5rAgTdtyQlLHlLR8bImQVEDz+6RHMxv4k44d0mU4URPF2saV+jcl4Watm6WbU 3YZqviUtjodS+j6r5KZ+m+zkD19Pv4AaL3fjvVgRbqIZ+2fEV4PHovZCmIxUBSv88+ cZ91CDirSz9Bjuy4rWs0mD9WxqCKdyZKKafvIQ6aNKg1uCQGamL2fuLaMp+iXYFroB WtJUFWALvbwoLPOYpKOYOIv2Pag32mvqNYC/fyfXpgquiY1pZsCIP3xMQc9GzDLJUC NMax/GPJSwaFZv4pOrC3oVRQnATNb0R6LubYWVuzXiZPM9AkltiCrMAB72m80FUIhF SdviJmqJDT4Xg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 10/21] kconfig: add 'success' and 'cc-option' macros Date: Tue, 27 Mar 2018 14:29:24 +0900 Message-Id: <1522128575-5326-11-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 'cc-option' will be the most frequently used macro. It evaluates to 'y' if the given argument is supported by the compiler, or 'n' otherwise. Signed-off-by: Masahiro Yamada --- Changes in v2: - Implement 'success' as a macro init/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.7.4 Reviewed-by: Kees Cook Reviewed-by: Ulf Magnusson diff --git a/init/Kconfig b/init/Kconfig index 0d6fe20..c456030 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -8,6 +8,12 @@ config DEFCONFIG_LIST default ARCH_DEFCONFIG default "arch/$ARCH/defconfig" +# expanded to y if the command exits with 0, n otherwise +macro success $(shell ($(1) && echo y) || echo n) + +# expanded to y if the given compiler flag is supported, n otherwise +macro cc-option $(success $CC -Werror $(1) -c -x c /dev/null -o /dev/null) + config CONSTRUCTORS bool depends on !UML From patchwork Tue Mar 27 05:29:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132438 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4653465ljb; Mon, 26 Mar 2018 22:32:14 -0700 (PDT) X-Google-Smtp-Source: AG47ELtms9bRahq5HSspQDOHrpExhm0deaKAzLAXAkpxXyAGlsAuEDMClIkZ1fRlTOoBCmzEwBET X-Received: by 10.98.200.130 with SMTP id i2mr26078543pfk.221.1522128734249; Mon, 26 Mar 2018 22:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128734; cv=none; d=google.com; s=arc-20160816; b=QtJLfwR8DdrTwJeXwvr0zLhsBFknRr/xOx8KqtFQBBtYYeVw6VA39O4BUnB2q7Ax3U i5/wuf4rqpaokHBk85maoc/44o1egWoH/w4lqtLfxUY0LOPr5aN/EGrwUZ3lCo4JFOS8 zywxyIC2RdeHeXnvM/Ec9GOAhguOjTvaBDjLC5SZQKsYdmvt4T/BbhgXn4+LGsmnHxw7 TI/duiL7FEEYYwa7Xphr2oKXKhGb3sgJMjmWhym5JycgmUb+g7ko00mgKN7znE6lKISQ P7Jx9A2X0QH4OhfZOhkbLEwxyXov+ZtCNB1t992vN+wgRGkOqgrUOQYL0xEFhzWS+kEs og6A== 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=CY3e32fP7VlTo1A1pABM84pkB3a/uXldaQMydua0XXU=; b=CldCDF0qlANCGUSjzvpHj3yxg0ObvICF55J6YSFrpKHYhZPzl5syRa/Z8rFNTX1sc1 YpVVGVguqUP8V+8b57WJk4h7nEmWzbT2hRYhdT6GEVSItoK8U7hLS8x4TGMOoKOJplAl LXO34lRGW31GgyYQ2WA80OePcoNlwwRatgyx95Z+ht80JksWRSrmUPV9yGmobVyab6t7 zSLREJvlWVuGWID0JMncpsfM1NZoaczdR1zZE3i5UM0kRXRQvshsYbnZxJ8OUlnLqI/G 4pWdDxYklbGhzF0EEmWChA7UInd/o1de8EJVyBVdu9LsFG08hhdQ1vNaT4FwM3LD8PSX DCIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=NR0YYPTc; 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 f4si356202pgc.267.2018.03.26.22.32.13; Mon, 26 Mar 2018 22:32: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=NR0YYPTc; 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 S1752169AbeC0FcI (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:08 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44864 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbeC0FcG (ORCPT ); Tue, 27 Mar 2018 01:32:06 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLu011947; Tue, 27 Mar 2018 14:29:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLu011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128592; bh=CY3e32fP7VlTo1A1pABM84pkB3a/uXldaQMydua0XXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NR0YYPTcoaEI39sh3dWThbX6xTQ7VvO+903mnibBquvFzZ52X76jDl9c91xEU04PO ewwbb1wg72Eir2N33xsqzL2fXvypu7EEco6tk7XmMzCX40JWzIHlrB47VkKdHHL6tx id8CH+CB9QMB4LW4ILENuYw0IGJTVu9vyWBo8fHZEGgXhOwi+SImtuRazZ4AkaHAzX IAuBaHXaiG7aanTI+kdB08dAhgMSgwYCMbWjVqwOOHPQjmO3nG7leINGAFlLYSiFBL IOBlJwohbB0nrMuA7BFxC20IRl4UNbfTJX/wmLPMAnUE1uv35AAODmQ+0bY1KqCuyq ADivMHNSd4yHQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org, Ingo Molnar Subject: [PATCH v2 11/21] stack-protector: test compiler capability in Kconfig and drop AUTO mode Date: Tue, 27 Mar 2018 14:29:25 +0900 Message-Id: <1522128575-5326-12-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 the option, but generates broken code. I added CC_HAS_SANE_STACKPROTECTOR to test this. I had to add -m32 to gcc-x86_32-has-stack-protector.sh to make it work correctly. Signed-off-by: Masahiro Yamada --- Changes in v2: - Describe $(cc-option ...) directly in depends on context Makefile | 93 ++----------------------------- arch/Kconfig | 29 +++------- arch/x86/Kconfig | 8 ++- scripts/gcc-x86_32-has-stack-protector.sh | 7 +-- scripts/gcc-x86_64-has-stack-protector.sh | 5 -- 5 files changed, 22 insertions(+), 120 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 5c395ed..5cadffa 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-y := -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,) @@ -1092,7 +1048,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 @@ -1118,43 +1074,6 @@ uapi-asm-generic: PHONY += prepare-objtool prepare-objtool: $(objtool_target) -# Check for CONFIG flags that require compiler support. Abort the build -# after .config has been processed, but before the kernel build starts. -# -# For security-sensitive CONFIG options, we don't want to fallback and/or -# silently change which compiler flags will be used, since that leads to -# producing kernels with different security feature characteristics -# depending on the compiler used. (For example, "But I selected -# CC_STACKPROTECTOR_STRONG! Why did it build with _REGULAR?!") -PHONY += prepare-compiler-check -prepare-compiler-check: FORCE -# Make sure compiler supports requested stack protector flag. -ifdef stackp-name - # Warn about CONFIG_CC_STACKPROTECTOR_AUTO having found no option. - ifeq ($(stackp-flag),) - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - Compiler does not support any known stack-protector >&2 - else - # Fail if specifically requested stack protector is missing. - ifeq ($(call cc-option, $(stackp-flag)),) - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) not supported by compiler >&2 && exit 1 - endif - endif -endif -# Make sure compiler does not have buggy stack-protector support. If a -# specific stack-protector was requested, fail the build, otherwise warn. -ifdef stackp-broken - ifeq ($(stackp-name),AUTO) - @echo CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) available but compiler is broken: disabling >&2 - else - @echo Cannot use CONFIG_CC_STACKPROTECTOR_$(stackp-name): \ - $(stackp-flag) available but compiler is broken >&2 && exit 1 - endif -endif - @: - # Generate some files # --------------------------------------------------------------------------- diff --git a/arch/Kconfig b/arch/Kconfig index 8e0d665..b42378d 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -535,13 +535,13 @@ 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_STACKPROTECTOR + bool "Stack Protector buffer overflow detection" depends on HAVE_CC_STACKPROTECTOR - default CC_STACKPROTECTOR_AUTO + depends on $(cc-option -fstack-protector) + default y help This option turns on the "stack-protector" GCC feature. This feature puts, at the beginning of functions, a canary value on @@ -551,14 +551,6 @@ choice overwrite the canary, which gets detected and the attack is then neutralized via a kernel panic. -config CC_STACKPROTECTOR_NONE - bool "None" - help - Disable "stack-protector" GCC feature. - -config CC_STACKPROTECTOR_REGULAR - bool "Regular" - help Functions will have the stack-protector canary logic added if they have an 8-byte or larger character array on the stack. @@ -570,7 +562,10 @@ config CC_STACKPROTECTOR_REGULAR by about 0.3%. config CC_STACKPROTECTOR_STRONG - bool "Strong" + bool "Strong Stack Protector" + depends on CC_STACKPROTECTOR + depends on $(cc-option -fstack-protector-strong) + default y help Functions will have the stack-protector canary logic added in any of the following conditions: @@ -588,14 +583,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 986fb0a..946bd9b 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -124,7 +124,7 @@ config X86 select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64 select HAVE_ARCH_VMAP_STACK if X86_64 select HAVE_ARCH_WITHIN_STACK_FRAMES - select HAVE_CC_STACKPROTECTOR + select HAVE_CC_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL select HAVE_CONTEXT_TRACKING if X86_64 @@ -340,6 +340,12 @@ 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) + 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 Tue Mar 27 05:29:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132449 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655223ljb; Mon, 26 Mar 2018 22:34:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/KhT4g1YxEupzT69MYE8CrGZC9eFICx30TygVcgfULwRdiPQy4cT/wPmvZ71LVLfeFrA3i X-Received: by 10.101.100.24 with SMTP id a24mr4947755pgv.7.1522128890729; Mon, 26 Mar 2018 22:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128890; cv=none; d=google.com; s=arc-20160816; b=I3K6fBP62igMOl3iovgYPU5p3ogDQSS61AEh7kxsbrrezRbORQbty7BNaKyWWCps4b 89l4BodseS0dPqWzniqZ2+GGzTZaK0jXT2N8y3a37zoSDK55hqj3XJIKGnvqecDnNwWF zhBBPaaSiibhZ58LEg0ab7Z8cH1Ih5CMaDjztMnQC1v97MAGQsEazdHl/3qa0Lvhf+ID 4b3Nk+L+ql0GPwRIumIlQMNQ7Ts4xtT9RtBlk57fj+Lw3yJ+NqUDH+mTy8+CAgjt3Ha/ Q6FJ4oza+yHf+4LLYRUGA9oEEU8+0ayrFkINCvXPHboCMNmYadJgiatiHj8nz9RlCsF+ 9VCQ== 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=Y0EgiF5xffNcee7N9S9KbbQwPIhX8Hv7iF7h8moPLZY=; b=lt6Y9nirS35eBSonZQKCABM7HmZsuIcrskkpSK3UxVb4J7csfEvItBhobEz7r2jWf5 jsM7BU+M3KshEkYVt8aVkql5v0yPJ71lEsyRSPHsSNsYq8Yd8YVQvMNfwsLbDml72vLH RAX9PgZqyW03tDvhR+L7YjMQMmzLdBJU2nx4lzE/txkQ5XgZo0sQUGBj6Vk4KMHqTiVJ b6TwcBj5SlKtTrCdKRYzlRMUteVP1f3wFfxkNjwEzymJYF3gFKqdNCmmrtyeJuAMBbLE OVx73f7YYXNvF1VBf08EyFXDwqiL+Je3ioaZABKgjcj0fi/YzJ8Bca5OKQByr9DtlRUx vJBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=BUh/7azb; 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-v6si512677pla.724.2018.03.26.22.34.50; Mon, 26 Mar 2018 22:34:50 -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=BUh/7azb; 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 S1752096AbeC0FcE (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:04 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44599 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLv011947; Tue, 27 Mar 2018 14:29:52 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLv011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128593; bh=Y0EgiF5xffNcee7N9S9KbbQwPIhX8Hv7iF7h8moPLZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BUh/7azbvSXym3RK9hyEVvCdE8sCN/fMp3SmWIjgXDsb5NIaOhhLaPlLXHk30mASd HrUJC6qR2uKJyco45ptBmMMBtn0poki2kuG/CzFsdjWU/9Jj7TYwCpet8xwhgHYkTC 58ITtQLOUf5bnY1gYsWXZVKpTADUH90vsNkVj7eI5DuVCWGRwNwQrb2bskJqTeqOga hneYruvR+smdoMDkEu47q9nsR6XrjsGLMKPKpJDJNAW0sG0ltlRRvpBKwrVzLZKN2+ QHr3fUJP/tT9HfUE5ujCCEbbRhHm2yiEFxQ4ND9VBrOwkHN/loelKedysKT1cra32R 2kecjWp3G2UMw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 12/21] kconfig: show compiler version text in the top comment Date: Tue, 27 Mar 2018 14:29:26 +0900 Message-Id: <1522128575-5326-13-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 'comment'. 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 --- Changes in v2: None Kconfig | 2 ++ Makefile | 2 ++ 2 files changed, 4 insertions(+) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/Kconfig b/Kconfig index e6ece5b..99ed4b8 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 5cadffa..3dc9eb8 100644 --- a/Makefile +++ b/Makefile @@ -450,6 +450,8 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL export KBUILD_ARFLAGS +export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1) + # When compiling out-of-tree modules, put MODVERDIR in the module # tree rather than in the kernel tree. The kernel tree might # even be read-only. From patchwork Tue Mar 27 05:29:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132454 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4655945ljb; Mon, 26 Mar 2018 22:35:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELt6ulkDECOOgSN2RtcITn67T8d8WFmLE1N/VDklRNxhZC5fBkM90FMoqQ/nh19Gdws0fHK3 X-Received: by 2002:a17:902:b414:: with SMTP id x20-v6mr17328313plr.165.1522128954931; Mon, 26 Mar 2018 22:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128954; cv=none; d=google.com; s=arc-20160816; b=J09DRwYHMN9JE5Q1y7VT5mSbkSxDo+zxDYqXlowDVfWTl+JASB9zxz28QzEdWFnO9l enq41Slvu8qpy1MjyTnCwWIsa+82/Z0UnnrceUSLQDaw3KUGKnImnytYwHi8K7/WNKhd mvcN00GhWV9F0IaGLxfYKr4wcc69SJwA2ozmH22b6lsNOJ7kGdBui2Zf/GYnzLEyAUN6 dW1hLTd38Vasb4Epecs91ZaC7rVVm/6DNd9YGZ5fduB71HH6RAN+C6g7eN6K6bGWzqCk LqtD1chGWiokxOW46TzvLcmdhL09QgcNqPrjc4m7MhmQ1Rov0HF94PfEGJdCmbglq6SV mjmg== 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=KTAFEIHDxVPUJqtgMqFg6fVfd1iEr3uJrY/KTE9qXDA=; b=eIJqKR4vGOp9dvhw9k4JeKtvYqHMN24j3C20ilinf/rGseK71TnGp7wiBG6J5v+o3J z0DpUcOLgHwR7cpexLcLV2sKuyWyTSAo5u7N5WWV6o8WSSHwOpgsAZJaY55PIp+EF6N1 YOgCPKFoPl7S8BldijyaTXauzXGK1/rvZpJjpfy+rWAOJfjYRZufJLBzop+J/65qijfo Vsb4RPQ5VGMkelP9jY0ZdhEmp2u6VEMCCld98EfADvG3T3KPGIhyq9BLdOaWPMS8mo3/ oXLBceWhQgCG6ns9aQVLUxWLNKKdDa09QZvVg8bICoh6uH+hirLYYSoXr8N9Pb6TeIsw AIeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=JRmZlpek; 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 b6si352496pgv.425.2018.03.26.22.35.54; Mon, 26 Mar 2018 22:35:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=JRmZlpek; 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 S1752145AbeC0Ffv (ORCPT + 28 others); Tue, 27 Mar 2018 01:35:51 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44616 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751862AbeC0FcA (ORCPT ); Tue, 27 Mar 2018 01:32:00 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLw011947; Tue, 27 Mar 2018 14:29:53 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLw011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128594; bh=KTAFEIHDxVPUJqtgMqFg6fVfd1iEr3uJrY/KTE9qXDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRmZlpeklQJIYWtyJmcMmBAIEdpOkeUA9qeM2/7kWQVdAPXvWOwtYaXR3Hs7ejFq0 L92x+SMzs48wCb0rz6Hqt7teAEFB3cB9kRfSbm9lvSyIzscGDC7VS011lx0YQmrmwf IiShRrob+oGhHomYaxq2UIIn4/eS/vB/j0X52LLbHJzEkngd0DDpaXk17aGk0J7f6L SmCiy4lB4n6sCisuBoq3KbMvwWzL5lE3kL2pLWLBX41ik3g6SIRx8C0MQxXPPb8xHd Gy5srNHT6mx3Xhd0pxHTUwAv2sgOPCGnITurotjIe8Xj/koqM3dsZCbUyLfchL2/fg G4CXkhdb8vrCg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 13/21] kconfig: add CC_IS_GCC and GCC_VERSION Date: Tue, 27 Mar 2018 14:29:27 +0900 Message-Id: <1522128575-5326-14-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will be useful to specify the required compiler version, like this: config FOO bool "Use Foo" depends on GCC_VERSION >= 408000 help This feature requires GCC 4.8 or newer. Signed-off-by: Masahiro Yamada --- Changes in v2: None init/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/init/Kconfig b/init/Kconfig index c456030..923cab5 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -14,6 +14,14 @@ macro success $(shell ($(1) && echo y) || echo n) # expanded to y if the given compiler flag is supported, n otherwise macro cc-option $(success $CC -Werror $(1) -c -x c /dev/null -o /dev/null) +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 Tue Mar 27 05:29:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132447 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654791ljb; Mon, 26 Mar 2018 22:34:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ZQO+4cSBlAgNSdxGUV0fp8kJsH5xwtsBJYX1qzhH23SpF/bSdRrcPJOReECIK8RRRpQpz X-Received: by 2002:a17:902:6b8b:: with SMTP id p11-v6mr6806189plk.213.1522128852068; Mon, 26 Mar 2018 22:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128852; cv=none; d=google.com; s=arc-20160816; b=qWEOx/jE2LnEnEmHpC3DPSdX1kCDU0DaRZyJatw4qW6z6NyGasI5h86UnXDeE/OhjI 9GmLN/c2EA+FeDuniEnt013zTbcwkFXP/hFg1V+S3+x/mB3JOxFHsOTUYzaQfsur0bya CyQ2HY9dCM5cse5zbskyvYDUzmW1qyMhW1jWEbeIPi2cgI9XAf2TKlnYlkpKudWPZfTc mCaXJGRubk+m0dtiO/xzIt9Sse+KCZ4VNAaiis7QO1irrNYrPiEGPGWPy5CCO+RzeFyZ RKLHumo1PvKsU8HJP2wXE79Oa72+Y9BIGrZH750YR6gX7brx4VcguNIrSYOGPC/O89C/ uzyQ== 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=RYqC1QRkceoAm9+CHevbEu7OH/qqF2FDZaEeQkX7ooA=; b=t2IPAViFE8WMbE7Atbe9vk3MQcvFxl+ugdKkQ9McImxHNOPsSZcCBdOp+4tEzdpoph mMptFdfHPlEXYogcAWhVuCd/4KNp72hVKx+wksLFkWirYH6X6oo/1/fGjqThiGGrpvP+ xGxGR4fyYMOVVp37QAq7mlhGIuuS/NzwSj57weCpoIOBmU2wMTF35RLjtozQoSaxcx/z f1eO9YLV5AeGZYrHws2Ru5oZ4FwWPAFpnJHnB8UWNiMowvA+U2B7rV5CFQ9hX4/7n/Pb ad7Eng+Xkl998DqNB1sxVbdJNZh2UOyO8iHHUtdPFMFBP22nB7G2Ez9v+F3lMVlf3t2i bgeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qfBbq9xZ; 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 o1-v6si533308pld.130.2018.03.26.22.34.11; Mon, 26 Mar 2018 22:34: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=qfBbq9xZ; 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 S1752555AbeC0FeH (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:07 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44827 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751185AbeC0FcF (ORCPT ); Tue, 27 Mar 2018 01:32:05 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaLx011947; Tue, 27 Mar 2018 14:29:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaLx011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128595; bh=RYqC1QRkceoAm9+CHevbEu7OH/qqF2FDZaEeQkX7ooA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfBbq9xZpkLZktyLSn3fl0c8ncv5jNBx9GT/3WR0oVyI4PbQC84NrVxEG915JvER/ tu9k2lx4WJXlHRaz5YabEVxvl5jgoSF7p291eZK/pLuMWPi/Sjyi/cRBDXUxAcS0MN vwZb39ejcMb1sbZ5+c6AdLmo05v78/AyA/Sbe062qbk6eDu4r/mdnSvdkPzf7QC1+Y T5kGReS/Y3pfNB0Al1dRIIpXvOa7Fruxpkemvc/Ik7SAkzSmRiBxzhcPqAgvCPE3dP PVBRs+7nJaKinEXumLzSE0WO8jbXKG4jbRA1wkZGJW7mPOkaLQ5TqvuT/D+lpUfrWa OvR6N2UnjWtkQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 14/21] kconfig: add CC_IS_CLANG and CLANG_VERSION Date: Tue, 27 Mar 2018 14:29:28 +0900 Message-Id: <1522128575-5326-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 --- Changes in v2: None init/Kconfig | 7 +++++++ scripts/clang-version.sh | 24 +++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/init/Kconfig b/init/Kconfig index 923cab5..5998034 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -22,6 +22,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..d8002d2 100755 --- a/scripts/clang-version.sh +++ b/scripts/clang-version.sh @@ -10,24 +10,22 @@ # 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" + echo "Error: No compiler specified." >&2 + printf "Usage:\n\t$0 \n" >&2 + echo 0 + exit 1 +fi + +if !( $compiler --version | grep -q clang) ; then + echo "This is not clang." >&2 + 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 Tue Mar 27 05:29:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132456 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4656250ljb; Mon, 26 Mar 2018 22:36:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELsy1PcncIoYJ2fvbDbmd2dagALeHCUzVBbhVace/w2WiMr3Edoaw7Tu5KVWRBjyQP3mQsyX X-Received: by 10.98.138.154 with SMTP id o26mr11762738pfk.82.1522128979996; Mon, 26 Mar 2018 22:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128979; cv=none; d=google.com; s=arc-20160816; b=aPck+SD+SyVuX/BMJZApvIGS7xP/xZWmVAQ00dS3eTR1OaDpAWwGp/54Hfhxo887oj 3DJFHhNqRfNpFP+OxDmABxbiW2VbikPWKlPmxwE+ktHVhXLuaaDCcVY46LyEanHe1tFL Y0Tzwqfx5ruZF7fwbNXq00vnk8ORknIyYUSpbNCmY7eB1ieisKCShab+TQaoxzohkScc V06fB+Cgzdz4esTjVMH07F9rqONx6Y/lb+bZUzFG4bqyLAOearv9Apt5zqeDDSXWyPf+ KiXLjBF1UhJhWx7b6rh/kr7dN/AOusGhoVqvp91HvQmE6Tdk/tTzY/ivlyetZa1UqI8k G5FQ== 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=+KtcYTB0i2G/+6IMyIjcZZUASKlIoX6zrXACCTEjvdQ=; b=oU45YSkHm28XjPS/P/HLAtiCITe9eW7PBfISgdi6D8WFmylQ9c6J3VFxRbQyF/7k7Q 5MxmD4rm/wtSKvPOFbDlWLVpYinh2ypV/44aPRs9Sd2YbULS8TP9+n8i3KAjFERx2QeK I/Z6QTkHlpRlyrmKphi5uZ8IruABB1HSD3lrGsWRpx6Ed75ZMRmgh8v5dNiXtJczc7pJ xDbwIxhiVPvSOV7QMb+EZDlAZAfIMHeQ3U+LQcy33wrjtPRL6LUFFXdRb1Tn2CPb53Pe iOFVRw6fJelVbRTc17cDszDKgQ080oNUgZS/w69pLTfFu7FvIoKsEWci6phca+uYYYWH BSQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qdNilvxk; 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 i1si350626pgc.229.2018.03.26.22.36.18; Mon, 26 Mar 2018 22:36: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=qdNilvxk; 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 S1752308AbeC0Fft (ORCPT + 28 others); Tue, 27 Mar 2018 01:35:49 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44672 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751903AbeC0FcB (ORCPT ); Tue, 27 Mar 2018 01:32:01 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM0011947; Tue, 27 Mar 2018 14:29:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM0011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128597; bh=+KtcYTB0i2G/+6IMyIjcZZUASKlIoX6zrXACCTEjvdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qdNilvxkL4W+hYn8vdM0wzWm4XKD1/Mk+AxPY0QFtmhhO39579JuGWB0Iz3uE91cd Q4LJR8/pHhxifju11Hg9foaAH2cJP7HnAJkXJSg9p9/vKFuXTKduTCd/raJuneO2+G 4tV20Af3wmNHqrJeiUmo+dNJH4Y+ePrbj/H0mimXQfl70OIA0zQQ/lMX1ELUchZ3eH gymLPEQJ/mxh++gjlOBFHriFlb/mU++R4gU6CXAXG2zmDur023XiMxnaTkfXri5cZo EWxSBLUbXhp+ajVTYIuJwduRUXhbTO64cuFo5phNmp2ualJu+LeXo3OYsFkWMZd7xz h6pHhM+C3TUXg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , Peter Oberparleiter , linux-kernel@vger.kernel.org Subject: [PATCH v2 15/21] gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT Date: Tue, 27 Mar 2018 14:29:29 +0900 Message-Id: <1522128575-5326-16-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 down-grade your compiler 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 --- Changes in v2: - Move the 'depends on' to the choice value. kernel/gcov/Kconfig | 17 +++++------------ kernel/gcov/Makefile | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) -- 2.7.4 Acked-by: Peter Oberparleiter Reviewed-by: Kees Cook 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 Tue Mar 27 05:29:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132446 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654751ljb; Mon, 26 Mar 2018 22:34:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELt3yY8flxfB7ekY5/SfLkSb/NgwN7ChoPfnvDm19jcEWQWlfgsA6NuK97qe/62GU9+JDm0l X-Received: by 10.99.119.195 with SMTP id s186mr30991360pgc.453.1522128849372; Mon, 26 Mar 2018 22:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128849; cv=none; d=google.com; s=arc-20160816; b=Bo1BGEHJk8m0XicMYPXbpvVCX32VkU0D5vks1Mrf9JYFcM5AuJ8rzwVyRZLubNIP76 STqYlJMNH3hLFnLlCrq/RTklBiqgciUni1x4Wjv6bb6+GPAic16TZElk3FSotplagZLT fs7XM5WiVAnAWfI9GtgZ0h4Vp+3iePxZuXH6GFmVQs+pw2+urcrVfSljRlYxcANI2rdh mxoH32GknQdFzr1gfwdmUf3N4Gnyyz0kvdkaessEBvvTASeu5P1miClAd4CGpKMfxH3s KpZoBsW6qjMXi5QQ8j6/c2CrcuLMuMzFMVYh1DlUWlKgW6fKaygGAR9oh+7+C5imN2sN T4Jg== 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=4pG48S2UlrsOT3ejNrzGZWeQQuZhLyLMFh52VdRj5G0=; b=fFGvIKBBH3gxYPa9+ifJ6G4mCvGQD5JGZclRdM6KzXVEmWmv5gLkL3mX/3ol6Qwj8h h1av5vVluCSc13LMGEXY5wza4SQSax8cn2tHkmdNLxvNAXDm+n/gQ7yosmH3XAfTmolf zsZ9l0mNAKmBQVavhxTyFRYTTE/GHR+l/ZH1JEdvJUG2grMXtVv646TrDEcpUYUptZKy Auyqnx3Rv7E8Uh0chqIriBIoFFkyLVYhCuIs3h1QRVBqegNSodY6tDcmXF7eOz1GNFDI qEfwdChxkhLCvOjN3wAQX992hoeKoYgmjfu66DqmakaRcj4u1FOufPn4dqgFQMMys5xS gehA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=rcvuR9M/; 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 o1-v6si533308pld.130.2018.03.26.22.34.09; Mon, 26 Mar 2018 22:34:09 -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=rcvuR9M/; 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 S1752538AbeC0FeF (ORCPT + 28 others); Tue, 27 Mar 2018 01:34:05 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:44829 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752090AbeC0FcF (ORCPT ); Tue, 27 Mar 2018 01:32:05 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM1011947; Tue, 27 Mar 2018 14:29:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM1011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128598; bh=4pG48S2UlrsOT3ejNrzGZWeQQuZhLyLMFh52VdRj5G0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcvuR9M/2isRNn+pgd2S8Nyq/HA0MTEO/S6q2kZIUEikiHac3q8rQtDha37zT/Knt b/3WRzHX9y2cRAcMrAdrbF10i4tACg14IS9ZqaEj1sEK1+VyyQEjY/yocF0pS3Z0Hu ENWxHx0yapLgyBPJ1Bvx19q6ppg6q8BXPYokWmvp36UeRwxQJS8eEmdIfou33J780J nrWjHiq6rWDQsYGTSdRE8E747OzxW1CnlY10U9j9rGQCdvM6BN6C2MJsBus3q7oxF6 kQv1BNLIKc1ou52JtFLiQkJ5HRZ3IBYM/jrrfbFbkTHX9rv9NlQcodF2p9XIJ1JNw9 2+mgsjwXmNNUA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 16/21] kcov: imply GCC_PLUGINS and GCC_PLUGIN_SANCOV instead of select'ing them Date: Tue, 27 Mar 2018 14:29:30 +0900 Message-Id: <1522128575-5326-17-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 used with care - it forces a lower limit of another symbol, ignoring the dependency. In this case, KCOV can select GCC_PLUGINS even if 'depends on HAVE_GCC_PLUGINS' is unmet. 'imply' is modest enough to observe the dependency, and this makes sense. If you enable KCOV, you will probably want to enable GCC_PLUGIN_SANCOV, but it should not break the dependency. I also remove unneeded code, I just happened to notice. Signed-off-by: Masahiro Yamada - Drop depends on GCC_VERSION --- Changes in v2: None lib/Kconfig.debug | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 5be22e4..8243c9d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -743,8 +743,8 @@ config KCOV bool "Code coverage for fuzzing" depends on ARCH_HAS_KCOV select DEBUG_FS - select GCC_PLUGINS if !COMPILE_TEST - select GCC_PLUGIN_SANCOV if !COMPILE_TEST + imply GCC_PLUGINS + imply GCC_PLUGIN_SANCOV help KCOV exposes kernel code coverage information in a form suitable for coverage-guided fuzzing (randomized testing). @@ -758,7 +758,6 @@ config KCOV config KCOV_ENABLE_COMPARISONS bool "Enable comparison operands collection by KCOV" depends on KCOV - default n help KCOV also exposes operands of every comparison in the instrumented code along with operand sizes and PCs of the comparison instructions. @@ -768,7 +767,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 From patchwork Tue Mar 27 05:29:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132441 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4653822ljb; Mon, 26 Mar 2018 22:32:47 -0700 (PDT) X-Google-Smtp-Source: AG47ELub9cbGCBUIM2UZGeytp+/3oxsO1FMwhFhs0+hrsPSMDcsx45s4eMtZA5XrDH5KoV7vsZIg X-Received: by 2002:a17:902:aa48:: with SMTP id c8-v6mr42644641plr.361.1522128767490; Mon, 26 Mar 2018 22:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128767; cv=none; d=google.com; s=arc-20160816; b=Wy3VEvFdr2AlOHyKmuvZaSGH3aDRDoEw22RwZV/Lr9xNV/+voybSDz3d/ObFrYtTNk fBytszK8VxMvbscuRTEJUMsmZPrSX1AGNXsJyCx0CN4ORb0CnNdIl9tgBSkoAm77tOrj LsIo7lxuLP+tnwc2wRwHsH6U15FmTrTBDsop6bLw03I16YXGZ+wBWVmLxR1b0+TtABjc s9oHrjrnuPeqU4q+Zd+Wf0cg4DOr37JSeeCY4qfS0zP4k1sOekVGndcMtIyIwnpcoJ0b YASPLJj5CjIKcwsxCeq1vs+DdABrz9ZNNgpp1RCuVmNAAT6MFEgSLLjdKFAhgQ2SIQqD 0mMw== 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=SmnoR5uX+QdJc5jR+e3JIIYITKB70ECICvL3cl8cDVA=; b=pT9jUa6siieD7Bx/mfJhMRe0AoI7iRpxRYQxzfgfe/4bzzx8FZb0ZbbO2hmNfcEOQ/ gENZNTIOjXBq7RDdeeSCv3hHpXO0cFB0U6le0aHURziIWa0T1zi4SALGP0Dz+55lQcmm vJqzr9hPf0J2VWSXZeG5Jbmghry+nzqbelMTN54t/rQUjQ8KpKQnPAWeJWY1BJOQbrr/ djgzyoG0cjJFHOhwiXf/q/ndeyc+p2CZdGAJPTV6L3/9isx+xWo2T9hEl6S2hElg/uQG dGKwwaNpiSUoLu/v0Biye9mGW3togtk+XBGU3sRP1eNjriTv/oP1WmFfBcFQl2pNFRSF ZNng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=teTvD2yn; 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 v20-v6si481748plo.199.2018.03.26.22.32.47; Mon, 26 Mar 2018 22:32:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=teTvD2yn; 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 S1752334AbeC0Fcn (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:43 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:45213 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752180AbeC0FcS (ORCPT ); Tue, 27 Mar 2018 01:32:18 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM2011947; Tue, 27 Mar 2018 14:29:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM2011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128599; bh=SmnoR5uX+QdJc5jR+e3JIIYITKB70ECICvL3cl8cDVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=teTvD2ynRoXyNj9YtZnvGTB5jOn1jLzK/WuofJKk1VZCt1aGfCaHtkBgoc89t9PYk iGoodLK7z2911DH0PrWwB6jE7/6atN7eSRAs8FdReVnYmtL3/+1RQIH5Fvb9qdy6Nl 0QANp+M0g3lPATvkb2jKNgw5hGwQOc6rhw+YS6dZ7qgNLfS27Mn6APcM3mECU/S3WK VDPtEQRG/lLdqlmv2sxCVvwZAldh99/6TnZkIs2Fn4Q45af/LDnL3hf53j/D8NKjvV HIPJKzJeDn0rbXgNJM44P9jztuUM0FQCh6qXHZYw6rXWWHL3aMX9CMAglE1A6RWW24 RRg0Hcumsa6OA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Emese Revfy Subject: [PATCH v2 17/21] gcc-plugins: always build plugins with C++ Date: Tue, 27 Mar 2018 14:29:31 +0900 Message-Id: <1522128575-5326-18-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 the target compiler is GCC 4.8 or newer, plugins are compiled with HOSTCXX. Otherwise, gcc-plugin.sh will select HOSTCC or HOSTCXX. To simplify things, drop the HOSTCC support for plugins. If you use GCC plugins, the requirement for the target compiler is GCC 4.8 (or older compiler with necessary features backported). This is a feature for advanced users, so this requirement would not be a big deal. Currently, building plugins requires GCC 4.5, so this is not a big jump. Remove the code that was needed to build plugins with HOSTCC as a preparation for Kconfig migration. Signed-off-by: Masahiro Yamada --- Changes in v2: None scripts/Makefile.gcc-plugins | 11 +++-------- scripts/gcc-plugin.sh | 38 +++----------------------------------- scripts/gcc-plugins/Makefile | 15 ++++----------- 3 files changed, 10 insertions(+), 54 deletions(-) -- 2.7.4 diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index b2a95af..b0f9108 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -1,7 +1,6 @@ # 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)") + PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCXX) $(CC)) SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so @@ -65,12 +64,8 @@ ifdef CONFIG_GCC_PLUGINS @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 - 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 + $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error $(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 endif endif endif diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh index d3caefe..0edbdae 100755 --- a/scripts/gcc-plugin.sh +++ b/scripts/gcc-plugin.sh @@ -8,42 +8,10 @@ if [ "$1" = "--show-error" ] ; then shift || true fi -gccplugins_dir=$($3 -print-file-name=plugin) -plugincc=$($1 -E -x c++ - -o /dev/null -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <= 4008 || defined(ENABLE_BUILD_WITH_CXX) -#warning $2 CXX -#else -#warning $1 CC -#endif -EOF -) - -if [ $? -ne 0 ] -then - if [ -n "$SHOW_ERROR" ] ; then - echo "${plugincc}" >&2 - fi - exit 1 -fi - -case "$plugincc" in - *"$1 CC"*) - echo "$1" - exit 0 - ;; - - *"$2 CXX"*) - # the c++ compiler needs another test, see below - ;; - - *) - exit 1 - ;; -esac +gccplugins_dir=$($2 -print-file-name=plugin) # we need a c++ compiler that supports the designated initializer GNU extension -plugincc=$($2 -c -x c++ -std=gnu++98 - -fsyntax-only -I"${srctree}"/gcc-plugins -I"${gccplugins_dir}"/include 2>&1 <&1 < X-Patchwork-Id: 132442 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654033ljb; Mon, 26 Mar 2018 22:33:03 -0700 (PDT) X-Google-Smtp-Source: AG47ELtppeYRFflQR/Huz/u7j1FoTGFOOoUUP8eCcSWJIwxI3m6i4vOQjDgyRlvozXw2a4t1Dk/4 X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr43394891pli.121.1522128783712; Mon, 26 Mar 2018 22:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128783; cv=none; d=google.com; s=arc-20160816; b=bblOKqFwpFcaElIT3tVFpn4VRq2+gCNmAZZBf7NKMmS7XmXgn8DHowO8UVyi+K1JGN ToR/3vq6hFkYRZe7NhFWOiy0iQ+Lya9NKHD0NGnMSrgtnbD6sxSngM3Vv+U3X8KjznE8 s+Vc35bh36p4ylZgGafoyp7zBHwm+Y99lGkIoO5187f+t7d/9eUqynfKUd5sqe0VQFm2 VL/lfaGuVGyMbMkCOl4yOM7VYaGPp6cgV/7e93EtM7VdD71Ju4so1ozct0lFM6ipRB+5 +oWx3VCEDv6BuSLeF6BTMKb72o7apPPg2Q7bhkg+QDaMx288Av7Zni+DsXIoIWHoSB1T 7DmA== 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=CJKNAks6CUvPLpPMuNPkql9N1J3NIbKvOlothThoRbk=; b=CkLMts+THos+ms+ARi3GiiNyAM6BtsYcy1iJVs6XbgE6JB4mLR6SkBp8dsqNHqDjVp f1HQ5MCZereAvLbBy08XZj+4hbzo1liPFsHOfhlbok4Wc2aF7+SII4KxqHJ4YIUvpLw1 2lJdMpwVwdew+nQsxGSiHBehm4ag/NtjgCk5DdltjUxAU8AkZS/S69O9EPizgM7k3D+b hZqagl8XxIa8AEZtSs4avoxC9ZF2j+j61JW/bP97tE3MaWdrLSURlAwO7Jq6XgTmOe5k NbO3uY44XWFTIn32ERSrkuE++u9CV0qiOWOMHcsUI8cgBD5qIbWqx9kvL8ADf3RA1Tfo KoQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ELYMf9z3; 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 p18si351268pgv.334.2018.03.26.22.33.03; Mon, 26 Mar 2018 22:33:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ELYMf9z3; 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 S1752427AbeC0FdA (ORCPT + 28 others); Tue, 27 Mar 2018 01:33:00 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:45040 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752173AbeC0FcM (ORCPT ); Tue, 27 Mar 2018 01:32:12 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM3011947; Tue, 27 Mar 2018 14:29:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM3011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128600; bh=CJKNAks6CUvPLpPMuNPkql9N1J3NIbKvOlothThoRbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELYMf9z3AfchcwwTWlnNP4mREzv+zLWkIeqfQyJDoUR77xSIbOPKXwX48L5YzG7LQ q0Jo337dzNRLHbdhF/IH/jJZKl5bWW21bHskd0sk1DuGWEhxCBdEFoF9MRNj5HnLrT tDowD+CQpLyYBrExDUmR0UVS474nvOH3b7KRTLbdnt+CkYssBhQpGmsUeZdtIjUOHH nMBL5daTgGMj9UeqwV4DUyJngGH52H/pVZoZGG4q1sBtDmN7TkX9FcYNy2K7VY6tNo vbWspCzBTwePPP09otZVmJH/mMZ0pZwplknvcoC4bgS926ozqKuGzu9YZG7qbydyov vkSETe4QdvgPQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Emese Revfy Subject: [PATCH v2 18/21] gcc-plugins: move GCC version check for PowerPC to Kconfig Date: Tue, 27 Mar 2018 14:29:32 +0900 Message-Id: <1522128575-5326-19-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For PowerPC, GCC 5.2 is the requirement for GCC plugins. Move the version check to Kconfig so that the GCC plugin menus will be hidden if an older compiler is in use. Signed-off-by: Masahiro Yamada Acked-by: Andrew Donnellan --- Changes in v2: None arch/powerpc/Kconfig | 2 +- scripts/Makefile.gcc-plugins | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) -- 2.7.4 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 73ce5dd..b8474c2 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 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 b0f9108..25da4c0 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -56,14 +56,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 $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error $(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 endif From patchwork Tue Mar 27 05:29:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132445 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654439ljb; Mon, 26 Mar 2018 22:33:42 -0700 (PDT) X-Google-Smtp-Source: AG47ELskXCF35GBJfosCG0k+2u8oytjxlz3eXKhNPqqXUmu8jlwnVXgcP/0eDfe5N9famXnRUdk5 X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr31826944pli.176.1522128822285; Mon, 26 Mar 2018 22:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128822; cv=none; d=google.com; s=arc-20160816; b=x5dBAHNG2tXqjhz7vUFqnT8W3RPPXskZ+PgjbdAjw1gOYzH72lE9OU9ZPlGFBypsyQ CzJWurlYhc0jablrRDGaRor0jcBZS6n/vmVMmUD80VmduCWSsVwilYXqytnIi095yNrS 620cZjkzz5sKEPZ5TG20FiTjhEq7JEWz46ZoB2tiGlrqRsQy5wlMnl7Jvplyza2TMnXS 9WqtfKyVTK6TZdgY7s4H6OZr9neaLAGLE6gTVp93/0uKQ2TPLLX9Nh9THtwPZJyl4yKG 223HhjliKuri+q5kB2fhq94BsFDOAJpg/Pm8ZF4O2WSrx47r23djdlYSNd2RpeSzFY0X GJSg== 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=J5s1k4WDxvrC/cEZRKsOAIhyqGKMiPt0AQZWKjK7RxU=; b=QvsiSK9ZuYxMBp5K4VRz0mIH2LnGfXvk5S1zTJzmt9yRgboOfTO+vxA6h43vf7HGZH WvdeimHrpkulLnF0tGYY0aSA4109To3hNJy98hwbQZ87N6kqkJhWbRgZHFCr6rsHXjfD GAHgQIH0mmRq8zMnRFXtSn7+nvANUELQ7ElSaDhdge/VwEEhykdsBH0K2E1rTCjUsqr7 l1vQ2lPOUAnOGE/KowYMT/GAT4Rmi6Urz6WG0DZCviMgZ48TdzIdgR4t8kt3zReesl1h 761B7cJi171Lg4r/L++vJ5J3AtS1vMumQux9OihH5ciawwd+vo8kBXTG7mKQpvldZ1RU pSSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=GNX1TWYc; 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 v190si407091pfv.59.2018.03.26.22.33.41; Mon, 26 Mar 2018 22:33:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=GNX1TWYc; 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 S1752496AbeC0Fdi (ORCPT + 28 others); Tue, 27 Mar 2018 01:33:38 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:45037 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbeC0FcM (ORCPT ); Tue, 27 Mar 2018 01:32:12 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM4011947; Tue, 27 Mar 2018 14:30:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM4011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128601; bh=J5s1k4WDxvrC/cEZRKsOAIhyqGKMiPt0AQZWKjK7RxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GNX1TWYcTFNOeF9x4OR0lIO7zYxyiH6YKKu6+aIBlFLTqLskst8NA/JqwzkYGh02V eCvPoSFbzduPPOUq4DaLjLPd5utMTFV2Lwm0ql/tIiUkWcwA5Vsv342ZK9c1mmm2oj SYD+oeIotnTP3CBdlnGfz98QLpDOT9HQvKUDz7gPkKUWEQepdAEI+LyiUxRHpMs0+v dinnYJ9nY+G7nH1ULUWFX31Mx8Oher+IQLybA9kyw5IRNG2MQbQ8IP4C+wsnmFYhTF h5jps7CHTwo/TRt/eF9YpKBgUfvWn4BscWE2gnwc8gRXVSNn1PSxIfM+OkGm0TLwiI XmWx/x5cNXr7w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Emese Revfy Subject: [PATCH v2 19/21] gcc-plugins: test GCC plugin support in Kconfig Date: Tue, 27 Mar 2018 14:29:33 +0900 Message-Id: <1522128575-5326-20-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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. Users can enable GCC_PLUGINS only when it is supported. Signed-off-by: Masahiro Yamada --- Changes in v2: None arch/Kconfig | 4 +++ scripts/Makefile.gcc-plugins | 82 ++++++++++++++++---------------------------- scripts/gcc-plugin.sh | 1 - 3 files changed, 33 insertions(+), 54 deletions(-) -- 2.7.4 diff --git a/arch/Kconfig b/arch/Kconfig index b42378d..88cc925 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -407,9 +407,13 @@ config HAVE_GCC_PLUGINS An arch should select this symbol if it supports building with GCC plugins. +config CC_HAS_GCC_PLUGINS + bool + menuconfig GCC_PLUGINS bool "GCC plugins" depends on HAVE_GCC_PLUGINS + depends on $(success $srctree/scripts/gcc-plugin.sh $HOSTCXX $CC) depends on !COMPILE_TEST help GCC plugins are loadable modules that provide extra features to the diff --git a/scripts/Makefile.gcc-plugins b/scripts/Makefile.gcc-plugins index 25da4c0..19d0d5b 100644 --- a/scripts/Makefile.gcc-plugins +++ b/scripts/Makefile.gcc-plugins @@ -1,71 +1,47 @@ # SPDX-License-Identifier: GPL-2.0 -ifdef CONFIG_GCC_PLUGINS - PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh $(HOSTCXX) $(CC)) - - SANCOV_PLUGIN := -fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so +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 - DISABLE_LATENT_ENTROPY_PLUGIN += -fplugin-arg-latent_entropy_plugin-disable - endif +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 - ifeq ($(CFLAGS_KCOV),) - # It is needed because of the gcc-plugin.sh and gcc version checks. - gcc-plugin-$(CONFIG_GCC_PLUGIN_SANCOV) += sancov_plugin.so +ifdef CONFIG_GCC_PLUGIN_SANCOV + ifeq ($(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 - $(warning warning: cannot use CONFIG_KCOV: -fsanitize-coverage=trace-pc is not supported by compiler) - endif - endif + CFLAGS_KCOV := $(SANCOV_PLUGIN) 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 - - 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_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 SANCOV_PLUGIN 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), $(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),) - $(Q)$(srctree)/scripts/gcc-plugin.sh --show-error $(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 - 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-plugin.sh b/scripts/gcc-plugin.sh index 0edbdae..b18c69c 100755 --- a/scripts/gcc-plugin.sh +++ b/scripts/gcc-plugin.sh @@ -24,7 +24,6 @@ EOF if [ $? -eq 0 ] then - echo "$1" exit 0 fi From patchwork Tue Mar 27 05:29:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132439 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4653585ljb; Mon, 26 Mar 2018 22:32:23 -0700 (PDT) X-Google-Smtp-Source: AG47ELteJBn8/pxfY1l4UjkT+2Tu9Z9gEPdNrIYr6ZMSpyUqvXD7hhmdvJfgNaTUtpmU+grtcHir X-Received: by 10.98.211.211 with SMTP id z80mr34928070pfk.16.1522128743719; Mon, 26 Mar 2018 22:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128743; cv=none; d=google.com; s=arc-20160816; b=YGMKutF15lTgrkBxxUQh9v05GoX0aUCy0qe+/68bxXih3Y3e2uLuloybVqoIp4+ipQ xnP7TEasZAVCdX6xGGjy+M35gB4tosMhuQplrL3p7h/ZZFpZH663Id6BKM3teL4pbhN4 KNf3hlhstCsn/XsGJRq1XXUV34NmOTWYgn/GKD0zL3ygivika+d+i/ojVX34YE0yq3q7 oqz8QYUO7f0hjuJXsFvHt8QBz/sToIJAGh1filX9+H/NW+0hq0cppssotIHMtHFvo4Np BYxqXhxx8WM3xG6BSFhONnOZnkP947d3t5VUTjfT9t3Gelk/8JGxEqNfpRdxQcYhsW/l DQ1g== 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=pm4buBS4qJN6Q1E4e28WuspeqHQ+lHRth0G3klYbkDo=; b=PrHjiEdJ5ydlEFaJVcJHaMxfoz7nThi0z9J8bS4eKPH27kMkyg9oDP1S4t8NxVzEHI g9tvl32AMcGlBMg+cwL4PlolC3cpQ2IFeco3eHAku2yXBVfM7ZANY42aaN7C8VNxaNSM U5/O+N5BobJGiCb1SebJ5SAyAXlQaQipE8HarKLu4w4zNrI6WEyplCoz8vMMFSzwAK+Z 5tt1FwNdj6OYL1EymMA43xJVbdlgZPJfmAR7eROvKtTI8gPctcpXvUqMCidPplN5J5B3 vmTgDijKUDR8R/TutByTterKnIWjmQ5OiDf5eGMexBnCa30/6KSsZMXo6Wnt6coJF4CY kuLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=LUG7XqQZ; 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 f4si356202pgc.267.2018.03.26.22.32.23; Mon, 26 Mar 2018 22:32:23 -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=LUG7XqQZ; 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 S1752218AbeC0FcT (ORCPT + 28 others); Tue, 27 Mar 2018 01:32:19 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:45156 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752171AbeC0FcQ (ORCPT ); Tue, 27 Mar 2018 01:32:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM5011947; Tue, 27 Mar 2018 14:30:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM5011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128603; bh=pm4buBS4qJN6Q1E4e28WuspeqHQ+lHRth0G3klYbkDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LUG7XqQZtMn3EMl4N5G/9qGgxrKl3uWoD9aMdf4RastLWvh/DLrZL5Q7N6gzQJIQB Ifb+zK1WNWDJfH0sFLmuqZn69RSUquq3pht98eipM06YySznpAlhAkO6+AChv67kiy blOcFlbSD/UW3yz2377lLE5piiH+u7n8u90i5yUDqEpmWtEJ2AVlg3VkK4c9YWsOS5 gVFnK537AkiEfK4+q3AQpw/PRfaXO2nMG9dgg/99R/0D3DDzvmnDOr1E7QlwGErk8e 2+/6Gc2EvGYiy9UhYmLdifEULiztHP5ZIP+jufBBiEOXknBUC4gBxVieF9EbBJkrQw l8AsjiybW4qdw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH v2 20/21] gcc-plugins: enable GCC_PLUGINS for COMPILE_TEST Date: Tue, 27 Mar 2018 14:29:34 +0900 Message-Id: <1522128575-5326-21-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-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 plugin availability is checked in Kconfig, so all{yes,mod}config will not be bothered. Remove 'depends on !COMPILE_TEST'. Signed-off-by: Masahiro Yamada --- Changes in v2: - Remove more 'depends on' arch/Kconfig | 4 ---- 1 file changed, 4 deletions(-) -- 2.7.4 diff --git a/arch/Kconfig b/arch/Kconfig index 88cc925..b07094c 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -414,7 +414,6 @@ menuconfig GCC_PLUGINS bool "GCC plugins" depends on HAVE_GCC_PLUGINS depends on $(success $srctree/scripts/gcc-plugin.sh $HOSTCXX $CC) - 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. @@ -424,7 +423,6 @@ 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 help The complexity M of a function's control flow graph is defined as: M = E - N + 2P @@ -487,7 +485,6 @@ 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 help This option will cause a warning to be printed each time the structleak plugin finds a variable it thinks needs to be @@ -527,7 +524,6 @@ config GCC_PLUGIN_RANDSTRUCT config GCC_PLUGIN_RANDSTRUCT_PERFORMANCE bool "Use cacheline-aware structure randomization" depends on GCC_PLUGIN_RANDSTRUCT - depends on !COMPILE_TEST help If you say Y here, the RANDSTRUCT randomization will make a best effort at restricting randomization to cacheline-sized From patchwork Tue Mar 27 05:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132444 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4654208ljb; Mon, 26 Mar 2018 22:33:19 -0700 (PDT) X-Google-Smtp-Source: AG47ELthQ+n8vJAGcN0FUJ5tFHK9pV0aUI9PonKc5rv55osSlS2/Q8cHpN5G1YEE/Uzrp1Vsz1YX X-Received: by 10.101.96.134 with SMTP id t6mr19740595pgu.58.1522128798957; Mon, 26 Mar 2018 22:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522128798; cv=none; d=google.com; s=arc-20160816; b=QnsGdmd5qga1iHeQRCQEZ4akMNTnObXtUjvzqu4VnuNaoAs6rFOzo3ClxCn3H9GIsl tALDm+SC/6u813VEq1Ak+gspN4nDVlcaAbxpETXLXlfAPM8rcmZPwcrzUcOawBJPo7k/ /HQWDANvTpMbzzuq8qAtYRri+j/ANzZfHx1vBB/Gn9iS9AKqxWEOIFXwZyX/COJew8Ai d2Uayld4isWhn79/FbGxlCk21pLbdwlFiD+OTqJ/tdKVcHHWZogvLcPU5yfokZPkwAls m/fmQLg4tP1AGEKsnW6r5FTZgnwIMq3aS9L87zYije6eKOv3UbTck+quVQaG0lFyWl4Y 2oDw== 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=E9yvcp/H6UoCgWpztkUxVXZwnZ0sa369vAzIJ0+As4M=; b=oaXkOWebIUzmektkeAwftXsuBow4eRzFBgFkHOeNvfhJYQ3r6u8qsjCP//QgGsF25Y DUa/8I7W8QxZsIFN/CNTRmawoX8LTHmCKanoo3vL89iLn1nWtSm87s3QwnRklkIbugtC ZN5dJkIamH56R1cuVogXi46bAB1e3csqBnPkC02caAsf78PPuBYJXBQUVifNZ+da8In5 v6r9OD3EEc6a3W+x8+EqQEFiyBAnKPwhwQM9bLX/SAbEmstzhIu1xIQDF2snR+/qH2IK cSkZgQlWiwCqFiCE6RlNsXEqJSLPFwhQRr/gCbUPseYrltyoIanCrdcPNzYtCgkclAfN oBJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Vn1WgzyT; 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-v6si499695plo.141.2018.03.26.22.33.18; Mon, 26 Mar 2018 22:33: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=Vn1WgzyT; 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 S1752480AbeC0FdO (ORCPT + 28 others); Tue, 27 Mar 2018 01:33:14 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:46446 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751028AbeC0Fc7 (ORCPT ); Tue, 27 Mar 2018 01:32:59 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2R5TaM6011947; Tue, 27 Mar 2018 14:30:03 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2R5TaM6011947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1522128604; bh=E9yvcp/H6UoCgWpztkUxVXZwnZ0sa369vAzIJ0+As4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vn1WgzyTjxXPpOwghdT7/BlpWKj7ox/6/eP63Wm9Nh8teYwgIv/7zIFk4XbIuFBu+ PZFjNL/TXCleGQ5/QSxtZhsn2bZMbmzRnCKLk/uwyCD2/hWUl8DoyTFoaUg/z0LhDX /3nYmVJ0M7saRdmXN8QgztPStOBa06mpqaOJpOzKD2QiN0v6A9WDu9QHty5kNCdl/c fmagMOOG1pOQ6swpFh4DRUHNhsuRFwBEvovXqZC8Ipj72TLiZAvunpQR1DCVhQT1qJ ZLMeiAtoThv20DGtp3HzdfsCKB8RziJHHchsgabuC79BdYbzU99NVHPkXNvQwiRKyc oCZ9ZkbgUhDpQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Linus Torvalds , Arnd Bergmann , Ulf Magnusson , Kees Cook , Thomas Gleixner , Greg Kroah-Hartman , Randy Dunlap , "Luis R . Rodriguez" , Nicolas Pitre , Masahiro Yamada , Will Deacon , Catalin Marinas , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 21/21] arm64: move GCC version check for ARCH_SUPPORTS_INT128 to Kconfig Date: Tue, 27 Mar 2018 14:29:35 +0900 Message-Id: <1522128575-5326-22-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> References: <1522128575-5326-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This becomes much neater in Kconfig. Signed-off-by: Masahiro Yamada --- Changes in v2: - Newly added arch/arm64/Kconfig | 1 + arch/arm64/Makefile | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) -- 2.7.4 Acked-by: Will Deacon Reviewed-by: Kees Cook diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 7381eeb..0c97f40 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -43,6 +43,7 @@ config ARM64 select ARCH_USE_QUEUED_RWLOCKS select ARCH_SUPPORTS_MEMORY_FAILURE select ARCH_SUPPORTS_ATOMIC_RMW + select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_COMPAT_IPC_PARSE_VERSION select ARCH_WANT_FRAME_POINTERS diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index b481b4a..7318165 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -57,8 +57,6 @@ KBUILD_AFLAGS += $(lseinstr) $(brokengasinst) KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) -KBUILD_CFLAGS += $(call cc-ifversion, -ge, 0500, -DCONFIG_ARCH_SUPPORTS_INT128) - ifeq ($(CONFIG_CPU_BIG_ENDIAN), y) KBUILD_CPPFLAGS += -mbig-endian CHECKFLAGS += -D__AARCH64EB__