Call bfd_close_all_done in ld_cleanup

This is similar to "Call bfd_close_all_done in output_file_close",
but with some code tidying in the pe/pep write_build_id functions.
write_build_id is passed the output bfd as its parameter, so there is
no need to go looking for the output bfd via link_info (and doing so
will no longer work since I clear link_info.output_bfd before calling
bfd_close).

	* emultempl/pe.em (write_build_id): Rename t to td.  Formatting.
	Don't access pe_data(link_info.output_bfd), use td instead.
	(setup_build_id): Rename t to td.  Formatting.
	* emultempl/pep.em: As for pe.em.
	* ldmain.c (ld_cleanup): Call bfd_close_all_done on linker bfds.
	(main): Clear link_info.output_bfd when closing.
This commit is contained in:
Alan Modra
2023-01-27 15:32:06 +10:30
parent 8219cab3f8
commit 1f5e6267aa
3 changed files with 57 additions and 42 deletions

View File

@ -212,7 +212,14 @@ write_dependency_file (void)
static void
ld_cleanup (void)
{
bfd_cache_close_all ();
bfd *ibfd, *inext;
if (link_info.output_bfd)
bfd_close_all_done (link_info.output_bfd);
for (ibfd = link_info.input_bfds; ibfd; ibfd = inext)
{
inext = ibfd->link.next;
bfd_close_all_done (ibfd);
}
#if BFD_SUPPORTS_PLUGINS
plugin_call_cleanup ();
#endif
@ -559,7 +566,9 @@ main (int argc, char **argv)
}
else
{
if (!bfd_close (link_info.output_bfd))
bfd *obfd = link_info.output_bfd;
link_info.output_bfd = NULL;
if (!bfd_close (obfd))
einfo (_("%F%P: %s: final close failed: %E\n"), output_filename);
/* If the --force-exe-suffix is enabled, and we're making an
@ -621,7 +630,7 @@ main (int argc, char **argv)
fflush (stderr);
}
/* Prevent ld_cleanup from doing anything, after a successful link. */
/* Prevent ld_cleanup from deleting the output file. */
output_filename = NULL;
xexit (0);