diff options
author | Alan Modra <amodra@gmail.com> | 2018-01-13 18:53:41 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2018-01-17 18:51:04 +1030 |
commit | 9e390558cef76767a98123994c422d0642d86cf8 (patch) | |
tree | fa46b2f2c764e30be6e6e512fe29a01de0b4ad04 /ld/emultempl | |
parent | 78742b93a5fef4b88b1391817e7bcc6738000044 (diff) | |
download | gdb-9e390558cef76767a98123994c422d0642d86cf8.zip gdb-9e390558cef76767a98123994c422d0642d86cf8.tar.gz gdb-9e390558cef76767a98123994c422d0642d86cf8.tar.bz2 |
PowerPC PLT stub tidy
This is in preparation for the next patch adding Spectre variant 2
mitigation for PowerPC and PowerPC64. Besides tidying code involved
in stub output (to reduce the number of places where bctr is output),
the patch adds some user visible features:
1) PowerPC64 ELFv2 global entry stubs now are aligned under the
control of --plt-align, with a default alignment of 32 bytes.
2) PowerPC64 __glink_PLTresolve is no longer padded out with nops.
3) PowerPC32 PLT stubs are aligned under the control of --plt-align,
with the default alignment being 16 bytes as before.
4) The PowerPC32 branch/nop table emitted before __glink_PLTresolve
is now smaller in many cases. It was sized incorrectly when the
__tls_get_addr_opt stub was used, and unnecessarily included space
for local ifuncs.
bfd/
* elf32-ppc.c (GLINK_ENTRY_SIZE): Add parameters, handle
__tls_get_addr_opt, and alignment sizing.
(TLS_GET_ADDR_GLINK_SIZE): Delete.
(is_nonpic_glink_stub): Don't use GLINK_ENTRY_SIZE.
(ppc_elf_get_synthetic_symtab): Recognize stubs spaced at 4, 6,
or 8 insns.
(ppc_elf_link_hash_table_create): Init new ppc_elf_params field.
(allocate_dynrelocs): Use new GLINK_ENTRY_SIZE.
(ppc_elf_size_dynamic_sections): Likewise. Size branch table
by PLT reloc count.
(write_glink_stub): Handle __tls_get_addr_opt stub.
Pad out to size given by GLINK_ENTRY_SIZE.
(ppc_elf_relocate_section): Adjust write_glink_stub call.
(ppc_elf_finish_dynamic_symbol): Likewise.
(ppc_elf_finish_dynamic_sections): Write PLTresolve without using
insn array since so many need rewriting.
* elf32-ppc.h (struct ppc_elf_params): Add plt_stub_align.
* elf64-ppc.c (GLINK_PLTRESOLVE_SIZE): Rename from
GLINK_CALL_STUB_SIZE. Add htab param and evaluate to size without
nops. Adjust all uses.
(ppc64_elf_get_synthetic_symtab): Don't use GLINK_CALL_STUB_SIZE
in glink_vma calculation.
(struct ppc_link_hash_table): Add global_entry section pointer.
(create_linkage_sections): Create separate section for global
entry stubs.
(PPC_LO, PPC_HI, PPC_HA): Move earlier.
(size_global_entry_stubs): Handle sizing for aligned stubs.
(ppc64_elf_size_dynamic_sections): Handle global_entry alloc,
and don't stash end of glink branch table in rawsize.
(ppc_build_one_stub): Rewrite stub size calculations.
(build_global_entry_stubs): Use new section.
(ppc64_elf_build_stubs): Don't pad __glink_PLTresolve with nops.
Build lazy link stubs out to end of section. Build global entry
stubs in new section.
gold/
* options.h (plt_align): Support for PowerPC32 too.
* powerpc.cc (Stub_table::stub_align): Heed --plt-align for 32-bit.
(Stub_table::plt_call_size, branch_stub_size): Tidy.
(Stub_table::plt_call_align): Implement using stub_align.
(Output_data_glink::global_entry_align): New function.
(Output_data_glink::global_entry_off): New function.
(Output_data_glink::global_entry_address): Use global_entry_off.
(Output_data_glink::pltresolve_size): New function, replacing
pltresolve_size_ constant. Update all uses.
(Output_data_glink::add_global_entry): Align offset.
(Output_data_glink::set_final_data_size): Use global_entry_align.
(Stub_table::do_write): Don't pad __glink_PLTrelsolve with nops.
Tidy stub output. Use global_entry_off.
ld/
* emultempl/ppc32elf.em (params): Init new field.
(enum ppc32_opt): New enum to define OPTION_* values. Add
OPTION_PLT_ALIGN and OPTION_NO_PLT_ALIGN.
(PARSE_AND_LIST_LONGOPTS): Handle new options.
(PARSE_AND_LIST_ARGS_CASES): Likewise.
(PARSE_AND_LIST_OPTIONS): Likewise. Break up help output.
* emultempl/ppc64elf.em (ppc_add_stub_section): Init alignment
correctly for negative --plt-stub-align.
* testsuite/ld-powerpc/elfv2exe.d,
* testsuite/ld-powerpc/elfv2so.d,
* testsuite/ld-powerpc/relbrlt.d,
* testsuite/ld-powerpc/relbrlt.s,
* testsuite/ld-powerpc/tlsexe.d,
* testsuite/ld-powerpc/tlsexe.r,
* testsuite/ld-powerpc/tlsexe32.d,
* testsuite/ld-powerpc/tlsexe32.g,
* testsuite/ld-powerpc/tlsexe32.r,
* testsuite/ld-powerpc/tlsexetoc.d,
* testsuite/ld-powerpc/tlsexetoc.r,
* testsuite/ld-powerpc/tlsopt5_32.d,
* testsuite/ld-powerpc/tlsso.d,
* testsuite/ld-powerpc/tlstocso.d: Update for changed stub order.
Diffstat (limited to 'ld/emultempl')
-rw-r--r-- | ld/emultempl/ppc32elf.em | 86 | ||||
-rw-r--r-- | ld/emultempl/ppc64elf.em | 2 |
2 files changed, 66 insertions, 22 deletions
diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em index 6852e9b..70dd5a0 100644 --- a/ld/emultempl/ppc32elf.em +++ b/ld/emultempl/ppc32elf.em @@ -38,7 +38,8 @@ static int notlsopt = 0; /* Choose the correct place for .got. */ static int old_got = 0; -static struct ppc_elf_params params = { PLT_UNSET, -1, 0, 0, 0, 0, 0, 0, 0 }; +static struct ppc_elf_params params = { PLT_UNSET, 0, -1, + 0, 0, 0, 0, 0, 0, 0 }; static void ppc_after_open_output (void) @@ -239,17 +240,22 @@ fi # parse_args and list_options functions. # PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}' -#define OPTION_NO_TLS_OPT 321 -#define OPTION_NO_TLS_GET_ADDR_OPT (OPTION_NO_TLS_OPT + 1) -#define OPTION_NEW_PLT (OPTION_NO_TLS_GET_ADDR_OPT + 1) -#define OPTION_OLD_PLT (OPTION_NEW_PLT + 1) -#define OPTION_OLD_GOT (OPTION_OLD_PLT + 1) -#define OPTION_STUBSYMS (OPTION_OLD_GOT + 1) -#define OPTION_NO_STUBSYMS (OPTION_STUBSYMS + 1) -#define OPTION_PPC476_WORKAROUND (OPTION_NO_STUBSYMS + 1) -#define OPTION_NO_PPC476_WORKAROUND (OPTION_PPC476_WORKAROUND + 1) -#define OPTION_NO_PICFIXUP (OPTION_NO_PPC476_WORKAROUND + 1) -#define OPTION_VLE_RELOC_FIXUP (OPTION_NO_PICFIXUP + 1) +enum ppc32_opt +{ + OPTION_NO_TLS_OPT = 321, + OPTION_NO_TLS_GET_ADDR_OPT, + OPTION_NEW_PLT, + OPTION_OLD_PLT, + OPTION_PLT_ALIGN, + OPTION_NO_PLT_ALIGN, + OPTION_OLD_GOT, + OPTION_STUBSYMS, + OPTION_NO_STUBSYMS, + OPTION_PPC476_WORKAROUND, + OPTION_NO_PPC476_WORKAROUND, + OPTION_NO_PICFIXUP, + OPTION_VLE_RELOC_FIXUP +}; ' PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' @@ -261,6 +267,8 @@ if test -z "$VXWORKS_BASE_EM_FILE" ; then PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' { "secure-plt", no_argument, NULL, OPTION_NEW_PLT }, { "bss-plt", no_argument, NULL, OPTION_OLD_PLT }, + { "plt-align", no_argument, NULL, OPTION_PLT_ALIGN }, + { "no-plt-align", no_argument, NULL, OPTION_NO_PLT_ALIGN }, { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },' fi PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' @@ -272,21 +280,47 @@ PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}' PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}' fprintf (file, _("\ - --emit-stub-syms Label linker stubs with a symbol.\n\ - --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n\ - --no-tls-optimize Don'\''t try to optimize TLS accesses.\n\ - --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n' + --emit-stub-syms Label linker stubs with a symbol.\n" + )); + fprintf (file, _("\ + --no-emit-stub-syms Don'\''t label linker stubs with a symbol.\n" + )); + fprintf (file, _("\ + --no-tls-optimize Don'\''t try to optimize TLS accesses.\n" + )); + fprintf (file, _("\ + --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call.\n" + ));' if test -z "$VXWORKS_BASE_EM_FILE" ; then PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ - --secure-plt Use new-style PLT if possible.\n\ - --bss-plt Force old-style BSS PLT.\n\ - --sdata-got Force GOT location just before .sdata.\n' + fprintf (file, _("\ + --secure-plt Use new-style PLT if possible.\n" + )); + fprintf (file, _("\ + --bss-plt Force old-style BSS PLT.\n" + )); + fprintf (file, _("\ + --plt-align Align PLT call stubs to fit cache lines.\n" + )); + fprintf (file, _("\ + --no-plt-align Dont'\''t align individual PLT call stubs.\n" + )); + fprintf (file, _("\ + --sdata-got Force GOT location just before .sdata.\n" + ));' fi PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'\ + fprintf (file, _("\ --ppc476-workaround [=pagesize]\n\ - Avoid a cache bug on ppc476.\n\ - --no-ppc476-workaround Disable workaround.\n\ - --no-pic-fixup Don'\''t edit non-pic to pic.\n\ + Avoid a cache bug on ppc476.\n" + )); + fprintf (file, _("\ + --no-ppc476-workaround Disable workaround.\n" + )); + fprintf (file, _("\ + --no-pic-fixup Don'\''t edit non-pic to pic.\n" + )); + fprintf (file, _("\ --vle-reloc-fixup Correct old object file 16A/16D relocation.\n" )); ' @@ -316,6 +350,14 @@ PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}' params.plt_style = PLT_OLD; break; + case OPTION_PLT_ALIGN: + params.plt_stub_align = 5; + break; + + case OPTION_NO_PLT_ALIGN: + params.plt_stub_align = 0; + break; + case OPTION_OLD_GOT: old_got = 1; break; diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em index 76eeb07..840bd44 100644 --- a/ld/emultempl/ppc64elf.em +++ b/ld/emultempl/ppc64elf.em @@ -412,6 +412,8 @@ ppc_add_stub_section (const char *stub_sec_name, asection *input_section) || !bfd_set_section_alignment (stub_file->the_bfd, stub_sec, (params.plt_stub_align > 5 ? params.plt_stub_align + : params.plt_stub_align < -5 + ? -params.plt_stub_align : 5))) goto err_ret; |