public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Peter Damianov <peter0x44@disroot.org>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH v2 1/2] Driver: Add new -truncate option
Date: Thu, 18 Apr 2024 08:26:14 +0200	[thread overview]
Message-ID: <CAFiYyc0txAGTjaWwfg3+YmHf1FkV0006DDszT2h214-NxvJPug@mail.gmail.com> (raw)
In-Reply-To: <20240418040912.6236-1-peter0x44@disroot.org>

On Thu, Apr 18, 2024 at 6:12 AM Peter Damianov <peter0x44@disroot.org> 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

I suppose it should have been

$ gcc hello.o -truncate hello.o

in the example.

> $ 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.

This looks good to me.

Thanks,
Richard.

> Signed-off-by: Peter Damianov <peter0x44@disroot.org>
> ---
> 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"));
> --
> 2.39.2
>

  parent reply	other threads:[~2024-04-18  6:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18  4:09 Peter Damianov
2024-04-18  4:09 ` [PATCH v2 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Peter Damianov
2024-04-18  6:27   ` Richard Biener
2024-04-18  6:26 ` Richard Biener [this message]
2024-04-18  8:26   ` [PATCH v2 1/2] Driver: Add new -truncate option Peter0x44

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc0txAGTjaWwfg3+YmHf1FkV0006DDszT2h214-NxvJPug@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=peter0x44@disroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).