OSDN Git Service

* Makefile.in (cgraphbuild.o): Add dependency on except.h.
[pf3gnuchains/gcc-fork.git] / gcc / collect2.c
index 481f739..6582185 100644 (file)
@@ -178,7 +178,7 @@ struct head
   int number;
 };
 
-int vflag;                             /* true if -v */
+bool vflag;                            /* true if -v or --version */ 
 static int rflag;                      /* true if -r */
 static int strip_flag;                 /* true if -s */
 static const char *demangle_flag;
@@ -197,7 +197,8 @@ enum lto_mode_d {
 /* Current LTO mode.  */
 static enum lto_mode_d lto_mode = LTO_MODE_NONE;
 
-int debug;                             /* true if -debug */
+bool debug;                            /* true if -debug */
+bool helpflag;                 /* true if --help */
 
 static int shared_obj;                 /* true if -shared */
 
@@ -1006,10 +1007,6 @@ maybe_run_lto_and_relink (char **lto_ld_argv, char **object_lst,
 
       *lto_c_ptr = NULL;
 
-      /* Save intermediate WPA files in lto1 if debug.  */
-      if (debug)
-       putenv (xstrdup ("WPA_SAVE_LTRANS=1"));
-
       /* Run the LTO back end.  */
       pex = collect_execute (prog, lto_c_argv, NULL, NULL, PEX_SEARCH);
       {
@@ -1243,7 +1240,7 @@ main (int argc, char **argv)
     for (i = 1; argv[i] != NULL; i ++)
       {
        if (! strcmp (argv[i], "-debug"))
-         debug = 1;
+         debug = true;
         else if (! strcmp (argv[i], "-flto") && ! use_plugin)
          {
            use_verbose = true;
@@ -1473,7 +1470,7 @@ main (int argc, char **argv)
       if (use_verbose && *q == '-' && q[1] == 'v' && q[2] == 0)
        {
          /* Turn on trace in collect2 if needed.  */
-         vflag = 1;
+         vflag = true;
        }
     }
   obstack_free (&temporary_obstack, temporary_firstobj);
@@ -1603,7 +1600,7 @@ main (int argc, char **argv)
 
            case 'v':
              if (arg[2] == '\0')
-               vflag = 1;
+               vflag = true;
              break;
 
            case '-':
@@ -1634,6 +1631,10 @@ main (int argc, char **argv)
                }
              else if (strncmp (arg, "--sysroot=", 10) == 0)
                target_system_root = arg + 10;
+             else if (strncmp (arg, "--version", 9) == 0)
+               vflag = true;
+             else if (strncmp (arg, "--help", 9) == 0)
+               helpflag = true;
              break;
            }
        }
@@ -1735,6 +1736,20 @@ main (int argc, char **argv)
       fprintf (stderr, "\n");
     }
 
+  if (helpflag)
+    {
+      fprintf (stderr, "Usage: collect2 [options]\n");
+      fprintf (stderr, " Wrap linker and generate constructor code if needed.\n");
+      fprintf (stderr, " Options:\n");
+      fprintf (stderr, "  -debug          Enable debug output\n");
+      fprintf (stderr, "  --help          Display this information\n");
+      fprintf (stderr, "  -v, --version   Display this program's version number\n");
+      fprintf (stderr, "Overview: http://gcc.gnu.org/onlinedocs/gccint/Collect2.html\n");
+      fprintf (stderr, "Report bugs: %s\n", bug_report_url);
+
+      collect_exit (0);
+    }
+
   if (debug)
     {
       const char *ptr;
@@ -1802,7 +1817,7 @@ main (int argc, char **argv)
        if (export_file != 0 && export_file[0])
          maybe_unlink (export_file);
 #endif
-       if (lto_mode)
+       if (lto_mode != LTO_MODE_NONE)
          maybe_run_lto_and_relink (ld1_argv, object_lst, object, false);
 
        maybe_unlink (c_file);
@@ -2548,16 +2563,23 @@ write_aix_file (FILE *stream, struct id *list)
 \f
 #ifdef OBJECT_FORMAT_NONE
 
-/* Check to make sure the file is an ELF file.  LTO objects must
-   be in ELF format.  */
+/* Check to make sure the file is an LTO object file.  */
 
 static bool
-is_elf_or_coff (const char *prog_name)
+maybe_lto_object_file (const char *prog_name)
 {
   FILE *f;
-  char buf[4];
-  static char magic[4] = { 0x7f, 'E', 'L', 'F' };
-  static char coffmag[2] = { 0x4c, 0x01 };
+  unsigned char buf[4];
+  int i;
+
+  static unsigned char elfmagic[4] = { 0x7f, 'E', 'L', 'F' };
+  static unsigned char coffmagic[2] = { 0x4c, 0x01 };
+  static unsigned char machomagic[4][4] = {
+    { 0xcf, 0xfa, 0xed, 0xfe },
+    { 0xce, 0xfa, 0xed, 0xfe },
+    { 0xfe, 0xed, 0xfa, 0xcf },
+    { 0xfe, 0xed, 0xfa, 0xce }
+  };
 
   f = fopen (prog_name, "rb");
   if (f == NULL)
@@ -2565,8 +2587,15 @@ is_elf_or_coff (const char *prog_name)
   if (fread (buf, sizeof (buf), 1, f) != 1)
     buf[0] = 0;
   fclose (f);
-  return memcmp (buf, magic, sizeof (magic)) == 0
-       || memcmp (buf, coffmag, sizeof (coffmag)) == 0;
+
+  if (memcmp (buf, elfmagic, sizeof (elfmagic)) == 0
+      || memcmp (buf, coffmagic, sizeof (coffmagic)) == 0)
+    return true;
+  for (i = 0; i < 4; i++)
+    if (memcmp (buf, machomagic[i], sizeof (machomagic[i])) == 0)
+      return true;
+
+  return false;
 }
 
 /* Generic version to scan the name list of the loaded program for
@@ -2596,7 +2625,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
   /* LTO objects must be in a known format.  This check prevents
      us from accepting an archive containing LTO objects, which
      gcc cannnot currently handle.  */
-  if (which_pass == PASS_LTOINFO && !is_elf_or_coff (prog_name))
+  if (which_pass == PASS_LTOINFO && !maybe_lto_object_file (prog_name))
     return;
 
   /* If we do not have an `nm', complain.  */