Nick Clifton 889b6e
diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.31.1/bfd/elf64-s390.c
Nick Clifton 889b6e
--- binutils.orig/bfd/elf64-s390.c	2018-07-19 12:37:28.107030007 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/bfd/elf64-s390.c	2018-07-19 12:38:11.235548717 +0100
Nick Clifton 889b6e
@@ -481,7 +481,7 @@ elf_s390_is_local_label_name (bfd *abfd,
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 #define RELA_ENTRY_SIZE sizeof (Elf64_External_Rela)
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-/* The first three entries in a procedure linkage table are reserved,
Nick Clifton 889b6e
+/* The first three entries in a global offset table are reserved,
Nick Clifton 889b6e
    and the initial contents are unimportant (we zero them out).
Nick Clifton 889b6e
    Subsequent entries look like this.  See the SVR4 ABI 386
Nick Clifton 889b6e
    supplement to see how this works.  */
Nick Clifton 889b6e
@@ -511,8 +511,8 @@ elf_s390_is_local_label_name (bfd *abfd,
Nick Clifton 889b6e
 	 LG   1,0(1)	  # 6 bytes  Load address from GOT in r1
Nick Clifton 889b6e
 	 BCR  15,1	  # 2 bytes  Jump to address
Nick Clifton 889b6e
    RET1: BASR 1,0	  # 2 bytes  Return from GOT 1st time
Nick Clifton 889b6e
-	 LGF  1,12(1)	  # 6 bytes  Load offset in symbl table in r1
Nick Clifton 889b6e
-	 BRCL 15,-x	  # 6 bytes  Jump to start of PLT
Nick Clifton 889b6e
+	 LGF  1,12(1)	  # 6 bytes  Load rela.plt offset into r1
Nick Clifton 889b6e
+	 BRCL 15,-x	  # 6 bytes  Jump to first PLT entry
Nick Clifton 889b6e
 	 .long ?	  # 4 bytes  offset into .rela.plt
Nick Clifton 889b6e
 
Nick Clifton 889b6e
    Total = 32 bytes per PLT entry
Nick Clifton 889b6e
@@ -1605,8 +1605,7 @@ allocate_dynrelocs (struct elf_link_hash
Nick Clifton 889b6e
 	  /* Make room for this entry.  */
Nick Clifton 889b6e
 	  s->size += PLT_ENTRY_SIZE;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-	  /* We also need to make an entry in the .got.plt section, which
Nick Clifton 889b6e
-	     will be placed in the .got section by the linker script.  */
Nick Clifton 889b6e
+	  /* We also need to make an entry in the .got.plt section.  */
Nick Clifton 889b6e
 	  htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  /* We also need to make an entry in the .rela.plt section.  */
Nick Clifton 889b6e
@@ -1831,6 +1830,20 @@ elf_s390_size_dynamic_sections (bfd *out
Nick Clifton 889b6e
 	}
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
+  if (htab->elf.sgot && s390_gotplt_after_got_p (info))
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      /* _bfd_elf_create_got_section adds the got header size always
Nick Clifton 889b6e
+	 to .got.plt but we need it in .got if this section comes
Nick Clifton 889b6e
+	 first.  */
Nick Clifton 889b6e
+      htab->elf.sgot->size += 3 * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
+      htab->elf.sgotplt->size -= 3 * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+      /* Make the _GLOBAL_OFFSET_TABLE_ symbol point to the .got
Nick Clifton 889b6e
+	 instead of .got.plt.  */
Nick Clifton 889b6e
+      htab->elf.hgot->root.u.def.section = htab->elf.sgot;
Nick Clifton 889b6e
+      htab->elf.hgot->root.u.def.value = 0;
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+
Nick Clifton 889b6e
   /* Set up .got offsets for local syms, and space for local dynamic
Nick Clifton 889b6e
      relocs.  */
Nick Clifton 889b6e
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
Nick Clifton 889b6e
@@ -2131,7 +2144,6 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
       bfd_boolean unresolved_reloc;
Nick Clifton 889b6e
       bfd_reloc_status_type r;
Nick Clifton 889b6e
       int tls_type;
Nick Clifton 889b6e
-      asection *base_got = htab->elf.sgot;
Nick Clifton 889b6e
       bfd_boolean resolved_to_zero;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
       r_type = ELF64_R_TYPE (rel->r_info);
Nick Clifton 889b6e
@@ -2172,7 +2184,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 		case R_390_PLTOFF16:
Nick Clifton 889b6e
 		case R_390_PLTOFF32:
Nick Clifton 889b6e
 		case R_390_PLTOFF64:
Nick Clifton 889b6e
-		  relocation -= htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+		  relocation -= s390_got_pointer (info);
Nick Clifton 889b6e
 		  break;
Nick Clifton 889b6e
 		case R_390_GOTPLT12:
Nick Clifton 889b6e
 		case R_390_GOTPLT16:
Nick Clifton 889b6e
@@ -2192,10 +2204,10 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 				htab->elf.sgot->contents +
Nick Clifton 889b6e
 				local_got_offsets[r_symndx]);
Nick Clifton 889b6e
 		    relocation = (local_got_offsets[r_symndx] +
Nick Clifton 889b6e
-				  htab->elf.sgot->output_offset);
Nick Clifton 889b6e
+				  s390_got_offset (info));
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 		    if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
-		      relocation += htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+		      relocation += s390_got_pointer (info);
Nick Clifton 889b6e
 		    break;
Nick Clifton 889b6e
 		  }
Nick Clifton 889b6e
 		default:
