diff options
Diffstat (limited to 'ld/ldmain.c')
-rw-r--r-- | ld/ldmain.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ld/ldmain.c b/ld/ldmain.c index d34d30a..94a745e 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -822,10 +822,6 @@ add_archive_element (struct bfd_link_info *info, input->local_sym_name = bfd_get_filename (abfd); input->the_bfd = abfd; - parent = bfd_usrdata (abfd->my_archive); - if (parent != NULL && !parent->flags.reload) - parent->next = input; - /* Save the original data for trace files/tries below, as plugins (if enabled) may possibly alter it to point to a replacement BFD, but we still want to output the original BFD filename. */ @@ -853,6 +849,23 @@ add_archive_element (struct bfd_link_info *info, } #endif /* BFD_SUPPORTS_PLUGINS */ + if (link_info.input_bfds_tail == &input->the_bfd->link.next + || input->the_bfd->link.next != NULL) + { + /* We have already loaded this element, and are attempting to + load it again. This can happen when the archive map doesn't + match actual symbols defined by the element. */ + free (input); + bfd_set_error (bfd_error_malformed_archive); + return FALSE; + } + + /* Set the file_chain pointer of archives to the last element loaded + from the archive. See ldlang.c:find_rescan_insertion. */ + parent = bfd_usrdata (abfd->my_archive); + if (parent != NULL && !parent->flags.reload) + parent->next = input; + ldlang_add_file (input); if (config.map_file != NULL) |