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

2e9b04
--- binutils.orig/bfd/elflink.c	2020-11-03 11:59:59.966565009 +0000
2e9b04
+++ binutils-2.35.1/bfd/elflink.c	2020-11-03 12:07:34.691991602 +0000
2e9b04
@@ -4477,7 +4477,12 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 	      h = (struct elf_link_hash_entry *) p;
2e9b04
 	      entsize += htab->root.table.entsize;
2e9b04
 	      if (h->root.type == bfd_link_hash_warning)
2e9b04
-		entsize += htab->root.table.entsize;
2e9b04
+		{
2e9b04
+		  entsize += htab->root.table.entsize;
2e9b04
+		  h = (struct elf_link_hash_entry *) h->root.u.i.link;
2e9b04
+		}
2e9b04
+	      if (h->root.type == bfd_link_hash_common)
2e9b04
+		entsize += sizeof (*h->root.u.c.p);
2e9b04
 	    }
2e9b04
 	}
2e9b04
 
2e9b04
@@ -4521,14 +4526,20 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 
2e9b04
 	  for (p = htab->root.table.table[i]; p != NULL; p = p->next)
2e9b04
 	    {
2e9b04
-	      memcpy (old_ent, p, htab->root.table.entsize);
2e9b04
-	      old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 	      h = (struct elf_link_hash_entry *) p;
2e9b04
+	      memcpy (old_ent, h, htab->root.table.entsize);
2e9b04
+	      old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 	      if (h->root.type == bfd_link_hash_warning)
2e9b04
 		{
2e9b04
-		  memcpy (old_ent, h->root.u.i.link, htab->root.table.entsize);
2e9b04
+		  h = (struct elf_link_hash_entry *) h->root.u.i.link;
2e9b04
+		  memcpy (old_ent, h, htab->root.table.entsize);
2e9b04
 		  old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 		}
2e9b04
+	      if (h->root.type == bfd_link_hash_common)
2e9b04
+		{
2e9b04
+		  memcpy (old_ent, h->root.u.c.p, sizeof (*h->root.u.c.p));
2e9b04
+		  old_ent = (char *) old_ent + sizeof (*h->root.u.c.p);
2e9b04
+		}
2e9b04
 	    }
2e9b04
 	}
2e9b04
     }
2e9b04
@@ -4899,7 +4910,8 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 	}
2e9b04
 
2e9b04
       if (! (_bfd_generic_link_add_one_symbol
2e9b04
-	     (info, abfd, name, flags, sec, value, NULL, FALSE, bed->collect,
2e9b04
+	     (info, abfd, name, flags, sec, value,
2e9b04
+	      NULL, FALSE, bed->collect,
2e9b04
 	      (struct bfd_link_hash_entry **) sym_hash)))
2e9b04
 	goto error_free_vers;
2e9b04
 
2e9b04
@@ -4970,11 +4982,10 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 	     object and a shared object.  */
2e9b04
 	  bfd_boolean dynsym = FALSE;
2e9b04
 
2e9b04
-	  /* Plugin symbols aren't normal.  Don't set def_regular or
2e9b04
-	     ref_regular for them, or make them dynamic.  */
2e9b04
+	  /* Plugin symbols aren't normal.  Don't set def/ref flags.  */
2e9b04
 	  if ((abfd->flags & BFD_PLUGIN) != 0)
2e9b04
 	    ;
2e9b04
-	  else if (! dynamic)
2e9b04
+	  else if (!dynamic)
2e9b04
 	    {
2e9b04
 	      if (! definition)
2e9b04
 		{
2e9b04
@@ -4991,14 +5002,6 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 		      h->ref_dynamic = 1;
2e9b04
 		    }
2e9b04
 		}
2e9b04
-
2e9b04
-	      /* If the indirect symbol has been forced local, don't
2e9b04
-		 make the real symbol dynamic.  */
2e9b04
-	      if ((h == hi || !hi->forced_local)
2e9b04
-		  && (bfd_link_dll (info)
2e9b04
-		      || h->def_dynamic
2e9b04
-		      || h->ref_dynamic))
2e9b04
-		dynsym = TRUE;
2e9b04
 	    }
2e9b04
 	  else
2e9b04
 	    {
2e9b04
@@ -5012,14 +5015,25 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 		  h->def_dynamic = 1;
2e9b04
 		  hi->def_dynamic = 1;
2e9b04
 		}
2e9b04
+	    }
2e9b04
 