Nick Clifton 889b6e
@@ -2254,25 +2266,23 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	      if (s390_is_ifunc_symbol_p (h))
Nick Clifton 889b6e
 		{
Nick Clifton 889b6e
+		  /* Entry indices of .iplt and .igot.plt match
Nick Clifton 889b6e
+		     1:1. No magic PLT first entry here.  */
Nick Clifton 889b6e
 		  plt_index = h->plt.offset / PLT_ENTRY_SIZE;
Nick Clifton 889b6e
-		  relocation = (plt_index * GOT_ENTRY_SIZE +
Nick Clifton 889b6e
-				htab->elf.igotplt->output_offset);
Nick Clifton 889b6e
-		  if (r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
-		    relocation += htab->elf.igotplt->output_section->vma;
Nick Clifton 889b6e
+		  relocation = (plt_index * GOT_ENTRY_SIZE
Nick Clifton 889b6e
+				+ s390_gotplt_offset (info)
Nick Clifton 889b6e
+				+ htab->elf.igotplt->output_offset);
Nick Clifton 889b6e
 		}
Nick Clifton 889b6e
 	      else
Nick Clifton 889b6e
 		{
Nick Clifton 889b6e
-		  /* Calc. index no.
Nick Clifton 889b6e
-		     Current offset - size first entry / entry size.  */
Nick Clifton 889b6e
-		  plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) /
Nick Clifton 889b6e
-		    PLT_ENTRY_SIZE;
Nick Clifton 889b6e
-
Nick Clifton 889b6e
-		  /* Offset in GOT is PLT index plus GOT headers(3)
Nick Clifton 889b6e
-		     times 8, addr & GOT addr.  */
Nick Clifton 889b6e
-		  relocation = (plt_index + 3) * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
-		  if (r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
-		    relocation += htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+		  plt_index = ((h->plt.offset - PLT_FIRST_ENTRY_SIZE)
Nick Clifton 889b6e
+			       / PLT_ENTRY_SIZE);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+		  relocation = (plt_index * GOT_ENTRY_SIZE
Nick Clifton 889b6e
+				+ s390_gotplt_offset (info));
Nick Clifton 889b6e
 		}
Nick Clifton 889b6e
+	      if (r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
+		relocation += s390_got_pointer (info);
Nick Clifton 889b6e
 	      unresolved_reloc = FALSE;
Nick Clifton 889b6e
 	      break;
Nick Clifton 889b6e
 	    }
Nick Clifton 889b6e
@@ -2286,7 +2296,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	case R_390_GOTENT:
Nick Clifton 889b6e
 	  /* Relocation is to the entry for this symbol in the global
Nick Clifton 889b6e
 	     offset table.  */
Nick Clifton 889b6e
-	  if (base_got == NULL)
Nick Clifton 889b6e
+	  if (htab->elf.sgot == NULL)
Nick Clifton 889b6e
 	    abort ();
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  if (h != NULL)
Nick Clifton 889b6e
@@ -2303,8 +2313,19 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 		    {
Nick Clifton 889b6e
 		      /* No explicit GOT usage so redirect to the
Nick Clifton 889b6e
 			 got.iplt slot.  */
Nick Clifton 889b6e
-		      base_got = htab->elf.igotplt;
Nick Clifton 889b6e
-		      off = h->plt.offset / PLT_ENTRY_SIZE * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
+		      relocation = (s390_gotplt_offset (info)
Nick Clifton 889b6e
+				    + htab->elf.igotplt->output_offset
Nick Clifton 889b6e
+				    + (h->plt.offset / PLT_ENTRY_SIZE
Nick Clifton 889b6e
+				       * GOT_ENTRY_SIZE));
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+		      /* For @GOTENT the relocation is against the offset between
Nick Clifton 889b6e
+			 the instruction and the symbols entry in the GOT and not
Nick Clifton 889b6e
+			 between the start of the GOT and the symbols entry. We
Nick Clifton 889b6e
+			 add the vma of the GOT to get the correct value.  */
Nick Clifton 889b6e
+		      if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
+			relocation += s390_got_pointer (info);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+		      break;
Nick Clifton 889b6e
 		    }
Nick Clifton 889b6e
 		  else
Nick Clifton 889b6e
 		    {
Nick Clifton 889b6e
@@ -2337,7 +2358,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 		  else
Nick Clifton 889b6e
 		    {
Nick Clifton 889b6e
 		      bfd_put_64 (output_bfd, relocation,
Nick Clifton 889b6e
-				  base_got->contents + off);
Nick Clifton 889b6e
+				  htab->elf.sgot->contents + off);
Nick Clifton 889b6e
 		      h->got.offset |= 1;
Nick Clifton 889b6e
 		    }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -2419,7 +2440,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	  if (off >= (bfd_vma) -2)
Nick Clifton 889b6e
 	    abort ();
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-	  relocation = base_got->output_offset + off;
Nick Clifton 889b6e
+	  relocation = s390_got_offset (info) + off;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  /* For @GOTENT the relocation is against the offset between
Nick Clifton 889b6e
 	     the instruction and the symbols entry in the GOT and not
Nick Clifton 889b6e
@@ -2427,7 +2448,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	     add the vma of the GOT to get the correct value.  */
Nick Clifton 889b6e
 	  if (   r_type == R_390_GOTENT
Nick Clifton 889b6e
 	      || r_type == R_390_GOTPLTENT)
Nick Clifton 889b6e
-	    relocation += base_got->output_section->vma;
Nick Clifton 889b6e
+	    relocation += s390_got_pointer (info);
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  break;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -2445,22 +2466,17 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	      relocation = (htab->elf.iplt->output_section->vma
Nick Clifton 889b6e
 			    + htab->elf.iplt->output_offset
Nick Clifton 889b6e
 			    + h->plt.offset
Nick Clifton 889b6e
-			    - htab->elf.sgot->output_section->vma);
Nick Clifton 889b6e
+			    - s390_got_pointer (info));
Nick Clifton 889b6e
 	      goto do_relocation;
