[prev in list] [next in list] [prev in thread] [next in thread] 

List:       binutils-cvs
Subject:    [binutils-gdb] PR27441, inconsistency in weak definitions
From:       Alan Modra via Binutils-cvs <binutils-cvs () sourceware ! org>
Date:       2021-02-25 3:59:22
Message-ID: 20210225035922.6A29F383540B () sourceware ! org
[Download RAW message or body]

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bbaddd4bbeba65200ee805d87c2e3a845842e3eb

commit bbaddd4bbeba65200ee805d87c2e3a845842e3eb
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 24 18:01:16 2021 +1030

    PR27441, inconsistency in weak definitions
    
    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.

Diff:
---
 bfd/ChangeLog |  8 ++++++++
 bfd/elf-bfd.h |  2 ++
 bfd/elflink.c | 11 ++++++++---
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 52d9bf26008..2fef817d734 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+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-24  Alan Modra  <amodra@gmail.com>
 
 	PR 27459
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 4b79ee8eb62..dd66d98883e 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -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.  */
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 291cec0df25..7b74f2653c2 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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),
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic