public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gas: output_file_close
@ 2022-07-09 12:35 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-07-09 12:35 UTC (permalink / raw)
To: bfd-cvs
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 */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-09 12:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09 12:35 [binutils-gdb] gas: output_file_close Alan Modra
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).