GNU Binutils with patches for OS216
Revision | bf54968b128a2133174d81c438d402ecfaf83042 (tree) |
---|---|
Zeit | 2018-03-25 21:02:32 |
Autor | H.J. Lu <hjl.tools@gmai...> |
Commiter | H.J. Lu |
x86-64: Add ENDBR64 to the TLSDESC PLT entry
The TLSDESC entry in a lazy procedure linkage table is called indirectly
with "callq *(%rax)". This patch adds an ENDBR64 to support indirect
branch tracking in Intel CET. The TLSDESC PLT entry now looks like:
0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */
0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */
0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */
The BND prefix isn't needed since MPX isn't used for TLSDESC.
bfd/
PR ld/23000
* elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Add
ENDBR64 to the TLSDESC PLT entry.
ld/
PR ld/23000
* testsuite/ld-x86-64/tlsdesc.pd: Updated.
@@ -1,3 +1,9 @@ | ||
1 | +2018-03-25 H.J. Lu <hongjiu.lu@intel.com> | |
2 | + | |
3 | + PR ld/23000 | |
4 | + * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Add | |
5 | + ENDBR64 to the TLSDESC PLT entry. | |
6 | + | |
1 | 7 | 2018-03-21 Alan Modra <amodra@gmail.com> |
2 | 8 | |
3 | 9 | * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Trim uninteresting |
@@ -4411,15 +4411,23 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd, | ||
4411 | 4411 | |
4412 | 4412 | if (htab->tlsdesc_plt) |
4413 | 4413 | { |
4414 | + /* The TLSDESC entry in a lazy procedure linkage table. */ | |
4415 | + static const bfd_byte tlsdesc_plt_entry[LAZY_PLT_ENTRY_SIZE] = | |
4416 | + { | |
4417 | + 0xf3, 0x0f, 0x1e, 0xfa, /* endbr64 */ | |
4418 | + 0xff, 0x35, 8, 0, 0, 0, /* pushq GOT+8(%rip) */ | |
4419 | + 0xff, 0x25, 16, 0, 0, 0 /* jmpq *GOT+TDG(%rip) */ | |
4420 | + }; | |
4421 | + | |
4414 | 4422 | bfd_put_64 (output_bfd, (bfd_vma) 0, |
4415 | 4423 | htab->elf.sgot->contents + htab->tlsdesc_got); |
4416 | 4424 | |
4417 | 4425 | memcpy (htab->elf.splt->contents + htab->tlsdesc_plt, |
4418 | - htab->lazy_plt->plt0_entry, | |
4419 | - htab->lazy_plt->plt0_entry_size); | |
4426 | + tlsdesc_plt_entry, LAZY_PLT_ENTRY_SIZE); | |
4420 | 4427 | |
4421 | - /* Add offset for pushq GOT+8(%rip), since the | |
4422 | - instruction uses 6 bytes subtract this value. */ | |
4428 | + /* Add offset for pushq GOT+8(%rip), since ENDBR64 uses 4 | |
4429 | + bytes and the instruction uses 6 bytes, subtract these | |
4430 | + values. */ | |
4423 | 4431 | bfd_put_32 (output_bfd, |
4424 | 4432 | (htab->elf.sgotplt->output_section->vma |
4425 | 4433 | + htab->elf.sgotplt->output_offset |
@@ -4427,14 +4435,13 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd, | ||
4427 | 4435 | - htab->elf.splt->output_section->vma |
4428 | 4436 | - htab->elf.splt->output_offset |
4429 | 4437 | - htab->tlsdesc_plt |
4430 | - - 6), | |
4438 | + - 4 - 6), | |
4431 | 4439 | (htab->elf.splt->contents |
4432 | 4440 | + htab->tlsdesc_plt |
4433 | - + htab->lazy_plt->plt0_got1_offset)); | |
4434 | - /* Add offset for the PC-relative instruction accessing | |
4435 | - GOT+TDG, where TDG stands for htab->tlsdesc_got, | |
4436 | - subtracting the offset to the end of that | |
4437 | - instruction. */ | |
4441 | + + 4 + 2)); | |
4442 | + /* Add offset for indirect branch via GOT+TDG, where TDG | |
4443 | + stands for htab->tlsdesc_got, subtracting the offset | |
4444 | + to the end of that instruction. */ | |
4438 | 4445 | bfd_put_32 (output_bfd, |
4439 | 4446 | (htab->elf.sgot->output_section->vma |
4440 | 4447 | + htab->elf.sgot->output_offset |
@@ -4442,10 +4449,9 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd, | ||
4442 | 4449 | - htab->elf.splt->output_section->vma |
4443 | 4450 | - htab->elf.splt->output_offset |
4444 | 4451 | - htab->tlsdesc_plt |
4445 | - - htab->lazy_plt->plt0_got2_insn_end), | |
4452 | + - 4 - 6 - 6), | |
4446 | 4453 | (htab->elf.splt->contents |
4447 | - + htab->tlsdesc_plt | |
4448 | - + htab->lazy_plt->plt0_got2_offset)); | |
4454 | + + htab->tlsdesc_plt + 4 + 6 + 2)); | |
4449 | 4455 | } |
4450 | 4456 | } |
4451 | 4457 |
@@ -1,3 +1,8 @@ | ||
1 | +2018-03-25 H.J. Lu <hongjiu.lu@intel.com> | |
2 | + | |
3 | + PR ld/23000 | |
4 | + * testsuite/ld-x86-64/tlsdesc.pd: Updated. | |
5 | + | |
1 | 6 | 2018-03-23 Nick Clifton <nickc@redhat.com> |
2 | 7 | |
3 | 8 | PR 22948 |
@@ -13,7 +13,7 @@ Disassembly of section .plt: | ||
13 | 13 | [0-9a-f]+: ff 35 .. .. 20 00 pushq .*\(%rip\) # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8> |
14 | 14 | [0-9a-f]+: ff 25 .. .. 20 00 jmpq \*.*\(%rip\) # 201360 <_GLOBAL_OFFSET_TABLE_\+0x10> |
15 | 15 | [0-9a-f]+: 0f 1f 40 00 nopl 0x0\(%rax\) |
16 | + [0-9a-f]+: f3 0f 1e fa endbr64 | |
16 | 17 | [0-9a-f]+: ff 35 .. .. 20 00 pushq .*\(%rip\) # 201358 <_GLOBAL_OFFSET_TABLE_\+0x8> |
17 | 18 | [0-9a-f]+: ff 25 .. .. 20 00 jmpq \*.*\(%rip\) # 201348 <.*> |
18 | - [0-9a-f]+: 0f 1f 40 00 nopl 0x0\(%rax\) | |
19 | 19 |