From patchwork Thu Apr 18 00:56:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1924780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=fS1a0cLd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VKfWl62pWz1yZP for ; Thu, 18 Apr 2024 10:57:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB951385841E for ; Thu, 18 Apr 2024 00:57:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id D66603858C62 for ; Thu, 18 Apr 2024 00:57:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D66603858C62 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=disroot.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D66603858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713401832; cv=none; b=vwfgD45E/UFIzl+T8I26+Bfq5vaFNACmi56mDc67Ibbqp23zb/Pj3/dJI+/X7Txt7coE4/74msGKHBhpfzIrbB8t20AY3gMPveLRtakGsex5sRYyVVDFR3m7ygE8DiSn6KkSpaojPySfjYrYX72UJ0lBukS1vSQJ4YyN1vZtvIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713401832; c=relaxed/simple; bh=Oz0/+TfZqzlBz1wdWAdI7XJEdq3ir1M2VI1SomKPFWQ=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=XZJ7NhYiu1eYBb5RUNTleW/h8DTjvQth6GAECh4tGNKxznHF8AzONlPlsW+XHLcVvFLp/zZC64VI+DPfMt7cqOHrfHzxVF8W4oTkOOvSVY3ii12I3YKA1S/zlNQntNcpVdt13KpOwK2wMNxswCti4SFVQMwQjAJfoMIwaoMfkAI= ARC-Authentication-Results: i=1; server2.sourceware.org X-Virus-Scanned: SPAM Filter at disroot.org From: Peter Damianov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1713401826; bh=Oz0/+TfZqzlBz1wdWAdI7XJEdq3ir1M2VI1SomKPFWQ=; h=From:To:Cc:Subject:Date; b=fS1a0cLdAhSAtk5eKdfuQ9u1eFiJtXVWEO1SDfcghxwjSdf3rsT+Y5tCrwvaPOvTw cLDI28UY7bLNflr8P4chGaePIo0LC05kWisf4l4UOpCdLHxPvAlk+8iQk5VSdJTU50 KZ83qI3+l2nJqLL3DthdGaQTiCvcZGMigiFd8KF/+yrjZnGa+q5rZXOKysXL19NGnM qzVgM3avQwf0Zv++aCenM9jg9mUeCvfMw1+6fbJu5l7lNoJCGVspnRiYnoTFP/xYjN cNTaTbmhzTaI+7qa/gMLPeKWkrT+rY5mLS288rIMj3cPaE4cBtrNFAFmFMZeGcsDZc AyJ8uv+0687eg== To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Peter Damianov Subject: [PATCH 1/2] Driver: Add new -truncate option Date: Wed, 17 Apr 2024 17:56:02 -0700 Message-Id: <20240418005602.24118-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This commit adds a new option to the driver that truncates one file after linking. Tested likeso: $ gcc hello.c -c $ du -h hello.o 4.0K hello.o $ gcc hello.o -truncate hello $ ./a.out Hello world $ du -h hello.o $ 0 hello.o $ gcc hello.o -truncate gcc: error: missing filename after '-truncate' The motivation for adding this is PR110710. It is used by lto-wrapper to truncate files in a shell-independent manner. Signed-off-by: Peter Damianov --- gcc/common.opt | 5 +++++ gcc/gcc.cc | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index ad348844775..3ede2fa8552 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -422,6 +422,11 @@ Display target specific command line options (including assembler and linker opt -time Driver Alias(time) +;; Truncate the file specified after linking. +;; This option is used by lto-wrapper to reduce the peak disk when linking with +;; many .LTRANS units. +Driver Separate Undocumented MissingArgError(missing filename after %qs) + -verbose Driver Alias(v) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 728332b8153..00017964295 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -2138,6 +2138,10 @@ static int have_E = 0; /* Pointer to output file name passed in with -o. */ static const char *output_file = 0; +/* Pointer to input file name passed in with -truncate. + This file should be truncated after linking. */ +static const char *totruncate_file = 0; + /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for it here. */ @@ -4607,6 +4611,10 @@ driver_handle_option (struct gcc_options *opts, save_switch ("-o", 1, &arg, validated, true); return true; + case OPT_truncate: + totruncate_file = arg; + break; + case OPT_pie: #ifdef ENABLE_DEFAULT_PIE /* -pie is turned on by default. */ @@ -9273,6 +9281,11 @@ driver::maybe_run_linker (const char *argv0) const option). */ error ("%s: linker input file not found: %m", outfiles[i]); } + + if (totruncate_file != NULL && linker_was_run && !seen_error ()) + /* Truncate file specified by -truncate. + Used by lto-wrapper to reduce temporary disk-space usage. */ + truncate(totruncate_file, 0); } /* The end of "main". */ From patchwork Thu Apr 18 00:56:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1924781 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=disroot.org header.i=@disroot.org header.a=rsa-sha256 header.s=mail header.b=SJfRaMaB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VKfXv3R87z1yZP for ; Thu, 18 Apr 2024 10:58:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A66F6384AB4A for ; Thu, 18 Apr 2024 00:58:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id 27A063849AEC for ; Thu, 18 Apr 2024 00:57:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27A063849AEC Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=disroot.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 27A063849AEC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=178.21.23.139 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713401860; cv=none; b=vBhxV5/CTIaGNWW7m5ZuRLlYNIlcU1y+3QfjYvgkiH6g1FpYPhZu0z1q+g5uWOBUze27jlDwrar2PuXFm6rtJNQTmT6urdeYYoc83+hZO3UW8I06yhPAAzLafw8bR/gruRnJoAsdM1vSwCU8op7Ls9YmfxVYg6aGnpjG6VkkHV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713401860; c=relaxed/simple; bh=iBsu7/fux0RFJrs+o4nnZ50EoLkLcMOOr4/efWn2wro=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=LSrjyVP4nZRfyGwUhfcs5aCm75dlTDkJVPVoMLgKA16jKAn94EQPMCXmLU+PNIe1/2FQ6lUAtWAaqX0yF05lNWm9YaYaxsKb7RbyXrVK0c4WMEv3mBHn6d7O80spe66H74ISqO/a/z8WOR+e0KZqvArtjxWk9P6ZDtZbZV6I6L0= ARC-Authentication-Results: i=1; server2.sourceware.org X-Virus-Scanned: SPAM Filter at disroot.org From: Peter Damianov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1713401854; bh=iBsu7/fux0RFJrs+o4nnZ50EoLkLcMOOr4/efWn2wro=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SJfRaMaBqjFkGCPM96wuYvsreMY4wznsKmSulSLtTJCdkG1/UZzQEw8wOIeEryynX je+fivMxYXrKUvERnyeD/w1Vyzf4EJ6u6yo9BvzW9PlQ5OFvVoXb8NuDWmQSra6z7T QkWHyMoz2Je1WpVvM4lvxt+XJeEMArFEbXlgOmUBV60+Gz3mpmggJ76p/mD370NWB7 l+6gZvzcyD/+B9jfGjKgz+VkpettT0rOnB8SqAVXB0u7uSapm8Fj+Zg1Jka7WggUmB /4kqArEKbkwEVDyjc45s9vzKrz5v/VNtxsFOt/wPM3r+P21z3ZRWhY9s5ZC9TX/vCa BWAPk/hSDQ5IA== To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Peter Damianov Subject: [PATCH 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Date: Wed, 17 Apr 2024 17:56:04 -0700 Message-Id: <20240418005602.24118-2-peter0x44@disroot.org> In-Reply-To: <20240418005602.24118-1-peter0x44@disroot.org> References: <20240418005602.24118-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This commit changes the Makefiles generated by lto-wrapper to no longer use the "mv" and "touch" shell commands. These don't exist on Windows, so when the Makefile attempts to call them, it results in errors like: The system cannot find the file specified. This problem only manifested when calling gcc from cmd.exe, and having no sh.exe present on the PATH. The Windows port of GNU Make searches the PATH for an sh.exe, and uses it if present. I have tested this in environments with and without sh.exe on the PATH and confirmed it works as expected. Signed-off-by: Peter Damianov --- gcc/lto-wrapper.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index 02579951569..a36a59e6fb8 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -2023,14 +2023,12 @@ cont: fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]); for (j = 1; new_argv[j] != NULL; ++j) fprintf (mstream, " '%s'", new_argv[j]); - fprintf (mstream, "\n"); /* If we are not preserving the ltrans input files then truncate them as soon as we have processed it. This reduces temporary disk-space usage. */ if (! save_temps) - fprintf (mstream, "\t@-touch -r \"%s\" \"%s.tem\" > /dev/null " - "2>&1 && mv \"%s.tem\" \"%s\"\n", - input_name, input_name, input_name, input_name); + fprintf (mstream, " '-truncate' '%s'", input_name); + fprintf (mstream, "\n"); } else {