Nick Clifton 889b6e
 	    }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-	  /* Note that sgot->output_offset is not involved in this
Nick Clifton 889b6e
-	     calculation.  We always want the start of .got.  If we
Nick Clifton 889b6e
-	     defined _GLOBAL_OFFSET_TABLE in a different way, as is
Nick Clifton 889b6e
-	     permitted by the ABI, we might have to change this
Nick Clifton 889b6e
-	     calculation.  */
Nick Clifton 889b6e
-	  relocation -= htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+	  relocation -= s390_got_pointer (info);
Nick Clifton 889b6e
 	  break;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	case R_390_GOTPC:
Nick Clifton 889b6e
 	case R_390_GOTPCDBL:
Nick Clifton 889b6e
 	  /* Use global offset table as symbol value.  */
Nick Clifton 889b6e
-	  relocation = htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+	  relocation = s390_got_pointer (info);
Nick Clifton 889b6e
 	  unresolved_reloc = FALSE;
Nick Clifton 889b6e
 	  break;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -2509,7 +2525,7 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	      || h->plt.offset == (bfd_vma) -1
Nick Clifton 889b6e
 	      || (htab->elf.splt == NULL && !s390_is_ifunc_symbol_p (h)))
Nick Clifton 889b6e
 	    {
Nick Clifton 889b6e
-	      relocation -= htab->elf.sgot->output_section->vma;
Nick Clifton 889b6e
+	      relocation -= s390_got_pointer (info);
Nick Clifton 889b6e
 	      break;
Nick Clifton 889b6e
 	    }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -2517,12 +2533,12 @@ elf_s390_relocate_section (bfd *output_b
Nick Clifton 889b6e
 	    relocation = (htab->elf.iplt->output_section->vma
Nick Clifton 889b6e
 			  + htab->elf.iplt->output_offset
Nick Clifton 889b6e
 			  + h->plt.offset
Nick Clifton 889b6e
-			  - htab->elf.sgot->output_section->vma);
Nick Clifton 889b6e
+			  - s390_got_pointer (info));
Nick Clifton 889b6e
 	  else
Nick Clifton 889b6e
 	    relocation = (htab->elf.splt->output_section->vma
Nick Clifton 889b6e
 			  + htab->elf.splt->output_offset
Nick Clifton 889b6e
 			  + h->plt.offset
Nick Clifton 889b6e
-			  - htab->elf.sgot->output_section->vma);
Nick Clifton 889b6e
+			  - s390_got_pointer (info));
Nick Clifton 889b6e
 	  unresolved_reloc = FALSE;
Nick Clifton 889b6e
 	  break;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -3296,7 +3312,7 @@ elf_s390_finish_dynamic_symbol (bfd *out
Nick Clifton 889b6e
   if (h->plt.offset != (bfd_vma) -1)
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
       bfd_vma plt_index;
Nick Clifton 889b6e
-      bfd_vma got_offset;
Nick Clifton 889b6e
+      bfd_vma gotplt_offset;
Nick Clifton 889b6e
       Elf_Internal_Rela rela;
Nick Clifton 889b6e
       bfd_byte *loc;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
@@ -3325,18 +3341,25 @@ elf_s390_finish_dynamic_symbol (bfd *out
Nick Clifton 889b6e
 	     Current offset - size first entry / entry size.  */
Nick Clifton 889b6e
 	  plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-	  /* Offset in GOT is PLT index plus GOT headers(3) times 8,
Nick Clifton 889b6e
-	     addr & GOT addr.  */
Nick Clifton 889b6e
-	  got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
+	  /* The slots in the .got.plt correspond to the PLT slots in
Nick Clifton 889b6e
+	     the same order.  */
Nick Clifton 889b6e
+	  gotplt_offset = plt_index * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+	  /* If .got.plt comes first it needs to contain the 3 header
Nick Clifton 889b6e
+	     entries.  */
Nick Clifton 889b6e
+	  if (!s390_gotplt_after_got_p (info))
Nick Clifton 889b6e
+	    gotplt_offset += 3 * GOT_ENTRY_SIZE;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  /* Fill in the blueprint of a PLT.  */
Nick Clifton 889b6e
 	  memcpy (htab->elf.splt->contents + h->plt.offset, elf_s390x_plt_entry,
Nick Clifton 889b6e
 		  PLT_ENTRY_SIZE);
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-	  /* Fixup the relative address to the GOT entry */
Nick Clifton 889b6e
+	  /* The first instruction in the PLT entry is a LARL loading
Nick Clifton 889b6e
+	     the address of the GOT slot.  We write the 4 byte
Nick Clifton 889b6e
+	     immediate operand of the LARL instruction here.  */
Nick Clifton 889b6e
 	  bfd_put_32 (output_bfd,
Nick Clifton 889b6e
 		      (htab->elf.sgotplt->output_section->vma +
Nick Clifton 889b6e
-		       htab->elf.sgotplt->output_offset + got_offset
Nick Clifton 889b6e
+		       htab->elf.sgotplt->output_offset + gotplt_offset
Nick Clifton 889b6e
 		       - (htab->elf.splt->output_section->vma +
Nick Clifton 889b6e
 			  htab->elf.splt->output_offset +
Nick Clifton 889b6e
 			  h->plt.offset))/2,
Nick Clifton 889b6e
@@ -3356,12 +3379,12 @@ elf_s390_finish_dynamic_symbol (bfd *out
Nick Clifton 889b6e
 		       + htab->elf.splt->output_offset
Nick Clifton 889b6e
 		       + h->plt.offset
Nick Clifton 889b6e
 		       + 14),
Nick Clifton 889b6e
-		      htab->elf.sgotplt->contents + got_offset);
Nick Clifton 889b6e
+		      htab->elf.sgotplt->contents + gotplt_offset);
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	  /* Fill in the entry in the .rela.plt section.  */
Nick Clifton 889b6e
 	  rela.r_offset = (htab->elf.sgotplt->output_section->vma
Nick Clifton 889b6e
 			   + htab->elf.sgotplt->output_offset
Nick Clifton 889b6e
-			   + got_offset);
Nick Clifton 889b6e
+			   + gotplt_offset);
Nick Clifton 889b6e
 	  rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
