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