Small cleanups before making collect2 use collect-utils.
authorbernds <bernds@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 26 Jun 2014 09:16:19 +0000 (09:16 +0000)
committerbernds <bernds@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 26 Jun 2014 09:16:19 +0000 (09:16 +0000)
* collect-utils.c (save_temps): New variable.
(do_wait): Use it instead of debug.  Use fatal_error.
* collect-utils.h (save_temps): Declare.
* collect2.c (verbose): Rename from vflag.  All uses changed.
(tool_cleanup): New function, copied from collect_atexit.
(collect_atexit, handler): Just call it.
* collect2.h (verbose): Declaration renamed from vflag.
* lto-wrapper.c (maybe_unlink, run_gcc): Use save_temps instead of
debug.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@212019 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/collect-utils.c
gcc/collect-utils.h
gcc/collect2.c
gcc/collect2.h
gcc/lto-wrapper.c
gcc/tlink.c

index 2e1ff3f..edcc341 100644 (file)
@@ -1,5 +1,15 @@
 2014-06-26  Bernd Schmidt  <bernds@codesourcery.com>
 
+       * collect-utils.c (save_temps): New variable.
+       (do_wait): Use it instead of debug.  Use fatal_error.
+       * collect-utils.h (save_temps): Declare.
+       * collect2.c (verbose): Rename from vflag.  All uses changed.
+       (tool_cleanup): New function, copied from collect_atexit.
+       (collect_atexit, handler): Just call it.
+       * collect2.h (verbose): Declaration renamed from vflag.
+       * lto-wrapper.c (maybe_unlink, run_gcc): Use save_temps instead of
+       debug.
+
         * Makefile.in (ALL_HOST_BACKEND_OBJS): Add collect-utils.o.
         (lto-wrapper$(exeext)): Link with collect-utils.o.
         * collect-utils.c: New file.
index 004569c..e92513c 100644 (file)
@@ -33,6 +33,7 @@ static char *response_file;
 
 bool debug;
 bool verbose;
+bool save_temps;
 
 /* Delete tempfiles.  */
 
@@ -159,12 +160,9 @@ do_wait (const char *prog, struct pex_obj *pex)
 {
   int ret = collect_wait (prog, pex);
   if (ret != 0)
-    {
-      error ("%s returned %d exit status", prog, ret);
-      exit (ret);
-    }
+    fatal_error ("%s returned %d exit status", prog, ret);
 
-  if (response_file && !debug)
+  if (response_file && !save_temps)
     {
       unlink (response_file);
       response_file = NULL;
index e47ab29..46c1160 100644 (file)
@@ -30,6 +30,7 @@ extern void utils_cleanup (void);
 
 extern bool debug;
 extern bool verbose;
+extern bool save_temps;
 
 /* Provided by the tool itself.  */
 
index ec8f733..5de1bb3 100644 (file)
@@ -175,7 +175,7 @@ struct head
   int number;
 };
 
-bool vflag;                            /* true if -v or --version */ 
+bool verbose;                          /* true if -v or --version */ 
 static int rflag;                      /* true if -r */
 static int strip_flag;                 /* true if -s */
 #ifdef COLLECT_EXPORT_LIST
@@ -383,7 +383,7 @@ static void scan_prog_file (const char *, scanpass, scanfilter);
 /* Delete tempfiles and exit function.  */
 
 static void
-collect_atexit (void)
+tool_cleanup (bool from_signal)
 {
   if (c_file != 0 && c_file[0])
     maybe_unlink (c_file);
@@ -401,20 +401,33 @@ collect_atexit (void)
 
   if (ldout != 0 && ldout[0])
     {
-      dump_ld_file (ldout, stdout);
+      if (!from_signal)
+       dump_ld_file (ldout, stdout);
       maybe_unlink (ldout);
     }
 
   if (lderrout != 0 && lderrout[0])
     {
-      dump_ld_file (lderrout, stderr);
+      if (!from_signal)
+       dump_ld_file (lderrout, stderr);
       maybe_unlink (lderrout);
     }
+}
 
-  if (response_file)
-    maybe_unlink (response_file);
+static void
+collect_atexit (void)
+{
+  tool_cleanup (false);
 }
 
+static void
+handler (int signo)
+{
+  tool_cleanup (true);
+
+  signal (signo, SIG_DFL);
+  raise (signo);
+}
 \f
 /* Notify user of a non-error.  */
 void
@@ -438,37 +451,6 @@ notice_translated (const char *cmsgid, ...)
   va_end (ap);
 }
 \f
