OSDN Git Service

Improve error for undefined name in imported package.
[pf3gnuchains/gcc-fork.git] / gcc / lto-wrapper.c
index 7454b54..f26b3ac 100644 (file)
@@ -32,18 +32,16 @@ along with GCC; see the file COPYING3.  If not see
    The above will print something like
    /tmp/ccwbQ8B2.lto.o
 
-   If -fwhopr is used instead, more than one file might be produced
+   If WHOPR is used instead, more than one file might be produced
    ./ccXj2DTk.lto.ltrans.o
    ./ccCJuXGv.lto.ltrans.o
 */
 
 #include "config.h"
 #include "system.h"
-#include <errno.h>
 #include "coretypes.h"
-#include "tm.h"
 #include "intl.h"
-#include "libiberty.h"
+#include "diagnostic.h"
 #include "obstack.h"
 
 int debug;                             /* true if -save-temps.  */
@@ -68,36 +66,45 @@ static char *makefile;
 
 static void maybe_unlink_file (const char *);
 
-/* Delete tempfiles and exit function.  */
+ /* Delete tempfiles.  */
 
 static void
-lto_wrapper_exit (int status)
+lto_wrapper_cleanup (void)
 {
   static bool cleanup_done = false;
-  if (!cleanup_done)
+  unsigned int i;
+
+  if (cleanup_done)
+    return;
+
+  /* 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);
+  if (makefile)
+    maybe_unlink_file (makefile);
+  for (i = 0; i < nr; ++i)
     {
-      unsigned int i;
-
-      /* 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);
-      if (makefile)
-       maybe_unlink_file (makefile);
-      for (i = 0; i < nr; ++i)
-       {
-         maybe_unlink_file (input_names[i]);
-         if (output_names[i])
-           maybe_unlink_file (output_names[i]);
-       }
+      maybe_unlink_file (input_names[i]);
+      if (output_names[i])
+       maybe_unlink_file (output_names[i]);
     }
-  exit (status);
+}
+
+static void
+fatal_signal (int signum)
+{
+  signal (signum, SIG_DFL);
+  lto_wrapper_cleanup ();
+  /* Get the same signal again, this time not handled,
+     so its normal effect occurs.  */
+  kill (getpid (), signum);
 }
 
 /* Just die. CMSGID is the error message. */
@@ -113,7 +120,8 @@ fatal (const char * cmsgid, ...)
   fprintf (stderr, "\n");
   va_end (ap);
 
-  lto_wrapper_exit (FATAL_EXIT_CODE);
+  lto_wrapper_cleanup ();
+  exit (FATAL_EXIT_CODE);
 }
 
 
@@ -131,7 +139,8 @@ fatal_perror (const char *cmsgid, ...)
   fprintf (stderr, ": %s\n", xstrerror (e));
   va_end (ap);
 
-  lto_wrapper_exit (FATAL_EXIT_CODE);
+  lto_wrapper_cleanup ();
+  exit (FATAL_EXIT_CODE);
 }
 
 
@@ -285,6 +294,8 @@ run_gcc (unsigned argc, char *argv[])
   struct obstack env_obstack;
   bool seen_o = false;
   int parallel = 0;
+  int jobserver = 0;
+  bool no_partition = false;
 
   /* Get the driver and options.  */
   collect_gcc = getenv ("COLLECT_GCC");
@@ -347,26 +358,42 @@ run_gcc (unsigned argc, char *argv[])
        if (strcmp (option, "-v") == 0)
          verbose = 1;
 
+       if (strcmp (option, "-flto-partition=none") == 0)
+         no_partition = true;
        /* We've handled these LTO options, do not pass them on.  */
-       if (strcmp (option, "-flto") == 0)
-         lto_mode = LTO_MODE_LTO;
-       else if (strncmp (option, "-fwhopr", 7) == 0)
+       if (strncmp (option, "-flto=", 6) == 0
+           || !strcmp (option, "-flto"))
          {
            lto_mode = LTO_MODE_WHOPR;
-           if (option[7] == '=')
+           if (option[5] == '=')
              {
-               parallel = atoi (option+8);
-               if (parallel <= 1)
-                 parallel = 0;
+               if (!strcmp (option + 6, "jobserver"))
+                 {
+                   jobserver = 1;
+                   parallel = 1;
+                 }
+               else
+                 {
+                   parallel = atoi (option + 6);
+                   if (parallel <= 1)
+                     parallel = 0;
+                 }
              }
          }
        else
          *argv_ptr++ = option;
       }
+  if (no_partition)
+    {
+      lto_mode = LTO_MODE_LTO;
+      jobserver = 0;
+      parallel = 0;
+    }
 
   if (linker_output)
     {
       char *output_dir, *base, *name;
+      bool bit_bucket = strcmp (linker_output, HOST_BIT_BUCKET) == 0;
 
       output_dir = xstrdup (linker_output);
       base = output_dir;
@@ -381,8 +408,11 @@ run_gcc (unsigned argc, char *argv[])
          static char current_dir[] = { '.', DIR_SEPARATOR, '\0' };
          output_dir = current_dir;
        }
-      *argv_ptr++ = "-dumpdir";
-      *argv_ptr++ = output_dir;
+      if (!bit_bucket)
+       {
+         *argv_ptr++ = "-dumpdir";
+         *argv_ptr++ = output_dir;
+       }
 
       *argv_ptr++ = "-dumpbase";
     }
@@ -396,9 +426,8 @@ run_gcc (unsigned argc, char *argv[])
        argv_ptr[0] = linker_output;
       argv_ptr[1] = "-o";
       argv_ptr[2] = flto_out;
-      argv_ptr[3] = "-combine";
     }
