public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] gas: output_file_close
Date: Sat,  9 Jul 2022 12:35:10 +0000 (GMT)	[thread overview]
Message-ID: <20220709123510.0405F383568C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=07e64e0b7c6cd4a73220eb57588d0db6b2a192e3

commit 07e64e0b7c6cd4a73220eb57588d0db6b2a192e3
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jul 7 19:56:10 2022 +0930

    gas: output_file_close
    
    This is mostly a tidy with the aim of being able to free
    out_file_name, but it does fix a possible attempt to unlink the output
    file twice (not that that matters).
    
            * as.h (keep_it): New global.
            * as.c (keep_it): Delete.
            (close_output_file): Delete, merged into..
            * output-file.c (output_file_close): ..here.  Delete parameter.
            * output-file.h (output_file_close): Update prototype.

Diff:
---
 gas/as.c          | 13 +------------
 gas/as.h          |  3 +++
 gas/output-file.c | 10 ++++++++--
 gas/output-file.h |  2 +-
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index 0262a6fec98..49a44863001 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -111,9 +111,6 @@ int flag_use_elf_stt_common = DEFAULT_GENERATE_ELF_STT_COMMON;
 bool flag_generate_build_notes = DEFAULT_GENERATE_BUILD_NOTES;
 #endif
 
-/* Keep the output file.  */
-static int keep_it = 0;
-
 segT reg_section;
 segT expr_section;
 segT text_section;
@@ -1155,14 +1152,6 @@ dump_statistics (void)
 #endif
 }
 
-static void
-close_output_file (void)
-{
-  output_file_close (out_file_name);
-  if (!keep_it)
-    unlink_if_ordinary (out_file_name);
-}
-
 /* The interface between the macro code and gas expression handling.  */
 
 static size_t
@@ -1361,7 +1350,7 @@ main (int argc, char ** argv)
   expr_begin ();
 
   /* It has to be called after dump_statistics ().  */
-  xatexit (close_output_file);
+  xatexit (output_file_close);
 
   if (flag_print_statistics)
     xatexit (dump_statistics);
diff --git a/gas/as.h b/gas/as.h
index 0ee3873bd1a..d179537f383 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -340,6 +340,9 @@ COMMON int flag_noexecstack;
 /* name of emitted object file */
 COMMON const char *out_file_name;
 
+/* Keep the output file.  */
+COMMON int keep_it;
+
 /* name of file defining extensions to the basic instruction set */
 COMMON char *insttbl_file_name;
 
diff --git a/gas/output-file.c b/gas/output-file.c
index 95e21d23dc1..584deb27c08 100644
--- a/gas/output-file.c
+++ b/gas/output-file.c
@@ -64,12 +64,13 @@ stash_frchain_obs (asection *sec)
 }
 
 void
-output_file_close (const char *filename)
+output_file_close (void)
 {
   bool res;
   bfd *obfd = stdoutput;
   struct obstack **obs;
   asection *sec;
+  const char *filename;
 
   if (obfd == NULL)
     return;
@@ -97,8 +98,13 @@ output_file_close (const char *filename)
   else
     res = bfd_close (obfd);
 
+  filename = out_file_name;
+  out_file_name = NULL;
+  if (!keep_it && filename)
+    unlink_if_ordinary (filename);
+
   subsegs_end (obs);
 
-  if (! res)
+  if (!res)
     as_fatal ("%s: %s", filename, bfd_errmsg (bfd_get_error ()));
 }
diff --git a/gas/output-file.h b/gas/output-file.h
index 8e738df1eee..3c65e25134a 100644
--- a/gas/output-file.h
+++ b/gas/output-file.h
@@ -19,7 +19,7 @@
    the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 void output_file_append (char *where, long length, char *filename);
-void output_file_close (const char *filename);
+void output_file_close (void);
 void output_file_create (const char *name);
 
 /* end of output-file.h */


                 reply	other threads:[~2022-07-09 12:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220709123510.0405F383568C@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).