PR24873, gcc -flto objects result in --start-group .. --end-group failure to include...
authorAlan Modra <amodra@gmail.com>
Tue, 6 Aug 2019 05:53:28 +0000 (15:23 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 6 Aug 2019 06:07:08 +0000 (15:37 +0930)
Reloading of archives (and checking --as-needed DSOs again) is
disabled until we hit the plugin insert point.  It's necessary to do
that because in a case like lib1.a lto.o lib2.a where lib1.a and
lib2.a contain duplicate symbols, we want the lto.o recompiled object
to pull in objects from lib2.a as necessary, but not from lib1.a.
Unfortunately this heuristic fails when the insert point is inside a
group, because ld actually loads the symbols from the recompiled
object before running over the contours of the script, thus missing
the fact that new undefs appeared in the group.

PR 24873
* ldlang.c (plugin_undefs): New static var.
(open_input_bfds <lang_group_statement_enum>): Loop on
plugin_undefs and hitting plugin_insert point.
(lang_process <lto_plugin_active>): Set plugin_undefs.

ld/ChangeLog
ld/ldlang.c

index 8015427ba1032fa14756cb7aaeef0074af8c7f90..8f9d1f02516ebb8c5d4dedd4ea90b0ca772f9f15 100644 (file)
@@ -1,3 +1,11 @@
+2019-08-06  Alan Modra  <amodra@gmail.com>
+
+       PR 24873
+       * ldlang.c (plugin_undefs): New static var.
+       (open_input_bfds <lang_group_statement_enum>): Loop on
+       plugin_undefs and hitting plugin_insert point.
+       (lang_process <lto_plugin_active>): Set plugin_undefs.
+
 2019-08-02  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-powerpc/tlsie.s: Correct medium model ELF sequence.
index 96daf0ef11d0fd6ca40f6be95e26bab44a77277b..b88c8418102e6b3b7175570a05bb36467af72320 100644 (file)
@@ -3444,6 +3444,7 @@ enum open_bfd_mode
   };
 #ifdef ENABLE_PLUGINS
 static lang_input_statement_type *plugin_insert = NULL;
+static struct bfd_link_hash_entry *plugin_undefs = NULL;
 #endif
 
 static void
@@ -3471,6 +3472,9 @@ open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode)
        case lang_group_statement_enum:
          {
            struct bfd_link_hash_entry *undefs;
+#ifdef ENABLE_PLUGINS
+           lang_input_statement_type *plugin_insert_save;
+#endif
 
            /* We must continually search the entries in the group
               until no new symbols are added to the list of undefined
@@ -3478,11 +3482,21 @@ open_input_bfds (lang_statement_union_type *s, enum open_bfd_mode mode)
 
            do
              {
+#ifdef ENABLE_PLUGINS
+               plugin_insert_save = plugin_insert;
+#endif
                undefs = link_info.hash->undefs_tail;
                open_input_bfds (s->group_statement.children.head,
                                 mode | OPEN_BFD_FORCE);
              }
-           while (undefs != link_info.hash->undefs_tail);
+           while (undefs != link_info.hash->undefs_tail
+#ifdef ENABLE_PLUGINS
+                  /* Objects inserted by a plugin, which are loaded
+                     before we hit this loop, may have added new
+                     undefs.  */
+                  || (plugin_insert != plugin_insert_save && plugin_undefs)
+#endif
+                  );
          }
          break;
        case lang_target_statement_enum:
@@ -7420,7 +7434,10 @@ lang_process (void)
        einfo (_("%F%P: %s: plugin reported error after all symbols read\n"),
               plugin_error_plugin ());
       /* Open any newly added files, updating the file chains.  */
+      plugin_undefs = link_info.hash->undefs_tail;
       open_input_bfds (*added.tail, OPEN_BFD_NORMAL);
+      if (plugin_undefs == link_info.hash->undefs_tail)
+       plugin_undefs = NULL;
       /* Restore the global list pointer now they have all been added.  */
       lang_list_remove_tail (stat_ptr, &added);
       /* And detach the fresh ends of the file lists.  */
This page took 0.0298389999999999 seconds and 4 git commands to generate.