-static void
-handler (int signo)
-{
-  if (c_file != 0 && c_file[0])
-    maybe_unlink (c_file);
-
-  if (o_file != 0 && o_file[0])
-    maybe_unlink (o_file);
-
-  if (ldout != 0 && ldout[0])
-    maybe_unlink (ldout);
-
-  if (lderrout != 0 && lderrout[0])
-    maybe_unlink (lderrout);
-
-#ifdef COLLECT_EXPORT_LIST
-  if (export_file != 0 && export_file[0])
-    maybe_unlink (export_file);
-#endif
-
-  if (lto_o_files)
-    maybe_unlink_list (lto_o_files);
-
-  if (response_file)
-    maybe_unlink (response_file);
-
-  signal (signo, SIG_DFL);
-  raise (signo);
-}
-
-\f
 int
 file_exists (const char *name)
 {
@@ -1056,7 +1038,7 @@ main (int argc, char **argv)
            aixlazy_flag = 1;
 #endif
       }
-    vflag = debug;
+    verbose = debug;
     find_file_set_debug (debug);
     if (use_plugin)
       lto_mode = LTO_MODE_NONE;
@@ -1451,7 +1433,7 @@ main (int argc, char **argv)
 
            case 'v':
              if (arg[2] == '\0')
-               vflag = true;
+               verbose = true;
              break;
 
            case '-':
@@ -1483,7 +1465,7 @@ main (int argc, char **argv)
              else if (strncmp (arg, "--sysroot=", 10) == 0)
                target_system_root = arg + 10;
              else if (strcmp (arg, "--version") == 0)
-               vflag = true;
+               verbose = true;
              else if (strcmp (arg, "--help") == 0)
                helpflag = true;
              break;
@@ -1578,7 +1560,7 @@ main (int argc, char **argv)
   *c_ptr++ = c_file;
   *c_ptr = *ld1 = *object = (char *) 0;
 
-  if (vflag)
+  if (verbose)
     notice ("collect2 version %s\n", version_string);
 
   if (helpflag)
@@ -1947,7 +1929,7 @@ collect_execute (const char *prog, char **argv, const char *outname,
       argv = response_argv;
     }
 
-  if (vflag || debug)
+  if (verbose || debug)
     {
       char **p_argv;
       const char *str;
@@ -2509,7 +2491,7 @@ scan_prog_file (const char *prog_name, scanpass which_pass,
   nm_argv[argc++] = (char *) 0;
 
   /* Trace if needed.  */
-  if (vflag)
+  if (verbose)
     {
       const char **p_argv;
       const char *str;
@@ -2706,7 +2688,7 @@ scan_libraries (const char *prog_name)
   ldd_argv[argc++] = (char *) 0;
 
   /* Trace if needed.  */
-  if (vflag)
+  if (verbose)
     {
       const char **p_argv;
       const char *str;
index bbfd676..344ad86 100644 (file)
@@ -36,7 +36,7 @@ extern const char *lderrout;
 extern const char *c_file_name;
 extern struct obstack temporary_obstack;
 extern char *temporary_firstobj;
-extern bool vflag, debug;
+extern bool verbose, debug;
 extern bool may_unlink_output_file;
 
 extern void notice_translated (const char *, ...) ATTRIBUTE_PRINTF_1;
index 45ce321..49f0895 100644 (file)
@@ -99,7 +99,7 @@ lto_wrapper_cleanup (void)
 void
 maybe_unlink (const char *file)
 {
-  if (! debug)
+  if (!save_temps)
     {
       if (unlink_if_ordinary (file)
          && errno != ENOENT)
@@ -540,7 +540,7 @@ run_gcc (unsigned argc, char *argv[])
          continue;
 
        case OPT_save_temps:
-         debug = 1;
+         save_temps = 1;
          break;
 
        case OPT_v:
@@ -647,7 +647,7 @@ run_gcc (unsigned argc, char *argv[])
          obstack_ptr_grow (&argv_obstack, dumpbase);
        }
 
-      if (linker_output && debug)
+      if (linker_output && save_temps)
        {
          ltrans_output_file = (char *) xmalloc (strlen (linker_output)
                                                 + sizeof (".ltrans.out") + 1);
@@ -785,7 +785,7 @@ cont:
              /* If we are not preserving the ltrans input files then
                 truncate them as soon as we have processed it.  This
                 reduces temporary disk-space usage.  */
-             if (! debug)
+             if (! save_temps)
                fprintf (mstream, "\t@-touch -r %s %s.tem > /dev/null 2>&1 "
                         "&& mv %s.tem %s\n",
                         input_name, input_name, input_name, input_name); 
index bc358b8..addea61 100644 (file)
@@ -275,7 +275,7 @@ tlink_init (void)
   else
     {
       tlink_verbose = 1;
-      if (vflag)
+      if (verbose)
        tlink_verbose = 2;
       if (debug)
        tlink_verbose = 3;