From a6ad7914429a22d3d835bd998b032212b776a08a Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 3 Aug 2022 13:31:57 +0100 Subject: 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. --- ld/emultempl/pe.em | 25 ++++++++++++++----------- ld/emultempl/pep.em | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'ld/emultempl') diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 2fd4ff4..ad969cc 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -1583,6 +1583,7 @@ gld${EMULATION_NAME}_after_open (void) { struct bfd_symbol *s; struct bfd_link_hash_entry * blhe; + bfd *other_bfd; const char *other_bfd_filename; s = (relocs[i]->sym_ptr_ptr)[0]; @@ -1599,20 +1600,25 @@ gld${EMULATION_NAME}_after_open (void) || blhe->type != bfd_link_hash_defined) continue; + other_bfd = blhe->u.def.section->owner; + if (other_bfd->my_archive == is->the_bfd->my_archive) + continue; + other_bfd_filename - = blhe->u.def.section->owner->my_archive - ? bfd_get_filename (blhe->u.def.section->owner->my_archive) - : bfd_get_filename (blhe->u.def.section->owner); + = (other_bfd->my_archive + ? bfd_get_filename (other_bfd->my_archive) + : bfd_get_filename (other_bfd)); if (filename_cmp (bfd_get_filename (is->the_bfd->my_archive), other_bfd_filename) == 0) continue; - /* Rename this implib to match the other one. */ - if (!bfd_set_filename (is->the_bfd->my_archive, - other_bfd_filename)) - einfo ("%F%P: %pB: %E\n", is->the_bfd); + /* Sort this implib to match the other one. */ + lang_input_statement_type *arch_is + = bfd_usrdata (is->the_bfd->my_archive); + arch_is->sort_key = other_bfd_filename; + break; } free (relocs); @@ -1719,10 +1725,7 @@ gld${EMULATION_NAME}_after_open (void) = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3); sprintf (new_name, "%s.%c", bfd_get_filename (is->the_bfd), seq); - is->filename = bfd_set_filename (is->the_bfd, new_name); - free (new_name); - if (!is->filename) - einfo ("%F%P: %pB: %E\n", is->the_bfd); + is->sort_key = new_name; } } } diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index e68d1e6..ee36a9a 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -1547,6 +1547,7 @@ gld${EMULATION_NAME}_after_open (void) { struct bfd_symbol *s; struct bfd_link_hash_entry * blhe; + bfd *other_bfd; const char *other_bfd_filename; s = (relocs[i]->sym_ptr_ptr)[0]; @@ -1563,20 +1564,25 @@ gld${EMULATION_NAME}_after_open (void) || blhe->type != bfd_link_hash_defined) continue; + other_bfd = blhe->u.def.section->owner; + if (other_bfd->my_archive == is->the_bfd->my_archive) + continue; + other_bfd_filename - = blhe->u.def.section->owner->my_archive - ? bfd_get_filename (blhe->u.def.section->owner->my_archive) - : bfd_get_filename (blhe->u.def.section->owner); + = (other_bfd->my_archive + ? bfd_get_filename (other_bfd->my_archive) + : bfd_get_filename (other_bfd)); if (filename_cmp (bfd_get_filename (is->the_bfd->my_archive), other_bfd_filename) == 0) continue; - /* Rename this implib to match the other one. */ - if (!bfd_set_filename (is->the_bfd->my_archive, - other_bfd_filename)) - einfo ("%F%P: %pB: %E\n", is->the_bfd); + /* Sort this implib to match the other one. */ + lang_input_statement_type *arch_is + = bfd_usrdata (is->the_bfd->my_archive); + arch_is->sort_key = other_bfd_filename; + break; } free (relocs); @@ -1683,10 +1689,7 @@ gld${EMULATION_NAME}_after_open (void) = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3); sprintf (new_name, "%s.%c", bfd_get_filename (is->the_bfd), seq); - is->filename = bfd_set_filename (is->the_bfd, new_name); - free (new_name); - if (!is->filename) - einfo ("%F%P: %pB: %E\n", is->the_bfd); + is->sort_key = new_name; } } } -- cgit v1.1