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.
This commit is contained in:
Alan Modra 2022-07-07 19:56:10 +09:30
parent c30081c1f9
commit 07e64e0b7c
4 changed files with 13 additions and 15 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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 ()));
}

View File

@ -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 */