diff mbox series

PING – Re: [Patch] collect-utils.c, lto-wrapper + mkoffload: Improve -save-temps filename

Message ID e86b22ab-e949-7171-d9ac-673f4dee60dd@codesourcery.com
State New
Headers show
Series PING – Re: [Patch] collect-utils.c, lto-wrapper + mkoffload: Improve -save-temps filename | expand

Commit Message

Tobias Burnus Oct. 19, 2020, 7:58 a.m. UTC
PING.

Attached patch has a minor change: the renamed suffixes for nvptx as
suggested by Tom
(and for considency, 'ltrans.args' → 'ltrans_args').

OK?

Tobias

On 10/13/20 9:37 PM, Tobias Burnus wrote:
> This patch avoids putting some [...] files to /tmp/cc* when
> -save-temps has been specified.
>
> For my testcase, it now generates:
> a.lto_wrapper_args
> a.offload_args
> a.xnvptx-none.args
> a.xnvptx-none.gcc_args
> a.xamdgcn-amdhsa.gcc_args
> a.xamdgcn-amdhsa.gccnative_args
> a.xamdgcn-amdhsa.ld_args
>
>
> This patch adds an additional argument to collect-utils.c's
> collect_execute (and is wrapper fork_execute) which, if not NULL,
> it is used in 'concat (dumppfx, atsuffix, NULL);'.
>
> This patch adds a suffix to gcc/config/gcn/mkoffload.c,
> gcc/config/nvptx/mkoffload.c and gcc/lto-wrapper.c.
>
> It does not (yet) add a suffix to gcc/collect2.c and
> gcc/config/i386/intelmic-mkoffload.c but just passes
> NULL; for intelmic it is not a work item as it does
> not use '@' files at all.
>
> Hopefully, there is no file which is written twice
> with the same name (or otherwise overridden) and
> the files names do make sense.
>
> OK?
>
> Tobias
>
> PS: There is still cceBdzZk.ofldlist (via lto-plugin/lto-plugin.c),
> and @/tmp/cc* in calls to lto1 and collect2. And collect2.c
> passes NULL also when use_atfile is true.
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Comments

Richard Biener Oct. 20, 2020, 9:27 a.m. UTC | #1
On Mon, 19 Oct 2020, Tobias Burnus wrote:

> PING.
> 
> Attached patch has a minor change: the renamed suffixes for nvptx as
> suggested by Tom
> (and for considency, 'ltrans.args' ? 'ltrans_args').
> 
> OK?

OK.

Thanks,
Richard.

> Tobias
> 
> On 10/13/20 9:37 PM, Tobias Burnus wrote:
> > This patch avoids putting some [...] files to /tmp/cc* when
> > -save-temps has been specified.
> >
> > For my testcase, it now generates:
> > a.lto_wrapper_args
> > a.offload_args
> > a.xnvptx-none.args
> > a.xnvptx-none.gcc_args
> > a.xamdgcn-amdhsa.gcc_args
> > a.xamdgcn-amdhsa.gccnative_args
> > a.xamdgcn-amdhsa.ld_args
> >
> >
> > This patch adds an additional argument to collect-utils.c's
> > collect_execute (and is wrapper fork_execute) which, if not NULL,
> > it is used in 'concat (dumppfx, atsuffix, NULL);'.
> >
> > This patch adds a suffix to gcc/config/gcn/mkoffload.c,
> > gcc/config/nvptx/mkoffload.c and gcc/lto-wrapper.c.
> >
> > It does not (yet) add a suffix to gcc/collect2.c and
> > gcc/config/i386/intelmic-mkoffload.c but just passes
> > NULL; for intelmic it is not a work item as it does
> > not use '@' files at all.
> >
> > Hopefully, there is no file which is written twice
> > with the same name (or otherwise overridden) and
> > the files names do make sense.
> >
> > OK?
> >
> > Tobias
> >
> > PS: There is still cceBdzZk.ofldlist (via lto-plugin/lto-plugin.c),
> > and @/tmp/cc* in calls to lto1 and collect2. And collect2.c
> > passes NULL also when use_atfile is true.
> -----------------
> Mentor Graphics (Deutschland) GmbH, Arnulfstra?e 201, 80634 M?nchen / Germany
> Registergericht M?nchen HRB 106955, Gesch?ftsf?hrer: Thomas Heurung, Alexander
> Walter
> 
>
Tobias Burnus Oct. 20, 2020, 5:49 p.m. UTC | #2
On 10/20/20 11:27 AM, Richard Biener wrote:

> OK.

Missed two things – a copy'n'paste issue using the wrong variable and to
update a testcase, adding the newly added dump files there.

Committed as obvious in r11-4132-g6267bb7a11f53381d77b2c0a6193fcb9115d2b30

Tobias

On 10/13/20 9:37 PM, Tobias Burnus wrote:
>>> This patch avoids putting some [...] files to /tmp/cc* when
>>> -save-temps has been specified.
>>>
>>> For my testcase, it now generates:
>>> a.lto_wrapper_args
>>> a.offload_args
>>> a.xnvptx-none.args
>>> a.xnvptx-none.gcc_args
>>> a.xamdgcn-amdhsa.gcc_args
>>> a.xamdgcn-amdhsa.gccnative_args
>>> a.xamdgcn-amdhsa.ld_args
>>>
>>>
>>> This patch adds an additional argument to collect-utils.c's
>>> collect_execute (and is wrapper fork_execute) which, if not NULL,
>>> it is used in 'concat (dumppfx, atsuffix, NULL);'.
>>>
>>> This patch adds a suffix to gcc/config/gcn/mkoffload.c,
>>> gcc/config/nvptx/mkoffload.c and gcc/lto-wrapper.c.
>>>
>>> It does not (yet) add a suffix to gcc/collect2.c and
>>> gcc/config/i386/intelmic-mkoffload.c but just passes
>>> NULL; for intelmic it is not a work item as it does
>>> not use '@' files at all.
>>>
>>> Hopefully, there is no file which is written twice
>>> with the same name (or otherwise overridden) and
>>> the files names do make sense.
>>>
>>> OK?
>>>
>>> Tobias
>>>
>>> PS: There is still cceBdzZk.ofldlist (via lto-plugin/lto-plugin.c),
>>> and @/tmp/cc* in calls to lto1 and collect2. And collect2.c
>>> passes NULL also when use_atfile is true.
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
diff mbox series

Patch

collect-utils.c, lto-wrapper + mkoffload: Improve -save-temps filename

gcc/ChangeLog:

	* collect-utils.c (collect_execute, fork_execute): Add at-file suffix
	argument.
	* collect-utils.h (collect_execute, fork_execute): Update prototype.
	* collect2.c (maybe_run_lto_and_relink, do_link, main, do_dsymutil):
	Update calls by passing NULL.
	* config/i386/intelmic-mkoffload.c (compile_for_target,
	generate_host_descr_file, prepare_target_image, main): Likewise.
	* config/gcn/mkoffload.c (compile_native, main): Pass at-file suffix.
	* config/nvptx/mkoffload.c (compile_native, main): Likewise.
	* lto-wrapper.c (compile_offload_image): Likewise.

 gcc/collect-utils.c                  | 13 +++++++++----
 gcc/collect-utils.h                  |  4 ++--
 gcc/collect2.c                       | 17 +++++++++--------
 gcc/config/gcn/mkoffload.c           |  7 ++++---
 gcc/config/i386/intelmic-mkoffload.c | 12 ++++++------
 gcc/config/nvptx/mkoffload.c         |  6 ++++--
 gcc/lto-wrapper.c                    | 13 +++++++++----
 7 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/gcc/collect-utils.c b/gcc/collect-utils.c
