From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 36C343858408 for ; Thu, 18 Apr 2024 01:08:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36C343858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36C343858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713402534; cv=none; b=w6/juPV0P2Zu87kQGx1Sx5xyOygm8MppkqwTQNMHUFvy4gpLd5dPYemPU7M/fACSnF/M0e1QB/ZXsicoQgPSzQBlFqL4b//fK0yhWHUsf74p4iMKotPhBmrWDPyh+Oe6KGMxHqVfb0tkdya4yTvbYXA76yiQCbKjq12VVzcPGfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713402534; c=relaxed/simple; bh=k9vvThtJEWUSf+YiFp8fJuijzI4M4FOkbT/MtrFc3Co=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=sT/xCZaOG5I7zJvQzdjrA6MvZuP/2o/KNxaVgRCrdEBHtwqfXaHE2TbvrEjSOF9JTnh8gPqYS2oajXbHMS5Bh9x4C6tqrjxzof2fQU2UESe6Llp4ngHXAkQV2FATof+xT3WH0xrHJUuHC8JnpXu4Gbwh0GOOJvEWJdQrqyj+dsk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5f769fd2bd0so237946a12.0 for ; Wed, 17 Apr 2024 18:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713402532; x=1714007332; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y825pd6qyTJR8o4AYcnbVrLb2BqVsAQee9ku8FXdBWw=; b=Ljvk7Qz2pIWCYGgama9LFDYg+9s7k4gZsj7ARnw4HGFQNLejkunt2/zJ6rf1FOZ3xz oKZ7crqr1jH6XYjKVZFWC8w/1oz/lFSTg0t6IJaiH1JwWbNIyqKLiLZjD89LBF4Z3Eao 4QCOtgFGyYwrf4ldQMQ+ORd3afSfhA5Y7veupLn2govAzRz2zTzITX4HF71NhLdLnLIm T6sDAjcylu+g3jSI0g6H1Enik2ZaH8hj5znlymW/O4T/QTqcbEcKn9pxmMjYmawV4Ozq KyIq6h4Xkk2o7grtFF+cmgwGCSoKSWJ7S+oO9qDKKW5CiZBmzq7/4KDVWTJMRSar4YP0 UrEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713402532; x=1714007332; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y825pd6qyTJR8o4AYcnbVrLb2BqVsAQee9ku8FXdBWw=; b=XgVkCXHcHXD78OKyfvdKvM32ZhtIgezNOpp0qCeXiBjgMaoB9LDyPLg+aiLM2BVI/e LC4JpFJM2z7RUCp/x/+lVTKPEb1m3EVmCaIeidVBRZOF4g/qkhk0tr+vglobl0F+iai5 mnHvD+XwdYu2bZTSkr4ZaDWRJLdamX+ATOc42UEtgrjtsqddwGatmhHBWamTDJbbQ7kA FROtMyCVBGwMlNNmdJ0jZXgcHJ8AVa/RgbGxSuuVfXz5ptOo059IxXfy6hWLGQ7zbeaf qGqc/Tjea+Jpr1+FuF99CaTZObpExpnhTecg4kzslcR3vsh31KpUdTrQQAB6P7w4GOSa GOFw== X-Gm-Message-State: AOJu0YxRq7GoihFw88H/5dVz6AKhPc3MLrWN/L0m86/tuCySdNi6e/r4 ow18M9q59WsA5FI/zyJXh/xZ1RkxkEufaP1Rg88ho3dwl8lcb2IbBN2G/eGIH2+57sHCVfgDDEk gJRuxkKHbRbA6rnljwJs3OkZdzV2PzA== X-Google-Smtp-Source: AGHT+IFlRyBSCcw7KhFrHH4mMS2RZg/MfuLZ95Smb9B0gnmnAhvPxXwwDWlr1XlykuQdYc5hDCAdIyVWt9hrVa1o7Yo= X-Received: by 2002:a17:90a:ac09:b0:2a5:1615:80e5 with SMTP id o9-20020a17090aac0900b002a5161580e5mr1232650pjq.6.1713402531897; Wed, 17 Apr 2024 18:08:51 -0700 (PDT) MIME-Version: 1.0 References: <20240418005602.24118-1-peter0x44@disroot.org> In-Reply-To: <20240418005602.24118-1-peter0x44@disroot.org> From: Andrew Pinski Date: Wed, 17 Apr 2024 18:08:39 -0700 Message-ID: Subject: Re: [PATCH 1/2] Driver: Add new -truncate option To: Peter Damianov Cc: gcc-patches@gcc.gnu.org, richard.guenther@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 Wed, Apr 17, 2024 at 5:57=E2=80=AFPM 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. I wonder if we should document this option or not. On one hand it is only supposed to be used by lto but on the other hand, someone could use it on accident from the command line and we would get a bug report saying the file passed to it is now 0. Thanks, Andrew Pinski > > 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 (includ= ing 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 linki= ng 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 =3D 0; > /* Pointer to output file name passed in with -o. */ > static const char *output_file =3D 0; > > +/* Pointer to input file name passed in with -truncate. > + This file should be truncated after linking. */ > +static const char *totruncate_file =3D 0; > + > /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associat= ed > temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made f= or > 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 =3D 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 !=3D 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". */ > -- > 2.39.2 >