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

b37122
diff -rup binutils.orig/bfd/elflink.c binutils-2.30/bfd/elflink.c
b37122
--- binutils.orig/bfd/elflink.c	2021-03-18 14:33:03.462295923 +0000
b37122
+++ binutils-2.30/bfd/elflink.c	2021-03-18 14:37:34.110465450 +0000
b37122
@@ -4661,7 +4661,10 @@ error_free_dyn:
b37122
 	     object and a shared object.  */
b37122
 	  bfd_boolean dynsym = FALSE;
b37122
 
b37122
-	  if (! dynamic)
b37122
+	  /* Plugin symbols aren't normal.  Don't set def/ref flags.  */
b37122
+	  if ((abfd->flags & BFD_PLUGIN) != 0)
b37122
+	    ;
b37122
+	  else if (!dynamic)
b37122
 	    {
b37122
 	      if (! definition)
b37122
 		{
b37122
@@ -4678,14 +4681,6 @@ error_free_dyn:
b37122
 		      h->ref_dynamic = 1;
b37122
 		    }
b37122
 		}
b37122
-
b37122
-	      /* If the indirect symbol has been forced local, don't
b37122
-		 make the real symbol dynamic.  */
b37122
-	      if ((h == hi || !hi->forced_local)
b37122
-		  && (bfd_link_dll (info)
b37122
-		      || h->def_dynamic
b37122
-		      || h->ref_dynamic))
b37122
-		dynsym = TRUE;
b37122
 	    }
b37122
 	  else
b37122
 	    {
b37122
@@ -4699,14 +4694,25 @@ error_free_dyn:
b37122
 		  h->def_dynamic = 1;
b37122
 		  hi->def_dynamic = 1;
b37122
 		}
b37122
+	    }
b37122
 
b37122
-	      /* If the indirect symbol has been forced local, don't
b37122
-		 make the real symbol dynamic.  */
b37122
-	      if ((h == hi || !hi->forced_local)
b37122
-		  && (h->def_regular
b37122
-		      || h->ref_regular
b37122
-		      || (h->is_weakalias
b37122
-			  && weakdef (h)->dynindx != -1)))
b37122
+	  /* If an indirect symbol has been forced local, don't
b37122
+	     make the real symbol dynamic.  */
b37122
+	  if (h != hi && hi->forced_local)
b37122
+	    ;
b37122
+	  else if (!dynamic)
b37122
+	    {
b37122
+	      if (bfd_link_dll (info)
b37122
+		  || h->def_dynamic
b37122
+		  || h->ref_dynamic)
b37122
+		dynsym = TRUE;
b37122
+	    }
b37122
+	  else
b37122
+	    {
b37122
+	      if (h->def_regular
b37122
+		  || h->ref_regular
b37122
+		  || (h->is_weakalias
b37122
+		      && weakdef (h)->dynindx != -1))
b37122
 		dynsym = TRUE;
b37122
 	    }
b37122
 
b37122
@@ -4841,6 +4847,10 @@ error_free_dyn:
b37122
 	      && !bfd_link_relocatable (info))
b37122
 	    dynsym = FALSE;
b37122
 
b37122
+	  /* Nor should we make plugin symbols dynamic.  */
b37122
+	  if ((abfd->flags & BFD_PLUGIN) != 0)
b37122
+	    dynsym = FALSE;
b37122
+
b37122
 	  if (definition)
b37122
 	    {
b37122
 	      h->target_internal = isym->st_target_internal;
b37122
@@ -4866,8 +4876,8 @@ error_free_dyn:
b37122
 		  nondeflt_vers[nondeflt_vers_cnt++] = h;
b37122
 		}
b37122
 	    }
