Fix a conflict between the linker's need to rename some PE format input libraries and the BFD library's file caching mechanism.

PR 29389
bfd	* bfd.c (BFD_CLOSED_BY_CACHE): New bfd flag.
	* cache.c (bfd_cache_delete): Set BFD_CLOSED_BY_DELETE on the
	closed bfd.
	(bfd_cache_lookup_worker): Clear BFD_CLOSED_BY_DELETE on the newly
	reopened bfd.
	* opncls.c (bfd_set_filename): Refuse to change the name of a bfd
	that has been closed by bfd_cache_delete.  Mark changed bfds as
	uncacheable.
	* bfd-in2.h: Regenerate.

ld	* ldlang.h (lang_input_statement_struct): Add sort_key field.
	* emultempl/pe.em (after_open): If multiple import libraries refer
	to the same bfd, store their names in the sort_key field.
	* emultempl/pep.em (after_open): Likewise.
	* ldlang.c (sort_filename): New function.  Returns the filename to
	be used when sorting input files.
	(wild_sort): Use the sort_filename function.
This commit is contained in:
Alan Modra
2022-08-03 13:31:57 +01:00
committed by Nick Clifton
parent 8b8da1a9f3
commit a6ad791442
10 changed files with 107 additions and 48 deletions

View File

@@ -177,6 +177,7 @@ bfd_cache_delete (bfd *abfd)
abfd->iostream = NULL;
--open_files;
abfd->flags |= BFD_CLOSED_BY_CACHE;
return ret;
}
@@ -265,10 +266,13 @@ bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag)
&& !(flag & CACHE_NO_SEEK_ERROR))
bfd_set_error (bfd_error_system_call);
else
return (FILE *) abfd->iostream;
{
abfd->flags &= ~BFD_CLOSED_BY_CACHE;
return (FILE *) abfd->iostream;
}
/* xgettext:c-format */
_bfd_error_handler (_("reopening %pB: %s\n"),
_bfd_error_handler (_("reopening %pB: %s"),
abfd, bfd_errmsg (bfd_get_error ()));
return NULL;
}