]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR27441, inconsistency in weak definitions
authorAlan Modra <amodra@gmail.com>
Wed, 24 Feb 2021 07:31:16 +0000 (18:01 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 1 Mar 2021 04:22:20 +0000 (14:52 +1030)
This makes IR objects use the same logic as normal objects with
respect to what sort of ref/def makes an as-needed library needed.
Testing the binding of the definition is just plain wrong.  What
matters is the binding of the reference.

PR 27441
* elf-bfd.h (struct elf_link_hash_entry): Add ref_ir_nonweak.
* elflink.c (elf_link_add_object_symbols): Set ref_ir_nonweak and
use when deciding an as-needed library should be loaded instead
of using the binding of the library definition.

(cherry picked from commit bbaddd4bbeba65200ee805d87c2e3a845842e3eb)

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elflink.c

index 0c4631e15e644f739b8a3fcbe2a4eb3b55196faf..d49efdb618acfaa0b555ae2403ba5593a2c5232b 100644 (file)
@@ -1,3 +1,13 @@
+2021-03-01  Alan Modra  <amodra@gmail.com>
+
+       Apply from mainline
+       2021-02-25  Alan Modra  <amodra@gmail.com>
+       PR 27441
+       * elf-bfd.h (struct elf_link_hash_entry): Add ref_ir_nonweak.
+       * elflink.c (elf_link_add_object_symbols): Set ref_ir_nonweak and
+       use when deciding an as-needed library should be loaded instead
+       of using the binding of the library definition.
+
 2021-02-06  Nick Clifton  <nickc@redhat.com>
 
        (development): Set to true.
index 15206b4e876777b28560ce0fbeaf8364a0b9cd80..2cff9f055c57372a489e23a23b7cf011243db818 100644 (file)
@@ -184,6 +184,8 @@ struct elf_link_hash_entry
   /* Symbol has a non-weak reference from a non-shared object (other than
      the object in which it is defined).  */
   unsigned int ref_regular_nonweak : 1;
+  /* Symbol has a non-weak reference from a LTO IR object file.  */
+  unsigned int ref_ir_nonweak : 1;
   /* Dynamic symbol has been adjustd.  */
   unsigned int dynamic_adjusted : 1;
   /* Symbol needs a copy reloc.  */
index 7afbc5b1072d310986988ddd8a387c9bb2780264..08f241d79a5d513135b0ba8388403cf68c452f48 100644 (file)
@@ -5029,7 +5029,12 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 
          /* Plugin symbols aren't normal.  Don't set def/ref flags.  */
          if ((abfd->flags & BFD_PLUGIN) != 0)
-           ;
+           {
+             /* Except for this flag to track nonweak references.  */
+             if (!definition
+                 && bind != STB_WEAK)
+               h->ref_ir_nonweak = 1;
+           }
          else if (!dynamic)
            {
              if (! definition)
@@ -5279,8 +5284,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                   && h->ref_regular_nonweak)
                  || (old_bfd != NULL
                      && (old_bfd->flags & BFD_PLUGIN) != 0
-                     && !info->lto_all_symbols_read
-                     && bind != STB_WEAK)
+                     && h->ref_ir_nonweak
+                     && !info->lto_all_symbols_read)
                  || (h->ref_dynamic_nonweak
                      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
                      && !on_needed_list (elf_dt_name (abfd),