Blame SOURCES/binutils-ld-IR-override.patch

1cefc9
diff -rup binutils.orig/include/bfdlink.h binutils-2.30/include/bfdlink.h
1cefc9
--- binutils.orig/include/bfdlink.h	2020-11-02 10:04:27.457826514 +0000
1cefc9
+++ binutils-2.30/include/bfdlink.h	2020-11-02 10:05:14.723537971 +0000
1cefc9
@@ -339,6 +339,9 @@ struct bfd_link_info
1cefc9
   /* TRUE if the LTO plugin is active.  */
1cefc9
   unsigned int lto_plugin_active: 1;
1cefc9
 
1cefc9
+  /* TRUE if all LTO IR symbols have been read.  */
1cefc9
+  unsigned int lto_all_symbols_read : 1;
1cefc9
+
1cefc9
   /* TRUE if global symbols in discarded sections should be stripped.  */
1cefc9
   unsigned int strip_discarded: 1;
1cefc9
 
1cefc9
diff -rup binutils.orig/ld/ldlang.c binutils-2.30/ld/ldlang.c
1cefc9
--- binutils.orig/ld/ldlang.c	2020-11-02 10:04:16.852890551 +0000
1cefc9
+++ binutils-2.30/ld/ldlang.c	2020-11-02 10:06:12.285185841 +0000
1cefc9
@@ -7162,6 +7162,7 @@ lang_process (void)
1cefc9
       if (plugin_call_all_symbols_read ())
1cefc9
 	einfo (_("%P%F: %s: plugin reported error after all symbols read\n"),
1cefc9
 	       plugin_error_plugin ());
1cefc9
+      link_info.lto_all_symbols_read = TRUE;
1cefc9
       /* Open any newly added files, updating the file chains.  */
1cefc9
       open_input_bfds (*added.tail, OPEN_BFD_NORMAL);
1cefc9
       /* Restore the global list pointer now they have all been added.  */
1cefc9
diff -rup binutils.orig/ld/plugin.c binutils-2.30/ld/plugin.c
1cefc9
--- binutils.orig/ld/plugin.c	2020-11-02 10:04:16.852890551 +0000
1cefc9
+++ binutils-2.30/ld/plugin.c	2020-11-02 10:08:11.010459546 +0000
1cefc9
@@ -1355,12 +1355,16 @@ plugin_notice (struct bfd_link_info *inf
1cefc9
 	     new value from a real BFD.  Weak symbols are not normally
1cefc9
 	     overridden by a new weak definition, and strong symbols
1cefc9
 	     will normally cause multiple definition errors.  Avoid
1cefc9
-	     this by making the symbol appear to be undefined.  */
1cefc9
-	  if (((h->type == bfd_link_hash_defweak
1cefc9
-		|| h->type == bfd_link_hash_defined)
1cefc9
-	       && is_ir_dummy_bfd (sym_bfd = h->u.def.section->owner))
1cefc9
-	      || (h->type == bfd_link_hash_common
1cefc9
-		  && is_ir_dummy_bfd (sym_bfd = h->u.c.p->section->owner)))
1cefc9
+	     this by making the symbol appear to be undefined.
1cefc9
+
1cefc9
+	     NB: We change the previous definition in the IR object to
1cefc9
+	     undefweak only after all LTO symbols have been read.  */
1cefc9
+	  if (info->lto_all_symbols_read
1cefc9
+              && (((h->type == bfd_link_hash_defweak
1cefc9
+                    || h->type == bfd_link_hash_defined)
1cefc9
+                   && is_ir_dummy_bfd (sym_bfd = h->u.def.section->owner))
1cefc9
+                  || (h->type == bfd_link_hash_common
1cefc9
+                      && is_ir_dummy_bfd (sym_bfd = h->u.c.p->section->owner))))
1cefc9
 	    {
1cefc9
 	      h->type = bfd_link_hash_undefweak;
1cefc9
 	      h->u.undef.abfd = sym_bfd;
1cefc9
diff -rup binutils.orig/ld/testsuite/ld-plugin/lto.exp binutils-2.30/ld/testsuite/ld-plugin/lto.exp
1cefc9
--- binutils.orig/ld/testsuite/ld-plugin/lto.exp	2020-11-02 10:04:16.926890104 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/lto.exp	2020-11-02 10:12:09.551000288 +0000
1cefc9
@@ -214,6 +214,36 @@ set lto_link_tests [list \
1cefc9
   [list "Build pr22502b.o" \
1cefc9
    "$plug_opt" "-flto $lto_no_fat" \
1cefc9
    {pr22502b.c}] \
1cefc9
+  [list "Build pr26262b.o" \
1cefc9
+   "" "-O2" \
1cefc9
+   {pr26262b.c} {} "" "c"] \
1cefc9
+  [list "Build pr26262c.o" \
1cefc9
+   "" "-O2" \
1cefc9
+   {pr26262c.c} {} "" "c"] \
1cefc9
+  [list "Build pr26267a.o" \
1cefc9
+   "" "-O2 -flto $lto_no_fat" \
1cefc9
+   {pr26267a.c} {} "" "c"] \
1cefc9
+  [list "Build pr26267b.o" \
1cefc9
+   "" "-O2" \
1cefc9
+   {pr26267b.c} {} "" "c"] \
1cefc9
+  [list "Build pr26267c.o" \
1cefc9
+   "" "-O2" \
1cefc9
+   {pr26267c.c} {} "" "c"] \
1cefc9
+  [list "Build pr26267a" \
1cefc9
+   "" "-O2" \
1cefc9
+   {pr26267a.c} {} "" "c"] \
1cefc9
+  [list "Build pr26267a" \
1cefc9
+   "-flto tmpdir/pr26267a.o tmpdir/pr26267b.o tmpdir/pr26267c.o" \
1cefc9
+   "-flto $lto_no_fat" \
1cefc9
+   {dummy.c} \
1cefc9
+   {{error_output "pr26267.err"}} \
1cefc9
+   "pr26267a"] \
1cefc9
+  [list "Build pr26267b" \
1cefc9
+   "-flto tmpdir/pr26267b.o tmpdir/pr26267c.o tmpdir/pr26267a.o" \
1cefc9
+   "-flto $lto_no_fat" \
1cefc9
+   {dummy.c} \
1cefc9
+   {{error_output "pr26267.err"}} \
1cefc9
+   "pr26267b"] \
1cefc9
 ]
1cefc9
 
1cefc9
 if { [at_least_gcc_version 4 7] } {
1cefc9
@@ -373,6 +403,16 @@ set lto_run_tests [list \
1cefc9
   [list "Run pr22502" \
1cefc9
    "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
1cefc9
    {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
1cefc9
+  [list "Run pr26262a" \
1cefc9
+   "-O2 -flto" "" \
1cefc9
+   {pr26262a.c} "pr26262a" "pass.out" \
1cefc9
+   "-flto -O2" "c" "" \
1cefc9
+   "tmpdir/pr26262b.o tmpdir/pr26262c.o"] \
1cefc9
+  [list "Run pr26262b" \
1cefc9
+   "-flto -O2 tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
1cefc9
+   {pr26262a.c} "pr26262b" "pass.out" \
1cefc9
+   "-flto -O2" "c" "" \
1cefc9
+   ""] \
1cefc9
 ]
1cefc9
 
1cefc9
 if { [at_least_gcc_version 4 7] } {
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26262a.c
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26262b.c
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26267.err
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26267a.c
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26267b.c
1cefc9
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26267c.c
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26262a.c	2020-11-02 10:13:16.624589913 +0000
1cefc9
@@ -0,0 +1,21 @@
1cefc9
+#include <stdio.h>
1cefc9
+
1cefc9
+int counter;
1cefc9
+extern void foo (void);
1cefc9
+extern void xxx (void);
1cefc9
+
1cefc9
+void
1cefc9
+bar (void)
1cefc9
+{
1cefc9
+}
1cefc9
+
1cefc9
+int
1cefc9
+main(void)
1cefc9
+{
1cefc9
+  bar ();
1cefc9
+  foo ();
1cefc9
+  xxx ();
1cefc9
+  if (counter == 1)
1cefc9
+    printf ("PASS\n");
1cefc9
+  return 0;
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26262b.c	2020-11-02 10:13:27.358523487 +0000
1cefc9
@@ -0,0 +1,16 @@
1cefc9
+#include <stdlib.h>
1cefc9
+
1cefc9
+extern int counter;
1cefc9
+
1cefc9
+void
1cefc9
+foo (void)
1cefc9
+{
1cefc9
+  counter++;
1cefc9
+}
1cefc9
+
1cefc9
+__attribute__((weak))
1cefc9
+void
1cefc9
+bar (void)
1cefc9
+{
1cefc9
+  abort ();
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26262c.c	2020-11-02 10:47:59.031665605 +0000
1cefc9
@@ -0,0 +1,6 @@
1cefc9
+extern void bar (void);
1cefc9
+void
1cefc9
+xxx (void)
1cefc9
+{
1cefc9
+  bar ();
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26267c.c	2020-11-02 10:13:39.665447327 +0000
1cefc9
@@ -0,0 +1,6 @@
1cefc9
+extern void bar (void);
1cefc9
+void
1cefc9
+xxx (void)
1cefc9
+{
1cefc9
+  bar ();
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26267b.c	2020-11-02 10:13:43.648422679 +0000
1cefc9
@@ -0,0 +1,15 @@
1cefc9
+#include <stdlib.h>
1cefc9
+
1cefc9
+extern int counter;
1cefc9
+
1cefc9
+void
1cefc9
+foo (void)
1cefc9
+{
1cefc9
+  counter++;
1cefc9
+}
1cefc9
+
1cefc9
+void
1cefc9
+bar (void)
1cefc9
+{
1cefc9
+  abort ();
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26267a.c	2020-11-02 10:13:47.556398495 +0000
1cefc9
@@ -0,0 +1,21 @@
1cefc9
+#include <stdio.h>
1cefc9
+
1cefc9
+int counter;
1cefc9
+extern void foo (void);
1cefc9
+extern void xxx (void);
1cefc9
+
1cefc9
+void
1cefc9
+bar (void)
1cefc9
+{
1cefc9
+}
1cefc9
+
1cefc9
+int
1cefc9
+main(void)
1cefc9
+{
1cefc9
+  bar ();
1cefc9
+  foo ();
1cefc9
+  xxx ();
1cefc9
+  if (counter == 1)
1cefc9
+    printf ("PASS\n");
1cefc9
+  return 0;
1cefc9
+}
1cefc9
--- /dev/null	2020-11-02 08:23:19.196542384 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26267.err	2020-11-02 10:14:01.785310441 +0000
1cefc9
@@ -0,0 +1,3 @@
1cefc9
+#...
1cefc9
+.*: multiple definition of `bar'; .*
1cefc9
+#...
1cefc9
diff -rup binutils.orig/ld/testsuite/ld-plugin/pr26267.err binutils-2.30/ld/testsuite/ld-plugin/pr26267.err
1cefc9
--- binutils.orig/ld/testsuite/ld-plugin/pr26267.err	2020-11-02 12:51:28.751137533 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26267.err	2020-11-02 13:01:38.430679516 +0000
1cefc9
@@ -1,3 +1,3 @@
1cefc9
 #...
1cefc9
-.*: multiple definition of `bar'; .*
1cefc9
+.*: multiple definition of `bar'.*
1cefc9
 #...
1cefc9
--- binutils.orig/ld/testsuite/ld-plugin/lto.exp	2020-11-02 12:51:28.751137533 +0000
1cefc9
+++ binutils-2.30/ld/testsuite/ld-plugin/lto.exp	2020-11-02 13:10:49.531708566 +0000
1cefc9
@@ -404,15 +404,13 @@ set lto_run_tests [list \
1cefc9
    "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
1cefc9
    {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
1cefc9
   [list "Run pr26262a" \
1cefc9
-   "-O2 -flto" "" \
1cefc9
+   "-O2 -flto tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
1cefc9
    {pr26262a.c} "pr26262a" "pass.out" \
1cefc9
-   "-flto -O2" "c" "" \
1cefc9
-   "tmpdir/pr26262b.o tmpdir/pr26262c.o"] \
1cefc9
+   "-flto -O2" "c" "" ] \
1cefc9
   [list "Run pr26262b" \
1cefc9
    "-flto -O2 tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
1cefc9
    {pr26262a.c} "pr26262b" "pass.out" \
1cefc9
-   "-flto -O2" "c" "" \
1cefc9
-   ""] \
1cefc9
+   "-flto -O2" "c" "" ] \
1cefc9
 ]
1cefc9
 
1cefc9
 if { [at_least_gcc_version 4 7] } {