Blame SOURCES/binutils-plugin-as-needed-correct.patch

987a74
--- binutils.orig/bfd/elf-bfd.h	2021-09-20 16:06:58.320914954 +0100
987a74
+++ binutils-2.30/bfd/elf-bfd.h	2021-09-20 16:26:11.307770371 +0100
987a74
@@ -180,6 +180,8 @@ struct elf_link_hash_entry
987a74
   /* Symbol has a non-weak reference from a non-shared object (other than
987a74
      the object in which it is defined).  */
987a74
   unsigned int ref_regular_nonweak : 1;
987a74
+  /* Symbol has a non-weak reference from a LTO IR object file.  */
987a74
+  unsigned int ref_ir_nonweak : 1;
987a74
   /* Dynamic symbol has been adjustd.  */
987a74
   unsigned int dynamic_adjusted : 1;
987a74
   /* Symbol needs a copy reloc.  */
987a74
--- binutils.orig/bfd/elflink.c	2021-09-29 14:36:01.294185139 +0100
987a74
+++ binutils-2.30/bfd/elflink.c	2021-09-29 14:39:08.113874485 +0100
987a74
@@ -4663,7 +4663,12 @@ error_free_dyn:
987a74
 
987a74
 	  /* Plugin symbols aren't normal.  Don't set def/ref flags.  */
987a74
 	  if ((abfd->flags & BFD_PLUGIN) != 0)
987a74
-	    ;
987a74
+	    {
987a74
+	      /* Except for this flag to track nonweak references.  */
987a74
+	      if (!definition
987a74
+		  && bind != STB_WEAK)
987a74
+		h->ref_ir_nonweak = 1;
987a74
+	    }
987a74
 	  else if (!dynamic)
987a74
 	    {
987a74
 	      if (! definition)
987a74
@@ -4906,11 +4911,13 @@ error_free_dyn:
987a74
 	  if (!add_needed
987a74
 	      && matched
987a74
 	      && definition
987a74
+	      && h->root.type != bfd_link_hash_indirect
987a74
 	      && ((dynsym
987a74
 		   && h->ref_regular_nonweak)
987a74
 		  || (old_bfd != NULL
987a74
 		      && (old_bfd->flags & BFD_PLUGIN) != 0
987a74
-		      && bind != STB_WEAK)
987a74
+		      && h->ref_ir_nonweak
987a74
+		      && !info->lto_all_symbols_read)
987a74
 		  || (h->ref_dynamic_nonweak
987a74
 		      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
987a74
 		      && !on_needed_list (elf_dt_name (abfd),