index d4fa2c3d345..095db8d7547 100644
--- a/gcc/collect-utils.c
+++ b/gcc/collect-utils.c
@@ -104,7 +104,8 @@  do_wait (const char *prog, struct pex_obj *pex)
 
 struct pex_obj *
 collect_execute (const char *prog, char **argv, const char *outname,
-		 const char *errname, int flags, bool use_atfile)
+		 const char *errname, int flags, bool use_atfile,
+		 const char *atsuffix)
 {
   struct pex_obj *pex;
   const char *errmsg;
@@ -126,7 +127,10 @@  collect_execute (const char *prog, char **argv, const char *outname,
       /* Note: we assume argv contains at least one element; this is
          checked above.  */
 
-      response_file = make_temp_file ("");
+      if (!save_temps || !atsuffix)
+	response_file = make_temp_file ("");
+      else
+	response_file = concat (dumppfx, atsuffix, NULL);
 
       f = fopen (response_file, "w");
 
@@ -202,12 +206,13 @@  collect_execute (const char *prog, char **argv, const char *outname,
 }
 
 void
-fork_execute (const char *prog, char **argv, bool use_atfile)
+fork_execute (const char *prog, char **argv, bool use_atfile,
+	      const char *atsuffix)
 {
   struct pex_obj *pex;
 
   pex = collect_execute (prog, argv, NULL, NULL,
-			 PEX_LAST | PEX_SEARCH, use_atfile);
+			 PEX_LAST | PEX_SEARCH, use_atfile, atsuffix);
   do_wait (prog, pex);
 }
 
diff --git a/gcc/collect-utils.h b/gcc/collect-utils.h
index 6ff7d9d96df..482225764a9 100644
--- a/gcc/collect-utils.h
+++ b/gcc/collect-utils.h
@@ -27,10 +27,10 @@  extern void fatal_signal (int);
 
 extern struct pex_obj *collect_execute (const char *, char **,
 					const char *, const char *,
-					int, bool);
+					int, bool, const char *);
 extern int collect_wait (const char *, struct pex_obj *);
 extern void do_wait (const char *, struct pex_obj *);
-extern void fork_execute (const char *, char **, bool);
+extern void fork_execute (const char *, char **, bool, const char *);
 extern void utils_cleanup (bool);
 
 
diff --git a/gcc/collect2.c b/gcc/collect2.c
index 6d074a79e91..3a43a5a61aa 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -644,7 +644,7 @@  maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
 
       /* Run the LTO back end.  */
       pex = collect_execute (prog, lto_c_argv, NULL, NULL, PEX_SEARCH,
-			     at_file_supplied);
+			     at_file_supplied, NULL);
       {
 	int c;
 	FILE *stream;
@@ -727,7 +727,8 @@  maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
 
       /* Run the linker again, this time replacing the object files
          optimized by the LTO with the temporary file generated by the LTO.  */
-      fork_execute ("ld", out_lto_ld_argv, HAVE_GNU_LD && at_file_supplied);
+      fork_execute ("ld", out_lto_ld_argv, HAVE_GNU_LD && at_file_supplied,
+		    NULL);
       /* We assume that temp files were created, and therefore we need to take
          that into account (maybe run dsymutil).  */
       post_ld_pass (/*temp_file*/true);
@@ -739,7 +740,7 @@  maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
     {
       /* Our caller is relying on us to do the link
          even though there is no LTO back end work to be done.  */
-      fork_execute ("ld", lto_ld_argv, HAVE_GNU_LD && at_file_supplied);
+      fork_execute ("ld", lto_ld_argv, HAVE_GNU_LD && at_file_supplied, NULL);
       /* No LTO objects were found, so no new temp file.  */
       post_ld_pass (/*temp_file*/false);
     }
@@ -756,7 +757,7 @@  do_link (char **ld_argv)
   const char *prog = "ld";
   pex = collect_execute (prog, ld_argv, NULL, NULL,
 			 PEX_LAST | PEX_SEARCH,
-			 HAVE_GNU_LD && at_file_supplied);
+			 HAVE_GNU_LD && at_file_supplied, NULL);
   int ret = collect_wait (prog, pex);
   if (ret)
     {
@@ -1722,7 +1723,7 @@  main (int argc, char **argv)
 	  strip_argv[0] = strip_file_name;
 	  strip_argv[1] = output_file;
 	  strip_argv[2] = (char *) 0;
-	  fork_execute ("strip", real_strip_argv, false);
+	  fork_execute ("strip", real_strip_argv, false, NULL);
 	}
 
 #ifdef COLLECT_EXPORT_LIST
