From patchwork Thu Apr 18 04:09:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1924808 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=Bm3+t/w3; 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 4VKkrj0mFPz1yZY for ; Thu, 18 Apr 2024 14:12:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 251DD3835411 for ; Thu, 18 Apr 2024 04:12:33 +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 03A113858D39 for ; Thu, 18 Apr 2024 04:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03A113858D39 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 03A113858D39 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=1713413533; cv=none; b=Gw6UfXWVckVnAIaKMbqqYcotDTZi/ZGh028bnirgcXktM0Bc6e6O7d0ip50nki5a2UdE9e4cvhf75SZL3iPo14j4BfHvuKhIGybHWC0rfODFiSUv8bZ8eTnXWYbfLe5LHWAKnJoC/SEnCYblcqxztQReCKxZrnjME3iBmJ4rgEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713413533; c=relaxed/simple; bh=GAiVDSclB/xnDvhatgj2jd9oPX1WFxoov/gyTpXH5QQ=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=MCPIWP0B87sCH3zbA4YtbFfgA9kSnDywRiPfpRFEkkzTBdTm/i34Ze4jtjl2AirPJfVprH5MdgIwjpSp1SSlClYV2UX2hJx7QMfZA5Q8z1zPdurP/Pwajo9SyrSOQY5hyX6btWi4Hd88nUWgAlM62CALTPOzyKcWQ+Am7CCoI5s= 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=1713413528; bh=GAiVDSclB/xnDvhatgj2jd9oPX1WFxoov/gyTpXH5QQ=; h=From:To:Cc:Subject:Date; b=Bm3+t/w3m6wLAindXSfihDnokgnC6yBYAH1FON44KVfx43jRdhKsp4fAXMSQ0pZ4t 5ZGCrORCGjnVGv3aEMPvDIC0s4WqwkbrfJT0MFYgHWHzGJtRSY3CGg0EzxEE8i/WHr X6B6b4DKO73ztXURxHFp13ULL7mlDWToQH+7e5svmHPK6nmyo33LKIaogjQhLqJcXH /9IdkLi9FUr3guEIpNrAQ1E8pKcT1ZAyk0YobqsFmo+FnuLAEsMfP4yEkM+KvmC64B JSK/P/B9Sa+ln7/ZuKiMkUeWfWmDjBHentsdQg7U8KFylzALBTEykGkoxMhGPp1Yq4 ij/dEQ4QiGmWA== To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Peter Damianov Subject: [PATCH v2 1/2] Driver: Add new -truncate option Date: Wed, 17 Apr 2024 21:09:12 -0700 Message-Id: <20240418040912.6236-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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 --- v2: moved truncation to driver::final_actions v2: moved handling of OPT_truncate to be in alphabetic order gcc/common.opt | 6 ++++++ gcc/gcc.cc | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index ad348844775..40cab3cb36a 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -422,6 +422,12 @@ 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-usage when +;; linking with many .LTRANS units. +truncate +Driver Separate Undocumented MissingArgError(missing filename after %qs) + -verbose Driver Alias(v) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 728332b8153..b4169bbd3be 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. */ @@ -4538,6 +4542,10 @@ driver_handle_option (struct gcc_options *opts, do_save = false; break; + case OPT_truncate: + totruncate_file = arg; + break; + case OPT____: /* "-###" This is similar to -v except that there is no execution @@ -9286,6 +9294,11 @@ driver::final_actions () const delete_failure_queue (); delete_temp_files (); + if (totruncate_file != NULL && !seen_error ()) + /* Truncate file specified by -truncate. + Used by lto-wrapper to reduce temporary disk-space usage. */ + truncate(totruncate_file, 0); + if (print_help_list) { printf (("\nFor bug reporting instructions, please see:\n")); From patchwork Thu Apr 18 04:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter0x44 X-Patchwork-Id: 1924809 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=i45cbqjq; 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 4VKkrp4Tn7z1yZY for ; Thu, 18 Apr 2024 14:12:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4D6F3881869 for ; Thu, 18 Apr 2024 04:12:40 +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 7AD4A3858D39 for ; Thu, 18 Apr 2024 04:12:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7AD4A3858D39 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 7AD4A3858D39 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=1713413543; cv=none; b=pJEcuwI0ejuHYVUMZwXQrlYcepZxKpSwAU+onRVwu7BpBcmMNDlNELTwkVLClQJD9pB3KQJyX1ygZdB0CzBbO00s7EGBOpSh1xWwlucR3ridLpFVDrrZAdfsbvtf3B6r6hfcG7AQcGExst9+6bCGO5j0Q2y7DVtdaz8x8GpjvDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713413543; c=relaxed/simple; bh=iBsu7/fux0RFJrs+o4nnZ50EoLkLcMOOr4/efWn2wro=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=hleF5j3UBJTWQu6s913DGZREKMj3lkJA1K3miCe7dmoE8hSSs/yu0SiLJ1rBsw8LxWaACJvU+PMzjTZBtBOUGpFv5By+hbEHRKb5pFJyhaIV6i3S5NztJDnDX/DS6FwJtReb+MnM0aXMrzTo52s309DjELsNDm/yvmgNvEE8arA= 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=1713413539; bh=iBsu7/fux0RFJrs+o4nnZ50EoLkLcMOOr4/efWn2wro=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i45cbqjqhy9I8vtvBTWbxm/xfFAnNjYo0+YS/qP4jXq1Z9MD8TJBFuJZlksmgR6ow DXBUZUHIoNsAS/6BjzDUxUnOoCxy4bxJdvnlIi239gOvJuvtFOkMkAga4RTF1NVWZr 5OS7wZ9LmjpCdMERHDpNy1NpTx6zsraJm4fEzf608orzmZ2j501uNuMOlpfd4XlnWe cKxMUCRgwaw0y+YedXCf+ZM5SOTRnR5Dwl4l9oUWnlrT4q6mvPPAW4mAmyKWhwSvlZ KJqWj+xWf9A9u527pxSGz1GFvFy6biCdftp1cuOB7CQqCa2vWwkSIbPBijijSWEglY xHBTVgtHpitTg== To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Peter Damianov Subject: [PATCH v2 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Date: Wed, 17 Apr 2024 21:09:14 -0700 Message-Id: <20240418040912.6236-2-peter0x44@disroot.org> In-Reply-To: <20240418040912.6236-1-peter0x44@disroot.org> References: <20240418040912.6236-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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 {