2e9b04
-	      /* If the indirect symbol has been forced local, don't
2e9b04
-		 make the real symbol dynamic.  */
2e9b04
-	      if ((h == hi || !hi->forced_local)
2e9b04
-		  && (h->def_regular
2e9b04
-		      || h->ref_regular
2e9b04
-		      || (h->is_weakalias
2e9b04
-			  && weakdef (h)->dynindx != -1)))
2e9b04
+	  /* If an indirect symbol has been forced local, don't
2e9b04
+	     make the real symbol dynamic.  */
2e9b04
+	  if (h != hi && hi->forced_local)
2e9b04
+	    ;
2e9b04
+	  else if (!dynamic)
2e9b04
+	    {
2e9b04
+	      if (bfd_link_dll (info)
2e9b04
+		  || h->def_dynamic
2e9b04
+		  || h->ref_dynamic)
2e9b04
+		dynsym = TRUE;
2e9b04
+	    }
2e9b04
+	  else
2e9b04
+	    {
2e9b04
+	      if (h->def_regular
2e9b04
+		  || h->ref_regular
2e9b04
+		  || (h->is_weakalias
2e9b04
+		      && weakdef (h)->dynindx != -1))
2e9b04
 		dynsym = TRUE;
2e9b04
 	    }
2e9b04
 
2e9b04
@@ -5214,6 +5228,9 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 	      && definition
2e9b04
 	      && ((dynsym
2e9b04
 		   && h->ref_regular_nonweak)
2e9b04
+		  || (old_bfd != NULL
2e9b04
+		      && (old_bfd->flags & BFD_PLUGIN) != 0
2e9b04
+		      && bind != STB_WEAK)
2e9b04
 		  || (h->ref_dynamic_nonweak
2e9b04
 		      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
2e9b04
 		      && !on_needed_list (elf_dt_name (abfd),
2e9b04
@@ -5338,49 +5355,31 @@ elf_link_add_object_symbols (bfd *abfd,
2e9b04
 	{
2e9b04
 	  struct bfd_hash_entry *p;
2e9b04
 	  struct elf_link_hash_entry *h;
2e9b04
-	  bfd_size_type size;
2e9b04
-	  unsigned int alignment_power;
2e9b04
 	  unsigned int non_ir_ref_dynamic;
2e9b04
 
2e9b04
 	  for (p = htab->root.table.table[i]; p != NULL; p = p->next)
2e9b04
 	    {
2e9b04
-	      h = (struct elf_link_hash_entry *) p;
2e9b04
-	      if (h->root.type == bfd_link_hash_warning)
2e9b04
-		h = (struct elf_link_hash_entry *) h->root.u.i.link;
2e9b04
-
2e9b04
-	      /* Preserve the maximum alignment and size for common
2e9b04
-		 symbols even if this dynamic lib isn't on DT_NEEDED
2e9b04
-		 since it can still be loaded at run time by another
2e9b04
-		 dynamic lib.  */
2e9b04
-	      if (h->root.type == bfd_link_hash_common)
2e9b04
-		{
2e9b04
-		  size = h->root.u.c.size;
2e9b04
-		  alignment_power = h->root.u.c.p->alignment_power;
2e9b04
-		}
2e9b04
-	      else
2e9b04
-		{
2e9b04
-		  size = 0;
2e9b04
-		  alignment_power = 0;
2e9b04
-		}
2e9b04
 	      /* Preserve non_ir_ref_dynamic so that this symbol
2e9b04
 		 will be exported when the dynamic lib becomes needed
2e9b04
 		 in the second pass.  */
2e9b04
+	      h = (struct elf_link_hash_entry *) p;
2e9b04
+	      if (h->root.type == bfd_link_hash_warning)
2e9b04
+		h = (struct elf_link_hash_entry *) h->root.u.i.link;
2e9b04
 	      non_ir_ref_dynamic = h->root.non_ir_ref_dynamic;
2e9b04
-	      memcpy (p, old_ent, htab->root.table.entsize);
2e9b04
-	      old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
+
2e9b04
 	      h = (struct elf_link_hash_entry *) p;
2e9b04
+	      memcpy (h, old_ent, htab->root.table.entsize);
2e9b04
+	      old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 	      if (h->root.type == bfd_link_hash_warning)
2e9b04
 		{
2e9b04
-		  memcpy (h->root.u.i.link, old_ent, htab->root.table.entsize);
2e9b04
-		  old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 		  h = (struct elf_link_hash_entry *) h->root.u.i.link;
2e9b04
+		  memcpy (h, old_ent, htab->root.table.entsize);
2e9b04
+		  old_ent = (char *) old_ent + htab->root.table.entsize;
2e9b04
 		}
2e9b04
 	      if (h->root.type == bfd_link_hash_common)
2e9b04
 		{
2e9b04
-		  if (size > h->root.u.c.size)
2e9b04
-		    h->root.u.c.size = size;
2e9b04
-		  if (alignment_power > h->root.u.c.p->alignment_power)
2e9b04
-		    h->root.u.c.p->alignment_power = alignment_power;
2e9b04
+		  memcpy (h->root.u.c.p, old_ent, sizeof (*h->root.u.c.p));
2e9b04
+		  old_ent = (char *) old_ent + sizeof (*h->root.u.c.p);
2e9b04
 		}
2e9b04
 	      h->root.non_ir_ref_dynamic = non_ir_ref_dynamic;
2e9b04
 	    }