@@ -1805,7 +1806,7 @@  main (int argc, char **argv)
   /* Assemble the constructor and destructor tables.
      Link the tables in with the rest of the program.  */
 
-  fork_execute ("gcc",  c_argv, at_file_supplied);
+  fork_execute ("gcc",  c_argv, at_file_supplied, NULL);
 #ifdef COLLECT_EXPORT_LIST
   /* On AIX we must call link because of possible templates resolution.  */
   do_link (ld2_argv);
@@ -1818,7 +1819,7 @@  main (int argc, char **argv)
     maybe_run_lto_and_relink (ld2_argv, object_lst, object, true);
   else
     {
-      fork_execute ("ld", ld2_argv, HAVE_GNU_LD && at_file_supplied);
+      fork_execute ("ld", ld2_argv, HAVE_GNU_LD && at_file_supplied, NULL);
       post_ld_pass (/*temp_file*/false);
     }
 
@@ -3040,7 +3041,7 @@  do_dsymutil (const char *output_file) {
   argv[2] = (char *) 0;
 
   pex = collect_execute (dsymutil, real_argv, NULL, NULL,
-			 PEX_LAST | PEX_SEARCH, false);
+			 PEX_LAST | PEX_SEARCH, false, NULL);
   do_wait (dsymutil, pex);
 }
 
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 0983b98e178..f7589a5a78c 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -737,7 +737,8 @@  compile_native (const char *infile, const char *outfile, const char *compiler,
   obstack_ptr_grow (&argv_obstack, NULL);
 
   const char **new_argv = XOBFINISH (&argv_obstack, const char **);
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true);
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true,
+		".gccnative_args");
   obstack_free (&argv_obstack, NULL);
 }
 
@@ -1001,7 +1002,7 @@  main (int argc, char **argv)
   unsetenv ("LIBRARY_PATH");
 
   /* Run the compiler pass.  */
-  fork_execute (cc_argv[0], CONST_CAST (char **, cc_argv), true);
+  fork_execute (cc_argv[0], CONST_CAST (char **, cc_argv), true,  ".gcc_args");
   obstack_free (&cc_argv_obstack, NULL);
 
   in = fopen (gcn_s1_name, "r");
@@ -1022,7 +1023,7 @@  main (int argc, char **argv)
   fclose (out);
 
   /* Run the assemble/link pass.  */
-  fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true);
+  fork_execute (ld_argv[0], CONST_CAST (char **, ld_argv), true, ".ld_args");
   obstack_free (&ld_argv_obstack, NULL);
 
   in = fopen (gcn_o_name, "r");
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index 15b5c3d771a..668208c1b23 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -231,7 +231,7 @@  compile_for_target (struct obstack *argv_obstack)
   unsetenv ("LIBRARY_PATH");
   unsetenv ("LD_RUN_PATH");
 
-  fork_execute (argv[0], argv, false);
+  fork_execute (argv[0], argv, false, NULL);
   obstack_free (argv_obstack, NULL);
 
   /* Restore environment variables.  */
@@ -455,7 +455,7 @@  generate_host_descr_file (const char *host_compiler)
   obstack_ptr_grow (&argv_obstack, NULL);
 
   char **argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (argv[0], argv, false);
+  fork_execute (argv[0], argv, false, NULL);
   obstack_free (&argv_obstack, NULL);
 
   return obj_filename;
@@ -538,7 +538,7 @@  prepare_target_image (const char *target_compiler, int argc, char **argv)
   obstack_ptr_grow (&argv_obstack, rename_section_opt);
   obstack_ptr_grow (&argv_obstack, NULL);
   char **new_argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (new_argv[0], new_argv, false);
