public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] Driver: Add new -truncate option
@ 2024-04-28 23:16 Peter Damianov
  2024-04-28 23:16 ` [PATCH v3 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Peter Damianov
  2024-04-28 23:27 ` [PATCH v3 1/2] Driver: Add new -truncate option Peter0x44
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Damianov @ 2024-04-28 23:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Peter Damianov

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 <peter0x44@disroot.org>
---
 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"));
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710]
  2024-04-28 23:16 [PATCH v3 1/2] Driver: Add new -truncate option Peter Damianov
@ 2024-04-28 23:16 ` Peter Damianov
  2024-04-28 23:27 ` [PATCH v3 1/2] Driver: Add new -truncate option Peter0x44
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Damianov @ 2024-04-28 23:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: Peter Damianov

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 <peter0x44@disroot.org>
---
 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..cfded757f26 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
 	    {
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/2] Driver: Add new -truncate option
  2024-04-28 23:16 [PATCH v3 1/2] Driver: Add new -truncate option Peter Damianov
  2024-04-28 23:16 ` [PATCH v3 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Peter Damianov
@ 2024-04-28 23:27 ` Peter0x44
  2024-05-02  9:34   ` Richard Biener
  1 sibling, 1 reply; 4+ messages in thread
From: Peter0x44 @ 2024-04-28 23:27 UTC (permalink / raw)
  To: gcc-patches

29 Apr 2024 12:16:26 am Peter Damianov <peter0x44@disroot.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 <peter0x44@disroot.org>
> ---
> 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"));
> --
> 2.39.2
I resubmitted the patch because the previous one had a mistake.

It didn't set "do_save" to false, so it resulted in problems like this:

./gcc/xgcc -truncate
xgcc: error: missing filename after ‘-truncate’
xgcc: fatal error: no input files

./gcc/xgcc -truncate ??
xgcc: error: unrecognized command-line option ‘-truncate’
xgcc: fatal error: no input files

Therefore regressing some tests, and not working properly.
After fixing this, I ran all of the LTO tests again and observed no 
failures.

I'm not sure how I ever observed it working before, but I'm reasonably 
confident this is correct now.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/2] Driver: Add new -truncate option
  2024-04-28 23:27 ` [PATCH v3 1/2] Driver: Add new -truncate option Peter0x44
@ 2024-05-02  9:34   ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2024-05-02  9:34 UTC (permalink / raw)
  To: Peter0x44; +Cc: gcc-patches

On Mon, Apr 29, 2024 at 1:27 AM Peter0x44 <peter0x44@disroot.org> wrote:
>
> 29 Apr 2024 12:16:26 am Peter Damianov <peter0x44@disroot.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 <peter0x44@disroot.org>
> > ---
> > 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"));
> > --
> > 2.39.2
> I resubmitted the patch because the previous one had a mistake.
>
> It didn't set "do_save" to false, so it resulted in problems like this:
>
> ./gcc/xgcc -truncate
> xgcc: error: missing filename after ‘-truncate’
> xgcc: fatal error: no input files
>
> ./gcc/xgcc -truncate ??
> xgcc: error: unrecognized command-line option ‘-truncate’
> xgcc: fatal error: no input files
>
> Therefore regressing some tests, and not working properly.
> After fixing this, I ran all of the LTO tests again and observed no
> failures.
>
> I'm not sure how I ever observed it working before, but I'm reasonably
> confident this is correct now.

The series is still OK.  I suppose you do not have git write access so
I am testing the series with a LTO bootstrap and will push it once
that's successful.

Thanks,
Richard.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-02  9:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-28 23:16 [PATCH v3 1/2] Driver: Add new -truncate option Peter Damianov
2024-04-28 23:16 ` [PATCH v3 2/2] lto-wrapper: Truncate files using -truncate driver option [PR110710] Peter Damianov
2024-04-28 23:27 ` [PATCH v3 1/2] Driver: Add new -truncate option Peter0x44
2024-05-02  9:34   ` Richard Biener

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