Blame SOURCES/binutils-ifunc-relocs-in-notes.patch

869a11
diff -rup binutils.orig/bfd/elf32-i386.c binutils-2.30/bfd/elf32-i386.c
869a11
--- binutils.orig/bfd/elf32-i386.c	2018-03-09 14:43:05.324208873 +0000
869a11
+++ binutils-2.30/bfd/elf32-i386.c	2018-03-09 14:43:23.158000456 +0000
869a11
@@ -2202,12 +2202,19 @@ elf_i386_relocate_section (bfd *output_b
869a11
 
869a11
 	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
 	    {
869a11
+	      /* If this is a SHT_NOTE section without SHF_ALLOC, treat
869a11
+	         STT_GNU_IFUNC symbol as STT_FUNC.  */
869a11
+	      if (elf_section_type (input_section) == SHT_NOTE)
869a11
+		goto skip_ifunc;
869a11
 	      /* Dynamic relocs are not propagated for SEC_DEBUGGING
869a11
 		 sections because such sections are not SEC_ALLOC and
869a11
 		 thus ld.so will not process them.  */
869a11
 	      if ((input_section->flags & SEC_DEBUGGING) != 0)
869a11
 		continue;
869a11
-	      abort ();
869a11
+	      _bfd_error_handler (_("%B: error: relocation againt ifunc symbol in non-alloc section %A"),
869a11
+				  input_bfd, input_section);
869a11
+	      bfd_set_error (bfd_error_invalid_operation);
869a11
+	      return FALSE;
869a11
 	    }
869a11
 
869a11
 	  /* STT_GNU_IFUNC symbol must go through PLT.  */
869a11
@@ -2421,6 +2428,7 @@ do_ifunc_pointer:
869a11
 	    }
869a11
 	}
869a11
 