Nick Clifton 889b6e
 	  rela.r_addend = 0;
Nick Clifton 889b6e
 	  loc = htab->elf.srelplt->contents + plt_index *
Nick Clifton 889b6e
@@ -3568,8 +3591,8 @@ elf_s390_finish_dynamic_sections (bfd *o
Nick Clifton 889b6e
 	      continue;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	    case DT_PLTGOT:
Nick Clifton 889b6e
-	      s = htab->elf.sgotplt;
Nick Clifton 889b6e
-	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
Nick Clifton 889b6e
+	      /* DT_PLTGOT matches _GLOBAL_OFFSET_TABLE_ */
Nick Clifton 889b6e
+	      dyn.d_un.d_ptr = s390_got_pointer (info);
Nick Clifton 889b6e
 	      break;
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 	    case DT_JMPREL:
Nick Clifton 889b6e
@@ -3606,10 +3629,11 @@ elf_s390_finish_dynamic_sections (bfd *o
Nick Clifton 889b6e
 	  /* fill in blueprint for plt 0 entry */
Nick Clifton 889b6e
 	  memcpy (htab->elf.splt->contents, elf_s390x_first_plt_entry,
Nick Clifton 889b6e
 		  PLT_FIRST_ENTRY_SIZE);
Nick Clifton 889b6e
-	  /* Fixup relative address to start of GOT */
Nick Clifton 889b6e
+	  /* The second instruction in the first PLT entry is a LARL
Nick Clifton 889b6e
+	     loading the GOT pointer.  Fill in the LARL immediate
Nick Clifton 889b6e
+	     address.  */
Nick Clifton 889b6e
 	  bfd_put_32 (output_bfd,
Nick Clifton 889b6e
-		      (htab->elf.sgotplt->output_section->vma
Nick Clifton 889b6e
-		       + htab->elf.sgotplt->output_offset
Nick Clifton 889b6e
+		      (s390_got_pointer (info)
Nick Clifton 889b6e
 		       - htab->elf.splt->output_section->vma
Nick Clifton 889b6e
 		       - htab->elf.splt->output_offset - 6)/2,
Nick Clifton 889b6e
 		      htab->elf.splt->contents + 8);
Nick Clifton 889b6e
@@ -3619,21 +3643,22 @@ elf_s390_finish_dynamic_sections (bfd *o
Nick Clifton 889b6e
 	  = PLT_ENTRY_SIZE;
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
-  if (htab->elf.sgotplt)
Nick Clifton 889b6e
+  if (htab->elf.hgot && htab->elf.hgot->root.u.def.section)
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
       /* Fill in the first three entries in the global offset table.  */
Nick Clifton 889b6e
-      if (htab->elf.sgotplt->size > 0)
Nick Clifton 889b6e
+      if (htab->elf.hgot->root.u.def.section->size > 0)
Nick Clifton 889b6e
 	{
Nick Clifton 889b6e
 	  bfd_put_64 (output_bfd,
Nick Clifton 889b6e
 		      (sdyn == NULL ? (bfd_vma) 0
Nick Clifton 889b6e
 		       : sdyn->output_section->vma + sdyn->output_offset),
Nick Clifton 889b6e
-		      htab->elf.sgotplt->contents);
Nick Clifton 889b6e
+		      htab->elf.hgot->root.u.def.section->contents);
Nick Clifton 889b6e
 	  /* One entry for shared object struct ptr.  */
Nick Clifton 889b6e
-	  bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + 8);
Nick Clifton 889b6e
+	  bfd_put_64 (output_bfd, (bfd_vma) 0,
Nick Clifton 889b6e
+		      htab->elf.hgot->root.u.def.section->contents + 8);
Nick Clifton 889b6e
 	  /* One entry for _dl_runtime_resolve.  */
Nick Clifton 889b6e
-	  bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + 16);
Nick Clifton 889b6e
+	  bfd_put_64 (output_bfd, (bfd_vma) 0,
Nick Clifton 889b6e
+		      htab->elf.hgot->root.u.def.section->contents + 16);
Nick Clifton 889b6e
 	}
Nick Clifton 889b6e
-
Nick Clifton 889b6e
       elf_section_data (htab->elf.sgot->output_section)
Nick Clifton 889b6e
 	->this_hdr.sh_entsize = 8;
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
diff -rup binutils.orig/bfd/elf-s390-common.c binutils-2.31.1/bfd/elf-s390-common.c
Nick Clifton 889b6e
--- binutils.orig/bfd/elf-s390-common.c	2018-07-19 12:37:28.113029940 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/bfd/elf-s390-common.c	2018-07-19 12:38:11.235548717 +0100
Nick Clifton 889b6e
@@ -30,6 +30,87 @@ s390_is_ifunc_symbol_p (struct elf_link_
Nick Clifton 889b6e
   return h->type == STT_GNU_IFUNC || eh->ifunc_resolver_address != 0;
Nick Clifton 889b6e
 }
Nick Clifton 889b6e
 
Nick Clifton 889b6e
+/* Return true if .got.plt is supposed to be emitted after .got.  */
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+static inline bfd_boolean
Nick Clifton 889b6e
+s390_gotplt_after_got_p (struct bfd_link_info *info)
Nick Clifton 889b6e
+{
Nick Clifton 889b6e
+  struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  if (!htab->elf.sgot || !htab->elf.sgotplt)
Nick Clifton 889b6e
+    return TRUE;
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  if (htab->elf.sgot->output_section == htab->elf.sgotplt->output_section)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (htab->elf.sgot->output_offset < htab->elf.sgotplt->output_offset)
Nick Clifton 889b6e
+	return TRUE;
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+  else
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (htab->elf.sgot->output_section->vma
Nick Clifton 889b6e
+	  <= htab->elf.sgotplt->output_section->vma)
Nick Clifton 889b6e
+	return TRUE;
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+  return FALSE;
Nick Clifton 889b6e
+}
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+/* Return the value of the _GLOBAL_OFFSET_TABLE_ symbol.  */
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+static inline bfd_vma
Nick Clifton 889b6e
+s390_got_pointer (struct bfd_link_info *info)
Nick Clifton 889b6e
+{
Nick Clifton 889b6e
+  struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
Nick Clifton 889b6e
+  bfd_vma got_pointer;
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  BFD_ASSERT (htab && htab->elf.hgot);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  got_pointer = (htab->elf.hgot->root.u.def.section->output_section->vma
Nick Clifton 889b6e
+		 + htab->elf.hgot->root.u.def.section->output_offset);
Nick Clifton 889b6e
+  /* Our ABI requires the GOT pointer to point at the very beginning
Nick Clifton 889b6e
+     of the global offset table.  */
Nick Clifton 889b6e
+  BFD_ASSERT (got_pointer
Nick Clifton 889b6e
+	      <= (htab->elf.sgot->output_section->vma
Nick Clifton 889b6e
+		  + htab->elf.sgot->output_offset));
Nick Clifton 889b6e
+  BFD_ASSERT (got_pointer
Nick Clifton 889b6e
+	      <= (htab->elf.sgotplt->output_section->vma
Nick Clifton 889b6e
+		  + htab->elf.sgotplt->output_offset));
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  return got_pointer;
Nick Clifton 889b6e
+}
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+/* Return the offset of the .got versus _GLOBAL_OFFSET_TABLE_.  */
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+static inline bfd_vma
Nick Clifton 889b6e
+s390_got_offset (struct bfd_link_info *info)
Nick Clifton 889b6e
+{
Nick Clifton 889b6e
+  struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  /* The absolute address of the .got in the target image.  */
Nick Clifton 889b6e
+  bfd_vma got_address = (htab->elf.sgot->output_section->vma
Nick Clifton 889b6e
+			 + htab->elf.sgot->output_offset);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  /* GOT offset must not be negative.  */
Nick Clifton 889b6e
+  BFD_ASSERT (s390_got_pointer (info) <= got_address);
Nick Clifton 889b6e
+  return got_address - s390_got_pointer (info);
Nick Clifton 889b6e
+}
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+/* Return the offset of the .got.plt versus _GLOBAL_OFFSET_TABLE_.  */
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+static inline bfd_vma
Nick Clifton 889b6e
+s390_gotplt_offset (struct bfd_link_info *info)
Nick Clifton 889b6e
+{
Nick Clifton 889b6e
+  struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  /* The absolute address of the .got.plt in the target image.  */
Nick Clifton 889b6e
+  bfd_vma gotplt_address = (htab->elf.sgotplt->output_section->vma
Nick Clifton 889b6e
+			    + htab->elf.sgotplt->output_offset);
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  /* GOT offset must not be negative.  */
Nick Clifton 889b6e
+  BFD_ASSERT (s390_got_pointer (info) <= gotplt_address);
Nick Clifton 889b6e
+  return gotplt_address - s390_got_pointer (info);
Nick Clifton 889b6e
+}
Nick Clifton 889b6e
+
Nick Clifton 889b6e
 /* Create sections needed by STT_GNU_IFUNC symbol.  */
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 static bfd_boolean
Nick Clifton 889b6e
diff -rup binutils.orig/ld/emulparams/elf64_s390.sh binutils-2.31.1/ld/emulparams/elf64_s390.sh
Nick Clifton 889b6e
--- binutils.orig/ld/emulparams/elf64_s390.sh	2018-07-19 12:37:28.544025130 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/ld/emulparams/elf64_s390.sh	2018-07-19 12:38:11.235548717 +0100
Nick Clifton 889b6e
@@ -11,9 +11,12 @@ NOP=0x07070707
Nick Clifton 889b6e
 TEMPLATE_NAME=elf32
Nick Clifton 889b6e
 GENERATE_SHLIB_SCRIPT=yes
Nick Clifton 889b6e
 GENERATE_PIE_SCRIPT=yes
Nick Clifton 889b6e
+GENERATE_RELRO_SCRIPT=yes
Nick Clifton 889b6e
 NO_SMALL_DATA=yes
Nick Clifton 889b6e
 EXTRA_EM_FILE=s390
Nick Clifton 889b6e
 IREL_IN_PLT=
Nick Clifton 889b6e
+SEPARATE_GOTPLT=0
Nick Clifton 889b6e
+test -z "$RELRO" && unset SEPARATE_GOTPLT
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 # Treat a host that matches the target with the possible exception of "x"
Nick Clifton 889b6e
 # in the name as if it were native.
Nick Clifton 889b6e
diff -rup binutils.orig/ld/emultempl/elf32.em binutils-2.31.1/ld/emultempl/elf32.em
Nick Clifton 889b6e
--- binutils.orig/ld/emultempl/elf32.em	2018-07-19 12:37:28.549025074 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/ld/emultempl/elf32.em	2018-07-19 12:37:39.041907980 +0100
Nick Clifton 889b6e
@@ -2376,17 +2376,41 @@ echo '             && link_info.combrelo
Nick Clifton 889b6e
 echo '             && link_info.relro'			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xdw			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xdceo              >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_pie (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.separate_code'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.combreloc) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xdce		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xdco               >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_pie (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.combreloc) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xdc			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xdeo               >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_pie (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.separate_code) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xde			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xdo                >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_pie (&link_info)) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xd			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
@@ -2402,17 +2426,41 @@ echo '             && link_info.combrelo
Nick Clifton 889b6e
 echo '             && link_info.relro'			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xsw			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xsceo              >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_dll (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.combreloc'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.separate_code) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xsce			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xsco               >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_dll (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.combreloc) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xsc			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xseo               >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_dll (&link_info)'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.separate_code) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xse			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xso               >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (bfd_link_dll (&link_info)) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xs			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
@@ -2425,14 +2473,34 @@ echo '  ; else if (link_info.combreloc'
Nick Clifton 889b6e
 echo '             && link_info.relro'			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xw			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.separate_code'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xceo                >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (link_info.combreloc'			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '             && link_info.separate_code) return'	>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xce			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xco                 >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else if (link_info.combreloc) return'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xc			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
-echo '  ; else if (link_info.separate_code) return'		>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (link_info.separate_code'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xeo                 >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
+echo '  ; else if (link_info.separate_code) return'     >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.xe			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+echo '  ; else if (link_info.relro) return'             >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+sed $sc ldscripts/${EMULATION_NAME}.xo                  >> e${EMULATION_NAME}.c
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 echo '  ; else return'					>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 sed $sc ldscripts/${EMULATION_NAME}.x			>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
 echo '; }'						>> e${EMULATION_NAME}.c
Nick Clifton 889b6e
@@ -2471,6 +2539,21 @@ fragment <
Nick Clifton 889b6e
       else
Nick Clifton 889b6e
 	return "ldscripts/${EMULATION_NAME}.xdw";
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (bfd_link_pie (&link_info)
Nick Clifton 889b6e
+	   && link_info.combreloc
Nick Clifton 889b6e
+	   && link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xdceo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xdco";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
   else if (bfd_link_pie (&link_info)
Nick Clifton 889b6e
 	   && link_info.combreloc)
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
@@ -2481,6 +2564,18 @@ fragment <
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
 EOF
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (bfd_link_pie (&link_info)
Nick Clifton 889b6e
+	   && link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xdeo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xdo";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 fragment <
Nick Clifton 889b6e
   else if (bfd_link_pie (&link_info))
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
@@ -2502,6 +2597,21 @@ fragment <
Nick Clifton 889b6e
       else
Nick Clifton 889b6e
 	return "ldscripts/${EMULATION_NAME}.xsw";
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (bfd_link_dll (&link_info)
Nick Clifton 889b6e
+	   && link_info.combreloc
Nick Clifton 889b6e
+	   && link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xsceo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xsco";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
   else if (bfd_link_dll (&link_info) && link_info.combreloc)
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
       if (link_info.separate_code)
Nick Clifton 889b6e
@@ -2511,6 +2621,18 @@ fragment <
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
 EOF
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (bfd_link_dll (&link_info)
Nick Clifton 889b6e
+	   && link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xseo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xso";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 fragment <
Nick Clifton 889b6e
   else if (bfd_link_dll (&link_info))
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
@@ -2531,6 +2653,20 @@ fragment <
Nick Clifton 889b6e
       else
Nick Clifton 889b6e
 	return "ldscripts/${EMULATION_NAME}.xw";
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (link_info.combreloc
Nick Clifton 889b6e
+	   && link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xceo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xco";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
   else if (link_info.combreloc)
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
       if (link_info.separate_code)
Nick Clifton 889b6e
@@ -2540,6 +2676,17 @@ fragment <
Nick Clifton 889b6e
     }
Nick Clifton 889b6e
 EOF
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT" ; then
Nick Clifton 889b6e
+fragment <
Nick Clifton 889b6e
+  else if (link_info.relro)
Nick Clifton 889b6e
+    {
Nick Clifton 889b6e
+      if (link_info.separate_code)
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xeo";
Nick Clifton 889b6e
+      else
Nick Clifton 889b6e
+	return "ldscripts/${EMULATION_NAME}.xo";
Nick Clifton 889b6e
+    }
Nick Clifton 889b6e
+EOF
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 fragment <
Nick Clifton 889b6e
   else
Nick Clifton 889b6e
     {
Nick Clifton 889b6e
diff -rup binutils.orig/ld/genscripts.sh binutils-2.31.1/ld/genscripts.sh
Nick Clifton 889b6e
--- binutils.orig/ld/genscripts.sh	2018-07-19 12:37:28.540025175 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/ld/genscripts.sh	2018-07-19 12:37:39.041907980 +0100
Nick Clifton 889b6e
@@ -306,6 +306,20 @@ LD_FLAG=textonly
Nick Clifton 889b6e
   . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
 ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xe
Nick Clifton 889b6e
 
Nick Clifton 889b6e
+if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+    LD_FLAG=
Nick Clifton 889b6e
+    RELRO=" "
Nick Clifton 889b6e
+    ( echo "/* Script for -z relo: generate normal executables with separate code segment */"
Nick Clifton 889b6e
+      . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+      . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+    ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xo
Nick Clifton 889b6e
+    LD_FLAG=textonly
Nick Clifton 889b6e
+    ( echo "/* Script for -z separate-code -z relo: generate normal executables with separate code segment */"
Nick Clifton 889b6e
+      . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+      . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+    ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xeo
Nick Clifton 889b6e
+    unset RELRO
Nick Clifton 889b6e
+fi
Nick Clifton 889b6e
 LD_FLAG=n
Nick Clifton 889b6e
 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
Nick Clifton 889b6e
 ( echo "/* Script for -n: mix text and data on same page */"
Nick Clifton 889b6e
@@ -353,6 +367,25 @@ if test -n "$GENERATE_COMBRELOC_SCRIPT";
Nick Clifton 889b6e
   rm -f ${COMBRELOC}
Nick Clifton 889b6e
   COMBRELOC=
Nick Clifton 889b6e
   unset RELRO_NOW
Nick Clifton 889b6e
+  if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+      LD_FLAG=c
Nick Clifton 889b6e
+      RELRO=" "
Nick Clifton 889b6e
+      COMBRELOC=ldscripts/${EMULATION_NAME}.xco.tmp
Nick Clifton 889b6e
+      ( echo "/* Script for -z combreloc -z relro: combine and sort reloc sections */"
Nick Clifton 889b6e
+	. ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xco
Nick Clifton 889b6e
+      rm -f ${COMBRELOC}
Nick Clifton 889b6e
+      LD_FLAG=ctextonly
Nick Clifton 889b6e
+      COMBRELOC=ldscripts/${EMULATION_NAME}.xceo.tmp
Nick Clifton 889b6e
+      ( echo "/* Script for -z combreloc -z separate-code -z relro: combine and sort reloc sections */"
Nick Clifton 889b6e
+	. ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xceo
Nick Clifton 889b6e
+      rm -f ${COMBRELOC}
Nick Clifton 889b6e
+      COMBRELOC=
Nick Clifton 889b6e
+      unset RELRO
Nick Clifton 889b6e
+  fi
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
 
Nick Clifton 889b6e
 if test -n "$GENERATE_SHLIB_SCRIPT"; then
Nick Clifton 889b6e
@@ -370,6 +403,23 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; the
Nick Clifton 889b6e
     . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
   ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xse
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+  if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+      RELRO=" "
Nick Clifton 889b6e
+      LD_FLAG=shared
Nick Clifton 889b6e
+      (
Nick Clifton 889b6e
+	  echo "/* Script for ld --shared -z relro: link shared library */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xso
Nick Clifton 889b6e
+      LD_FLAG=sharedtextonly
Nick Clifton 889b6e
+      (
Nick Clifton 889b6e
+	  echo "/* Script for ld --shared -z relro -z separate-code: link shared library with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xseo
Nick Clifton 889b6e
+      unset RELRO
Nick Clifton 889b6e
+  fi
Nick Clifton 889b6e
   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
Nick Clifton 889b6e
     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
Nick Clifton 889b6e
     LD_FLAG=cshared
Nick Clifton 889b6e
@@ -401,8 +451,27 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; the
Nick Clifton 889b6e
       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
     ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xswe
Nick Clifton 889b6e
     rm -f ${COMBRELOC}
Nick Clifton 889b6e
-    COMBRELOC=
Nick Clifton 889b6e
     unset RELRO_NOW
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+    if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+	LD_FLAG=wshared
Nick Clifton 889b6e
+	RELRO=" "
Nick Clifton 889b6e
+	COMBRELOC=ldscripts/${EMULATION_NAME}.xsco.tmp
Nick Clifton 889b6e
+	( echo "/* Script for --shared -z combreloc -z relro: shared library, combine & sort relocs with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+	) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xsco
Nick Clifton 889b6e
+	rm -f ${COMBRELOC}
Nick Clifton 889b6e
+	LD_FLAG=wsharedtextonly
Nick Clifton 889b6e
+	COMBRELOC=ldscripts/${EMULATION_NAME}.xsceo.tmp
Nick Clifton 889b6e
+	( echo "/* Script for --shared -z combreloc -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+	) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xsceo
Nick Clifton 889b6e
+	rm -f ${COMBRELOC}
Nick Clifton 889b6e
+	unset RELRO
Nick Clifton 889b6e
+    fi
Nick Clifton 889b6e
+    COMBRELOC=
Nick Clifton 889b6e
   fi
Nick Clifton 889b6e
   unset CREATE_SHLIB
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
@@ -422,6 +491,22 @@ if test -n "$GENERATE_PIE_SCRIPT"; then
Nick Clifton 889b6e
     . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
     . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
   ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xde
Nick Clifton 889b6e
+  if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+      RELRO=" "
Nick Clifton 889b6e
+      LD_FLAG=pie
Nick Clifton 889b6e
+      (
Nick Clifton 889b6e
+	  echo "/* Script for ld -pie -z relro: link position independent executable */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xdo
Nick Clifton 889b6e
+      LD_FLAG=pietextonly
Nick Clifton 889b6e
+      (
Nick Clifton 889b6e
+	  echo "/* Script for ld -pie -z relro -z separate-code: link position independent executable with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+      ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xdeo
Nick Clifton 889b6e
+      unset RELRO
Nick Clifton 889b6e
+  fi
Nick Clifton 889b6e
   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
Nick Clifton 889b6e
     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
Nick Clifton 889b6e
     COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
Nick Clifton 889b6e
@@ -453,8 +538,28 @@ if test -n "$GENERATE_PIE_SCRIPT"; then
Nick Clifton 889b6e
       . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
     ) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xdwe
Nick Clifton 889b6e
     rm -f ${COMBRELOC}
Nick Clifton 889b6e
-    COMBRELOC=
Nick Clifton 889b6e
     unset RELRO_NOW
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+    if test -n "$GENERATE_RELRO_SCRIPT"; then
Nick Clifton 889b6e
+	LD_FLAG=wpie
Nick Clifton 889b6e
+	RELRO=" "
Nick Clifton 889b6e
+	COMBRELOC=ldscripts/${EMULATION_NAME}.xdco.tmp
Nick Clifton 889b6e
+	( echo "/* Script for -pie -z combreloc -z relro: position independent executable, combine & sort relocs with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+	) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xdco
Nick Clifton 889b6e
+	rm -f ${COMBRELOC}
Nick Clifton 889b6e
+	LD_FLAG=wpietextonly
Nick Clifton 889b6e
+	COMBRELOC=ldscripts/${EMULATION_NAME}.xdceo.tmp
Nick Clifton 889b6e
+	( echo "/* Script for -pie -z combreloc -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
Nick Clifton 889b6e
+	  . ${CUSTOMIZER_SCRIPT}
Nick Clifton 889b6e
+	  . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
Nick Clifton 889b6e
+	) | sed -e '/^ *$/d;s/[	 ]*$//' > ldscripts/${EMULATION_NAME}.xdceo
Nick Clifton 889b6e
+	rm -f ${COMBRELOC}
Nick Clifton 889b6e
+
Nick Clifton 889b6e
+	unset RELRO
Nick Clifton 889b6e
+    fi
Nick Clifton 889b6e
+    COMBRELOC=
Nick Clifton 889b6e
   fi
Nick Clifton 889b6e
   unset CREATE_PIE
Nick Clifton 889b6e
 fi
Nick Clifton 889b6e
Only in binutils.orig/ld/testsuite/ld-s390: gotreloc_64-1.dd
Nick Clifton 889b6e
Only in binutils-2.31.1/ld/testsuite/ld-s390: gotreloc_64-norelro-1.dd
Nick Clifton 889b6e
Only in binutils-2.31.1/ld/testsuite/ld-s390: gotreloc_64-relro-1.dd
Nick Clifton 889b6e
diff -rup binutils.orig/ld/testsuite/ld-s390/s390.exp binutils-2.31.1/ld/testsuite/ld-s390/s390.exp
Nick Clifton 889b6e
--- binutils.orig/ld/testsuite/ld-s390/s390.exp	2018-07-19 12:37:28.498025644 +0100
Nick Clifton 889b6e
+++ binutils-2.31.1/ld/testsuite/ld-s390/s390.exp	2018-07-19 12:38:11.236548705 +0100
Nick Clifton 889b6e
@@ -70,10 +70,15 @@ set s390xtests {
Nick Clifton 889b6e
      {{readelf -WSsrl tlsbin_64.rd} {objdump -dzrj.text tlsbin_64.dd}
Nick Clifton 889b6e
       {objdump -sj.got tlsbin_64.sd} {objdump -sj.tdata tlsbin_64.td}}
Nick Clifton 889b6e
      "tlsbin_64"}
Nick Clifton 889b6e
-    {"GOT: symbol address load from got to larl"
Nick Clifton 889b6e
-     "-shared -melf64_s390 --hash-style=sysv --version-script=gotreloc-1.ver" ""
Nick Clifton 889b6e
+    {"GOT: norelro symbol address load from got to larl"
Nick Clifton 889b6e
+     "-shared -melf64_s390 -z norelro --hash-style=sysv --version-script=gotreloc-1.ver" ""
Nick Clifton 889b6e
      "-m64" {gotreloc-1.s}
Nick Clifton 889b6e
-     {{objdump -dzrj.text gotreloc_64-1.dd}}
Nick Clifton 889b6e
+     {{objdump -dzrj.text gotreloc_64-norelro-1.dd}}
Nick Clifton 889b6e
+     "gotreloc_64-1"}
Nick Clifton 889b6e
+    {"GOT: relro symbol address load from got to larl"
Nick Clifton 889b6e
+     "-shared -melf64_s390 -z relro --hash-style=sysv --version-script=gotreloc-1.ver" ""
Nick Clifton 889b6e
+     "-m64" {gotreloc-1.s}
Nick Clifton 889b6e
+     {{objdump -dzrj.text gotreloc_64-relro-1.dd}}
Nick Clifton 889b6e
      "gotreloc_64-1"}
Nick Clifton 889b6e
     {"PLT: offset test"
Nick Clifton 889b6e
      "-shared -m elf64_s390 -dT pltoffset-1.ld" ""