aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada2020-06-14 09:43:40 -0500
committerSasha Levin2020-06-30 22:17:15 -0500
commit27e3fa7e9ccf31c4a21a257034cfa560cd189449 (patch)
treeac797686882003e9d55ddda966b753109814b888
parent2c0053203879bd4ebb4c9935977558cf70536d63 (diff)
downloadkernel-27e3fa7e9ccf31c4a21a257034cfa560cd189449.tar.gz
kernel-27e3fa7e9ccf31c4a21a257034cfa560cd189449.tar.xz
kernel-27e3fa7e9ccf31c4a21a257034cfa560cd189449.zip
kbuild: improve cc-option to clean up all temporary files
[ Upstream commit f2f02ebd8f3833626642688b2d2c6a7b3c141fa9 ] 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 .<pid>.tmp, here <pid> 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 .<pid>.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_<pid>/tmp, and removes .tmp_<pid> directory when exiting. Separate build artifacts such as *.dwo will be cleaned up all together because 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 <base-name-of-object>.gcno Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--scripts/Kbuild.include11
1 files changed, 6 insertions, 5 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index ce53639a864a..c830750d725b 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -81,20 +81,21 @@ cc-cross-prefix = \
81 fi))) 81 fi)))
82 82
83# output directory for tests below 83# output directory for tests below
84TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) 84TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
85 85
86# try-run 86# try-run
87# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) 87# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
88# Exit code chooses option. "$$TMP" serves as a temporary file and is 88# Exit code chooses option. "$$TMP" serves as a temporary file and is
89# automatically cleaned up. 89# automatically cleaned up.
90try-run = $(shell set -e; \ 90try-run = $(shell set -e; \
91 TMP="$(TMPOUT).$$$$.tmp"; \ 91 TMP=$(TMPOUT)/tmp; \
92 TMPO="$(TMPOUT).$$$$.o"; \ 92 TMPO=$(TMPOUT)/tmp.o; \
93 mkdir -p $(TMPOUT); \
94 trap "rm -rf $(TMPOUT)" EXIT; \
93 if ($(1)) >/dev/null 2>&1; \ 95 if ($(1)) >/dev/null 2>&1; \
94 then echo "$(2)"; \ 96 then echo "$(2)"; \
95 else echo "$(3)"; \ 97 else echo "$(3)"; \
96 fi; \ 98 fi)
97 rm -f "$$TMP" "$$TMPO")
98 99
99# as-option 100# as-option
100# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 101# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)