[PATCH, driver specs][3] Put -flto-partition= on the collect2 c/l

Iain Sandoe iain@sandoe.co.uk
Wed Aug 22 13:06:00 GMT 2018


> On 20 Aug 2018, at 11:01, Richard Biener <richard.guenther@gmail.com> wrote:
> 
> On Sat, Aug 18, 2018 at 9:00 PM Iain Sandoe <iain@sandoe.co.uk> wrote:
>> 
>> Hi
>> 
>> While working on the Darwin LTO issues I noticed that collect2 looks for "-flto-partition=none” in its command line option, but it doesn’t get passed.
>> 
>> So - is the attached patch the right idea, or should collect2 be looking in the COLLECT_GCC_OPTIONS as the lto-wrapper does?
> 
> Looking at COLLECT_GCC_OPTIONS is probably better.

related;  
collect2 is currently “non-obvious” in that it doesn’t respond to -save-temps and to get the tempories saved we have to invoke “-debug” which produces a bunch of other output we probably don’t care about most times.

So .. perhaps we could move to 
 -save-temps (does the “usual thing”)
 -v (does the “usual thing”)
 -debug imples the two above + other informative output

(it would be kinda nice if there was some way to implement -### so that we could see the collect subordinate pass structure)

comments?
thanks
Iain

gcc/
	* collect2.c (main): Parse the output file early so we can make nicer
	temp names.  Respond to “-save-temps” in the GCC OPTIONS.
	(maybe_unlink): Don’t print “[Leaving…”] for files we never created
	and don’t exist.

---
 gcc/collect2.c | 57 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 43 insertions(+), 14 deletions(-)

diff --git a/gcc/collect2.c b/gcc/collect2.c
index 4b0f191ad3..b892e1a2aa 100644
--- a/gcc/collect2.c
+++ b/gcc/collect2.c
@@ -205,8 +205,8 @@ bool helpflag;			/* true if --help */
 static int shared_obj;			/* true if -shared */
 static int static_obj;			/* true if -static */
 
-static const char *c_file;		/* <xxx>.c for constructor/destructor list.  */
-static const char *o_file;		/* <xxx>.o for constructor/destructor list.  */
+static char *c_file;		/* <xxx>.c for constructor/destructor list.  */
+static char *o_file;		/* <xxx>.o for constructor/destructor list.  */
 #ifdef COLLECT_EXPORT_LIST
 static const char *export_file;		/* <xxx>.x for AIX export list.  */
 #endif
@@ -989,6 +989,13 @@ main (int argc, char **argv)
 
   save_temps = false;
   verbose = false;
+
+#ifndef DEFAULT_A_OUT_NAME
+  output_file = "a.out";
+#else
+  output_file = DEFAULT_A_OUT_NAME;
+#endif
+
   /* Parse command line / environment for flags we want early.
      This allows the debug flag to be set before functions like find_a_file()
      are called. */
@@ -1011,7 +1018,17 @@ main (int argc, char **argv)
 	  selected_linker = USE_BFD_LD;
 	else if (strcmp (argv[i], "-fuse-ld=gold") == 0)
 	  selected_linker = USE_GOLD_LD;
-
+	else if (strncmp (argv[i], "-o", 2) == 0)
+	  {
+	    /* Parse the output filename if it's given so that we can make
+	       meaningful temp filenames.  */
+	    if (argv[i][2] == '\0')
+	      output_file = argv[i+1];
+	    else if (argv[i][2] == '=')
+	      output_file = &argv[i][3];
+	    else
+	      output_file = &argv[i][2];
+	  }
 #ifdef COLLECT_EXPORT_LIST
 	/* These flags are position independent, although their order
 	   is important - subsequent flags override earlier ones. */
@@ -1032,12 +1049,6 @@ main (int argc, char **argv)
 #endif
       }
 
-#ifndef DEFAULT_A_OUT_NAME
-  output_file = "a.out";
-#else
-  output_file = DEFAULT_A_OUT_NAME;
-#endif
-
     obstack_begin (&temporary_obstack, 0);
     temporary_firstobj = (char *) obstack_alloc (&temporary_obstack, 0);
 
@@ -1058,6 +1069,9 @@ main (int argc, char **argv)
 	  no_partition = true;
 	else if (strncmp (q, "-fno-lto", 8) == 0)
 	  lto_mode = LTO_MODE_NONE;
+	else if (strncmp (q, "-save-temps", 11) == 0)
+	  /* FIXME: Honour =obj.  */
+	  save_temps = true;
     }
     obstack_free (&temporary_obstack, temporary_firstobj);
 
@@ -1217,8 +1231,22 @@ main (int argc, char **argv)
   *ld1++ = *ld2++ = ld_file_name;
 
   /* Make temp file names.  */
-  c_file = make_temp_file (".c");
-  o_file = make_temp_file (".o");
+  if (save_temps)
+    {
+      c_file = (char *) xmalloc (strlen (output_file)
+				  + sizeof (".cdtor.c") + 1);
+      strcpy (c_file, output_file);
+      strcat (c_file, ".cdtor.c");
+      o_file = (char *) xmalloc (strlen (output_file)
+				  + sizeof (".cdtor.o") + 1);
+      strcpy (o_file, output_file);
+      strcat (o_file, ".cdtor.o");
+    }
+  else
+    {
+      c_file = make_temp_file (".cdtor.c");
+      o_file = make_temp_file (".cdtor.o");
+    }
 #ifdef COLLECT_EXPORT_LIST
   export_file = make_temp_file (".x");
 #endif
@@ -1227,6 +1255,7 @@ main (int argc, char **argv)
       ldout = make_temp_file (".ld");
       lderrout = make_temp_file (".le");
     }
+  /* Build the command line to compile the ctor/dtor list.  */
   *c_ptr++ = c_file_name;
   *c_ptr++ = "-x";
   *c_ptr++ = "c";
@@ -1440,6 +1469,8 @@ main (int argc, char **argv)
 	    case 'o':
 	      if (arg[2] == '\0')
 		output_file = *ld1++ = *ld2++ = *++argv;
+	      else if (arg[2] == '=')
+		output_file = &arg[3];
 	      else
 		output_file = &arg[2];
 	      break;
@@ -1684,8 +1715,6 @@ main (int argc, char **argv)
 	else
 	  post_ld_pass (/*temp_file*/false);
 
-	maybe_unlink (c_file);
-	maybe_unlink (o_file);
 	return 0;
       }
   }
@@ -1873,7 +1902,7 @@ main (int argc, char **argv)
 void
 maybe_unlink (const char *file)
 {
-  if (debug)
+  if (save_temps && file_exists (file))
     {
       notice ("[Leaving %s]\n", file);
       return;
-- 
2.17.1




More information about the Gcc-patches mailing list