From patchwork Sun Jun 14 14:43:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11603341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72F7892A for ; Sun, 14 Jun 2020 14:44:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59721206D7 for ; Sun, 14 Jun 2020 14:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592145871; bh=TgUCzye5s+XEY3cUuTnXm7QohfH0TQdeBnxjPjBZUOc=; h=From:To:Cc:Subject:Date:List-ID:From; b=BeSX9y//20OlXtcCDBcIoGVznbWtC6269fhHn2qR7TnpE4kyQtXXBiHBoxukELRDJ aYKDy3oEsnZxe4xfLezcHaCueOOHQvTW98/X6Ad/gNqQb6AdV4vcWWFZZXo/pqEbSQ TnhSmH779DcsPaBRPJcz466JJ9LDJS/jt59uDPLU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726717AbgFNOob (ORCPT ); Sun, 14 Jun 2020 10:44:31 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:54494 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgFNOoa (ORCPT ); Sun, 14 Jun 2020 10:44:30 -0400 Received: from oscar.flets-west.jp (softbank126090202047.bbtec.net [126.90.202.47]) (authenticated) by conuserg-11.nifty.com with ESMTP id 05EEhjq0024323; Sun, 14 Jun 2020 23:43:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com 05EEhjq0024323 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1592145826; bh=WqbBHTeTcTELu7HZYZJkll6J0fXNCMEhU1vE64ROybI=; h=From:To:Cc:Subject:Date:From; b=xpYkCjJxeLziMPFOJzjg7ApXaz44bK6GCZaIVP+/fsukFsadvYzfqMxtnCFEsWFys pFjy6ZIRuYZPg+qkpJImx9ZBjxWwXhl3BSI4RCN34X+q2gP6T1/3COHiTwqS78RP31 s6H74dB4O65n0onYptUtbGF8DdKw30Oq2a38bABEHmNIIzPGPD96hz3XvFnOKeNA6x cBsHyLIPrgI+mvxizRJjTyoEmByvfHbwWXmkW2/6CeZ2p4scBiZchfOItor8Y+kQIx ef/rkj2BqA1/KnuSQdGQrxj+K9B4IA1S9Z5aGk71RM1V+sGM4NxaXdok9tnusRP+1w 2XCcv4LPFrwtQ== X-Nifty-SrcIP: [126.90.202.47] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Nick Desaulniers , Arvind Sankar , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kbuild: improve cc-option to clean up all temporary files Date: Sun, 14 Jun 2020 23:43:40 +0900 Message-Id: <20200614144341.1077495-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org When cc-option and friends evaluate compiler flags, the temporary file $$TMP is created as an output object, and automatically cleaned up. The actual file path of $$TMP is ..tmp, here is the process ID of $(shell ....) invoked from cc-option. (Please note $$$$ is the escape sequence of $$). Such garbage files are cleaned up in most cases, but some compiler flags create additional output files. For example, -gsplit-dwarf creates a .dwo file. When CONFIG_DEBUG_INFO_SPLIT=y, you will see a bunch of ..dwo files left in the top of build directories. You may not notice them unless you do 'ls -a', but the garbage files will increase every time you run 'make'. This commit changes the temporary object path to .tmp_/tmp, and removes .tmp_ directory when exiting. The additional files .tmp_/tmp.dwo, will be cleaned away altogether. When the compiler creates separate build artifacts, their file paths are usually determined based on the base name of the object. Another example is -ftest-coverage, which outputs the coverage data into .gcno Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 0c3dc983439b..5dfd224599b7 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -86,20 +86,21 @@ cc-cross-prefix = $(firstword $(foreach c, $(1), \ $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) # output directory for tests below -TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) +TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ # try-run # Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) -# Exit code chooses option. "$$TMP" serves as a temporary file and is +# Exit code chooses option. "$$TMP" serves as a temporary directory and is # automatically cleaned up. try-run = $(shell set -e; \ - TMP="$(TMPOUT).$$$$.tmp"; \ - TMPO="$(TMPOUT).$$$$.o"; \ + TMP=$(TMPOUT)/tmp; \ + TMPO=$(TMPOUT)/tmp.o; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ if ($(1)) >/dev/null 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; \ - fi; \ - rm -f "$$TMP" "$$TMPO") + fi) # as-option # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) From patchwork Sun Jun 14 14:43:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 11603347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C82092A for ; Sun, 14 Jun 2020 14:45:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22EFA20578 for ; Sun, 14 Jun 2020 14:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592145923; bh=wa4ADyDCZs0ntNfI9DvqdjwuNtQIO0NWurv/WWurd84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ikJtunIxySyLZO7JNI15eR8RD59Qu4B7YzRi95nkqjzFOoFM5Qz3q5THS7JZ0GonQ 9NSPmeVPqiuld03oNIordjTmylM+Wd5gaqVVa2lZPRy2oD4G+SN3L8X9zAwuvN4ffu tMaZTjqQqgWXeK/Q/gR0lwJer2y6NJcNp/pRIJRI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbgFNOpW (ORCPT ); Sun, 14 Jun 2020 10:45:22 -0400 Received: from conuserg-11.nifty.com ([210.131.2.78]:55629 "EHLO conuserg-11.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgFNOpW (ORCPT ); Sun, 14 Jun 2020 10:45:22 -0400 Received: from oscar.flets-west.jp (softbank126090202047.bbtec.net [126.90.202.47]) (authenticated) by conuserg-11.nifty.com with ESMTP id 05EEhjq1024323; Sun, 14 Jun 2020 23:43:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com 05EEhjq1024323 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1592145827; bh=2tNBTLIrpjvalARV+ZKm1wYdYtOnuZzF6U2fUm+curc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0MkqVwFcLmqBEkbwbyIVa3kclqsXzYF/ckTbUtRz6QfEd/JnCZ9JnDydoLKUEFQ7s mpvI5rUGsxigQs2ynVeFgVee8i8Jqm3Azb2xyMBa7JHkrDi9zLimnrzziIm1xQXikg S63ZoDQwP5Omql9Wmz9guRCQKIxj3Eywm8Mbe4qE3BrW8zvcqNLn1jrQGP9IJZuzwR mT7SrcbjxR8uIERzDPERllhaV+/l//g3ktsutBTeKTACqI3HG69bjeKgumT3WgL6q5 YUsXnYSBSXvNUQ6KkMAqtLZBoNuQ5DamQq5igzLXy2TXUd4xftlBGSADXsLfJDdSWk f+Nri5Ra+LB1w== X-Nifty-SrcIP: [126.90.202.47] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Nick Desaulniers , Arvind Sankar , Masahiro Yamada , Andrew Morton , Brendan Higgins , Catalin Marinas , Changbin Du , Krzysztof Kozlowski , Mauro Carvalho Chehab , Randy Dunlap , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kconfig: unify cc-option and as-option Date: Sun, 14 Jun 2020 23:43:41 +0900 Message-Id: <20200614144341.1077495-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200614144341.1077495-1-masahiroy@kernel.org> References: <20200614144341.1077495-1-masahiroy@kernel.org> MIME-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org cc-option and as-option are almost the same; both pass the flag to $(CC). The main difference is the cc-option stops before the assemble stage (-S option) whereas as-option stops after it (-c option). I chose -S because it is slightly faster, but $(cc-option,-gz=zlib) returns a wrong result (https://lkml.org/lkml/2020/6/9/1529). It has been fixed by a separate patch, but using -c is more robust. However, you cannot simply replace -S with -c because the following code would break: depends on $(cc-option,-gsplit-dwarf) The combination of -c and -gsplit-dwarf does not accept /dev/null as output. $ cat /dev/null | gcc -gsplit-dwarf -S -x c - -o /dev/null $ echo $? 0 $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o /dev/null objcopy: Warning: '/dev/null' is not an ordinary file $ echo $? 1 $ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o tmp.o $ echo $? 0 There is another flag that creates an separate file based on the object file path: $ cat /dev/null | gcc -ftest-coverage -c -x c - -o /dev/null :1: error: cannot open /dev/null.gcno So, we cannot use /dev/null to sink the output. Align the cc-option implementation with scripts/Kbuild.include. With -c option used in cc-option, as-option is unneeded. Signed-off-by: Masahiro Yamada Acked-by: Will Deacon --- arch/arm64/Kconfig | 2 +- lib/Kconfig.debug | 1 - scripts/Kconfig.include | 8 +------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 31380da53689..6eb18f45258e 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1564,7 +1564,7 @@ config CC_HAS_SIGN_RETURN_ADDRESS def_bool $(cc-option,-msign-return-address=all) config AS_HAS_PAC - def_bool $(as-option,-Wa$(comma)-march=armv8.3-a) + def_bool $(cc-option,-Wa$(comma)-march=armv8.3-a) config AS_HAS_CFI_NEGATE_RA_STATE def_bool $(as-instr,.cfi_startproc\n.cfi_negate_ra_state\n.cfi_endproc\n) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 96999d4d2dda..9ad9210d70a1 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -229,7 +229,6 @@ config DEBUG_INFO_COMPRESSED bool "Compressed debugging information" depends on DEBUG_INFO depends on $(cc-option,-gz=zlib) - depends on $(as-option,-gz=zlib) depends on $(ld-option,--compress-debug-sections=zlib) help Compress the debug information using zlib. Requires GCC 5.0+ or Clang diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index c264da2b9b30..a5fe72c504ff 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -25,18 +25,12 @@ failure = $(if-success,$(1),n,y) # $(cc-option,) # Return y if the compiler supports , n otherwise -cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null) +cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o) # $(ld-option,) # Return y if the linker supports , n otherwise ld-option = $(success,$(LD) -v $(1)) -# $(as-option,) -# /dev/zero is used as output instead of /dev/null as some assembler cribs when -# both input and output are same. Also both of them have same write behaviour so -# can be easily substituted. -as-option = $(success, $(CC) $(CLANG_FLAGS) $(1) -c -x assembler /dev/null -o /dev/zero) - # $(as-instr,) # Return y if the assembler supports , n otherwise as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)