-  else if (lto_mode == LTO_MODE_WHOPR)
+  else 
     {
       const char *list_option = "-fltrans-output-list=";
       size_t list_option_len = strlen (list_option);
@@ -407,13 +436,21 @@ run_gcc (unsigned argc, char *argv[])
       if (linker_output)
        {
          char *dumpbase = (char *) xmalloc (strlen (linker_output)
-                                            + sizeof(".wpa") + 1);
+                                            + sizeof (".wpa") + 1);
          strcpy (dumpbase, linker_output);
          strcat (dumpbase, ".wpa");
          argv_ptr[0] = dumpbase;
        }
 
-      ltrans_output_file = make_temp_file (".ltrans.out");
+      if (linker_output && debug)
+       {
+         ltrans_output_file = (char *) xmalloc (strlen (linker_output)
+                                                + sizeof (".ltrans.out") + 1);
+         strcpy (ltrans_output_file, linker_output);
+         strcat (ltrans_output_file, ".ltrans.out");
+       }
+      else
+       ltrans_output_file = make_temp_file (".ltrans.out");
       list_option_full = (char *) xmalloc (sizeof (char) *
                         (strlen (ltrans_output_file) + list_option_len + 1));
       tmp = list_option_full;
@@ -424,15 +461,12 @@ run_gcc (unsigned argc, char *argv[])
       strcpy (tmp, ltrans_output_file);
 
       argv_ptr[2] = "-fwpa";
-      argv_ptr[3] = "-combine";
     }
-  else
-    fatal ("invalid LTO mode");
 
   /* Append the input objects and possible preceeding arguments.  */
   for (i = 1; i < argc; ++i)
-    argv_ptr[3 + i] = argv[i];
-  argv_ptr[3 + i] = NULL;
+    argv_ptr[2 + i] = argv[i];
+  argv_ptr[2 + i] = NULL;
 
   fork_execute (CONST_CAST (char **, new_argv));
 
@@ -442,7 +476,7 @@ run_gcc (unsigned argc, char *argv[])
       free (flto_out);
       flto_out = NULL;
     }
-  else if (lto_mode == LTO_MODE_WHOPR)
+  else
     {
       FILE *stream = fopen (ltrans_output_file, "r");
       FILE *mstream = NULL;
@@ -516,7 +550,7 @@ cont:
                                      + sizeof(DUMPBASE_SUFFIX) + 1);
              snprintf (dumpbase,
                        strlen (linker_output) + sizeof(DUMPBASE_SUFFIX),
-                       "%s.ltrans%u", linker_output, nr);
+                       "%s.ltrans%u", linker_output, i);
              argv_ptr[0] = dumpbase;
            }
 
@@ -541,23 +575,32 @@ cont:
        {
          struct pex_obj *pex;
          char jobs[32];
+
          fprintf (mstream, "all:");
          for (i = 0; i < nr; ++i)
            fprintf (mstream, " \\\n\t%s", output_names[i]);
          fprintf (mstream, "\n");
          fclose (mstream);
-         /* Avoid passing --jobserver-fd= and similar flags.  */
-         putenv (xstrdup ("MAKEFLAGS="));
-         putenv (xstrdup ("MFLAGS="));
+         if (!jobserver)
+           {
+             /* Avoid passing --jobserver-fd= and similar flags 
+                unless jobserver mode is explicitly enabled.  */
+             putenv (xstrdup ("MAKEFLAGS="));
+             putenv (xstrdup ("MFLAGS="));
+           }
          new_argv[0] = getenv ("MAKE");
          if (!new_argv[0])
            new_argv[0] = "make";
          new_argv[1] = "-f";
          new_argv[2] = makefile;
-         snprintf (jobs, 31, "-j%d", parallel);
-         new_argv[3] = jobs;
-         new_argv[4] = "all";
-         new_argv[5] = NULL;
+         i = 3;
+         if (!jobserver)
+           {
+             snprintf (jobs, 31, "-j%d", parallel);
+             new_argv[i++] = jobs;
+           }
+         new_argv[i++] = "all";
+         new_argv[i++] = NULL;
          pex = collect_execute (CONST_CAST (char **, new_argv));
          collect_wait (new_argv[0], pex);
          maybe_unlink_file (makefile);
@@ -575,8 +618,6 @@ cont:
       free (input_names);
       free (list_option_full);
     }
-  else
-    fatal ("invalid LTO mode");
 
   obstack_free (&env_obstack, NULL);
 }
@@ -587,8 +628,37 @@ cont:
 int
 main (int argc, char *argv[])
 {
+  const char *p;
+
+  p = argv[0] + strlen (argv[0]);
+  while (p != argv[0] && !IS_DIR_SEPARATOR (p[-1]))
+    --p;
+  progname = p;
+
+  xmalloc_set_program_name (progname);
+
   gcc_init_libintl ();
 
+  diagnostic_initialize (global_dc, 0);
+
+  if (signal (SIGINT, SIG_IGN) != SIG_IGN)
+    signal (SIGINT, fatal_signal);
+#ifdef SIGHUP
+  if (signal (SIGHUP, SIG_IGN) != SIG_IGN)
+    signal (SIGHUP, fatal_signal);
+#endif
+  if (signal (SIGTERM, SIG_IGN) != SIG_IGN)
+    signal (SIGTERM, fatal_signal);
+#ifdef SIGPIPE
+  if (signal (SIGPIPE, SIG_IGN) != SIG_IGN)
+    signal (SIGPIPE, fatal_signal);
+#endif
+#ifdef SIGCHLD
+  /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will
+     receive the signal.  A different setting is inheritable */
+  signal (SIGCHLD, SIG_DFL);
+#endif
+
   /* We may be called with all the arguments stored in some file and
      passed with @file.  Expand them into argv before processing.  */
   expandargv (&argc, &argv);