Blob Blame History Raw
--- binutils.orig/bfd/elflink.c	2020-02-18 17:32:29.506802884 +0000
+++ binutils-2.32/bfd/elflink.c	2020-02-18 17:34:09.783017828 +0000
@@ -12988,6 +12988,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
 {
   unsigned long r_symndx;
   struct elf_link_hash_entry *h;
+  struct elf_link_hash_entry *hw;
 
   r_symndx = cookie->rel->r_info >> cookie->r_sym_shift;
   if (r_symndx == STN_UNDEF)
@@ -13007,12 +13008,16 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
 	     || h->root.type == bfd_link_hash_warning)
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;
       h->mark = 1;
-      /* If this symbol is weak and there is a non-weak definition, we
-	 keep the non-weak definition because many backends put
-	 dynamic reloc info on the non-weak definition for code
-	 handling copy relocs.  */
-      if (h->is_weakalias)
-	weakdef (h)->mark = 1;
+      /* Keep all aliases of the symbol too.  If an object symbol
+        needs to be copied into .dynbss then all of its aliases
+        should be present as dynamic symbols, not just the one used
+        on the copy relocation.  */
+      hw = h;
+      while (hw->is_weakalias)
+       {
+         hw = hw->u.alias;
+         hw->mark = 1;
+       }
 
       if (start_stop != NULL)
 	{