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

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