b37122
-
b37122
-	  if (dynsym && (abfd->flags & BFD_PLUGIN) == 0 && h->dynindx == -1)
b37122
+	
b37122
+	  if (dynsym && h->dynindx == -1)
b37122
 	    {
b37122
 	      if (! bfd_elf_link_record_dynamic_symbol (info, h))
b37122
 		goto error_free_vers;
b37122
@@ -4897,9 +4907,10 @@ error_free_dyn:
b37122
 	      && matched
b37122
 	      && definition
b37122
 	      && ((dynsym
b37122
-		   && h->ref_regular_nonweak
b37122
-		   && (old_bfd == NULL
b37122
-		       || (old_bfd->flags & BFD_PLUGIN) == 0))
b37122
+		   && h->ref_regular_nonweak)
b37122
+		  || (old_bfd != NULL
b37122
+		      && (old_bfd->flags & BFD_PLUGIN) != 0
b37122
+		      && bind != STB_WEAK)
b37122
 		  || (h->ref_dynamic_nonweak
b37122
 		      && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0
b37122
 		      && !on_needed_list (elf_dt_name (abfd),
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: lto-19.h
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: lto-19a.c
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: lto-19b.c
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: lto-19c.c
b37122
diff -rup binutils.orig/ld/testsuite/ld-plugin/lto.exp binutils-2.30/ld/testsuite/ld-plugin/lto.exp
b37122
--- binutils.orig/ld/testsuite/ld-plugin/lto.exp	2021-03-18 14:33:02.366303344 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/lto.exp	2021-03-18 14:41:51.419725611 +0000
b37122
@@ -133,7 +133,16 @@ set lto_link_tests [list \
b37122
    {lto-15a.c} {} ""] \
b37122
   [list "Build liblto-15.a" \
b37122
    "$plug_opt" "-flto" \
b37122
-   {lto-15b.c} {} "liblto-15.a"] \
b37122
+       {lto-15b.c} {} "liblto-15.a"] \
b37122
+  [list {liblto-19.a} \
b37122
+   "$plug_opt" {-flto -O2 -fPIC} \
b37122
+   {lto-19a.c} {} {liblto-19.a}] \
b37122
+  [list {compile lto-19b.c} \
b37122
+   "$plug_opt" {-flto -O2 -fPIC} \
b37122
+   {lto-19b.c} {} {} {c}] \
b37122
+  [list {liblto-19.so} \
b37122
+   {-shared tmpdir/lto-19b.o tmpdir/liblto-19.a} {-O2 -fPIC} \
b37122
+   {dummy.c} {} {liblto-19.so}] \
b37122
   [list "PR ld/12696" \
b37122
    "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
b37122
    {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
b37122
@@ -244,6 +253,9 @@ set lto_link_tests [list \
b37122
    {dummy.c} \
b37122
    {{error_output "pr26267.err"}} \
b37122
    "pr26267b"] \
b37122
+  [list {pr26806.so} \
b37122
+   {-shared} {-fpic -O2 -flto} \
b37122
+   {pr26806.c} {{nm {-D} pr26806.d}} {pr26806.so}] \
b37122
 ]
b37122
 
b37122
 if { [at_least_gcc_version 4 7] } {
b37122
@@ -438,6 +450,10 @@ set lto_run_elf_shared_tests [list \
b37122
   [list {pr22220b} \
b37122
    {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
b37122
    {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
b37122
+  [list {lto-19} \
b37122
+   {-Wl,--as-needed,-R,tmpdir} {} \
b37122
+   {lto-19a.c lto-19b.c lto-19c.c} {lto-19.exe} {pass.out} {-flto -O2} {c} {} \
b37122
+   {tmpdir/liblto-19.so tmpdir/liblto-19.a}] \
b37122
 ]
b37122
 
b37122
 # LTO run-time tests for ELF
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26806.c
b37122
Only in binutils-2.30/ld/testsuite/ld-plugin: pr26806.d
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/lto-19.h	2021-03-18 14:38:53.903925902 +0000
b37122
@@ -0,0 +1,6 @@
b37122
+struct re_dfa_t {
b37122
+  const int *sb_char;
b37122
+};
b37122
+struct re_dfa_t *xregcomp (void);
b37122
+struct re_dfa_t *rpl_regcomp (void);
b37122
+void rpl_regfree (struct re_dfa_t *);
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/lto-19a.c	2021-03-18 14:38:53.903925902 +0000
b37122
@@ -0,0 +1,19 @@
b37122
+#include <stdio.h>
b37122
+#include <stdlib.h>
b37122
+#include "lto-19.h"
b37122
+
b37122
+static const int utf8_sb_map[4] = { 0x12, 0x34, 0x56, 0x78 };
b37122
+
b37122
+struct re_dfa_t *
b37122
+rpl_regcomp ()
b37122
+{
b37122
+  struct re_dfa_t *dfa = malloc (sizeof (struct re_dfa_t));
b37122
+  dfa->sb_char = utf8_sb_map;
b37122
+  return dfa;
b37122
+}
b37122
+
b37122
+void
b37122
+rpl_regfree (struct re_dfa_t *dfa)
b37122
+{
b37122
+  puts (dfa->sb_char == utf8_sb_map ? "PASS" : "FAIL");
b37122
+}
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/lto-19b.c	2021-03-18 14:38:53.903925902 +0000
b37122
@@ -0,0 +1,7 @@
b37122
+#include "lto-19.h"
b37122
+
b37122
+struct re_dfa_t *
b37122
+xregcomp (void)
b37122
+{
b37122
+  return rpl_regcomp ();
b37122
+}
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/lto-19c.c	2021-03-18 14:38:53.903925902 +0000
b37122
@@ -0,0 +1,9 @@
b37122
+#include "lto-19.h"
b37122
+
b37122
+int
b37122
+main ()
b37122
+{
b37122
+  struct re_dfa_t *dfa = xregcomp ();
b37122
+  rpl_regfree (dfa);
b37122
+  return 0;
b37122
+}
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26806.c	2021-03-18 14:39:16.319774345 +0000
b37122
@@ -0,0 +1,2 @@
b37122
+#include <unistd.h>
b37122
+int foo (int x) { if (__builtin_constant_p (x)) return getpid (); return 0; }
b37122
--- /dev/null	2021-03-18 09:46:54.398732368 +0000
b37122
+++ binutils-2.30/ld/testsuite/ld-plugin/pr26806.d	2021-03-18 14:39:16.319774345 +0000
b37122
@@ -0,0 +1,4 @@
b37122
+#failif
b37122
+#...
b37122
+.* _*getpid[@ ].*
b37122
+#...