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

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