+  fork_execute (new_argv[0], new_argv, false, NULL);
   obstack_free (&argv_obstack, NULL);
 
   /* Objcopy has created symbols, containing the input file name with
@@ -580,7 +580,7 @@  prepare_target_image (const char *target_compiler, int argc, char **argv)
   obstack_ptr_grow (&argv_obstack, opt_for_objcopy[2]);
   obstack_ptr_grow (&argv_obstack, NULL);
   new_argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (new_argv[0], new_argv, false);
+  fork_execute (new_argv[0], new_argv, false, NULL);
   obstack_free (&argv_obstack, NULL);
 
   return target_so_filename;
@@ -672,7 +672,7 @@  main (int argc, char **argv)
   obstack_ptr_grow (&argv_obstack, out_obj_filename);
   obstack_ptr_grow (&argv_obstack, NULL);
   char **new_argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (new_argv[0], new_argv, false);
+  fork_execute (new_argv[0], new_argv, false, NULL);
   obstack_free (&argv_obstack, NULL);
 
   /* Run objcopy on the resultant object file to localize generated symbols
@@ -688,7 +688,7 @@  main (int argc, char **argv)
   obstack_ptr_grow (&argv_obstack, out_obj_filename);
   obstack_ptr_grow (&argv_obstack, NULL);
   new_argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (new_argv[0], new_argv, false);
+  fork_execute (new_argv[0], new_argv, false, NULL);
   obstack_free (&argv_obstack, NULL);
 
   return 0;
diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c
index 7c43e617dcf..a3c4099b9e7 100644
--- a/gcc/config/nvptx/mkoffload.c
+++ b/gcc/config/nvptx/mkoffload.c
@@ -399,7 +399,8 @@  compile_native (const char *infile, const char *outfile, const char *compiler,
   obstack_ptr_grow (&argv_obstack, NULL);
 
   const char **new_argv = XOBFINISH (&argv_obstack, const char **);
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true);
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true,
+		".gccnative_args");
   obstack_free (&argv_obstack, NULL);
 }
 
@@ -582,7 +583,8 @@  main (int argc, char **argv)
       unsetenv ("COMPILER_PATH");
       unsetenv ("LIBRARY_PATH");
 
-      fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true);
+      fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true,
+		    ".gcc_args");
       obstack_free (&argv_obstack, NULL);
 
       xputenv (concat ("GCC_EXEC_PREFIX=", execpath, NULL));
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 4d93313241d..e458347860c 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -950,7 +950,7 @@  compile_offload_image (const char *target, const char *compiler_path,
 
   obstack_ptr_grow (&argv_obstack, NULL);
   argv = XOBFINISH (&argv_obstack, char **);
-  fork_execute (argv[0], argv, true);
+  fork_execute (argv[0], argv, true, "offload_args");
   obstack_free (&argv_obstack, NULL);
 
   free_array_of_ptrs ((void **) paths, n_paths);
@@ -1777,7 +1777,8 @@  cont1:
 
   new_argv = XOBFINISH (&argv_obstack, const char **);
   argv_ptr = &new_argv[new_head_argc];
-  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true);
+  fork_execute (new_argv[0], CONST_CAST (char **, new_argv), true,
+		"ltrans_args");
 
   /* Copy the early generated debug info from the objects to temporary
      files and append those to the partial link commandline.  */
@@ -1921,8 +1922,12 @@  cont:
 	    }
 	  else
 	    {
+	      char argsuffix[sizeof (DUMPBASE_SUFFIX) + 1];
+	      if (save_temps)
+		snprintf (dumpbase, sizeof (DUMPBASE_SUFFIX),
+			  "ltrans%u.ltrans_args", i);
 	      fork_execute (new_argv[0], CONST_CAST (char **, new_argv),
-			    true);
+			    true, save_temps ? argsuffix : NULL);
 	      maybe_unlink (input_name);
 	    }
 
@@ -1973,7 +1978,7 @@  cont:
 	  new_argv = XOBFINISH (&argv_obstack, const char **);
 
 	  pex = collect_execute (new_argv[0], CONST_CAST (char **, new_argv),
-				 NULL, NULL, PEX_SEARCH, false);
+				 NULL, NULL, PEX_SEARCH, false, NULL);
 	  do_wait (new_argv[0], pex);
 	  freeargv (make_argv);
 	  maybe_unlink (makefile);