diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-10-16 03:49:54 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2017-10-16 03:50:13 -0700 |
commit | 5c3261b0e834647cf9eb555320e20871b7854f98 (patch) | |
tree | 16de4f57b1d4ff511e632f97bda5e365e7f84a3e /bfd/elf32-cris.c | |
parent | 5bfda25568c34410129c91042cdfdf10c143edac (diff) | |
download | gdb-5c3261b0e834647cf9eb555320e20871b7854f98.zip gdb-5c3261b0e834647cf9eb555320e20871b7854f98.tar.gz gdb-5c3261b0e834647cf9eb555320e20871b7854f98.tar.bz2 |
ELF: Call check_relocs after opening all inputs
For all ELF targers, call check_relocs after opening all inputs and
garbage collection. Since the symbol resolution is known, check_relocs
can be simplified. Also garbage collection doesn't need to undo what
check_relocs has done for symbols which have been garbage collected.
Since ELF targets never see the removed sections, gc_sweep_hook can be
removed from elf_backend_data and we can avoid GOT/PLT with garbage
collection now.
Set link_info.check_relocs_after_open_input to TRUE for all linker
targets which use ELF linker and update garbage collection tests to
remove unused GOT section.
ldemul_after_check_relocs is added for powerpc to support --secure-plt,
--bss-plt and --sdata-got.
Tested natively without regressions on i686, x86-64 and x32. Tested
cross binutils on x86-64 without regressions for aarch64-linux,
alpha-linux, arm-linux, bfin-elf, cr16-elf, cris-elf, crx-elf, frv-linux,
hppa64-linux, hppa-linux, ia64-linux, lm32-elf, m32r-elf, m68k-linux,
mcore-elf, metag-elf, microblaze-linux, mips-linux, mmix, mn10300-elf,
nds32le-linux, nios2-linux, or1k-elf, powerpc64-linux, powerpc-linux,
riscv32-linux, riscv64-linux, s390-linux, s390x-linux, score-elf,
sh3-linux, sparc64-linux, sparc-linux, tic6x-elf, tilegx-linux,
tilepro-linux, vax-linux, x86_64-mingw32 and xtensa-linux.
bfd/
* elf-bfd.h (elf_backend_data): Remove gc_sweep_hook.
* elf32-arm.c (elf32_arm_gc_sweep_hook): Removed.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-bfin.c (bfin_gc_sweep_hook): Likewise.
(bfinfdpic_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-cr16.c (elf32_cr16_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-cris.c (cris_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-hppa.c (elf32_hppa_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-lm32.c (lm32_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-m32r.c (m32r_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-m68k.c (elf_m68k_got_entry): Remove elf_m68k_gc_sweep_hook
from comments.
(elf_m68k_remove_got_entry_type): Removed.
(elf_m68k_find_got_entry_ptr): Likewise.
(elf_m68k_remove_got_entry): Likewise.
(elf_m68k_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-mcore.c (mcore_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-metag.c (elf_metag_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-microblaze.c (elf_backend_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-mips.c (elf_backend_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-nds32.c (nds32_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-nios2.c (nios2_elf32_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-or1k.c (or1k_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-ppc.c (ppc_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-s390.c (elf_s390_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-sparc.c (elf_backend_gc_sweep_hook): Likewise.
* elf32-tic6x.c (elf32_tic6x_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-tilegx.c (elf_backend_gc_sweep_hook): Likewise.
* elf32-tilepro.c (tilepro_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-vax.c (elf_vax_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf32-xtensa.c (elf_xtensa_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf64-alpha.c (elf64_alpha_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf64-mips.c (elf_backend_gc_sweep_hook): Likewise.
* elf64-mmix.c (mmix_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf64-ppc.c (elf_backend_gc_sweep_hook): Likewise.
(ppc64_elf_gc_sweep_hook): Likewise.
* elf64-s390.c (elf_s390_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elf64-sparc.c (elf_backend_gc_sweep_hook): Likewise.
* elf64-tilegx.c (elf_backend_gc_sweep_hook): Likewise.
* elflink.c (elf_link_add_object_symbols): Don't call
_bfd_elf_link_check_relocs here.
(gc_sweep_hook_fn): Removed.
(elf_gc_sweep): Remove gc_sweep_hook.
* elfnn-aarch64.c (elfNN_aarch64_gc_sweep_hook): Removed.
(elf_backend_gc_sweep_hook): Likewise.
* elfnn-riscv.c (riscv_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elfxx-mips.c (_bfd_mips_elf_gc_sweep_hook): Likewise.
* elfxx-mips.h (_bfd_mips_elf_gc_sweep_hook): Likewise.
(elf_backend_gc_sweep_hook): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_gc_sweep_hook): Likewise.
* elfxx-sparc.h (_bfd_sparc_elf_gc_sweep_hook): Likewise.
* elfxx-target.h (elf_backend_gc_sweep_hook): Likewise.
(elfNN_bed): Remove elf_backend_gc_sweep_hook.
* elfxx-tilegx.c (tilegx_elf_gc_sweep_hook): Removed.
* elfxx-tilegx.h (tilegx_elf_gc_sweep_hook): Likewise.
ld/
* emulparams/elf32_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Removed.
* emulparams/elf_i386_be.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_i386_chaos.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_i386_ldso.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_i386_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_iamcu.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_k1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_l1om.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/elf_x86_64.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/i386lynx.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/i386moss.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/i386nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/i386nw.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shelf.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shelf32.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shelf_nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shelf_vxworks.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shlelf32_linux.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shlelf_linux.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emulparams/shlelf_nto.sh (CHECK_RELOCS_AFTER_OPEN_INPUT):
Likewise.
* emultempl/aarch64elf.em (gld${EMULATION_NAME}_before_parse):
Set link_info.check_relocs_after_open_input to TRUE.
* emultempl/armelf.em (gld${EMULATION_NAME}_before_parse):
Likewise.
* emultempl/scoreelf.em (gld${EMULATION_NAME}_before_parse):
Likewise.
* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
after_parse_default.
* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/gld960.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/gld960c.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/lnk960.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/m68kcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/sunos.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/vanilla.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Always
set link_info.check_relocs_after_open_input to TRUE.
(ld_${EMULATION_NAME}_emulation): Add $LDEMUL_AFTER_CHECK_RELOCS.
* emultempl/linux.em (gld${EMULATION_NAME}_before_parse):
Set link_info.check_relocs_after_open_input to TRUE.
(ld_${EMULATION_NAME}_emulation): Add after_check_relocs_default.
* emultempl/mmix-elfnmmo.em (mmix_before_parse): New function.
(LDEMUL_BEFORE_PARSE): New.
* emultempl/mmixelf.em (elfmmix_before_parse): Replace
gld${EMULATION_NAME}_before_parse with mmix_before_parse.
* emultempl/ppc32elf.em (ppc_after_open): Renamed to ...
(ppc_after_check_relocs): This. Call after_check_relocs_default
instead of gld${EMULATION_NAME}_after_open.
(LDEMUL_AFTER_OPEN): Removed.
(LDEMUL_AFTER_CHECK_RELOCS): New.
* ldemul.c (ldemul_after_check_relocs): New.
(after_check_relocs_default): Likewise.
* ldemul.h (ldemul_after_check_relocs): Likewise.
(after_check_relocs_default): Likewise.
(ld_emulation_xfer_struct): Add after_check_relocs.
* ldlang.c (lang_process): Call ldemul_after_check_relocs after
lang_check_relocs.
* testsuite/ld-aarch64/gc-got-relocs.d: Don't expect GOT section.
* testsuite/ld-aarch64/gc-tls-relocs.d: Likewise.
* testsuite/ld-cris/tls-gc-68.d: Likewise.
* testsuite/ld-cris/tls-gc-69.d: Likewise.
* testsuite/ld-cris/tls-gc-70.d: Likewise.
* testsuite/ld-cris/tls-gc-75.d: Likewise.
* testsuite/ld-cris/tls-gc-79.d: Likewise.
* testsuite/ld-mmix/bpo-10.d: Don't expect .MMIX.reg_contents
section.
Diffstat (limited to 'bfd/elf32-cris.c')
-rw-r--r-- | bfd/elf32-cris.c | 188 |
1 files changed, 0 insertions, 188 deletions
diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index 387c7c7..012e663 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -2456,193 +2456,6 @@ cris_elf_gc_mark_hook (asection *sec, return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); } -/* Update the got entry reference counts for the section being removed. */ - -static bfd_boolean -cris_elf_gc_sweep_hook (bfd *abfd, - struct bfd_link_info *info, - asection *sec, - const Elf_Internal_Rela *relocs) -{ - struct elf_cris_link_hash_table * htab; - Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes; - bfd_signed_vma *local_got_refcounts; - const Elf_Internal_Rela *rel, *relend; - bfd *dynobj; - asection *sgot; - asection *srelgot; - - if (bfd_link_relocatable (info)) - return TRUE; - - dynobj = elf_hash_table (info)->dynobj; - if (dynobj == NULL) - return TRUE; - - htab = elf_cris_hash_table (info); - if (htab == NULL) - return FALSE; - - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - sym_hashes = elf_sym_hashes (abfd); - local_got_refcounts = elf_local_got_refcounts (abfd); - - sgot = htab->root.sgot; - srelgot = htab->root.srelgot; - - relend = relocs + sec->reloc_count; - for (rel = relocs; rel < relend; rel++) - { - unsigned long r_symndx; - struct elf_link_hash_entry *h = NULL; - bfd_signed_vma got_element_size = 4; - bfd_signed_vma *specific_refcount = NULL; - enum elf_cris_reloc_type r_type; - - r_symndx = ELF32_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - while (h->root.type == bfd_link_hash_indirect - || h->root.type == bfd_link_hash_warning) - h = (struct elf_link_hash_entry *) h->root.u.i.link; - } - - r_type = ELF32_R_TYPE (rel->r_info); - switch (r_type) - { - case R_CRIS_32_GOT: - case R_CRIS_16_GOT: - case R_CRIS_16_GOTPLT: - case R_CRIS_32_GOTPLT: - specific_refcount = h != NULL - ? &((struct elf_cris_link_hash_entry *) h)->reg_got_refcount - : &local_got_refcounts[LGOT_REG_NDX (r_symndx)]; - break; - - case R_CRIS_32_GD: - case R_CRIS_32_GOT_GD: - case R_CRIS_16_GOT_GD: - got_element_size = 8; - specific_refcount = h != NULL - ? &((struct elf_cris_link_hash_entry *) h)->dtp_refcount - : &local_got_refcounts[LGOT_DTP_NDX (r_symndx)]; - break; - - case R_CRIS_32_IE: - case R_CRIS_16_GOT_TPREL: - case R_CRIS_32_GOT_TPREL: - specific_refcount = h != NULL - ? &((struct elf_cris_link_hash_entry *) h)->tprel_refcount - : &local_got_refcounts[LGOT_TPREL_NDX (r_symndx)]; - break; - - default: - break; - } - - switch (r_type) - { - case R_CRIS_32_IE: - case R_CRIS_32_GD: - case R_CRIS_16_GOT_TPREL: - case R_CRIS_32_GOT_TPREL: - case R_CRIS_32_GOT_GD: - case R_CRIS_16_GOT_GD: - case R_CRIS_16_GOT: - case R_CRIS_32_GOT: - if (h != NULL) - { - /* If the counters are 0 when we got here, we've - miscounted somehow somewhere, an internal error. */ - BFD_ASSERT (h->got.refcount > 0); - --h->got.refcount; - - BFD_ASSERT (*specific_refcount > 0); - --*specific_refcount; - if (*specific_refcount == 0) - { - /* We don't need the .got entry any more. */ - sgot->size -= got_element_size; - srelgot->size -= sizeof (Elf32_External_Rela); - } - break; - } - - local_got_reloc: - if (local_got_refcounts != NULL) - { - /* If the counters are 0 when we got here, we've - miscounted somehow somewhere, an internal error. */ - BFD_ASSERT (local_got_refcounts[r_symndx] > 0); - --local_got_refcounts[r_symndx]; - - BFD_ASSERT (*specific_refcount > 0); - --*specific_refcount; - if (*specific_refcount == 0) - { - /* We don't need the .got entry any more. */ - sgot->size -= got_element_size; - if (bfd_link_pic (info)) - srelgot->size -= sizeof (Elf32_External_Rela); - } - } - break; - - case R_CRIS_16_GOTPLT: - case R_CRIS_32_GOTPLT: - /* For local symbols, treat these like GOT relocs. */ - if (h == NULL) - goto local_got_reloc; - else - /* For global symbols, adjust the reloc-specific refcount. */ - elf_cris_hash_entry (h)->gotplt_refcount--; - /* Fall through. */ - - case R_CRIS_32_PLT_GOTREL: - /* FIXME: We don't garbage-collect away the .got section. */ - if (local_got_refcounts != NULL) - local_got_refcounts[-1]--; - /* Fall through. */ - - case R_CRIS_8: - case R_CRIS_16: - case R_CRIS_32: - case R_CRIS_8_PCREL: - case R_CRIS_16_PCREL: - case R_CRIS_32_PCREL: - case R_CRIS_32_PLT_PCREL: - /* Negate the increment we did in cris_elf_check_relocs. */ - if (h != NULL) - { - if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT - && h->plt.refcount > 0) - --h->plt.refcount; - } - break; - - case R_CRIS_32_DTPREL: - /* This'd be a .dtpreld entry in e.g. debug info. */ - if ((sec->flags & SEC_ALLOC) == 0) - break; - /* Fall through. */ - case R_CRIS_16_DTPREL: - htab->dtpmod_refcount--; - if (htab->dtpmod_refcount == 0) - htab->next_gotplt_entry -= 8; - BFD_ASSERT (local_got_refcounts != NULL); - local_got_refcounts[-1]--; - break; - - default: - break; - } - } - - return TRUE; -} - /* The elf_backend_plt_sym_val hook function. */ static bfd_vma @@ -4297,7 +4110,6 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED, #define elf_info_to_howto cris_info_to_howto_rela #define elf_backend_relocate_section cris_elf_relocate_section #define elf_backend_gc_mark_hook cris_elf_gc_mark_hook -#define elf_backend_gc_sweep_hook cris_elf_gc_sweep_hook #define elf_backend_plt_sym_val cris_elf_plt_sym_val #define elf_backend_check_relocs cris_elf_check_relocs #define elf_backend_grok_prstatus cris_elf_grok_prstatus |