From patchwork Sun Apr 28 23:16:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Damianov X-Patchwork-Id: 1928741 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=Zy8le8pP; 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 4VSMmL29DBz23t4 for ; Mon, 29 Apr 2024 09:16:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B753385842C for ; Sun, 28 Apr 2024 23:16:48 +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 D0A6C3858D35 for ; Sun, 28 Apr 2024 23:16:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D0A6C3858D35 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 D0A6C3858D35 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=1714346190; cv=none; b=eIie+hxgayLmsbWGsCX/EZcmUdz//Xx94CunZx8QIaTiLBbv1+nONRTG4tY1FHKJLf+6vdp4HWRCZEwofPtUwBYPhVaOHsmXvjH5MNM/s/y7+AMd7Xe8GoQT4JfEHUf+VNSHl9urtMb0YhCTAB9NUHhGbiHUtIuajpatO+zBe2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714346190; c=relaxed/simple; bh=FNb6ZvisqArdcv0Aqn9FW1h+2t2PptmshjYCRCMIDQ8=; h=From:DKIM-Signature:To:Subject:Date:Message-Id:MIME-Version; b=CiEo0kk5lvbBQ2oPrYC5I2z/7dCuP8uZSx84SSbwK9eBtc6e45AqZA1OlFFS6ScaMFQI6FeVu4vzz5Cg78U8YeTyjKudtUxbdDLfR46X4b0I5BvveybPZb5ZY/M6IfIwibta0EcblsLcCNAepKQDAXtLnL4umuqU3JCjIfTNztk= 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=1714346185; bh=FNb6ZvisqArdcv0Aqn9FW1h+2t2PptmshjYCRCMIDQ8=; h=From:To:Cc:Subject:Date; b=Zy8le8pPXtv4zUNVajg2Bt+Xi5wkNdkgcb24f4nZf9WnmPc7s2GOPDQpzuQK8akIy wecLtKpC0vjIensKOA1lrhllAx1ydz6JccSkXDwcVRhduUFV5E6Qzr9jcrX+5/HVbJ O+eSLIdn3aEAmOEgNea9RBV8BcN7BXaUHCKcP3a4XOfLdqN8r0c5nlSW6jU14rSgpi l7s7gH/A1m9JX+WYV7GJ8QOADg7e2ASEe8I3/yF6nmgk6kT3HQNDT8LdDDYHkbnCGJ NolhKGfMoLXaejVfsMSdD1FI4RtmQmUa/O7oqHvFF/tLM2oGnVd+HNqmhAql3Zs1yF guiH37zA+UAMw== To: gcc-patches@gcc.gnu.org Cc: Peter Damianov Subject: [PATCH v3 1/2] Driver: Add new -truncate option Date: Sun, 28 Apr 2024 16:16:11 -0700 Message-Id: <20240428231612.25802-1-peter0x44@disroot.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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.o $ ./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 | 6 ++++++ gcc/gcc.cc | 14 ++++++++++++++ 2 files changed, 20 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..830a4700a87 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,11 @@ driver_handle_option (struct gcc_options *opts, do_save = false; break; + case OPT_truncate: + totruncate_file = arg; + do_save = false; + break; + case OPT____: /* "-###" This is similar to -v except that there is no execution @@ -9286,6 +9295,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"));