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-ifunc/ifunc-16-x86-64-now.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-ifunc/ifunc-16-x86-64-now.d')
-rw-r--r-- | ld/testsuite/ld-ifunc/ifunc-16-x86-64-now.d | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ld/testsuite/ld-ifunc/ifunc-16-x86-64-now.d b/ld/testsuite/ld-ifunc/ifunc-16-x86-64-now.d new file mode 100644 index 0000000..acc5093 --- /dev/null +++ b/ld/testsuite/ld-ifunc/ifunc-16-x86-64-now.d @@ -0,0 +1,14 @@ +#source: ifunc-16-x86.s +#as: --64 +#ld: -z now -shared -melf_x86_64 +#readelf: -r --wide +#target: x86_64-*-* +#notarget: x86_64-*-nacl* + +Relocation section '.rela.dyn' at .* +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_GLOB_DAT[ ]+0+[ ]+ifunc \+ 0 + +Relocation section '.rela.plt' at .* +[ ]+Offset[ ]+Info[ ]+Type[ ]+.* +[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_IRELATIVE[ ]+[0-9a-f]* |