re PR driver/57652 (collect2 does not clean up temporary files)
authorDavid Edelsohn <dje.gcc@gmail.com>
Wed, 19 Jun 2013 23:51:05 +0000 (23:51 +0000)
committerDavid Edelsohn <dje@gcc.gnu.org>
Wed, 19 Jun 2013 23:51:05 +0000 (19:51 -0400)
        PR driver/57652
        * collect2.c (collect_atexit): New.
        (collect_exit): Delete.
        (main): Register collect_atexit with atexit.
        (collect_wait): Change collect_exit to exit.
        (do_wait): Same.
        * collect2.h (collect_exit): Delete.
        * tlink.c (do_tlink): Rename exit to ret. Change collect_exit to exit.

From-SVN: r200226

gcc/ChangeLog
gcc/collect2.c
gcc/collect2.h
gcc/tlink.c

index 8973cb9e2fcbfa7665380f15ecc02e62a5dff7a3..6d2d7c915e6166eeccfc878369b4cbb44b9340b2 100644 (file)
@@ -1,3 +1,14 @@
+2013-06-19  David Edelsohn  <dje.gcc@gmail.com>
+
+       PR driver/57652
+       * collect2.c (collect_atexit): New.
+       (collect_exit): Delete.
+       (main): Register collect_atexit with atexit.
+       (collect_wait): Change collect_exit to exit.
+       (do_wait): Same.
+       * collect2.h (collect_exit): Delete.
+       * tlink.c (do_tlink): Rename exit to ret. Change collect_exit to exit.
+
 2013-06-19  Wei Mi  <wmi@google.com>
 
        PR rtl-optimization/57518
index b1eafb84b5b1cdaa79885373ca3b22eba41648dc..43b9defafd81f7f2f0beb18fc9ab668250fb0aac 100644 (file)
@@ -366,8 +366,8 @@ static void scan_prog_file (const char *, scanpass, scanfilter);
 \f
 /* Delete tempfiles and exit function.  */
 
-void
-collect_exit (int status)
+static void
+collect_atexit (void)
 {
   if (c_file != 0 && c_file[0])
     maybe_unlink (c_file);
@@ -395,13 +395,8 @@ collect_exit (int status)
       maybe_unlink (lderrout);
     }
 
-  if (status != 0 && output_file != 0 && output_file[0])
-    maybe_unlink (output_file);
-
   if (response_file)
     maybe_unlink (response_file);
-
-  exit (status);
 }
 
 \f
@@ -970,6 +965,9 @@ main (int argc, char **argv)
   signal (SIGCHLD, SIG_DFL);
 #endif
 
+  if (atexit (collect_atexit) != 0)
+    fatal_error ("atexit failed");
+
   /* Unlock the stdio streams.  */
   unlock_std_streams ();
 
@@ -1816,7 +1814,7 @@ collect_wait (const char *prog, struct pex_obj *pex)
          error ("%s terminated with signal %d [%s]%s",
                 prog, sig, strsignal(sig),
                 WCOREDUMP(status) ? ", core dumped" : "");
-         collect_exit (FATAL_EXIT_CODE);
+         exit (FATAL_EXIT_CODE);
        }
 
       if (WIFEXITED (status))
@@ -1832,7 +1830,7 @@ do_wait (const char *prog, struct pex_obj *pex)
   if (ret != 0)
     {
       error ("%s returned %d exit status", prog, ret);
-      collect_exit (ret);
+      exit (ret);
     }
 
   if (response_file)
index 1765bc438efb8d1a79599abf0eef66e6f0a700cb..2385e4a981325b9d78b426ccead3a062deb84ae6 100644 (file)
@@ -25,8 +25,6 @@ extern void do_tlink (char **, char **);
 extern struct pex_obj *collect_execute (const char *, char **, const char *,
                                        const char *, int flags);
 
-extern void collect_exit (int) ATTRIBUTE_NORETURN;
-
 extern int collect_wait (const char *, struct pex_obj *);
 
 extern void dump_ld_file (const char *, FILE *);
index 7a64c79db7c7947a75bbc2005775fdd7372a97a0..8365bd3cfa14a2b64c960440dc99a545ff791a43 100644 (file)
@@ -817,18 +817,18 @@ scan_linker_output (const char *fname)
 void
 do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
 {
-  int exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
+  int ret = tlink_execute ("ld", ld_argv, ldout, lderrout);
 
   tlink_init ();
 
-  if (exit)
+  if (ret)
     {
       int i = 0;
 
       /* Until collect does a better job of figuring out which are object
         files, assume that everything on the command line could be.  */
       if (read_repo_files (ld_argv))
-       while (exit && i++ < MAX_ITERATIONS)
+       while (ret && i++ < MAX_ITERATIONS)
          {
            if (tlink_verbose >= 3)
              {
@@ -843,7 +843,7 @@ do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
              break;
            if (tlink_verbose)
              fprintf (stderr, _("collect: relinking\n"));
-           exit = tlink_execute ("ld", ld_argv, ldout, lderrout);
+           ret = tlink_execute ("ld", ld_argv, ldout, lderrout);
          }
     }
 
@@ -851,10 +851,10 @@ do_tlink (char **ld_argv, char **object_lst ATTRIBUTE_UNUSED)
   unlink (ldout);
   dump_ld_file (lderrout, stderr);
   unlink (lderrout);
-  if (exit)
+  if (ret)
     {
-      error ("ld returned %d exit status", exit);
-      collect_exit (exit);
+      error ("ld returned %d exit status", ret);
+      exit (ret);
     }
   else
     {