Blame SOURCES/binutils-x86_64-ibt-enabled-tlsdesc.patch

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-10-08 15:24:17.980797510 +0100
869a11
+++ binutils-2.30/bfd/elf64-x86-64.c	2018-10-08 15:25:02.643458607 +0100
869a11
@@ -4399,15 +4399,23 @@ elf_x86_64_finish_dynamic_sections (bfd
869a11
 
869a11
       if (htab->tlsdesc_plt)
869a11
 	{
869a11
+	  /* The TLSDESC entry in a lazy procedure linkage table.  */
869a11
+	  static const bfd_byte tlsdesc_plt_entry[LAZY_PLT_ENTRY_SIZE] =
869a11
+	    {
869a11
+	      0xf3, 0x0f, 0x1e, 0xfa,	/* endbr64		*/
869a11
+	      0xff, 0x35, 8, 0, 0, 0,	/* pushq GOT+8(%rip)	*/
869a11
+	      0xff, 0x25, 16, 0, 0, 0	/* jmpq *GOT+TDG(%rip)	*/
869a11
+	    };
869a11
+
869a11
 	  bfd_put_64 (output_bfd, (bfd_vma) 0,
869a11
 		      htab->elf.sgot->contents + htab->tlsdesc_got);
869a11
 
869a11
 	  memcpy (htab->elf.splt->contents + htab->tlsdesc_plt,
869a11
-		  htab->lazy_plt->plt0_entry,
869a11
-		  htab->lazy_plt->plt0_entry_size);
869a11
+		  tlsdesc_plt_entry, LAZY_PLT_ENTRY_SIZE);
869a11
 
869a11
-	  /* Add offset for pushq GOT+8(%rip), since the
869a11
-	     instruction uses 6 bytes subtract this value.  */
869a11
+	  /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4
869a11
+	     bytes and the instruction uses 6 bytes, subtract these
869a11
+	     values.  */
869a11
 	  bfd_put_32 (output_bfd,
869a11
 		      (htab->elf.sgotplt->output_section->vma
869a11
 		       + htab->elf.sgotplt->output_offset
869a11
@@ -4415,14 +4423,13 @@ elf_x86_64_finish_dynamic_sections (bfd
869a11
 		       - htab->elf.splt->output_section->vma
869a11
 		       - htab->elf.splt->output_offset
869a11
 		       - htab->tlsdesc_plt
869a11
-		       - 6),
869a11
+		       - 4 - 6),
869a11
 		      (htab->elf.splt->contents
869a11
 		       + htab->tlsdesc_plt
869a11
-		       + htab->lazy_plt->plt0_got1_offset));
869a11
-	  /* Add offset for the PC-relative instruction accessing
869a11
-	     GOT+TDG, where TDG stands for htab->tlsdesc_got,
869a11
-	     subtracting the offset to the end of that
869a11
-	     instruction.  */
869a11
+		       + 4 + 2));
869a11
+	  /* Add offset for indirect branch via GOT+TDG, where TDG
869a11
+	     stands for htab->tlsdesc_got, subtracting the offset
869a11
+	     to the end of that instruction.  */
869a11
 	  bfd_put_32 (output_bfd,
869a11
 		      (htab->elf.sgot->output_section->vma
869a11
 		       + htab->elf.sgot->output_offset
869a11
@@ -4430,10 +4437,9 @@ elf_x86_64_finish_dynamic_sections (bfd
869a11
 		       - htab->elf.splt->output_section->vma
869a11
 		       - htab->elf.splt->output_offset
869a11
 		       - htab->tlsdesc_plt
869a11
-		       - htab->lazy_plt->plt0_got2_insn_end),
869a11
+		       - 4 - 6 - 6),
869a11
 		      (htab->elf.splt->contents
869a11
-		       + htab->tlsdesc_plt
869a11
-		       + htab->lazy_plt->plt0_got2_offset));
869a11
+		       + htab->tlsdesc_plt + 4 + 6 + 2));
869a11
 	}
869a11
     }
869a11
 
869a11
Only in binutils-2.30/bfd: elf64-x86-64.c.orig
869a11
diff -rup binutils.orig/ld/testsuite/ld-x86-64/tlsdesc.pd binutils-2.30/ld/testsuite/ld-x86-64/tlsdesc.pd
869a11
--- binutils.orig/ld/testsuite/ld-x86-64/tlsdesc.pd	2018-10-08 15:24:17.293802722 +0100
869a11
+++ binutils-2.30/ld/testsuite/ld-x86-64/tlsdesc.pd	2018-10-08 15:25:07.515421664 +0100
869a11
@@ -13,7 +13,7 @@ Disassembly of section .plt:
869a11
  [0-9a-f]+:	ff 35 .. .. 20 00    	pushq  .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
869a11
  [0-9a-f]+:	ff 25 .. .. 20 00    	jmpq   \*.*\(%rip\)        # 201360 <_GLOBAL_OFFSET_TABLE_\+0x10>
869a11
  [0-9a-f]+:	0f 1f 40 00          	nopl   0x0\(%rax\)
869a11
+ [0-9a-f]+:	f3 0f 1e fa          	endbr64 
869a11
  [0-9a-f]+:	ff 35 .. .. 20 00    	pushq  .*\(%rip\)        # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8>
869a11
  [0-9a-f]+:	ff 25 .. .. 20 00    	jmpq   \*.*\(%rip\)        # 201348 <.*>
869a11
- [0-9a-f]+:	0f 1f 40 00          	nopl   0x0\(%rax\)
869a11