diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-05-08 12:24:11 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2017-05-08 12:24:29 -0700 |
commit | 38b123494b38ae09168387c0502acd1f23c1b601 (patch) | |
tree | 723d1c636b173f5d94346879cefaa4c2b2bb5f68 /ld/testsuite/ld-x86-64/load1b.d | |
parent | d7ab4911f8aa3e1cd06ece40f74d0b4a532d6a10 (diff) | |
download | gdb-38b123494b38ae09168387c0502acd1f23c1b601.zip gdb-38b123494b38ae09168387c0502acd1f23c1b601.tar.gz gdb-38b123494b38ae09168387c0502acd1f23c1b601.tar.bz2 |
x86-64: Improve PLT generation and synthetic PLT symbols
On x86-64, the procedure linkage table (PLT) is used to
1. Call external function.
2. Call internal IFUNC function. The best implementation is selected
for the target processor at run-time.
3. Act as the canonical function address.
4. Support LD_AUDIT to audit external function calls.
5. Support LD_PROFILE to profile external function calls.
PLT looks like:
PLT0: push GOT[1]
jmp *GOT[2]
nop
PLT1: jmp *GOT[name1_index]
push name1_reloc_index
jmp PLT0
GOT is an array of addresses. Initially the GOT entry of name1 is
filled with the address of the "push name1_reloc_index" instruction.
The function, name1, is called via "jmp *GOT[name1]" in the PLT entry.
Even when lazy binding is disabled by "-z now", the PLT0 entry may
still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
canonical function address.
When linker is invoked with "-z bndplt", a different PLT layout in .plt
is used:
PLT0: push GOT[1]
bnd jmp *GOT[2]
nop
PLT1: push name1_reloc_index
bnd jmp PLT0
nop
together with a second PLT section, .pl.bnd:
PLT1: bnd jmp *GOT[name1_index]
nop
where the GOT entry of name1 is filled with the address of the push
instruction of the corresponding entry in .plt.
1. With lazy binding, when the external function, name1, is called the
first time, dynamic linker is called via PLT0 to update GOT[name1_index]
with the actual address of name1 and transfers control to name1
afterwards.
2. PLT is also used to call a local IFUNC function, name1, run-time
loader updates GOT[name1_index] when loading the module.
This patch
1. Remove PLT layout configurations from x86-64 backend_data.
2. Add generic, lay and non-lazy PLT layout configurations to x86-64
link_hash_table. Generic PLT layout includes the PLT entry templates,
information how to update the first instruction in PLT and PLT eh_frame
informaton, which are initialized in x86-64 setup_gnu_properties, based
on "-z bndplt" and target selection. PLT section alignment is also set
to PLT entry size for non-NaCl target.
3. Remove elf_x86_64_create_dynamic_sections. create_dynamic_sections
isn't always called, but GOT relocations need GOT relocations. Instead,
create all x86-64 specific dynamic sections with alignment to their entry
size in x86-64 setup_gnu_properties, which initializes elf.dynobj, so
that x86-64 check_relocs can be simplified.
4. Rewrite elf_x86_64_get_synthetic_symtab to check PLT sections against
all dynamic relocations to support both lazy and non-lazy PLTs.
There is no change in PLT. The only externally visible change is the
improvement of synthetic PLT symbols for .plt.got.
bfd/
* elf64-x86-64.c (PLT_ENTRY_SIZE): Renamed to ...
(LAZY_PLT_ENTRY_SIZE): This.
(NON_LAZY_PLT_ENTRY_SIZE): New.
(elf_x86_64_plt0_entry): Renamed to ...
(elf_x86_64_lazy_plt0_entry): This.
(elf_x86_64_plt_entry): Renamed to ...
(elf_x86_64_lazy_plt_entry): This.
(elf_x86_64_bnd_plt0_entry): Renamed to ...
(elf_x86_64_lazy_bnd_plt0_entry): This.
(elf_x86_64_legacy_plt_entry): Removed.
(elf_x86_64_bnd_plt_entry): Renamed to ...
(elf_x86_64_lazy_bnd_plt_entry): This.
(elf_x86_64_legacy_plt2_entry): Renamed to ...
(elf_x86_64_non_lazy_plt_entry): This.
(elf_x86_64_bnd_plt2_entry): Renamed to ...
(elf_x86_64_non_lazy_bnd_plt_entry): This.
(elf_x86_64_eh_frame_plt): Renamed to ...
(elf_x86_64_eh_frame_lazy_plt): This.
(elf_x86_64_eh_frame_bnd_plt): Renamed to ...
(elf_x86_64_eh_frame_lazy_bnd_plt): This.
(elf_x86_64_eh_frame_plt_got): Renamed to ...
(elf_x86_64_eh_frame_non_lazy_plt): This.
(elf_x86_64_lazy_plt_layout): New.
(elf_x86_64_non_lazy_plt_layout): Likewise.
(elf_x86_64_plt_layout): Likewise.
(elf_x86_64_backend_data): Remove PLT layout information. Add
os for target system.
(GET_PLT_ENTRY_SIZE): Removed.
(elf_x86_64_lazy_plt): New.
(elf_x86_64_non_lazy_plt): Likewise.
(elf_x86_64_lazy_bnd_plt): Likewise.
(elf_x86_64_non_lazy_bnd_plt): Likewise.
(elf_x86-64_arch_bed): Updated.
(elf_x86_64_link_hash_table): Add plt, lazy_plt and non_lazy_plt.
(elf_x86_64_create_dynamic_sections): Removed.
(elf_x86_64_check_relocs): Don't check elf.dynobj. Don't call
_bfd_elf_create_ifunc_sections nor _bfd_elf_create_got_section.
(elf_x86-64_adjust_dynamic_symbol): Updated.
(elf_x86_64_allocate_dynrelocs): Updated. Pass 0 as PLT header
size to _bfd_elf_allocate_ifunc_dyn_relocs and don't allocate
size for PLT0 if there is no PLT0. Get plt_entry_size from
non_lazy_plt for non-lazy PLT entries.
(elf_x86_64_size_dynamic_sections): Updated. Get plt_entry_size
from non_lazy_plt for non-lazy PLT entries.
(elf_x86-64_relocate_section): Updated. Properly get PLT index
if there is no PLT0.
(elf_x86_64_finish_dynamic_symbol): Updated. Fill the first slot
in the PLT entry with generic PLT layout. Fill the non-lazy PLT
entries with non-lazy PLT layout. Don't fill the second and third
slots in the PLT entry if there is no PLT0.
(elf_x86_64_finish_dynamic_sections): Updated. Don't fill PLT0
if there is no PLT0. Set sh_entsize on the .plt.got section.
(compare_relocs): New.
(elf_x86_64_plt_type): Likewise.
(elf_x86_64_plt): Likewise.
(elf_x86_64_nacl_plt): New. Forward declaration.
(elf_x86_64_get_plt_sym_val): Removed.
(elf_x86_64_get_synthetic_symtab): Rewrite to check PLT sections
against all dynamic relocations.
(elf_x86_64_link_setup_gnu_properties): New function.
(elf_backend_create_dynamic_sections): Updated.
(elf_backend_setup_gnu_properties): New.
(elf_x86_64_nacl_plt): New.
(elf_x86_64_nacl_arch_bed): Updated.
ld/
* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: New file.
* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
* testsuite/ld-x86-64/mpx3n.dd: Likewise.
* testsuite/ld-x86-64/mpx4n.dd: Likewise.
* testsuite/ld-x86-64/plt-main-bnd-now.rd: Likewise.
* testsuite/ld-x86-64/plt2.dd: Likewise.
* testsuite/ld-x86-64/plt2.rd: Likewise.
* testsuite/ld-x86-64/plt2.s: Likewise.
* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
* testsuite/ld-x86-64/load1b-nacl.d: Updated.
* testsuite/ld-x86-64/load1b.d: Likewise.
* testsuite/ld-x86-64/plt-main-bnd.dd: Likewise.
* testsuite/ld-x86-64/pr20253-1h.d: Likewise.
* testsuite/ld-x86-64/pr20830a.d: Update the .plt.got section
with func@plt.
* testsuite/ld-x86-64/pr20830b.d: Likewise.
* testsuite/ld-x86-64/pr21038a.d: Likewise.
* testsuite/ld-x86-64/pr21038c.d: Likewise.
* testsuite/ld-x86-64/mpx.exp: Add some -z now tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
Diffstat (limited to 'ld/testsuite/ld-x86-64/load1b.d')
-rw-r--r-- | ld/testsuite/ld-x86-64/load1b.d | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/ld/testsuite/ld-x86-64/load1b.d b/ld/testsuite/ld-x86-64/load1b.d index 8827f38..acbd2fc 100644 --- a/ld/testsuite/ld-x86-64/load1b.d +++ b/ld/testsuite/ld-x86-64/load1b.d @@ -8,49 +8,50 @@ SYMBOL TABLE: #... -0+60017c l O .data 0+1 bar +0+600180 l O .data 0+1 bar #... -0+60017d g O .data 0+1 foo +0+600181 g O .data 0+1 foo #... Disassembly of section .text: 0+400074 <_start>: -[ ]*[a-f0-9]+: 81 d0 7c 01 60 00 adc \$0x60017c,%eax -[ ]*[a-f0-9]+: 81 c3 7c 01 60 00 add \$0x60017c,%ebx -[ ]*[a-f0-9]+: 81 e1 7c 01 60 00 and \$0x60017c,%ecx -[ ]*[a-f0-9]+: 81 fa 7c 01 60 00 cmp \$0x60017c,%edx -[ ]*[a-f0-9]+: 81 ce 7c 01 60 00 or \$0x60017c,%esi -[ ]*[a-f0-9]+: 81 df 7c 01 60 00 sbb \$0x60017c,%edi -[ ]*[a-f0-9]+: 81 ed 7c 01 60 00 sub \$0x60017c,%ebp -[ ]*[a-f0-9]+: 41 81 f0 7c 01 60 00 xor \$0x60017c,%r8d -[ ]*[a-f0-9]+: 41 f7 c7 7c 01 60 00 test \$0x60017c,%r15d -[ ]*[a-f0-9]+: 48 81 d0 7c 01 60 00 adc \$0x60017c,%rax -[ ]*[a-f0-9]+: 48 81 c3 7c 01 60 00 add \$0x60017c,%rbx -[ ]*[a-f0-9]+: 48 81 e1 7c 01 60 00 and \$0x60017c,%rcx -[ ]*[a-f0-9]+: 48 81 fa 7c 01 60 00 cmp \$0x60017c,%rdx -[ ]*[a-f0-9]+: 48 81 cf 7c 01 60 00 or \$0x60017c,%rdi -[ ]*[a-f0-9]+: 48 81 de 7c 01 60 00 sbb \$0x60017c,%rsi -[ ]*[a-f0-9]+: 48 81 ed 7c 01 60 00 sub \$0x60017c,%rbp -[ ]*[a-f0-9]+: 49 81 f0 7c 01 60 00 xor \$0x60017c,%r8 -[ ]*[a-f0-9]+: 49 f7 c7 7c 01 60 00 test \$0x60017c,%r15 -[ ]*[a-f0-9]+: 81 d0 7d 01 60 00 adc \$0x60017d,%eax -[ ]*[a-f0-9]+: 81 c3 7d 01 60 00 add \$0x60017d,%ebx -[ ]*[a-f0-9]+: 81 e1 7d 01 60 00 and \$0x60017d,%ecx -[ ]*[a-f0-9]+: 81 fa 7d 01 60 00 cmp \$0x60017d,%edx -[ ]*[a-f0-9]+: 81 ce 7d 01 60 00 or \$0x60017d,%esi -[ ]*[a-f0-9]+: 81 df 7d 01 60 00 sbb \$0x60017d,%edi -[ ]*[a-f0-9]+: 81 ed 7d 01 60 00 sub \$0x60017d,%ebp -[ ]*[a-f0-9]+: 41 81 f0 7d 01 60 00 xor \$0x60017d,%r8d -[ ]*[a-f0-9]+: 41 f7 c7 7d 01 60 00 test \$0x60017d,%r15d -[ ]*[a-f0-9]+: 48 81 d0 7d 01 60 00 adc \$0x60017d,%rax -[ ]*[a-f0-9]+: 48 81 c3 7d 01 60 00 add \$0x60017d,%rbx -[ ]*[a-f0-9]+: 48 81 e1 7d 01 60 00 and \$0x60017d,%rcx -[ ]*[a-f0-9]+: 48 81 fa 7d 01 60 00 cmp \$0x60017d,%rdx -[ ]*[a-f0-9]+: 48 81 cf 7d 01 60 00 or \$0x60017d,%rdi -[ ]*[a-f0-9]+: 48 81 de 7d 01 60 00 sbb \$0x60017d,%rsi -[ ]*[a-f0-9]+: 48 81 ed 7d 01 60 00 sub \$0x60017d,%rbp -[ ]*[a-f0-9]+: 49 81 f0 7d 01 60 00 xor \$0x60017d,%r8 -[ ]*[a-f0-9]+: 49 f7 c7 7d 01 60 00 test \$0x60017d,%r15 + +[a-f0-9]+: 81 d0 80 01 60 00 adc \$0x600180,%eax + +[a-f0-9]+: 81 c3 80 01 60 00 add \$0x600180,%ebx + +[a-f0-9]+: 81 e1 80 01 60 00 and \$0x600180,%ecx + +[a-f0-9]+: 81 fa 80 01 60 00 cmp \$0x600180,%edx + +[a-f0-9]+: 81 ce 80 01 60 00 or \$0x600180,%esi + +[a-f0-9]+: 81 df 80 01 60 00 sbb \$0x600180,%edi + +[a-f0-9]+: 81 ed 80 01 60 00 sub \$0x600180,%ebp + +[a-f0-9]+: 41 81 f0 80 01 60 00 xor \$0x600180,%r8d + +[a-f0-9]+: 41 f7 c7 80 01 60 00 test \$0x600180,%r15d + +[a-f0-9]+: 48 81 d0 80 01 60 00 adc \$0x600180,%rax + +[a-f0-9]+: 48 81 c3 80 01 60 00 add \$0x600180,%rbx + +[a-f0-9]+: 48 81 e1 80 01 60 00 and \$0x600180,%rcx + +[a-f0-9]+: 48 81 fa 80 01 60 00 cmp \$0x600180,%rdx + +[a-f0-9]+: 48 81 cf 80 01 60 00 or \$0x600180,%rdi + +[a-f0-9]+: 48 81 de 80 01 60 00 sbb \$0x600180,%rsi + +[a-f0-9]+: 48 81 ed 80 01 60 00 sub \$0x600180,%rbp + +[a-f0-9]+: 49 81 f0 80 01 60 00 xor \$0x600180,%r8 + +[a-f0-9]+: 49 f7 c7 80 01 60 00 test \$0x600180,%r15 + +[a-f0-9]+: 81 d0 81 01 60 00 adc \$0x600181,%eax + +[a-f0-9]+: 81 c3 81 01 60 00 add \$0x600181,%ebx + +[a-f0-9]+: 81 e1 81 01 60 00 and \$0x600181,%ecx + +[a-f0-9]+: 81 fa 81 01 60 00 cmp \$0x600181,%edx + +[a-f0-9]+: 81 ce 81 01 60 00 or \$0x600181,%esi + +[a-f0-9]+: 81 df 81 01 60 00 sbb \$0x600181,%edi + +[a-f0-9]+: 81 ed 81 01 60 00 sub \$0x600181,%ebp + +[a-f0-9]+: 41 81 f0 81 01 60 00 xor \$0x600181,%r8d + +[a-f0-9]+: 41 f7 c7 81 01 60 00 test \$0x600181,%r15d + +[a-f0-9]+: 48 81 d0 81 01 60 00 adc \$0x600181,%rax + +[a-f0-9]+: 48 81 c3 81 01 60 00 add \$0x600181,%rbx + +[a-f0-9]+: 48 81 e1 81 01 60 00 and \$0x600181,%rcx + +[a-f0-9]+: 48 81 fa 81 01 60 00 cmp \$0x600181,%rdx + +[a-f0-9]+: 48 81 cf 81 01 60 00 or \$0x600181,%rdi + +[a-f0-9]+: 48 81 de 81 01 60 00 sbb \$0x600181,%rsi + +[a-f0-9]+: 48 81 ed 81 01 60 00 sub \$0x600181,%rbp + +[a-f0-9]+: 49 81 f0 81 01 60 00 xor \$0x600181,%r8 + +[a-f0-9]+: 49 f7 c7 81 01 60 00 test \$0x600181,%r15 +#pass #pass |