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

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