Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3034519ybt; Mon, 29 Jun 2020 13:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTAxcXmVB0ppDUcArUHQfn6BHe/QrjgZPQcolBQQAwQkf/I4XcwC087Eo8x5qS/mTpkS1b X-Received: by 2002:a50:dacf:: with SMTP id s15mr20380904edj.136.1593462583761; Mon, 29 Jun 2020 13:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593462583; cv=none; d=google.com; s=arc-20160816; b=RAL9Q1GnF11TEcF9GyuQvHWFLOatKJYiIJzLDFD9d0hSjPJAZpFcspeHQjBWxf7VJK 2rgtiWCoxgZcNL8yO0eU3UdOl3Q4XJxHb82+HKbEso5PJGkD1j48/g6sKhxQqH0XZbL+ EmnUM4ttvPCZwjkAI8H21rqgeq5bZsc1/Czm/3wvuNjY/V7eNgNuIHwsC54VBmZ80key CuOE0vmgLYKK3fBpNjMzCgX+bSyziL5yZKf62R7bVzQOiq2dJxvsHIavkw20MbJCCJex 6z2qgbImM4EbtdWzISWuEWkLchJ7/rmO50ERxnMzK34BKF4j3rWHEAyExIawLNMG3DnU Fn7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cmEe4aROiCE42WaYST9Bea78/eZkOvabPl+ixi7y/tY=; b=u+JuTB8aTgIYHuXNxpwGbgTu/sjFeF2OTnaSVDnMeAL8gMfYCCKzQiww0t+E+RnlX+ XAG6xFo+IB09N8ZLvlG0I6fF6e1HzLWdODLYYqfHxEXLkdS73WTWl6YtoCw+KZBIvNXF RLqVDqaldxny4UebdV/KzxFgnE4chEy0F/AoHvdmskfiiLQYJBzq8cTG/hj1fJOTZwi+ A6iov5iN2R6IVeM/bqSWoRAU3cfXwSTM2fO5Yrv3W3YqYF2yH6YT9UDNyfCESUQGUkP9 JE3vLTJ6G8c+CZC0XSVSYCfjDspX0dr529eqY7+2GG+K0TyhltI6iYj4V5T8w5CA+ry2 OIMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bM5a3IxI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n24si303002edt.561.2020.06.29.13.29.20; Mon, 29 Jun 2020 13:29:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bM5a3IxI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388853AbgF2U05 (ORCPT + 99 others); Mon, 29 Jun 2020 16:26:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:37028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732455AbgF2TZZ (ORCPT ); Mon, 29 Jun 2020 15:25:25 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D62DD25324; Mon, 29 Jun 2020 15:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593445156; bh=f2UiAtHANs9tFRVesQfBZNsitQGOznVCjZKCH6GXzDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bM5a3IxILeCPiMNMSkdHU7mvmmHg5R1X7ysVLL0MZH7Ru8SoAnRfAVmrfVmx2c/3v o6amw4pdOIv/VMHthjTi3SsfizAU+HRybuYXRucQZOjZUXvMkGsmXLrjkNbVpcMbWT fnZn5iRR6Mqn5mbHJXOsaYBXw9r0Vn5XSQwrq2h0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Masahiro Yamada , Sasha Levin Subject: [PATCH 4.14 57/78] kbuild: improve cc-option to clean up all temporary files Date: Mon, 29 Jun 2020 11:37:45 -0400 Message-Id: <20200629153806.2494953-58-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153806.2494953-1-sashal@kernel.org> References: <20200629153806.2494953-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.186-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.186-rc1 X-KernelTest-Deadline: 2020-07-01T15:38+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada [ 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 ..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. 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 .gcno Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/Kbuild.include | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index a33fa1a918731..28bfb4378dbd8 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -82,20 +82,21 @@ cc-cross-prefix = \ fi))) # 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 # 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,) -- 2.25.1