From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) by sourceware.org (Postfix) with ESMTPS id 1AE8F3858D20 for ; Thu, 18 Apr 2024 02:43:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1AE8F3858D20 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 1AE8F3858D20 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=1713408203; cv=none; b=xdGwlUAZ1ICMpKiFj62/g1v+SAECUxoF+HIJqL9j9Z9UAqXz236HXZjqulPvva7uExD/UVqPiuYSOSFsW0KlD7RfLU5rqppO3EdCO7OlI+9Ea3PwNHHSt2HeUZIn6IafoO6ezzaP/lUOpQcWkpeMQlo2Mb99Kj/EgpuoELlkS50= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713408203; c=relaxed/simple; bh=oY3sPmch37nVUs6a1b0ZJnGWovTtbzNbZkUPmUdQ4M8=; h=MIME-Version:DKIM-Signature:Date:From:To:Subject:Message-ID; b=CJmo3AAqvU/FJhSTXT1GTFHmQlpeCBWUkeE3CM81Dm74FXJzkBpvt4np9FB5QcR88nQnVYE3oa0dHIjhfLJlfQdC8H4TAPIwpfxuphnW16qzEAJaTXv5G3X6p271tNFe4Si8+qWSBLDYUDqfn6tOEuKiUpdkg7d/OA0Ul95SKSE= ARC-Authentication-Results: i=1; server2.sourceware.org X-Virus-Scanned: SPAM Filter at disroot.org MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1713408198; bh=oY3sPmch37nVUs6a1b0ZJnGWovTtbzNbZkUPmUdQ4M8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=K1cj+Km0wGThCKjVcV5KVIShLMhZksu3UgLWORPz8u9a1JIJqngibQLChdFxNRYw+ PcdbAbn8qINmNyyG4Rf7vDHMbmrjKtHYTzRGXPgws5ah/u2eDhQNUcE9W8OSsEOq1K Z8o1xp/s54A2ymnPX3wWe0pMtSYjGXTBp9UBVZFbIYCRo2nsQ+ivn4VYXbE9jIi9Xb 8sjd1IkS826V/+u52EEx1uDZvkl2wZZWH3I8RJ/t5TqUGxExLlTdquqHwT3aB7jv7+ Vn6gTmIsBl8NkJ4VjAfOYPTmJXpGY6wyKftpbE049LY5JhzU1ZMQ/J9pOGfPgVUQzt rlr98xQoFEXtw== Date: Wed, 17 Apr 2024 19:43:18 -0700 From: Peter0x44 To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com Subject: Re: [PATCH 1/2] Driver: Add new -truncate option In-Reply-To: <20240418005602.24118-1-peter0x44@disroot.org> References: <20240418005602.24118-1-peter0x44@disroot.org> Message-ID: <4bbf41580095ecad1c6e24f1be7b5fd4@disroot.org> X-Sender: peter0x44@disroot.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.0 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 List-Id: On 2024-04-17 17:56, Peter Damianov wrote: > 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); On second thought, doing the truncation in driver::maybe_run_linker() seems wrong. driver::final_actions seems like the better place to put this code. Will resubmit. > } > > /* The end of "main". */