summaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-08-03 13:31:57 +0100
committerNick Clifton <nickc@redhat.com>2022-08-03 13:31:57 +0100
commita6ad7914429a22d3d835bd998b032212b776a08a (patch)
treed81caa6275932745dedefa9f17d391454a84a19f /ld/ldlang.c
parent8b8da1a9f31941fa167c9f2bd2a80cdd1dccb452 (diff)
downloadbinutils-gdb-a6ad7914429a22d3d835bd998b032212b776a08a.tar.gz
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.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index e7bc9f2d268..b7bb4a3aeda 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1125,6 +1125,7 @@ new_afile (const char *name,
p->flags.add_DT_NEEDED_for_regular = input_flags.add_DT_NEEDED_for_regular;
p->flags.whole_archive = input_flags.whole_archive;
p->flags.sysrooted = input_flags.sysrooted;
+ p->sort_key = NULL;
switch (file_type)
{
@@ -2723,6 +2724,17 @@ lang_add_section (lang_statement_list_type *ptr,
new_section->pattern = pattern;
}
+/* PE puts the sort key in the input statement. */
+
+static const char *
+sort_filename (bfd *abfd)
+{
+ lang_input_statement_type *is = bfd_usrdata (abfd);
+ if (is->sort_key)
+ return is->sort_key;
+ return bfd_get_filename (abfd);
+}
+
/* Handle wildcard sorting. This returns the lang_input_section which
should follow the one we are going to create for SECTION and FILE,
based on the sorting requirements of WILD. It returns NULL if the
@@ -2762,28 +2774,17 @@ wild_sort (lang_wild_statement_type *wild,
the archive and then the name of the file within the
archive. */
- if (file->the_bfd != NULL
- && file->the_bfd->my_archive != NULL)
- {
- fn = bfd_get_filename (file->the_bfd->my_archive);
- fa = true;
- }
+ fa = file->the_bfd->my_archive != NULL;
+ if (fa)
+ fn = sort_filename (file->the_bfd->my_archive);
else
- {
- fn = file->filename;
- fa = false;
- }
+ fn = sort_filename (file->the_bfd);
- if (ls->section->owner->my_archive != NULL)
- {
- ln = bfd_get_filename (ls->section->owner->my_archive);
- la = true;
- }
+ la = ls->section->owner->my_archive != NULL;
+ if (la)
+ ln = sort_filename (ls->section->owner->my_archive);
else
- {
- ln = bfd_get_filename (ls->section->owner);
- la = false;
- }
+ ln = sort_filename (ls->section->owner);
i = filename_cmp (fn, ln);
if (i > 0)
@@ -2794,9 +2795,9 @@ wild_sort (lang_wild_statement_type *wild,
if (fa || la)
{
if (fa)
- fn = file->filename;
+ fn = sort_filename (file->the_bfd);
if (la)
- ln = bfd_get_filename (ls->section->owner);
+ ln = sort_filename (ls->section->owner);
i = filename_cmp (fn, ln);
if (i > 0)