PowerPC inline PLT call support
authorAlan Modra <amodra@gmail.com>
Sun, 8 Apr 2018 23:55:10 +0000 (09:25 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 9 Apr 2018 07:55:20 +0000 (17:25 +0930)
commit23cedd1dc90d05c4b80d4a4b000ed5f37b9c3268
treef2973eade7f265f64490faa75ed9fa36d229f39b
parent2d7ad24e8726ba4c45c9e67be08223a146a837ce
PowerPC inline PLT call support

In addition to the existing relocs we need two more to mark all
instructions in the call sequence, PLTCALL on the call itself (plus
the toc restore insn for ppc64), and PLTSEQ on others.  All
relocations in a particular sequence have the same symbol.

Example ppc64 ELFv2 assembly:
 .reloc .,R_PPC64_PLTSEQ,puts
std 2,24(1)
addis 12,2,puts@plt@ha # .reloc .,R_PPC64_PLT16_HA,puts
ld 12,puts@plt@l(12) # .reloc .,R_PPC64_PLT16_LO_DS,puts
 .reloc .,R_PPC64_PLTSEQ,puts
mtctr 12
 .reloc .,R_PPC64_PLTCALL,puts
bctrl
ld 2,24(1)

Example ppc32 -fPIC assembly:
addis 12,30,puts+32768@plt@ha # .reloc .,R_PPC_PLT16_HA,puts+0x8000
lwz 12,12,puts+32768@plt@l    # .reloc .,R_PPC_PLT16_LO,puts+0x8000
 .reloc .,R_PPC_PLTSEQ,puts+32768
mtctr 12
 .reloc .,R_PPC_PLTCALL,puts+32768
bctrl

Marking sequences like this allows the linker to convert them to nops
and a direct call if the target symbol turns out to be local.

When the call is __tls_get_addr, each relocation shown above is paired
with an R_PPC*_TLSLD or R_PPC*_TLSGD reloc to additionally mark the
sequence for possible TLS optimization.  The TLSLD or TLSGD relocs are
emitted first.

include/
* elf/ppc.h (R_PPC_PLTSEQ, R_PPC_PLTCALL): Define.
* elf/ppc64.h (R_PPC64_PLTSEQ, R_PPC64_PLTCALL): Define.
bfd/
* elf32-ppc.c (ppc_elf_howto_raw): Add PLTSEQ and PLTCALL howtos.
(is_plt_seq_reloc): New function.
(ppc_elf_check_relocs): Handle PLTSEQ and PLTCALL relocs.
(ppc_elf_tls_optimize): Handle inline plt call sequence.
(ppc_elf_relax_section): Handle PLTCALL reloc.
(ppc_elf_relocate_section): Nop out inline plt call sequence when
resolving locally.
* elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_PLTSEQ and
R_PPC64_PLTCALL entries.  Comment R_PPC64_TOCSAVE.
(has_tls_get_addr_call): Correct comment.
(is_branch_reloc): Add PLTCALL.
(is_plt_seq_reloc): New function.
(ppc64_elf_check_relocs): Handle PLT16_LO_DS reloc.  Set
has_tls_reloc for R_PPC64_TLSGD and R_PPC64_TLSLD.  Create plt
entry for R_PPC64_PLTCALL.
(ppc64_elf_tls_optimize): Handle inline plt call sequence.
(ppc_type_of_stub): Handle PLTCALL reloc.
(toc_adjusting_stub_needed): Likewise.
(ppc64_elf_relocate_section): Set "can_plt_call" for PLTCALL
reloc insn.  Nop out inline plt call sequence when resolving
locally.  Handle __tls_get_addr inline plt call optimization.
elfcpp/
* powerpc.h (R_POWERPC_PLTSEQ, R_POWERPC_PLTCALL): Define.
gold/
* powerpc.cc (Target_powerpc::Track_tls::maybe_skip_tls_get_addr_call):
Handle inline plt sequence relocs.
(Stub_table::Plt_stub_key::Plt_stub_key): Likewise.
(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Likewise.
(Target_powerpc::Relocate::relocate): Likewise.
bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c
elfcpp/ChangeLog
elfcpp/powerpc.h
gold/ChangeLog
gold/powerpc.cc
include/ChangeLog
include/elf/ppc.h
include/elf/ppc64.h
This page took 0.025202 seconds and 4 git commands to generate.