f378ab099d
ELFv2 functions with localentry:0 are those with a single entry point, ie. global entry == local entry, and that have no requirement on r2 or r12, and guarantee r2 is unchanged on return. Such an external function can be called via the PLT without saving r2 or restoring it on return, avoiding a common load-hit-store for small functions. The optimization is attractive. The TOC pointer load-hit-store is a major reason why calls to small functions that need no register saves, or with shrink-wrap, no register saves on a fast path, are slow on powerpc64le. To be safe, this optimization needs ld.so support to check that the run-time matches link-time function implementation. If a function in a shared library with st_other localentry non-zero is called without saving and restoring r2, r2 will be trashed on return, leading to segfaults. For that reason the optimization does not happen for weak functions since a weak definition is a fairly solid hint that the function will likely be overridden. I'm also not enabling the optimization by default unless glibc-2.26 is detected, which should have the ld.so checks implemented. bfd/ * elf64-ppc.c (struct ppc_link_hash_table): Add has_plt_localentry0. (ppc64_elf_merge_symbol_attribute): Merge localentry bits from dynamic objects. (is_elfv2_localentry0): New function. (ppc64_elf_tls_setup): Default params->plt_localentry0. (plt_stub_size): Adjust size for tls_get_addr_opt stub. (build_tls_get_addr_stub): Use a simpler stub when r2 is not saved. (ppc64_elf_size_stubs): Leave stub_type as ppc_stub_plt_call for optimized localentry:0 stubs. (ppc64_elf_build_stubs): Save r2 in ELFv2 __glink_PLTresolve. (ppc64_elf_relocate_section): Leave nop unchanged for optimized localentry:0 stubs. (ppc64_elf_finish_dynamic_sections): Set PPC64_OPT_LOCALENTRY in DT_PPC64_OPT. * elf64-ppc.h (struct ppc64_elf_params): Add plt_localentry0. include/ * elf/ppc64.h (PPC64_OPT_LOCALENTRY): Define. ld/ * emultempl/ppc64elf.em (params): Init plt_localentry0 field. (enum ppc64_opt): New, replacing OPTION_* defines. Add OPTION_PLT_LOCALENTRY, and OPTION_NO_PLT_LOCALENTRY. (PARSE_AND_LIST_*): Support --plt-localentry and --no-plt-localentry. * testsuite/ld-powerpc/elfv2so.d: Update. * testsuite/ld-powerpc/powerpc.exp (TLS opt 5): Use --no-plt-localentry. * testsuite/ld-powerpc/tlsopt5.d: Update.
100 lines
3.2 KiB
C
100 lines
3.2 KiB
C
/* PowerPC64-specific support for 64-bit ELF.
|
|
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
|
|
|
This file is part of BFD, the Binary File Descriptor library.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
MA 02110-1301, USA. */
|
|
|
|
/* Used to pass info between ld and bfd. */
|
|
struct ppc64_elf_params
|
|
{
|
|
/* Linker stub bfd. */
|
|
bfd *stub_bfd;
|
|
|
|
/* Linker call-backs. */
|
|
asection * (*add_stub_section) (const char *, asection *);
|
|
void (*layout_sections_again) (void);
|
|
|
|
/* Maximum size of a group of input sections that can be handled by
|
|
one stub section. A value of +/-1 indicates the bfd back-end
|
|
should use a suitable default size. */
|
|
bfd_signed_vma group_size;
|
|
|
|
/* Whether to use a special call stub for __tls_get_addr. */
|
|
int tls_get_addr_opt;
|
|
|
|
/* Whether to allow multiple toc sections. */
|
|
int no_multi_toc;
|
|
|
|
/* Set if PLT call stubs should load r11. */
|
|
int plt_static_chain;
|
|
|
|
/* Set if PLT call stubs need to be thread safe on power7+. */
|
|
int plt_thread_safe;
|
|
|
|
/* Set if individual PLT call stubs should be aligned. */
|
|
int plt_stub_align;
|
|
|
|
/* Set if PLT call stubs for localentry:0 functions should omit r2 save. */
|
|
int plt_localentry0;
|
|
|
|
/* Whether to canonicalize .opd so that there are no overlapping
|
|
.opd entries. */
|
|
int non_overlapping_opd;
|
|
|
|
/* Whether to emit symbols for stubs. */
|
|
int emit_stub_syms;
|
|
|
|
/* Whether to generate out-of-line register save/restore for gcc -Os code. */
|
|
int save_restore_funcs;
|
|
|
|
/* Set when a potential variable is detected in .toc. */
|
|
int object_in_toc;
|
|
};
|
|
|
|
bfd_boolean ppc64_elf_init_stub_bfd
|
|
(struct bfd_link_info *, struct ppc64_elf_params *);
|
|
bfd_boolean ppc64_elf_edit_opd
|
|
(struct bfd_link_info *);
|
|
asection *ppc64_elf_tls_setup
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_tls_optimize
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_edit_toc
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_has_small_toc_reloc
|
|
(asection *);
|
|
bfd_vma ppc64_elf_set_toc
|
|
(struct bfd_link_info *, bfd *);
|
|
int ppc64_elf_setup_section_lists
|
|
(struct bfd_link_info *);
|
|
void ppc64_elf_start_multitoc_partition
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_next_toc_section
|
|
(struct bfd_link_info *, asection *);
|
|
bfd_boolean ppc64_elf_layout_multitoc
|
|
(struct bfd_link_info *);
|
|
void ppc64_elf_finish_multitoc_partition
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_check_init_fini
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_next_input_section
|
|
(struct bfd_link_info *, asection *);
|
|
bfd_boolean ppc64_elf_size_stubs
|
|
(struct bfd_link_info *);
|
|
bfd_boolean ppc64_elf_build_stubs
|
|
(struct bfd_link_info *, char **);
|