From 1fa4ec6ae707402c6b61cde33cfe4bdeafd53f82 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 2 Sep 2017 11:08:05 +0930 Subject: LTO rescan archives ld ought to be more clever about where it puts LTO recompiled objects. Ideally the recompiled objects ought to be ordered to the same place their IR objects were, and files extracted from archives on the second pass ought to go in the same place as they would if extracted on the first pass. This patch addresses the archive problem. Without this fix, objects extracted from archives might be placed after the crt files intended to go at the end of an executable or shared library, possibly causing exception handling failures. * ldlang.h (lang_input_statement_type): Expand comments. (LANG_FOR_EACH_INPUT_STATEMENT): Rewrite without casts. * ldlang.c (lang_for_each_input_file): Likewise. (load_symbols): Set usrdata for archives. (find_rescan_insertion): New function. (lang_process): Trim off and reinsert entries added to file chain when rescanning archives for LTO. * ldmain.c (add_archive_element): Set my_archive input_statement next pointer to last element added. --- ld/ldmain.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'ld/ldmain.c') diff --git a/ld/ldmain.c b/ld/ldmain.c index 2b09f20..d223587 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -793,6 +793,7 @@ add_archive_element (struct bfd_link_info *info, bfd **subsbfd ATTRIBUTE_UNUSED) { lang_input_statement_type *input; + lang_input_statement_type *parent; lang_input_statement_type orig_input; input = (lang_input_statement_type *) @@ -802,6 +803,10 @@ add_archive_element (struct bfd_link_info *info, input->local_sym_name = abfd->filename; input->the_bfd = abfd; + parent = abfd->my_archive->usrdata; + if (parent != NULL && !parent->flags.reload) + parent->next = (lang_statement_union_type *) 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. */ -- cgit v1.1