869a11
+    skip_ifunc:
869a11
       resolved_to_zero = (eh != NULL
869a11
 			  && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
869a11
 
869a11
diff -rup binutils.orig/bfd/elf32-s390.c binutils-2.30/bfd/elf32-s390.c
869a11
--- binutils.orig/bfd/elf32-s390.c	2018-03-09 14:43:05.325208861 +0000
869a11
+++ binutils-2.30/bfd/elf32-s390.c	2018-03-09 14:43:31.353904647 +0000
869a11
@@ -2601,6 +2601,9 @@ elf_s390_relocate_section (bfd *output_b
869a11
 	case R_390_8:
869a11
 	case R_390_16:
869a11
 	case R_390_32:
869a11
+	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
+	    break;
869a11
+
869a11
 	  if (h != NULL
869a11
 	      && s390_is_ifunc_symbol_p (h)
869a11
 	      && h->def_regular)
869a11
@@ -2662,9 +2665,6 @@ elf_s390_relocate_section (bfd *output_b
869a11
 		}
869a11
 	    }
869a11
 
869a11
-	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
-	    break;
869a11
-
869a11
 	  if ((bfd_link_pic (info)
869a11
 	       && (h == NULL
869a11
 		   || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
869a11
Only in binutils-2.30/bfd: elf32-s390.c.orig
869a11
diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.30/bfd/elf64-s390.c
869a11
--- binutils.orig/bfd/elf64-s390.c	2018-03-09 14:43:05.341208674 +0000
869a11
+++ binutils-2.30/bfd/elf64-s390.c	2018-03-09 14:43:31.354904635 +0000
869a11
@@ -2559,6 +2559,9 @@ elf_s390_relocate_section (bfd *output_b
869a11
 	case R_390_32:
869a11
 	case R_390_64:
869a11
 
869a11
+	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
+	    break;
869a11
+
869a11
 	  if (h != NULL
869a11
 	      && s390_is_ifunc_symbol_p (h)
869a11
 	      && h->def_regular)
869a11
@@ -2621,9 +2624,6 @@ elf_s390_relocate_section (bfd *output_b
869a11
 		}
869a11
 	    }
869a11
 
869a11
-	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
-	    break;
869a11
-
869a11
 	  if ((bfd_link_pic (info)
869a11
 	       && (h == NULL
869a11
 		   || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
869a11
Only in binutils-2.30/bfd: elf64-s390.c.orig
869a11
diff -rup binutils.orig/bfd/elf64-x86-64.c binutils-2.30/bfd/elf64-x86-64.c
869a11
--- binutils.orig/bfd/elf64-x86-64.c	2018-03-09 14:43:05.344208639 +0000
869a11
+++ binutils-2.30/bfd/elf64-x86-64.c	2018-03-09 14:43:23.161000420 +0000
869a11
@@ -2499,12 +2499,19 @@ elf_x86_64_relocate_section (bfd *output
869a11
 
869a11
 	  if ((input_section->flags & SEC_ALLOC) == 0)
869a11
 	    {
869a11
+	      /* If this is a SHT_NOTE section without SHF_ALLOC, treat
869a11
+	         STT_GNU_IFUNC symbol as STT_FUNC.  */
869a11
+	      if (elf_section_type (input_section) == SHT_NOTE)
869a11
+		goto skip_ifunc;
869a11
 	      /* Dynamic relocs are not propagated for SEC_DEBUGGING
869a11
 		 sections because such sections are not SEC_ALLOC and
869a11
 		 thus ld.so will not process them.  */
869a11
 	      if ((input_section->flags & SEC_DEBUGGING) != 0)
869a11
 		continue;
869a11
-	      abort ();
869a11
+	      _bfd_error_handler (_("%B: error: relocation againt ifunc symbol in non-alloc section %A"),
869a11
+				  input_bfd, input_section);
869a11
+	      bfd_set_error (bfd_error_invalid_operation);
869a11
+	      return FALSE;
869a11
 	    }
869a11
 
869a11
 	  switch (r_type)
869a11
@@ -2722,6 +2729,7 @@ do_ifunc_pointer:
869a11
 	    }
869a11
 	}
869a11
 
869a11
+    skip_ifunc:
869a11
       resolved_to_zero = (eh != NULL
869a11
 			  && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
869a11
 
869a11
diff -rup binutils.orig/bfd/elfnn-aarch64.c binutils-2.30/bfd/elfnn-aarch64.c
869a11
--- binutils.orig/bfd/elfnn-aarch64.c	2018-03-09 14:43:05.337208721 +0000
869a11
+++ binutils-2.30/bfd/elfnn-aarch64.c	2018-03-09 14:43:31.355904624 +0000
869a11
@@ -4987,6 +4987,11 @@ elfNN_aarch64_final_link_relocate (reloc
869a11
 
869a11
       if ((input_section->flags & SEC_ALLOC) == 0)
869a11
 	{
869a11
+	  /* If this is a SHT_NOTE section without SHF_ALLOC, treat
869a11
+	     STT_GNU_IFUNC symbol as STT_FUNC.  */
869a11
+	  if (elf_section_type (input_section) == SHT_NOTE)
869a11
+	    goto skip_ifunc;
869a11
+
869a11
 	  /* Dynamic relocs are not propagated for SEC_DEBUGGING
869a11
 	     sections because such sections are not SEC_ALLOC and
869a11
 	     thus ld.so will not process them.  */
869a11
@@ -5180,6 +5185,7 @@ bad_ifunc_reloc:
869a11
 	}
869a11
     }
869a11
 
869a11
+ skip_ifunc:
869a11
   resolved_to_zero = (h != NULL
869a11
 		      && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
869a11
 
869a11
Only in binutils-2.30/bfd: elfnn-aarch64.c.orig
869a11
diff -rup binutils.orig/bfd/elfxx-sparc.c binutils-2.30/bfd/elfxx-sparc.c
869a11
--- binutils.orig/bfd/elfxx-sparc.c	2018-03-09 14:43:05.333208768 +0000
869a11
+++ binutils-2.30/bfd/elfxx-sparc.c	2018-03-09 14:43:31.355904624 +0000
869a11
@@ -3026,7 +3026,13 @@ _bfd_sparc_elf_relocate_section (bfd *ou
869a11
 
869a11
 	  if ((input_section->flags & SEC_ALLOC) == 0
869a11
 	      || h->plt.offset == (bfd_vma) -1)
869a11
-	    abort ();
869a11
+	    {
869a11
+	      /* If this is a SHT_NOTE section without SHF_ALLOC, treat
869a11
+	         STT_GNU_IFUNC symbol as STT_FUNC.  */
869a11
+	      if (elf_section_type (input_section) == SHT_NOTE)
869a11
+		goto skip_ifunc;
869a11
+	      abort ();
869a11
+	    }
869a11
 
869a11
 	  plt_sec = htab->elf.splt;
869a11
 	  if (! plt_sec)
869a11
@@ -3130,6 +3136,7 @@ _bfd_sparc_elf_relocate_section (bfd *ou
869a11
 	    }
869a11
 	}
869a11
 
869a11
+    skip_ifunc:
869a11
       eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
869a11
       resolved_to_zero = (eh != NULL
869a11
 			  && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh));
869a11
Only in binutils-2.30/bfd: elfxx-sparc.c.orig
869a11
diff -rup binutils.orig/ld/testsuite/ld-ifunc/ifunc.exp binutils-2.30/ld/testsuite/ld-ifunc/ifunc.exp
869a11
--- binutils.orig/ld/testsuite/ld-ifunc/ifunc.exp	2018-03-09 14:43:04.844214486 +0000
869a11
+++ binutils-2.30/ld/testsuite/ld-ifunc/ifunc.exp	2018-03-09 14:43:31.355904624 +0000
869a11
@@ -47,6 +47,9 @@ if ![check_shared_lib_support] {
869a11
     return
869a11
 }
869a11
 
869a11
+# This test does not need a compiler...
869a11
+run_dump_test "ifuncmod5"
869a11
+
869a11
 # We need a working compiler.  (Strictly speaking this is
869a11
 # not true, we could use target specific assembler files).
869a11
 if { [which $CC] == 0 } {
869a11
Only in binutils-2.30: testsuite
869a11
--- /dev/null	2018-03-09 07:59:09.608015200 +0000
869a11
+++ binutils-2.30/ld/testsuite/ld-ifunc/ifuncmod5.s	2018-03-09 14:45:45.698334500 +0000
869a11
@@ -0,0 +1,105 @@
869a11
+	.file	"ifuncmod5.c"
869a11
+
869a11
+	.text
869a11
+	.type ifuncmod5.c, STT_NOTYPE
869a11
+ifuncmod5.c:
869a11
+	.size ifuncmod5.c, 0
869a11
+
869a11
+	.pushsection .gnu.build.attributes, "", %note
869a11
+	.balign 4
869a11
+	.dc.l 8 	
869a11
+	.dc.l 16	
869a11
+	.dc.l 0x100	
869a11
+	.asciz "GA$?3p4"	
869a11
+	.dc.a ifuncmod5.c
869a11
+	.dc.a ifuncmod5.c_end	
869a11
+	.popsection
869a11
+
869a11
+.Ltext0:
869a11
+#APP
869a11
+	.protected global
869a11
+	.type foo, %gnu_indirect_function
869a11
+	.type foo_hidden, %gnu_indirect_function
869a11
+	.type foo_protected, %gnu_indirect_function
869a11
+	.hidden foo_hidden
869a11
+	.protected foo_protected
869a11
+#NO_APP
869a11
+	.align	8
869a11
+	.type	one, %function
869a11
+one:
869a11
+	.dc.l 0
869a11
+	.size	one, .-one
869a11
+	.align	8
869a11
+
869a11
+.globl foo
869a11
+	.type	foo, %function
869a11
+foo:
869a11
+	.dc.l	0
869a11
+	.size	foo, .-foo
869a11
+
869a11
+	.pushsection .gnu.build.attributes
869a11
+	.dc.l 6		
869a11
+	.dc.l 16	
869a11
+	.dc.l 0x101	
869a11
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 	
869a11
+	.dc.b 0, 0 	
869a11
+	.dc.a foo
869a11
+	.dc.a foo_end	
869a11
+	.popsection
869a11
+
869a11
+foo_end:
869a11
+	.align	8
869a11
+.globl foo_hidden
869a11
+	.type	foo_hidden, %function
869a11
+foo_hidden:
869a11
+	.dc.l	0
869a11
+	.size	foo_hidden, .-foo_hidden
869a11
+
869a11
+	.pushsection .gnu.build.attributes
869a11
+	.dc.l 6		
869a11
+	.dc.l 16	
869a11
+	.dc.l 0x101	
869a11
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 	
869a11
+	.dc.b 0, 0 	
869a11
+	.dc.a foo_hidden
869a11
+	.dc.a foo_hidden_end	
869a11
+	.popsection
869a11
+
869a11
+foo_hidden_end:
869a11
+	.align	8
869a11
+
869a11
+	.globl foo_protected
869a11
+	.type	foo_protected, %function
869a11
+foo_protected:
869a11
+	.dc.l	0
869a11
+
869a11
+	.size	foo_protected, .-foo_protected
869a11
+
869a11
+	.pushsection .gnu.build.attributes
869a11
+	.dc.l 6		
869a11
+	.dc.l 16	
869a11
+	.dc.l 0x101	
869a11
+	.dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 	
869a11
+	.dc.b 0, 0 	
869a11
+	.dc.a foo_protected
869a11
+	.dc.a foo_protected_end	
869a11
+	.popsection
869a11
+
869a11
+foo_protected_end:
869a11
+	.globl global
869a11
+
869a11
+	.data
869a11
+	.align	4
869a11
+	.type	global, %object
869a11
+	.size	global, 4
869a11
+global:
869a11
+	.long	-1
869a11
+
869a11
+	.text
869a11
+	.Letext0:
869a11
+
869a11
+ifuncmod5.c_end:
869a11
+	.type ifuncmod5.c_end, STT_NOTYPE
869a11
+	.size ifuncmod5.c_end, 0
869a11
+
869a11
+
869a11
--- /dev/null	2018-03-09 07:59:09.608015200 +0000
869a11
+++ binutils-2.30/ld/testsuite/ld-ifunc/ifuncmod5.d	2018-03-09 14:45:45.698334500 +0000
869a11
@@ -0,0 +1,8 @@
869a11
+# name: Reloc against IFUNC symbol in NOTE section
869a11
+# ld: -shared
869a11
+# nm: -p
869a11
+
869a11
+# We do not actually care about the notes at the moment.
869a11
+# The purpose of this test is to make sure that the link completes successfully.
869a11
+#pass
869a11
+