OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / lto-wrapper.c
index 228a0a4..ec0a96e 100644 (file)
@@ -1,5 +1,5 @@
 /* Wrapper to call lto.  Used by collect2 and the linker plugin.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 
    Factored out of collect2 by Rafael Espindola <espindola@google.com>
 
@@ -55,6 +55,34 @@ enum lto_mode_d {
 /* Current LTO mode.  */
 static enum lto_mode_d lto_mode = LTO_MODE_NONE;
 
+static char *ltrans_output_file;
+static char *flto_out;
+static char *args_name;
+
+static void maybe_unlink_file (const char *);
+
+/* Delete tempfiles and exit function.  */
+
+static void
+lto_wrapper_exit (int status)
+{
+  static bool cleanup_done = false;
+  if (!cleanup_done)
+    {
+      /* Setting cleanup_done prevents an infinite loop if one of the
+         calls to maybe_unlink_file fails. */
+      cleanup_done = true;
+
+      if (ltrans_output_file)
+        maybe_unlink_file (ltrans_output_file);
+      if (flto_out)
+        maybe_unlink_file (flto_out);
+      if (args_name)
+        maybe_unlink_file (args_name);
+    }
+  exit (status);
+}
+
 /* Just die. CMSGID is the error message. */
 
 static void __attribute__ ((format (printf, 1, 2)))
@@ -68,7 +96,7 @@ fatal (const char * cmsgid, ...)
   fprintf (stderr, "\n");
   va_end (ap);
 
-  exit (FATAL_EXIT_CODE);
+  lto_wrapper_exit (FATAL_EXIT_CODE);
 }
 
 
@@ -86,7 +114,7 @@ fatal_perror (const char *cmsgid, ...)
   fprintf (stderr, ": %s\n", xstrerror (e));
   va_end (ap);
 
-  exit (FATAL_EXIT_CODE);
+  lto_wrapper_exit (FATAL_EXIT_CODE);
 }
 
 
@@ -190,11 +218,13 @@ fork_execute (char **argv)
 {
   struct pex_obj *pex;
   char *new_argv[3];
-  char *args_name = make_temp_file (".args");
-  char *at_args = concat ("@", args_name, NULL);
-  FILE *args = fopen (args_name, "w");
+  char *at_args;
+  FILE *args;
   int status;
 
+  args_name = make_temp_file (".args");
+  at_args = concat ("@", args_name, NULL);
+  args = fopen (args_name, "w");
   if (args == NULL)
     fatal ("failed to open %s", args_name);
 
@@ -213,7 +243,6 @@ fork_execute (char **argv)
   collect_wait (new_argv[0], pex);
 
   maybe_unlink_file (args_name);
-  free (args_name);
   free (at_args);
 }
 
@@ -227,11 +256,9 @@ run_gcc (unsigned argc, char *argv[])
   unsigned new_argc = argc;
   const char **new_argv;
   const char **argv_ptr;
-  char *ltrans_output_file = NULL;
-  char *flto_out = NULL;
   char *list_option_full = NULL;
 
-  new_argc += 8;
+  new_argc += 12;
   new_argv = (const char **) xcalloc (sizeof (char *), new_argc);
 
   argv_ptr = new_argv;
@@ -289,7 +316,31 @@ run_gcc (unsigned argc, char *argv[])
             temporary file for the LTO output.  The `-o' option
             will be interpreted by the linker.  */
          if (s[2] == '\0')
-           i++;
+           {
+             char *output_dir, *base, *name;
+
+             i++;
+             output_dir = xstrdup (argv[i]);
+             base = output_dir;
+             for (name = base; *name; name++)
+               if (IS_DIR_SEPARATOR (*name))
+                 base = name + 1;
+             *base = '\0';
+
+             *argv_ptr++ = "-dumpbase";
+             if (*output_dir == '\0')
+               {
+                 static char current_dir[] =
+                   { '.', DIR_SEPARATOR, '\0' };
+                 output_dir = current_dir;
+                 *argv_ptr++ = argv[i];
+               }
+             else
+               *argv_ptr++ = &argv[i][base - output_dir];
+
+             *argv_ptr++ = "-dumpdir";
+             *argv_ptr++ = output_dir;
+           }
        }
       else
        /* Pass the option or argument to LTO.  */
@@ -320,7 +371,6 @@ run_gcc (unsigned argc, char *argv[])
        putc (c, stdout);
       fclose (stream);
       maybe_unlink_file (ltrans_output_file);
-      free (ltrans_output_file);
       free (list_option_full);
     }
   else