From patchwork Thu Feb 8 16:19:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127681 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1642524ljc; Thu, 8 Feb 2018 08:23:21 -0800 (PST) X-Google-Smtp-Source: AH8x227FFr3it3fso/Z2tR8M6tXt0N5cDJ3LoL6rJBGHoKdCBSIsw6X456cK8ImMjomCNPWnqSLQ X-Received: by 10.98.238.2 with SMTP id e2mr1239438pfi.206.1518107001138; Thu, 08 Feb 2018 08:23:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518107001; cv=none; d=google.com; s=arc-20160816; b=LsUsykcmpAMHFVjxt7zR7x4JwL/euO5E29U0kUMM0OdyWepJFHeBGIkQBIcIDsIBJG qx9CxN3ZYa5kgZhHs/FJ3QrZaLWBs4nGYU/AO4cfN9TDvZEFyGZRCS2X3R0anMWg1bK5 a87mF2jvkANvP76GgMLOZVJA23mZWb2Sv5h/+DEipDPwVv0DErhtKkXRl7vBE/CpnBGS VLM5/EkpujdqOzh9XVUHCBfDfGe99TLrzCKPBLtNwQY8MLAI65S3pghrt8tAP1lTvBl9 6gBSVgYTXQwbLyA+T+4IXcfDaBgGZNVRaM+rd+ZpEuO1kAKmevsmlkPWGov4l9zUuimL qssQ== 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=x/5Ua+VC1TCWa9+yLVks6vJN+TVTMSbOGSmxjHICH54=; b=hhrKNiOV3Tn4MWGEbRBzOi+J633JAUOdRD0TkeCdcRG3gXWMRYPSKw1vgCkdJ3dkjU Yf0idqAQ6eUcYhv9XIeScYjSAG9R6OX1R/ES3+39wQfuUchGHFfowTKgV27T1zQOYlwQ funlFnet6Fn2mI2Rh42DAkAF8Kj9aDLzvZmj0SCigirAMWN73i4w5Vb7A4aeAfCY0MAI 1pOQQtM6cZC7yzulUZy2YhXe2o9x41pI3Ih7wrlEhsvJdmU52O7Yr9+QyZkxKBMy9qWu QNcrjSeMiIenoe5f01Wc9dwxVbdEulooDwfaz5yOF65kAhnq3eR80nruBf3qLdnUOHZY y1rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=e0Tx9GeH; 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 v12si149542pgq.50.2018.02.08.08.23.20; Thu, 08 Feb 2018 08:23:21 -0800 (PST) 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=e0Tx9GeH; 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 S1752674AbeBHQXS (ORCPT + 13 others); Thu, 8 Feb 2018 11:23:18 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19348 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752228AbeBHQVg (ORCPT ); Thu, 8 Feb 2018 11:21:36 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1D021191; Fri, 9 Feb 2018 01:19:26 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1D021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106767; bh=x/5Ua+VC1TCWa9+yLVks6vJN+TVTMSbOGSmxjHICH54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0Tx9GeHdMjK8AXtilHX2j8Ae6W/W3TFY8gl6A9RtDhx3zMxGBcocdBI/nWtqiTSn 5Oq6A6Qu9OMLWhCDXjmLoka7YRf76KPNCZ3SMjK/OXVJfag6I65V5fpMYfMwzjvL2Z yRXgxYZzyvjLfqWfXOTqAo1gabKARpL3lsZSAKQXskEKKZVYrVARqpfBoAvv1q7sLv segn+el98l1UoYnFG6DXA+7FoIs542awBM0wSJ2Z04B/9xIFhegmO3koEbgFptNE0M eZFMaZipxAVOnVykNgD9bF+HlIFsRz0NAwLQsYqdoGxMJ1uMhYG5J5gmvdH0n/NBHw RPP8ip75Kkx6Q== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/7] kbuild: remove kbuild cache Date: Fri, 9 Feb 2018 01:19:06 +0900 Message-Id: <1518106752-29228-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-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 With compiler flag tests moved to the configuration phase, the result of $(call cc-option,...) will be cached in the .config file. Remove kbuild cache to make it easier to move on. Revert the following commits: Commit 9a234a2e384349 ("kbuild: create directory for make cache only when necessary") Commit e17c400ae194945ee ("kbuild: shrink .cache.mk when it exceeds 1000 lines") Commit 4e56207130eda9 ("kbuild: Cache a few more calls to the compiler") Commit 3298b690b21cdb ("kbuild: Add a cache for generated variables") Signed-off-by: Masahiro Yamada --- Makefile | 5 +-- scripts/Kbuild.include | 101 +++++++------------------------------------------ 2 files changed, 16 insertions(+), 90 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index d192dd8..2ee49c9 100644 --- a/Makefile +++ b/Makefile @@ -655,7 +655,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 @@ -1602,7 +1602,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 065324a..9776946 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,23 +159,23 @@ 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-option = $(call try-run,\ $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -x c /dev/null -c -o "$$TMPO"; \ $(LD) $(LDFLAGS) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) # ar-option # Usage: KBUILD_ARFLAGS := $(call ar-option,D) # Important: no spaces around options -ar-option = $(call try-run-cached, $(AR) rc$(1) "$$TMP",$(1),$(2)) +ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) # ld-version # Note this is mainly for HJ Lu's 3 number binutil versions -ld-version = $(call shell-cached,$(LD) --version | $(srctree)/scripts/ld-version.sh) +ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) # ld-ifversion # Usage: $(call ld-ifversion, -ge, 22252, y) From patchwork Thu Feb 8 16:19:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127680 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1642008ljc; Thu, 8 Feb 2018 08:22:46 -0800 (PST) X-Google-Smtp-Source: AH8x2270hdJvBXvS3n7Azm/uM0udCiEW6f5PYGMTSo0Wk3ES8aHnIfu9e/g7nBeIRVFfVNcxdqN/ X-Received: by 10.101.80.6 with SMTP id f6mr936678pgo.272.1518106966406; Thu, 08 Feb 2018 08:22:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518106966; cv=none; d=google.com; s=arc-20160816; b=T/pqkwn2k8Hw0nSD8FiZ2W9EcqJJV+w1abSKPgxzPEk6DtbBzTbqItPig0T8NQ468n XchyZLN3PuvpCeZIYO9YS1cEk0O+5wlOOZWDzuR0m5KOiy3WFRqqQ7fBA3GdhcJyhIwE d4v7Z15IAHBBIsHcu1c+Idmhkf75uWUQTLc1FJnM7nvPxACjARdxcNPhIJ6YGqbn9+mJ VsZhXIwFu5Tt/DPzFoMbAn/ZJqGbZfA+Bww9voGU4nzuQn8hA2MuY0gHK7BygdqZIEJP Cig/Li70cn5Sw1vyfdDWxIR0VYXCLEX8EBfy6cpKuTYRGlKEGU9ihpYAuoinYNY1IhSZ hbgQ== 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=u39XhiSy2FIvQt8O3MtdRJJg6CV6UlnbVTrzkUrASnw=; b=eEHUSOjUxJTPUWr46fK8GK0w/iyTTtKwCZ0kSsTUOVlYJSDqCCU7GEwqvLgKxgKP65 +4KpJUy95115Y7Am4qMI35fxZSjDtNwSwkq14aRuk2wywYAQTu+P3srm9SzgCJoDCimB VHwFL/9avpSPWKlMgqviAzPcJ7TOA1bDDVQilZ5Erm5YNDFyUk2qwlOOaVpk7AgbF61t QYyIzQlXHDFNI7c7VzrkKi3ftRvHekePxyFm+dLlaSj0PSXk3pncBv/cmG8ci2sC0Zpq zFeLjB0vtbvZeXDJYJZJuBxfIdrWyjNmMB5hl+pBwq8sbMkBI/iPkIWLyU9ZRBSzH4yB 5duA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=rDT1CHPk; 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 a33-v6si164696pld.666.2018.02.08.08.22.46; Thu, 08 Feb 2018 08:22:46 -0800 (PST) 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=rDT1CHPk; 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 S1752587AbeBHQW2 (ORCPT + 13 others); Thu, 8 Feb 2018 11:22:28 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19359 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752255AbeBHQVh (ORCPT ); Thu, 8 Feb 2018 11:21:37 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1E021191; Fri, 9 Feb 2018 01:19:27 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1E021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106768; bh=u39XhiSy2FIvQt8O3MtdRJJg6CV6UlnbVTrzkUrASnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rDT1CHPksHL97rtD3gKbYcuLdO0xFE51CFZkSF2zrJ3u8gUKNh1kO7mtL1W9aSOKP e4EBO+askpCIA49RRdH6tVX63xqLcv9UzQFInRcNwmUdORkvFABdndJlSqc36xwp3d 1qRimeaOIg/uFyr94IKsr3T1ta0OPJlfTIsICmuFlbuJb0kkvUFP9V3gS5PhQMysuc PPnlXhIuNYH/IZukiNYwMAp3RNWfgWF9thWkaJmH9Ny3mYEyjSI3A9UQXm356gH0mt fQoSagiR6HaEQbgL6STywwipu30/vLnxBIW+3LWuPg+3YEee7hudLWO4k0WGesE+a4 0DEjUHSknAggw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/7] kconfig: add xrealloc() helper Date: Fri, 9 Feb 2018 01:19:07 +0900 Message-Id: <1518106752-29228-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-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 We have xmalloc(), xcalloc() already. Add xrealloc() as well to save tedious error handling. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 2 +- scripts/kconfig/lkc.h | 1 + scripts/kconfig/nconf.gui.c | 2 +- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/util.c | 11 ++++++++++- scripts/kconfig/zconf.l | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f792739..5c12dc9 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -201,7 +201,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n) if (new_size > *n) { new_size += LINE_GROWTH - 1; new_size *= 2; - nline = realloc(*lineptr, new_size); + nline = xrealloc(*lineptr, new_size); if (!nline) return -1; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 16cb62b..4e23feb 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -114,6 +114,7 @@ struct file *file_lookup(const char *name); int file_write_dep(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); +void *xrealloc(void *p, size_t size); struct gstr { size_t len; diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c index a64b1c3..93e3d0c 100644 --- a/scripts/kconfig/nconf.gui.c +++ b/scripts/kconfig/nconf.gui.c @@ -374,7 +374,7 @@ int dialog_inputbox(WINDOW *main_window, if (strlen(init)+1 > *result_len) { *result_len = strlen(init)+1; - *resultp = result = realloc(result, *result_len); + *resultp = result = xrealloc(result, *result_len); } /* find the widest line of msg: */ diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index c9123ed..bc3ec6a 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -938,7 +938,7 @@ const char *sym_expand_string_value(const char *in) newlen = strlen(res) + strlen(symval) + strlen(src) + 1; if (newlen > reslen) { reslen = newlen; - res = realloc(res, reslen); + res = xrealloc(res, reslen); } strcat(res, symval); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 0e76042..01ead28 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s) if (s) { l = strlen(gs->s) + strlen(s) + 1; if (l > gs->len) { - gs->s = realloc(gs->s, l); + gs->s = xrealloc(gs->s, l); gs->len = l; } strcat(gs->s, s); @@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size) fprintf(stderr, "Out of memory.\n"); exit(1); } + +void *xrealloc(void *p, size_t size) +{ + p = realloc(p, size); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 07e074d..0bc43db 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -52,7 +52,7 @@ static void append_string(const char *str, int size) if (new_size > text_asize) { new_size += START_STRSIZE - 1; new_size &= -START_STRSIZE; - text = realloc(text, new_size); + text = xrealloc(text, new_size); text_asize = new_size; } memcpy(text + text_size, str, size); From patchwork Thu Feb 8 16:19:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127676 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1641168ljc; Thu, 8 Feb 2018 08:21:46 -0800 (PST) X-Google-Smtp-Source: AH8x2257PgoMF5kzjXKS7QxKykPBfRAjgyHtWcCF21JTmPhM2Zee1VdhH07okDOIzWyHkjB+fPVX X-Received: by 2002:a17:902:70cc:: with SMTP id l12-v6mr1120434plt.67.1518106906060; Thu, 08 Feb 2018 08:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518106906; cv=none; d=google.com; s=arc-20160816; b=xuT9tX42JyHaXuxjebU0VP9C7xEk4Utg2gMTtqQM+sVQ0mdHNTi55O/NPJzprQ5lsq qdL9VXRETdNZdJDlmRxv5N5J1UAuyjdAUTkcKnIyTUgQzyNoWD1aF6050fZlQ8EOUJpd xh621PxuVKz9eU5JODSwWaJ8vvDVl2JOZZ42HbD+FWaXB5KAbjpTRFVED2ijJQ2nCxXZ SRs76lLj+fWot5/8JoFpT1lZQZsgP1Y8N35phTinnRO7qux6ofE922uz5wpww0K7TANJ qNOdy7+3r08cAZOpxbU2pgDebEFd5Kua+gL3W5ghDwPEV9kzEccJeFSfrSKDB4Omd8zN vM5g== 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=I9Hg17wLX5kmhRTYQxGVGOrJ6uikTpQIK1iRwVy31w4=; b=ymB3Y3GJPykwm4skGEJz3BwEozbWMSejTtfG08iyHg0pn7UaEx5QVMGoLwoXvgoGhX IrVdGLGfyBCNEuGwuYKqJyS2+4W9vaPjr5TuYqlrkXMj0+bBARl+AMqo9+1t6VkfisTU T9S9/8a+Gi68Zp+KWubTjMG6DArZ93aWWBDzTUSpVYIhHoncQ8d7l2W+0nYHzACXYCTl /LpXyPXPRW02sylSOMbPKVjLDW0yezNqGkeXcZ3SdRaWcNdLgtUH2CQZuPRpoSmijFDS 3vuaWc8ZTPwI36jZ/DChT9mmm3aOLG6N495vp7rv8g4BeQ0+9EIJpuSeowxQrBnjdjtc qYpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=uOpsnhMm; 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 q187si134694pga.547.2018.02.08.08.21.45; Thu, 08 Feb 2018 08:21:46 -0800 (PST) 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=uOpsnhMm; 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 S1752562AbeBHQVm (ORCPT + 13 others); Thu, 8 Feb 2018 11:21:42 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19339 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbeBHQVg (ORCPT ); Thu, 8 Feb 2018 11:21:36 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1F021191; Fri, 9 Feb 2018 01:19:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1F021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106769; bh=I9Hg17wLX5kmhRTYQxGVGOrJ6uikTpQIK1iRwVy31w4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOpsnhMmLvQJ1ufjabp45JUOqL2NTF/HxNNk5nPY4MUKoteKX55T4aeqZusT5JQVn kSQEkWS0TPW4Xxe7s2LFScBmBZdHXsZhQilA3mQre9Wu/AHn22GlkWholM90SRNuFM Qskq5Lu73w3t2QVDo6mNiKPygnxgTmdPLszuDBP9T6r48JIWqAN52DUzxdWKXc0C59 IvEnvv25mtxu0J2X4Q36WvH+WOOVwbiImk1amVsMPVXOuScp/SsZoi5b1FmVln7oQx 9jgXepmWfoYRpVsxStkMLdpn4RPOc+dOgWak8Sl1EbLaCs5COgH5OtXpD6HT1yKAFP P+XPo6YlsUCMw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/7] kconfig: remove const qualifier from sym_expand_string_value() Date: Fri, 9 Feb 2018 01:19:08 +0900 Message-Id: <1518106752-29228-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-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 function returns realloc'ed memory, so the returned pointer must be passed to free() when done. Change the return value type to save casting. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/symbol.c | 2 +- scripts/kconfig/util.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 5d86e2d..9dc8abf 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -31,7 +31,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); -const char * sym_expand_string_value(const char *in); +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 bc3ec6a..893eae6 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -901,7 +901,7 @@ struct symbol *sym_find(const char *name) * name to be expanded shall be prefixed by a '$'. Unknown symbol expands to * the empty string. */ -const char *sym_expand_string_value(const char *in) +char *sym_expand_string_value(const char *in) { const char *src; char *res; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 01ead28..befaec9 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -14,11 +14,11 @@ struct file *file_lookup(const char *name) { struct file *file; - const char *file_name = sym_expand_string_value(name); + char *file_name = sym_expand_string_value(name); for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { - free((void *)file_name); + free(file_name); return file; } } From patchwork Thu Feb 8 16:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127677 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1641319ljc; Thu, 8 Feb 2018 08:21:58 -0800 (PST) X-Google-Smtp-Source: AH8x225QDsJTqrHeZTtCgvrZu11XxbhVj4vZyDiu2w0O0VZEvwJvjqWgZ5dZUtXs/l5uYkpwOaaw X-Received: by 10.99.103.69 with SMTP id b66mr919655pgc.233.1518106917982; Thu, 08 Feb 2018 08:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518106917; cv=none; d=google.com; s=arc-20160816; b=LHkcAT3+8nCnd94XbNYIyhXYkueYxQLrwJqKh1siwqnuXCKafotz/teUGC8MewfgGF DAv9wbI3HtbrA1HaEusgKLQJo6vJ6rDNrYRfxFhSWHLIJM+wTTU0lSdTB5f5zxd9YuKO 26TKjblGFUfFU1gif/VXetPAhFj3BXAJ4GIrjpMB0y9nkCZIQR6RLg6GYl3iz6VpmC7j N7FwhcDe2BPXjuZ2ckQ0XAC46pQM6S+oPuDM2zXZFlpaMwK2rmWg2wWuXX5A9+jWoz05 UfVKR1pW8ZpX8Q8b+UBBXbeZmMdELaTbe0Z6tCNvaigWl8DyS1hLyiA7nTIHjIPBTpZ+ wWmQ== 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=SjFMsbSS827T9u8KgXcclZ/8GFOfEMUu9MVypLM9Z3w=; b=mTSS/+qoOFRHs6lgGd4NYGGMNAkGdrsqyhIMRKJ8dYA0FwBSeSq4o1bOrEUazkBOI2 pwnMqKmaqJZ9T2uFHjGWJYWnRoKREV8fEklGuoRrhJ3/b5/IrUGMOkWA4/ktZ6u7Ah2F j2U26hWIkltnqEtR9VGB5vFCBPHzdNgn/2CfSvoA1UiQlPofDtCcbQXrvI17E1OVTUVf jLxJ+kH94P/i2YGN4uTyYJiG/CsbV8Ck1gOa1RwiGYPEqKOuHp3SrHnJwlkKBloVxMvK 1p0Vilm0EfBF5Aj+ZR+4WE5hSY04yKWHsJISPHWnDzpuzyh4mrbW9zz+/uOqPHfu0Gu5 A/5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=n9mJvTC8; 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 q187si134694pga.547.2018.02.08.08.21.57; Thu, 08 Feb 2018 08:21:57 -0800 (PST) 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=n9mJvTC8; 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 S1752519AbeBHQVl (ORCPT + 13 others); Thu, 8 Feb 2018 11:21:41 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19347 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752196AbeBHQVg (ORCPT ); Thu, 8 Feb 2018 11:21:36 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1G021191; Fri, 9 Feb 2018 01:19:30 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1G021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106771; bh=SjFMsbSS827T9u8KgXcclZ/8GFOfEMUu9MVypLM9Z3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n9mJvTC8YlattLwD2kw2JQVUdj1+N8cCZmnSL1X+nIpDPJQb5JZ2Xv6BxsUihPT4w LUxstTgw9RC4kpwOUDra/kkMJsVhQlhFV2N4a8bWiKT17G1dqhK/kmUruQeixnOmhm MKOA6xapgBh/ialtxBbs2DiWc5J7LjNLXhROjM/62VCdGy/+pNBIRQKRyxMJKX4zL0 GC6d7p+6dmLGoyPo0S9qfA4xlRobwY1Aigd/nzCrsLmnBw98kdlRXiAROXEZPQcmg0 TqN+3+V/G4CNdLJnh/KomufWLVEQC2fnkl+DiNI9s/UV91ZZOtr0cKucWwfd+2XR9v Fcn4UaHAeZn6w== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/7] kconfig: support new special property shell= Date: Fri, 9 Feb 2018 01:19:09 +0900 Message-Id: <1518106752-29228-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-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 works with bool, int, hex, string types. For bool, the symbol is set to 'y' or 'n' depending on the exit value of the command. For int, hex, string, the symbol is set to the value to the stdout of the command. (only the first line of the stdout) The following shows how to write this and how it works. --------------------(example Kconfig)------------------ config srctree string option env="srctree" config CC string option env="CC" config CC_HAS_STACKPROTECTOR bool option shell="$CC -Werror -fstack-protector -c -x c /dev/null" config CC_HAS_STACKPROTECTOR_STRONG bool option shell="$CC -Werror -fstack-protector-strong -c -x c /dev/null" config CC_VERSION int option shell="$srctree/scripts/gcc-version.sh $CC | sed 's/^0*//'" help gcc-version.sh returns 4 digits number. Unfortunately, the preceding zero would cause 'number is invalid'. Cut it off. config CC_IS_CLANG bool option shell="$CC --version | grep -q clang" config CC_IS_GCC bool option shell="$CC --version | grep -q gcc" ----------------------------------------------------- $ make alldefconfig scripts/kconfig/conf --alldefconfig Kconfig # # configuration written to .config # $ cat .config # # Automatically generated file; DO NOT EDIT. # Linux Kernel Configuration # CONFIG_CC_HAS_STACKPROTECTOR=y CONFIG_CC_HAS_STACKPROTECTOR_STRONG=y CONFIG_CC_VERSION=504 # CONFIG_CC_IS_CLANG is not set CONFIG_CC_IS_GCC=y Suggested-by: Linus Torvalds Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 1 + scripts/kconfig/kconf_id.c | 1 + scripts/kconfig/lkc.h | 1 + scripts/kconfig/menu.c | 3 ++ scripts/kconfig/symbol.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index c16e82e..83029f92 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -183,6 +183,7 @@ enum prop_type { P_IMPLY, /* imply BAR */ P_RANGE, /* range 7..100 (for a symbol) */ P_ENV, /* value from environment variable */ + P_SHELL, /* shell command */ P_SYMBOL, /* where a symbol is defined */ }; diff --git a/scripts/kconfig/kconf_id.c b/scripts/kconfig/kconf_id.c index 3ea9c5f..0db9d1c 100644 --- a/scripts/kconfig/kconf_id.c +++ b/scripts/kconfig/kconf_id.c @@ -34,6 +34,7 @@ static struct kconf_id kconf_id_array[] = { { "defconfig_list", T_OPT_DEFCONFIG_LIST, TF_OPTION }, { "env", T_OPT_ENV, TF_OPTION }, { "allnoconfig_y", T_OPT_ALLNOCONFIG_Y, TF_OPTION }, + { "shell", T_OPT_SHELL, TF_OPTION }, }; #define KCONF_ID_ARRAY_SIZE (sizeof(kconf_id_array)/sizeof(struct kconf_id)) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 4e23feb..8d05042 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -60,6 +60,7 @@ enum conf_def_mode { #define T_OPT_DEFCONFIG_LIST 2 #define T_OPT_ENV 3 #define T_OPT_ALLNOCONFIG_Y 4 +#define T_OPT_SHELL 5 struct kconf_id { const char *name; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 9922285..6254dfb 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -216,6 +216,9 @@ void menu_add_option(int token, char *arg) case T_OPT_ENV: prop_add_env(arg); break; + case T_OPT_SHELL: + prop_add_shell(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 893eae6..02ac4f4 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -1370,6 +1371,8 @@ const char *prop_get_type_name(enum prop_type type) return "prompt"; case P_ENV: return "env"; + case P_SHELL: + return "shell"; case P_COMMENT: return "comment"; case P_MENU: @@ -1420,3 +1423,74 @@ static void prop_add_env(const char *env) else menu_warn(current_entry, "environment variable %s undefined", env); } + +static void prop_add_shell(const char *cmd) +{ + struct symbol *sym, *sym2; + struct property *prop; + char *expanded_cmd; + FILE *p; + char stdout[256]; + int ret, len; + + sym = current_entry->sym; + for_all_properties(sym, prop, P_SHELL) { + sym2 = prop_get_symbol(prop); + if (strcmp(sym2->name, cmd)) + menu_warn(current_entry, "redefining shell command symbol from %s", + sym2->name); + return; + } + + prop = prop_alloc(P_SHELL, sym); + prop->expr = expr_alloc_symbol(sym_lookup(cmd, SYMBOL_CONST)); + + expanded_cmd = sym_expand_string_value(cmd); + + /* surround the command with ( ) in case it is piped commands */ + len = strlen(expanded_cmd); + expanded_cmd = xrealloc(expanded_cmd, len + 3); + memmove(expanded_cmd + 1, expanded_cmd, len); + expanded_cmd[0] = '('; + expanded_cmd[len + 1] = ')'; + expanded_cmd[len + 2] = 0; + + switch (sym->type) { + case S_BOOLEAN: + /* suppress both stdout and stderr. */ + len = strlen(expanded_cmd) + strlen(" >/dev/null 2>&1") + 1; + expanded_cmd = realloc(expanded_cmd, len); + strcat(expanded_cmd, " >/dev/null 2>&1"); + + ret = system(expanded_cmd); + sym_add_default(sym, ret == 0 ? "y" : "n"); + break; + case S_INT: + case S_HEX: + case S_STRING: + /* suppress only stderr. we want to get stdout. */ + len = strlen(expanded_cmd) + strlen(" 2>/dev/null") + 1; + expanded_cmd = realloc(expanded_cmd, len); + strcat(expanded_cmd, " 2>/dev/null"); + + p = popen(expanded_cmd, "r"); + if (!p) + goto free; + if (fgets(stdout, sizeof(stdout), p)) { + stdout[sizeof(stdout) - 1] = 0; + len = strlen(stdout); + if (stdout[len - 1] == '\n') + stdout[len - 1] = 0; + } else { + stdout[0] = 0; + } + sym_add_default(sym, stdout); + break; + default: + menu_warn(current_entry, "unsupported type for shell command\n"); + break; + } + +free: + free(expanded_cmd); +} From patchwork Thu Feb 8 16:19:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127679 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1641786ljc; Thu, 8 Feb 2018 08:22:32 -0800 (PST) X-Google-Smtp-Source: AH8x227g6t15ZxZOwKVvqVKp8FzRpZC11psS3QKDpTvOcz62ZqYkHdRHmv1QkxSbr9ryyVJEv3jI X-Received: by 10.98.135.204 with SMTP id i195mr1223609pfe.41.1518106952726; Thu, 08 Feb 2018 08:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518106952; cv=none; d=google.com; s=arc-20160816; b=E6SE6v5ofwvRHblD7LImoVT87Pcj3f+oW69LsC63Csw3NGI8FbwAuy7yXyI9Vtm2qN 2/jW1yaKQK2KCW51xO03VVTwvvco/bjYmTN+bSJVmk+hxmIs4SOlhe7BhPsLekYCs5xH DyKv4mlMTYDZBK8Ud33Quv03lA0BMB0clKnYvXvowESe/XEYxXdk2IOV5KEZk/sDKslk nG5zg/dCeN6C+4UyAA/T9gEeRSbdwsYRavLzFHhylp2aTEwuC6M9G38acIb+VCplzgO/ d1yHrnq3++rc5wTtZ1Aosvl86wXeBL4RVOx0qVeqynVTbZKk4t0Hnr+IKOFnpdigyu1m gUbA== 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=/g1y1Iw1M86dfdHAksqnjpCIIERRxDGzTanKycUqsIw=; b=w5YQRvsz7fFyftpqbFsq4DXuO9HjKsV4t7YidWctrjCoU36vQVvJ7//pmV/+HW2tpH m36K9TbS7hn3yPBKHFYffIGBuliXz/5oOM3vrIUUVDubEuMqcT+56EAvmi5i2VqUb8dh MqRtYiUusuucpypGVm9QH3IhBxkTPXtZJDJpxGHAwvr2Df6/3FF7rj8LiH0i/Khv5tSo iqwSAIUvIfe1OmeZ/LnKJP1Gn+mYpYeBj6O5M3ir8ZJIcRIcC+4B5pLtFSHo6nqEKwzi DEr9nwBzIcCo9eLyeF2n1cLma5QRZzMNd1cd+cBZsItHFR5XE+lff6kClC+9pROc9qpu y72Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=zcIAyvom; 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 u8si133503pgr.631.2018.02.08.08.22.32; Thu, 08 Feb 2018 08:22:32 -0800 (PST) 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=zcIAyvom; 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 S1752617AbeBHQWa (ORCPT + 13 others); Thu, 8 Feb 2018 11:22:30 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19360 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752275AbeBHQVh (ORCPT ); Thu, 8 Feb 2018 11:21:37 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1H021191; Fri, 9 Feb 2018 01:19:31 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1H021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106772; bh=/g1y1Iw1M86dfdHAksqnjpCIIERRxDGzTanKycUqsIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zcIAyvompiaZrVI+RLGR8xnP0qT0sVA7c45lqr9Ibmu/tkVnbTKI7KKbDA0ui6dPN kbgVaswX4DIBXO92awYknr1hpyhsE2vUPTHtErygXdVGBmdR+WtNKI2lTANcNPDaR8 eh3CfcJ6GnwLRXTHKytO11YWZcF4DniLehLX1d3etSrcqhfaAo8vkZCl/22TfFkEDE pBH8K+vhOtNnxuISENoGaXLhJFpK1ukaNB0/N/XtWMU+EFwYhA0CflKehi8HaRwMbP 0+4UA8gXD9rP0mPArGtjF6JnfWWmHhtZ1XwV6R0PYeFXt1o9iI7guudKAb3sz66F1q A+3J9LbtEV6JA== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/7] kconfig: invoke silentoldconfig when compiler is updated Date: Fri, 9 Feb 2018 01:19:10 +0900 Message-Id: <1518106752-29228-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-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 Moving compiler option tests to Kconfig means you need to re-run Kconfig when you update your compiler. All CC_HAS_... symbols and other symbols that depend on them must be re-calculated. It will be nice to detect the compiler update and automatically invoke silentoldconfig. This can be done by adding one environment. With this, silentoldconfig will add something like follows into include/config/auto.conf.cmd: ifneq "$(CC_VERSION_TEXT)" "gcc (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609" include/config/auto.conf: FORCE endif CC_VERSION_TEXT contains the first line of "$(CC) --version". If this text is changed, silentoldconfig will be invoked. Signed-off-by: Masahiro Yamada --- Makefile | 2 ++ init/Kconfig | 9 +++++++++ 2 files changed, 11 insertions(+) -- 2.7.4 diff --git a/Makefile b/Makefile index 2ee49c9..9afd617 100644 --- a/Makefile +++ b/Makefile @@ -441,6 +441,8 @@ export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL export KBUILD_ARFLAGS +export CC_VERSION_TEXT := $(shell $(CC) --version | head -n 1) + # When compiling out-of-tree modules, put MODVERDIR in the module # tree rather than in the kernel tree. The kernel tree might # even be read-only. diff --git a/init/Kconfig b/init/Kconfig index e37f4b2..64f9dd2 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -16,6 +16,15 @@ config DEFCONFIG_LIST default "$ARCH_DEFCONFIG" default "arch/$ARCH/defconfig" +# CC_VERSION_TEXT is needed here to invoke Kconfig when compiler is updated +config CC_VERSION_TEXT + string + option env="CC_VERSION_TEXT" + help + This is used to detect if the compiler is changed. If the version + text does not match, silentoldconfig will be invoked because we need + to re-compute compiler capabilities and symbols that depends on them. + config CONSTRUCTORS bool depends on !UML From patchwork Thu Feb 8 16:19:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127682 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1642950ljc; Thu, 8 Feb 2018 08:23:52 -0800 (PST) X-Google-Smtp-Source: AH8x2270s8bg652w53IDBDkaNw6Ni+kdsetOYl0AZRe0X89Y2oI1Jb1WmeaQc3OQfSNMVAYgmFPz X-Received: by 10.99.182.12 with SMTP id j12mr967974pgf.113.1518107032071; Thu, 08 Feb 2018 08:23:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518107032; cv=none; d=google.com; s=arc-20160816; b=RExKFDvgpJZB7L9ehPLnH4zyQLat48Qwtz9Ht4AqWsPjvL3UrY8hZZT2Yt46jdAsuA rKaOEk3OgEYyBMFQftalrllxcFV2SuJtdtxsqARqJcVVC1leL9b/3A7W+LxUs1cuhO/D qnX3OkEZqKsZQr4X7xjt+HDb2FEDr61XXVxuohKIbSVdj+iJIbjzDg20yEAKFK1kpvTf J3ITjs4y7bbyxwRumUDHyOuS4DlfiWQVeG4hAI7/R2sU237G77hk9rpUpRvpOTQR71qI V4dbzA9o4lwIfbsBrvyCzUNEiDaJC7ql5uqgI9JKf1NnHqBefFzdNMSd3XqawBIfWnAx Eqfg== 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=vjBn6qmZtO3pYXfyXNULY3CphaqOCdqNsvaqSKBMzkE=; b=DRvTHWXqR2Mf0eTqW/5hTJ/WDkjUix0WCp/gA1WsrMIHPmV7uBBbMhrvuunkXxLI9s YkI3sXWnTqjt7TEorqzPG8yZqPompzfYrchg2EqTj/8m2bkERJhMmzq3s3i1cu5PaczK RhZ/8AoVMs4ACsHFkXHhbEwcSKz2bRdb8h0T+IqNMGIfKYKz2bAzgwCuwnIZuZvEc+L4 ij3wciVQTqxV71+OgECyg4reUC9OExN7knSyrUsyycp3LpBOadlOjgmSFcBp8cobzwOC pNOIwiiYvSBB64okgVt3YXm8EhklNjM6aHIW5QHXbyCFKXV6UutmfPYZ0fIOQcewF8iL Howg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=M6acOxXq; 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 10si186255pfu.318.2018.02.08.08.23.51; Thu, 08 Feb 2018 08:23:52 -0800 (PST) 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=M6acOxXq; 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 S1752649AbeBHQXQ (ORCPT + 13 others); Thu, 8 Feb 2018 11:23:16 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19352 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752249AbeBHQVh (ORCPT ); Thu, 8 Feb 2018 11:21:37 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1I021191; Fri, 9 Feb 2018 01:19:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1I021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106773; bh=vjBn6qmZtO3pYXfyXNULY3CphaqOCdqNsvaqSKBMzkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6acOxXqovrBfcSb9ZlgU+b3dNbqPz+OhxFw9M7w9l6T/loOzoqD3PCA8Z3qYrSx1 8shLBRSgGQblSRoXh46Ne9I2bfOuPoTSkeDsdmZXmc8rl1S+hOncvOAifjpnCFW2dT UY8/1MHnI+UjEI6gRACcm853Y8MPNTda+IBIMv+I1w91KKqBHyYd5PbySOzM0qsUEX LqE5p40KdnhKoNSjzZUrqLy4RiqKsLbiBHlOmE5Pidh32GkKYPmJCv6/UTTdZ4+AqL WCdW/0DmDCEu3G6BUSXStdKiTQTJXTx/xCuw77xDA+JhQGEyO1vlnlSm+org4+odfM JWIDonadq959A== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/7] kconfig: add basic environments to evaluate C flags in Kconfig Date: Fri, 9 Feb 2018 01:19:11 +0900 Message-Id: <1518106752-29228-7-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add minimum environments to start with. Signed-off-by: Masahiro Yamada --- init/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.7.4 diff --git a/init/Kconfig b/init/Kconfig index 64f9dd2..31fbc6e 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -25,6 +25,14 @@ config CC_VERSION_TEXT text does not match, silentoldconfig will be invoked because we need to re-compute compiler capabilities and symbols that depends on them. +config srctree + string + option env="srctree" + +config CC + string + option env="CC" + config CONSTRUCTORS bool depends on !UML From patchwork Thu Feb 8 16:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 127678 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1641567ljc; Thu, 8 Feb 2018 08:22:17 -0800 (PST) X-Google-Smtp-Source: AH8x225zW6dy/j9gvLSutVnCNcRqV5cCCdQc/dQpdelHd9ti5IO2sv814BaThHs3o25xsGsiNGZv X-Received: by 10.98.71.146 with SMTP id p18mr1220049pfi.3.1518106937536; Thu, 08 Feb 2018 08:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518106937; cv=none; d=google.com; s=arc-20160816; b=mAtsin2YEv3tUlh0xD+9+woXnlP1s3wFYLYLqotVzWdBRqKHjzuYvFYUrIQQikXUmn A+MuquCFYg+ov9nvAldIsBqcIvMulqMZVGCZwMkNv45i3k5PuwfOOFsRtAwqW6yL+DhW t/Lxdog3PUKKLINMmvIHMq5irWVasZ6uo/2yKCXAm4PvGVvaalBg8KeKfIBQ8kS5+0uv Af0gh4JoO9VJh46JOuUn8LDQhNZXZLOjA6v32/xZtL5G1UeL0nPA3xJnx96CCVTYY+We iZSJKv7Uh3i0eCX9IOFMD9ewHHxWz3TSG7tgOgvgj2h3cNqj43N0HenPE04JPiK+NOhz docA== 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=dIcQHxJOo1WEOZ1InbfU14tiSNMjCN+ELjZYvOPLjWU=; b=OTZVXVSzPuucKoSbudgAViKwNqAnESwcCtegVsrYD6hH8xPu863JxAukZCNCf+OWFE RdhZDPyMrnPkYhwdHWQcBZGGSCX7chv05H4PKjKonZeNuyhWrtftp5SsoOQ8UST0iucU 3dMmDVbJPMBUSVoWFzV8CwavxkmZtmrQWbZPfdXtXIfXsrGSJApylYzGguI1tjO5Wyni CykqujoTvM94rhzUbkW4xiEH8vhkJh1In41hx47TRnrTj5iVcvzAlv0ZS6nOEeIudlC9 8GNLU4/ILOFg7OoT3oB4nsApJC8QMOJ8CSNkYFbXbNGn50YtK/sper3NLepQq5jdXIkr cxjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=vku4TdNu; 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 u8si133503pgr.631.2018.02.08.08.22.17; Thu, 08 Feb 2018 08:22:17 -0800 (PST) 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=vku4TdNu; 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 S1752444AbeBHQVj (ORCPT + 13 others); Thu, 8 Feb 2018 11:21:39 -0500 Received: from conuserg-12.nifty.com ([210.131.2.79]:19340 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751706AbeBHQVg (ORCPT ); Thu, 8 Feb 2018 11:21:36 -0500 X-Greylist: delayed 59751 seconds by postgrey-1.27 at vger.kernel.org; Thu, 08 Feb 2018 11:21:36 EST Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-12.nifty.com with ESMTP id w18GJP1J021191; Fri, 9 Feb 2018 01:19:33 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w18GJP1J021191 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518106774; bh=dIcQHxJOo1WEOZ1InbfU14tiSNMjCN+ELjZYvOPLjWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vku4TdNuz4PfC9iSe3DGdfioMprQoYs9TloIDDGqFXnOn4Fjwn1u6k8Esv7j4V6Xm aMjQpAIoPGjjlz6K+SN/O9+uCxetZi004vmZ806oFeAIHACX6iB9QaZN72m4OLbWdz KpGwxv7nzphUsIiOFSAxriLH6TkhnTtBvTkhOepWlgiVsPuV0cCNcqiI98ElY4UdSD PUbxODx4H7U/Wsu2N5S3IbIi1yTB3mDrSve6k/mWt0rJCfsyC8I9ktmrSYYDwYfKZE LfWOep4TdztXrl+5HQMtlhSvwwIuF6G63kGDVp5V48s3zqz9dvqoqs8ge80dL9WE76 zaCWMMHe0ZNCw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Andrew Morton , Kees Cook , Nicolas Pitre , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Martin Schwidefsky , Pavel Machek , linux-s390@vger.kernel.org, Jiri Kosina , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/7] Test stackprotector options in Kconfig to kill CC_STACKPROTECTOR_AUTO Date: Fri, 9 Feb 2018 01:19:12 +0900 Message-Id: <1518106752-29228-8-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> References: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add CC_HAS_STACKPROTECTOR(_STRONG) and proper dependency. I re-arranged the choice values, _STRONG, _REGULAR, _NONE in this order because the default of choice is the first visible symbol. TODO: Broken stackprotector is not tested. scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh should be evaluated in Kconfig. Signed-off-by: Masahiro Yamada Test stackprotector options in Kconfig to kill CC_STACKPROTECTOR_AUTO Add CC_HAS_STACKPROTECTOR(_STRONG) and proper dependency. I re-arranged the choice values, _STRONG, _REGULAR, _NONE in this order because the default of choice is the first visible symbol. TODO: Broken stackprotector is not tested. scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh should be evaluated in Kconfig. --- Makefile | 58 +++++++++++----------------------------------------------- arch/Kconfig | 54 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 70 deletions(-) -- 2.7.4 diff --git a/Makefile b/Makefile index 9afd617..8123ccf 100644 --- a/Makefile +++ b/Makefile @@ -679,56 +679,20 @@ 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 +ifeq ($(CONFIG_CC_STACKPROTECTOR_STRONG),y) +KBUILD_CFLAGS += -fstack-protector-strong endif +ifeq ($(CONFIG_CC_STACKPROTECTOR_REGULAR),y) +KBUILD_CFLAGS += -fstack-protector endif +# is this necessary? +#ifeq ($(CONFIG_CC_STACKPROTECTOR_NONE),y) +#KBUILD_CFLAGS += -fno-stack-protector +#endif + +# TODO: run scripts/gcc-$(SRCARCH)_$(BITS)-has-stack-protector.sh from Kconfig + ifeq ($(cc-name),clang) KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) diff --git a/arch/Kconfig b/arch/Kconfig index 76c0b54..50723d8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -538,10 +538,20 @@ config HAVE_CC_STACKPROTECTOR - its compiler supports the -fstack-protector option - it has implemented a stack canary (e.g. __stack_chk_guard) +config CC_HAS_STACKPROTECTOR + bool + option shell="$CC -Werror -fstack-protector -c -x c /dev/null" + +config CC_HAS_STACKPROTECTOR_STRONG + bool + option shell="$CC -Werror -fstack-protector-strong -c -x c /dev/null" + +config CC_STACKPROTECTOR + bool + choice prompt "Stack Protector buffer overflow detection" depends on HAVE_CC_STACKPROTECTOR - default CC_STACKPROTECTOR_AUTO help This option turns on the "stack-protector" GCC feature. This feature puts, at the beginning of functions, a canary value on @@ -551,26 +561,10 @@ 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. - - This feature requires gcc version 4.2 or above, or a distribution - gcc with the feature backported ("-fstack-protector"). - - On an x86 "defconfig" build, this feature adds canary checks to - about 3% of all kernel functions, which increases kernel code size - by about 0.3%. - config CC_STACKPROTECTOR_STRONG bool "Strong" + depends on CC_HAS_STACKPROTECTOR_STRONG + select CC_STACKPROTECTOR help Functions will have the stack-protector canary logic added in any of the following conditions: @@ -588,11 +582,25 @@ 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" +config CC_STACKPROTECTOR_REGULAR + bool "Regular" + depends on CC_HAS_STACKPROTECTOR + select CC_STACKPROTECTOR + help + Functions will have the stack-protector canary logic added if they + have an 8-byte or larger character array on the stack. + + This feature requires gcc version 4.2 or above, or a distribution + gcc with the feature backported ("-fstack-protector"). + + On an x86 "defconfig" build, this feature adds canary checks to + about 3% of all kernel functions, which increases kernel code size + by about 0.3%. + +config CC_STACKPROTECTOR_NONE + bool "None" help - If the compiler supports it, the best available stack-protector - option will be chosen. + Disable "stack-protector" GCC feature. endchoice