]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR26314, Linking LTO objects with symbols from static and shared libraries
authorAlan Modra <amodra@gmail.com>
Fri, 31 Jul 2020 07:07:17 +0000 (16:37 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 31 Jul 2020 11:01:20 +0000 (20:31 +0930)
gcc -O2 -g -o ar -Wl,--as-needed arparse.o arlex.o ar.o not-ranlib.o arsup.o rename.o binemul.o emul_vanilla.o bucomm.o version.o filemode.o libbfd-2.35-3.fc33.so libiberty.a -Wl,-R,.

All of the above .o files are lto, leading to libbfd-2.35-3.fc33.so
not being found needed when loading the IR objects.  That's problem
number one:  We exclude IR references when deciding a shared library
is needed.  See PR15146.  Thus none of the libbfd.so symbols are
loaded before libiberty.a is scanned, and libbfd.so contains copies of
libiberty.a functions.  We ought to be using the libbfd.so copies
rather than extracting them from the archive (an object is extracted
even to satisfy IR symbols).  After lto recompilation, libbfd.so is of
course found to be needed and loaded.  But that causes more problems.
The lto recompilation didn't see symbol references from libbfd.so and
variables like _xexit_cleanup are made local in the recompiled
objects.  Oops, two copies of them.  Finally, those silly undefined
symbols in the lto output debug files, combined with definitions in
both libbfd.so and IR objects result in IR symbols being made
dynamic.

The main fix here is to revert the PR15146 change to
elf_link_add_object_symbols.

PR 26314
* elflink.c (bfd_elf_link_record_dynamic_symbol): Don't allow
IR symbols to become dynamic.
(elf_link_add_object_symbols): Don't exclude IR symbols when
deciding whether an as-needed shared library is needed.

bfd/ChangeLog
bfd/elflink.c

index e507a9d6c0f0ff32426427646f9ca73b5e403401..d0a5916d378c03c72791914517390a52c8a2fae5 100644 (file)
@@ -1,3 +1,11 @@
+2020-07-31  Alan Modra  <amodra@gmail.com>
+
+       PR 26314
+       * elflink.c (bfd_elf_link_record_dynamic_symbol): Don't allow
+       IR symbols to become dynamic.
+       (elf_link_add_object_symbols): Don't exclude IR symbols when
+       deciding whether an as-needed shared library is needed.
+
 2020-07-30  Szabolcs Nagy  <szabolcs.nagy@arm.com>
 
        PR ld/26312
index ae5ff50ed62dac407621e0b4a546ef27b3eb117c..0a7f5bb1528f7dc1f44e355ef1faa69929cdba5b 100644 (file)
@@ -505,6 +505,16 @@ bfd_elf_link_record_dynamic_symbol (struct bfd_link_info *info,
       const char *name;
       size_t indx;
 
+      if (h->root.type == bfd_link_hash_defined
+         || h->root.type == bfd_link_hash_defweak)
+       {
+         /* An IR symbol should not be made dynamic.  */
+         if (h->root.u.def.section != NULL
+             && h->root.u.def.section->owner != NULL
+             && (h->root.u.def.section->owner->flags & BFD_PLUGIN) != 0)
+           return TRUE;
+       }
+
       /* XXX: The ABI draft says the linker must turn hidden and
         internal symbols into STB_LOCAL symbols when producing the
         DSO. However, if ld.so honors st_other in the dynamic table,
@@ -5199,15 +5209,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                break;
              }
 
-         /* Don't add DT_NEEDED for references from the dummy bfd nor
-            for unmatched symbol.  */
          if (!add_needed
              && matched
              && definition
              && ((dynsym
-                  && h->ref_regular_nonweak
-                  && (old_bfd == NULL
-                      || (old_bfd->flags & BFD_PLUGIN) == 0))
+                  && h->ref_regular_nonweak)
                  || (h->ref_dynamic_nonweak
                      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
                      && !on_needed_list (elf_dt_name (abfd),