Blame SOURCES/binutils-mark-all-weak-aliases.patch

bf7c0a
--- binutils.orig/bfd/elflink.c	2021-03-19 13:03:56.464793790 +0000
bf7c0a
+++ binutils-2.30/bfd/elflink.c	2021-03-19 13:05:17.475264954 +0000
bf7c0a
@@ -12825,7 +12825,7 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
bf7c0a
 		       bfd_boolean *start_stop)
bf7c0a
 {
bf7c0a
   unsigned long r_symndx;
bf7c0a
-  struct elf_link_hash_entry *h;
bf7c0a
+  struct elf_link_hash_entry *h, *hw;
bf7c0a
 
bf7c0a
   r_symndx = cookie->rel->r_info >> cookie->r_sym_shift;
bf7c0a
   if (r_symndx == STN_UNDEF)
bf7c0a
@@ -12845,12 +12845,16 @@ _bfd_elf_gc_mark_rsec (struct bfd_link_i
bf7c0a
 	     || h->root.type == bfd_link_hash_warning)
bf7c0a
 	h = (struct elf_link_hash_entry *) h->root.u.i.link;
bf7c0a
       h->mark = 1;
bf7c0a
-      /* If this symbol is weak and there is a non-weak definition, we
bf7c0a
-	 keep the non-weak definition because many backends put
bf7c0a
-	 dynamic reloc info on the non-weak definition for code
bf7c0a
-	 handling copy relocs.  */
bf7c0a
-      if (h->is_weakalias)
bf7c0a
-	weakdef (h)->mark = 1;
bf7c0a
+      /* Keep all aliases of the symbol too.  If an object symbol
bf7c0a
+        needs to be copied into .dynbss then all of its aliases
bf7c0a
+        should be present as dynamic symbols, not just the one used
bf7c0a
+        on the copy relocation.  */
bf7c0a
+      hw = h;
bf7c0a
+      while (hw->is_weakalias)
bf7c0a
+       {
bf7c0a
+         hw = hw->u.alias;
bf7c0a
+         hw->mark = 1;
bf7c0a
+       }
bf7c0a
 
bf7c0a
       if (start_stop != NULL)
bf7c0a
 	{
bf7c0a
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458.map
bf7c0a
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458.rd
bf7c0a
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458a.s
bf7c0a
Only in binutils-2.30/ld/testsuite/ld-elf: pr25458b.s
bf7c0a
diff -rup binutils.orig/ld/testsuite/ld-elf/shared.exp binutils-2.30/ld/testsuite/ld-elf/shared.exp
bf7c0a
--- binutils.orig/ld/testsuite/ld-elf/shared.exp	2021-03-19 13:03:56.141795899 +0000
bf7c0a
+++ binutils-2.30/ld/testsuite/ld-elf/shared.exp	2021-03-19 13:08:57.839826387 +0000
bf7c0a
@@ -296,6 +296,38 @@ if { [check_gc_sections_available] } {
bf7c0a
 	    "pr22150" \
bf7c0a
 	] \
bf7c0a
     ]
bf7c0a
+
bf7c0a
+    switch -glob $target_triplet {
bf7c0a
+       # Exclude targets that don't support copy relocs.
bf7c0a
+       bfin-*-* { }
bf7c0a
+       frv-*-* { }
bf7c0a
+       lm32-*-* { }
bf7c0a
+       mips*-*-* { }
bf7c0a
+       tic6x-*-* { }
bf7c0a
+       xtensa-*-* { }
bf7c0a
+       default {
bf7c0a
+           run_ld_link_tests [list \
bf7c0a
+               [list \
bf7c0a
+                    "Build pr25458.so" \
bf7c0a
+                    "$LFLAGS -shared --version-script=pr25458.map" \
bf7c0a
+                    "" \
bf7c0a
+                    "$AFLAGS_PIC" \
bf7c0a
+                    {pr25458b.s} \
bf7c0a
+                    {} \
bf7c0a
+                    "pr25458.so" \
bf7c0a
+               ] \
bf7c0a
+               [list \
bf7c0a
+                    "Build pr25458" \
bf7c0a
+                    "$LFLAGS -e _start --gc-sections" \
bf7c0a
+                    "tmpdir/pr25458.so" \
bf7c0a
+                    "$AFLAGS_PIC" \
bf7c0a
+                    {pr25458a.s} \
bf7c0a
+                    {{readelf {--dyn-sym --wide} pr25458.rd}} \
bf7c0a
+                    "pr25458" \
bf7c0a
+               ] \
bf7c0a
+           ]
bf7c0a
+       }
bf7c0a
+    } 
bf7c0a
 }
bf7c0a
 
bf7c0a
 set ASFLAGS $old_ASFLAGS
bf7c0a
--- /dev/null	2021-03-19 08:56:47.991465597 +0000
bf7c0a
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458.map	2021-03-19 13:06:34.859759781 +0000
bf7c0a
@@ -0,0 +1,4 @@
bf7c0a
+FOO {
bf7c0a
+global:
bf7c0a
+  __environ; _environ; environ;
bf7c0a
+};
bf7c0a
--- /dev/null	2021-03-19 08:56:47.991465597 +0000
bf7c0a
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458.rd	2021-03-19 13:06:34.860759774 +0000
bf7c0a
@@ -0,0 +1,10 @@
bf7c0a
+#...
bf7c0a
+Symbol table '\.dynsym' contains [0-9]+ entries:
bf7c0a
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
bf7c0a
+#...
bf7c0a
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
bf7c0a
+#...
bf7c0a
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
bf7c0a
+#...
bf7c0a
+ +[0-9]+: [0-9a-f]+ +(4|8)+ OBJECT +(WEAK|GLOBAL) +DEFAULT +[0-9]+ _*environ@FOO \(2\)
bf7c0a
+#pass
bf7c0a
--- /dev/null	2021-03-19 08:56:47.991465597 +0000
bf7c0a
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458a.s	2021-03-19 13:06:34.860759774 +0000
bf7c0a
@@ -0,0 +1,6 @@
bf7c0a
+	.text
bf7c0a
+	.globl	_start
bf7c0a
+	.type	_start, %function
bf7c0a
+_start:
bf7c0a
+	.dc.a	environ
bf7c0a
+	.size	_start, .-_start
bf7c0a
--- /dev/null	2021-03-19 08:56:47.991465597 +0000
bf7c0a
+++ binutils-2.30/ld/testsuite/ld-elf/pr25458b.s	2021-03-19 13:06:34.860759774 +0000
bf7c0a
@@ -0,0 +1,11 @@
bf7c0a
+	.data
bf7c0a
+	.globl __environ
bf7c0a
+	.type __environ,%object
bf7c0a
+__environ:
bf7c0a
+	.dc.a	0
bf7c0a
+	.size	__environ, .-__environ
bf7c0a
+	.weak _environ
bf7c0a
+	.globl _environ
bf7c0a
+	.set _environ, __environ
bf7c0a
+	.weak environ
bf7c0a
+	.set environ, __environ