From 64f52338e924cce3a205527136e145da660a4686 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 23 Nov 2016 15:07:17 +1030 Subject: [PATCH] elf_backend_dtrel_excludes_plt Now that all targets creating .rel.plt/.rela.plt use the ELF hash table shortcut srelplt, the generic ELF code can set up DT_RELSZ/ DT_RELASZ and DT_REL/DT_RELA for targets that don't want PLT relocs included in those tags. * elf-bfd.h (struct elf_backend_data): Add dtrel_excludes_plt. * elfxx-target.h (elf_backend_dtrel_excludes_plt): Define. (elfNN_bed): Init new field. * elflink.c (bfd_elf_final_link): Add and use htab variable. Handle dtrel_excludes_plt. * elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-arc.c (elf_arc_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-arm.c (elf32_arm_finish_dynamic_sections): Delete code subtracting off plt relocs from DT_RELSZ, DT_RELASZ. (elf_backend_dtrel_excludes_plt): Define. * elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-cris.c (elf_cris_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Delete DT_RELASZ and DT_RELA code. (elf_backend_dtrel_excludes_plt): Define. * elf32-i386.c (elf_i386_finish_dynamic_sections): Delete DT_RELSZ and DT_REL code. (elf_backend_dtrel_excludes_plt): Define. * elf32-lm32.c (lm32_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-m32r.c (m32r_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-m68k.c (elf_m68k_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-metag.c (elf_metag_finish_dynamic_sections): Delete DT_RELASZ and DT_RELA code. (elf_backend_dtrel_excludes_plt): Define. * elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Delete DT_RELASZ and DT_RELA code. Use ELF htab shortcuts for other dynamic sections. (elf_backend_dtrel_excludes_plt): Define. * elf32-mips.c (elf_backend_dtrel_excludes_plt): Define. * elf32-nds32.c (nds32_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-or1k.c (or1k_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-ppc.c (ppc_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-sh.c (sh_elf_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-sparc.c (elf_backend_dtrel_excludes_plt): Define. * elf32-vax.c (elf_vax_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Delete DT_RELASZ and DT_RELA code. (elf_backend_dtrel_excludes_plt): Define. * elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elfnn-ia64.c (elfNN_ia64_finish_dynamic_sections): Delete DT_RELASZ code. (elf_backend_dtrel_excludes_plt): Define. * elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Delete DT_RELASZ code. * elfxx-sparc.c (sparc_finish_dyn): Delete DT_RELASZ code. --- bfd/ChangeLog | 88 ++++++++++++++++++++++++++++++++++++++++++ bfd/elf-bfd.h | 4 ++ bfd/elf-m10300.c | 17 +------- bfd/elf32-arc.c | 8 +--- bfd/elf32-arm.c | 29 +++----------- bfd/elf32-cr16.c | 17 +------- bfd/elf32-cris.c | 15 +------ bfd/elf32-hppa.c | 22 +---------- bfd/elf32-i386.c | 26 +------------ bfd/elf32-lm32.c | 19 +-------- bfd/elf32-m32r.c | 20 +--------- bfd/elf32-m68k.c | 15 +------ bfd/elf32-metag.c | 23 +---------- bfd/elf32-microblaze.c | 56 +++++++++++++++------------ bfd/elf32-mips.c | 2 + bfd/elf32-nds32.c | 19 +-------- bfd/elf32-nios2.c | 15 +------ bfd/elf32-or1k.c | 19 +-------- bfd/elf32-ppc.c | 11 +----- bfd/elf32-sh.c | 19 +-------- bfd/elf32-sparc.c | 2 + bfd/elf32-vax.c | 15 +------ bfd/elf32-xtensa.c | 12 +----- bfd/elf64-alpha.c | 11 +----- bfd/elf64-ppc.c | 22 +---------- bfd/elf64-sh64.c | 17 +------- bfd/elf64-x86-64.c | 16 +------- bfd/elflink.c | 72 ++++++++++++++++++---------------- bfd/elfnn-aarch64.c | 16 +------- bfd/elfnn-ia64.c | 8 +--- bfd/elfxx-mips.c | 7 ---- bfd/elfxx-sparc.c | 12 +----- bfd/elfxx-target.h | 5 +++ 33 files changed, 203 insertions(+), 456 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 3f43a5a3857..19a1026af36 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,91 @@ +2016-11-23 Alan Modra + + * elf-bfd.h (struct elf_backend_data): Add dtrel_excludes_plt. + * elfxx-target.h (elf_backend_dtrel_excludes_plt): Define. + (elfNN_bed): Init new field. + * elflink.c (bfd_elf_final_link): Add and use htab variable. Handle + dtrel_excludes_plt. + * elf-m10300.c (_bfd_mn10300_elf_finish_dynamic_sections): Delete + DT_RELASZ code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-arc.c (elf_arc_finish_dynamic_sections): Delete DT_RELASZ code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-arm.c (elf32_arm_finish_dynamic_sections): Delete code + subtracting off plt relocs from DT_RELSZ, DT_RELASZ. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-cr16.c (_bfd_cr16_elf_finish_dynamic_sections): Delete + DT_RELASZ code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-cris.c (elf_cris_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-hppa.c (elf32_hppa_finish_dynamic_sections): Delete DT_RELASZ + and DT_RELA code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-i386.c (elf_i386_finish_dynamic_sections): Delete DT_RELSZ + and DT_REL code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-lm32.c (lm32_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-m32r.c (m32r_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-m68k.c (elf_m68k_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-metag.c (elf_metag_finish_dynamic_sections): Delete DT_RELASZ + and DT_RELA code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-microblaze.c (microblaze_elf_finish_dynamic_sections): Delete + DT_RELASZ and DT_RELA code. Use ELF htab shortcuts for other + dynamic sections. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-mips.c (elf_backend_dtrel_excludes_plt): Define. + * elf32-nds32.c (nds32_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-or1k.c (or1k_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-ppc.c (ppc_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-sh.c (sh_elf_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-sparc.c (elf_backend_dtrel_excludes_plt): Define. + * elf32-vax.c (elf_vax_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf64-alpha.c (elf64_alpha_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Delete DT_RELASZ + and DT_RELA code. + (elf_backend_dtrel_excludes_plt): Define. + * elf64-sh64.c (sh64_elf64_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_sections): Delete + DT_RELASZ code. + (elf_backend_dtrel_excludes_plt): Define. + * elfnn-ia64.c (elfNN_ia64_finish_dynamic_sections): Delete DT_RELASZ + code. + (elf_backend_dtrel_excludes_plt): Define. + * elfxx-mips.c (_bfd_mips_elf_finish_dynamic_sections): Delete + DT_RELASZ code. + * elfxx-sparc.c (sparc_finish_dyn): Delete DT_RELASZ code. + 2016-11-23 Alan Modra * elf-m10300.c (mn10300_elf_check_relocs): Use elf htab shortcuts diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 50151cbcbb0..7c78899c34e 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1427,6 +1427,10 @@ struct elf_backend_data backend relocate_section routine for relocatable linking. */ unsigned rela_normal : 1; + /* Set if DT_REL/DT_RELA/DT_RELSZ/DT_RELASZ should not include PLT + relocations. */ + unsigned dtrel_excludes_plt : 1; + /* TRUE if addresses "naturally" sign extend. This is used when swapping in from Elf32 when BFD64. */ unsigned sign_extend_vma : 1; diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index 0b62fa9cc48..1ea5c27b4f5 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -5453,22 +5453,6 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = htab->root.srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -5609,5 +5593,6 @@ mn10300_elf_mkobject (bfd *abfd) #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #include "elf32-target.h" diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c index 314a162dc90..3d39c3a1352 100644 --- a/bfd/elf32-arc.c +++ b/bfd/elf32-arc.c @@ -2240,7 +2240,6 @@ elf_arc_finish_dynamic_sections (bfd * output_bfd, GET_SYMBOL_OR_SECTION (DT_PLTGOT, NULL, ".plt") GET_SYMBOL_OR_SECTION (DT_JMPREL, NULL, ".rela.plt") GET_SYMBOL_OR_SECTION (DT_PLTRELSZ, NULL, ".rela.plt") - GET_SYMBOL_OR_SECTION (DT_RELASZ, NULL, ".rela.plt") GET_SYMBOL_OR_SECTION (DT_VERSYM, NULL, ".gnu.version") GET_SYMBOL_OR_SECTION (DT_VERDEF, NULL, ".gnu.version_d") GET_SYMBOL_OR_SECTION (DT_VERNEED, NULL, ".gnu.version_r") @@ -2290,12 +2289,6 @@ elf_arc_finish_dynamic_sections (bfd * output_bfd, do_it = TRUE; break; - case DT_RELASZ: - if (s != NULL) - internal_dyn.d_un.d_val -= s->size; - do_it = TRUE; - break; - default: break; } @@ -2628,6 +2621,7 @@ elf32_arc_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) #define elf_backend_rela_plts_and_copies_p 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_may_use_rel_p 0 #define elf_backend_may_use_rela_p 1 diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index dced01aa00d..b1bec39d65d 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -16489,35 +16489,15 @@ elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info case DT_RELSZ: case DT_RELASZ: - if (!htab->symbian_p) - { - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_REL). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELSZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rel(a).plt to follow all - other relocation sections, we don't have to worry - about changing the DT_REL entry. */ - s = htab->root.srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; - } - /* Fall through. */ - case DT_REL: case DT_RELA: /* In the BPABI, the DT_REL tag must point at the file offset, not the VMA, of the first relocation section. So, we use code similar to that in elflink.c, but do not check for SHF_ALLOC on the - relcoation section, since relocations sections are - never allocated under the BPABI. The comments above - about Unixware notwithstanding, we include all of the - relocations here. */ + relocation section, since relocation sections are + never allocated under the BPABI. PLT relocs are also + included. */ if (htab->symbian_p) { unsigned int i; @@ -19419,6 +19399,7 @@ elf32_arm_backend_symbol_processing (bfd *abfd, asymbol *sym) #define elf_backend_may_use_rel_p 1 #define elf_backend_may_use_rela_p 0 #define elf_backend_default_use_rela_p 0 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_got_header_size 12 #define elf_backend_extern_protected_data 1 @@ -19980,6 +19961,8 @@ elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt, #define elf_backend_default_use_rela_p 0 #undef elf_backend_want_plt_sym #define elf_backend_want_plt_sym 0 +#undef elf_backend_dtrel_excludes_plt +#define elf_backend_dtrel_excludes_plt 0 #undef ELF_MAXPAGESIZE #define ELF_MAXPAGESIZE 0x8000 diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index 631445d58c9..3424c77d70a 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -2735,22 +2735,6 @@ _bfd_cr16_elf_finish_dynamic_sections (bfd * output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = elf_hash_table (info)->srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -2968,5 +2952,6 @@ _bfd_cr16_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSE #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #include "elf32-target.h" diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index 7d388018d37..3de29ec5074 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -2360,20 +2360,6 @@ elf_cris_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = elf_hash_table (info)->srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -4338,6 +4324,7 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBUTE_UNUSED, #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 #define elf_backend_got_elt_size elf_cris_got_elt_size +#define elf_backend_dtrel_excludes_plt 1 /* Later, we my want to optimize RELA entries into REL entries for dynamic linking and libraries (if it's a win of any significance). Until then, diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 63e9e69bea0..de3b7ead52d 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -4547,27 +4547,6 @@ elf32_hppa_finish_dynamic_sections (bfd *output_bfd, s = htab->etab.srelplt; dyn.d_un.d_val = s->size; break; - - case DT_RELASZ: - /* Don't count procedure linkage table relocs in the - overall reloc count. */ - s = htab->etab.srelplt; - if (s == NULL) - continue; - dyn.d_un.d_val -= s->size; - break; - - case DT_RELA: - /* We may not be using the standard ELF linker script. - If .rela.plt is the first .rela section, we adjust - DT_RELA to not include it. */ - s = htab->etab.srelplt; - if (s == NULL) - continue; - if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) - continue; - dyn.d_un.d_ptr += s->size; - break; } bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -4670,6 +4649,7 @@ elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type) #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 8 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define TARGET_BIG_SYM hppa_elf32_vec #define TARGET_BIG_NAME "elf32-hppa" diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 311ca37cdb4..6b1f1b02a60 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -5746,31 +5746,6 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, s = htab->elf.srelplt; dyn.d_un.d_val = s->size; break; - - case DT_RELSZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_REL). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELSZ entry - here to make it not include the JMPREL relocs. */ - s = htab->elf.srelplt; - if (s == NULL) - continue; - dyn.d_un.d_val -= s->size; - break; - - case DT_REL: - /* We may not be using the standard ELF linker script. - If .rel.plt is the first .rel section, we adjust - DT_REL to not include it. */ - s = htab->elf.srelplt; - if (s == NULL) - continue; - if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) - continue; - dyn.d_un.d_ptr += s->size; - break; } bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -6075,6 +6050,7 @@ elf_i386_hash_symbol (struct elf_link_hash_entry *h) #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 #define elf_backend_plt_alignment 4 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_extern_protected_data 1 #define elf_backend_caches_rawsize 1 diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 405768cf228..23129e065b0 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -1428,24 +1428,6 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -2656,6 +2638,7 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #define elf_backend_want_got_plt 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #define bfd_elf32_bfd_link_hash_table_create lm32_elf_link_hash_table_create #define elf_backend_check_relocs lm32_elf_check_relocs #define elf_backend_reloc_type_class lm32_elf_reloc_type_class diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 9d1492553b8..885917d4a8d 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -3330,24 +3330,6 @@ m32r_elf_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -4014,6 +3996,7 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_may_use_rel_p 1 #ifdef USE_M32R_OLD_RELOC @@ -4048,4 +4031,3 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, #define elf32_bed elf32_m32r_lin_bed #include "elf32-target.h" - diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 58df4c90705..af3f02f2617 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -4471,20 +4471,6 @@ elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = elf_hash_table (info)->srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -4854,5 +4840,6 @@ elf_m68k_add_symbol_hook (bfd *abfd, #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #include "elf32-target.h" diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c index 60d47287a37..39d3fffcb66 100644 --- a/bfd/elf32-metag.c +++ b/bfd/elf32-metag.c @@ -3331,28 +3331,6 @@ elf_metag_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* Don't count procedure linkage table relocs in the - overall reloc count. */ - if (htab->etab.srelplt) { - s = htab->etab.srelplt; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; - - case DT_RELA: - /* We may not be using the standard ELF linker script. - If .rela.plt is the first .rela section, we adjust - DT_RELA to not include it. */ - if (htab->etab.srelplt) { - s = htab->etab.srelplt; - if (dyn.d_un.d_ptr == s->output_section->vma + s->output_offset) - dyn.d_un.d_ptr += s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -4314,6 +4292,7 @@ elf_metag_plt_sym_val (bfd_vma i, const asection *plt, #define elf_backend_want_got_sym 0 #define elf_backend_want_plt_sym 0 #define elf_backend_plt_readonly 1 +#define elf_backend_dtrel_excludes_plt 1 #define bfd_elf32_bfd_reloc_type_lookup metag_reloc_type_lookup #define bfd_elf32_bfd_reloc_name_lookup metag_reloc_name_lookup diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c index c700bcb64ff..c1691f857ca 100644 --- a/bfd/elf32-microblaze.c +++ b/bfd/elf32-microblaze.c @@ -3331,47 +3331,52 @@ microblaze_elf_finish_dynamic_sections (bfd *output_bfd, asection *splt; Elf32_External_Dyn *dyncon, *dynconend; - splt = htab->elf.splt; - BFD_ASSERT (splt != NULL && sdyn != NULL); - dyncon = (Elf32_External_Dyn *) sdyn->contents; dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); for (; dyncon < dynconend; dyncon++) { Elf_Internal_Dyn dyn; - const char *name; + asection *s; bfd_boolean size; bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); switch (dyn.d_tag) { - case DT_PLTGOT: name = ".got.plt"; size = FALSE; break; - case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break; - case DT_JMPREL: name = ".rela.plt"; size = FALSE; break; - case DT_RELA: name = ".rela.dyn"; size = FALSE; break; - case DT_RELASZ: name = ".rela.dyn"; size = TRUE; break; - default: name = NULL; size = FALSE; break; - } + case DT_PLTGOT: + s = htab->elf.sgotplt; + size = FALSE; + break; - if (name != NULL) - { - asection *s; + case DT_PLTRELSZ: + s = htab->elf.srelplt; + size = TRUE; + break; - s = bfd_get_section_by_name (output_bfd, name); - if (s == NULL) - dyn.d_un.d_val = 0; - else - { - if (! size) - dyn.d_un.d_ptr = s->vma; - else - dyn.d_un.d_val = s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); + case DT_JMPREL: + s = htab->elf.srelplt; + size = FALSE; + break; + + default: + continue; } + + if (s == NULL) + dyn.d_un.d_val = 0; + else + { + if (!size) + dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; + else + dyn.d_un.d_val = s->size; + } + bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); } + splt = htab->elf.splt; + BFD_ASSERT (splt != NULL && sdyn != NULL); + /* Clear the first entry in the procedure linkage table, and put a nop in the last four bytes. */ if (splt->size > 0) @@ -3465,6 +3470,7 @@ microblaze_elf_add_symbol_hook (bfd *abfd, #define elf_backend_plt_readonly 1 #define elf_backend_got_header_size 12 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol #define elf_backend_create_dynamic_sections microblaze_elf_create_dynamic_sections diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index 4438ee83c2a..d398810ce63 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -2617,6 +2617,8 @@ mips_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) #define elf_backend_default_use_rela_p 1 #undef elf_backend_got_header_size #define elf_backend_got_header_size (4 * 3) +#undef elf_backend_dtrel_excludes_plt +#define elf_backend_dtrel_excludes_plt 1 #undef elf_backend_finish_dynamic_symbol #define elf_backend_finish_dynamic_symbol \ diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c index 8a06da5cc95..1722e1f83e1 100644 --- a/bfd/elf32-nds32.c +++ b/bfd/elf32-nds32.c @@ -5685,24 +5685,6 @@ nds32_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -15694,6 +15676,7 @@ nds32_elf_ex9_itb_base (struct bfd_link_info *link_info) #define elf_backend_may_use_rel_p 1 #define elf_backend_default_use_rela_p 1 #define elf_backend_may_use_rela_p 1 +#define elf_backend_dtrel_excludes_plt 1 #include "elf32-target.h" diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c index ad8eb45342c..c63932fd1b0 100644 --- a/bfd/elf32-nios2.c +++ b/bfd/elf32-nios2.c @@ -5366,20 +5366,6 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = htab->root.srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; - case DT_NIOS2_GP: s = htab->root.sgotplt; dyn.d_un.d_ptr @@ -6278,6 +6264,7 @@ const struct bfd_elf_special_section elf32_nios2_special_sections[] = #define elf_backend_plt_readonly 1 #define elf_backend_want_got_plt 1 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_relocate_section nios2_elf32_relocate_section #define elf_backend_section_flags nios2_elf32_section_flags diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c index 3ec16aab3d6..23de76221b9 100644 --- a/bfd/elf32-or1k.c +++ b/bfd/elf32-or1k.c @@ -1729,23 +1729,6 @@ or1k_elf_finish_dynamic_sections (bfd *output_bfd, s = htab->root.srelplt; dyn.d_un.d_val = s->size; break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt; - dyn.d_un.d_val -= s->size; - } - break; } bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); } @@ -2790,6 +2773,8 @@ elf32_or1k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) #define elf_backend_want_got_plt 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 + #define bfd_elf32_bfd_link_hash_table_create or1k_elf_link_hash_table_create #define elf_backend_copy_indirect_symbol or1k_elf_copy_indirect_symbol #define elf_backend_create_dynamic_sections or1k_elf_create_dynamic_sections diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 35a505c4bc5..323cc0f482e 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -10468,15 +10468,6 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_ptr = got; break; - case DT_RELASZ: - if (htab->is_vxworks) - { - if (htab->elf.srelplt) - dyn.d_un.d_ptr -= htab->elf.srelplt->size; - break; - } - continue; - default: if (htab->is_vxworks && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn)) @@ -11054,6 +11045,8 @@ ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) #define elf_backend_plt_readonly 1 #undef elf_backend_got_header_size #define elf_backend_got_header_size 12 +#undef elf_backend_dtrel_excludes_plt +#define elf_backend_dtrel_excludes_plt 1 #undef bfd_elf32_get_synthetic_symtab diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index c9a9fc384f4..5da1d088f57 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -6974,24 +6974,6 @@ sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt->output_section; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -7316,6 +7298,7 @@ sh_elf_encode_eh_address (bfd *abfd, #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #if !defined INCLUDE_SHMEDIA && !defined SH_TARGET_ALREADY_DEFINED diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c index d93c93eee2a..528cba29eac 100644 --- a/bfd/elf32-sparc.c +++ b/bfd/elf32-sparc.c @@ -332,6 +332,8 @@ elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) #define elf_backend_plt_readonly 1 #undef elf_backend_got_header_size #define elf_backend_got_header_size 12 +#undef elf_backend_dtrel_excludes_plt +#define elf_backend_dtrel_excludes_plt 1 #undef elf_backend_add_symbol_hook #define elf_backend_add_symbol_hook \ elf_vxworks_add_symbol_hook diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c index d7c6137554e..8912bf0c855 100644 --- a/bfd/elf32-vax.c +++ b/bfd/elf32-vax.c @@ -1905,20 +1905,6 @@ elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = elf_hash_table (info)->srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -2026,5 +2012,6 @@ elf_vax_plt_sym_val (bfd_vma i, const asection *plt, #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 16 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #include "elf32-target.h" diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index c4a00642834..5963458a810 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -3429,17 +3429,6 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd, case DT_PLTRELSZ: dyn.d_un.d_val = htab->elf.srelplt->size; break; - - case DT_RELASZ: - /* Adjust RELASZ to not include JMPREL. This matches what - glibc expects and what is done for several other ELF - targets (e.g., i386, alpha), but the "correct" behavior - seems to be unresolved. Since the linker script arranges - for .rela.plt to follow all other relocation sections, we - don't have to worry about changing the DT_RELA entry. */ - if (htab->elf.srelplt) - dyn.d_un.d_val -= htab->elf.srelplt->size; - break; } bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -11341,6 +11330,7 @@ static const struct bfd_elf_special_section elf_xtensa_special_sections[] = #define elf_backend_got_header_size 4 #define elf_backend_want_dynbss 0 #define elf_backend_want_got_plt 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_info_to_howto elf_xtensa_info_to_howto_rela diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 54205bc930e..44f2cfe0048 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -5057,16 +5057,6 @@ elf64_alpha_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_ptr = srelaplt ? (srelaplt->output_section->vma + srelaplt->output_offset) : 0; break; - - case DT_RELASZ: - /* My interpretation of the TIS v1.1 ELF document indicates - that RELASZ should not include JMPREL. This is not what - the rest of the BFD does. It is, however, what the - glibc ld.so wants. Do this fixup here until we found - out who is right. */ - if (srelaplt) - dyn.d_un.d_val -= srelaplt->size; - break; } bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -5596,6 +5586,7 @@ static const struct elf_size_info alpha_elf_size_info = #define elf_backend_plt_readonly 0 #define elf_backend_want_plt_sym 1 #define elf_backend_got_header_size 0 +#define elf_backend_dtrel_excludes_plt 1 #include "elf64-target.h" diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index 41343e5b852..d0113035551 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -75,6 +75,7 @@ static bfd_vma opd_entry_value #define elf_backend_can_gc_sections 1 #define elf_backend_can_refcount 1 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_default_execstack 0 #define bfd_elf64_mkobject ppc64_elf_mkobject @@ -15564,27 +15565,6 @@ ppc64_elf_finish_dynamic_sections (bfd *output_bfd, case DT_PLTRELSZ: dyn.d_un.d_val = htab->elf.srelplt->size; break; - - case DT_RELASZ: - /* Don't count procedure linkage table relocs in the - overall reloc count. */ - s = htab->elf.srelplt; - if (s == NULL) - continue; - dyn.d_un.d_val -= s->size; - break; - - case DT_RELA: - /* We may not be using the standard ELF linker script. - If .rela.plt is the first .rela section, we adjust - DT_RELA to not include it. */ - s = htab->elf.srelplt; - if (s == NULL) - continue; - if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset) - continue; - dyn.d_un.d_ptr += s->size; - break; } bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index 352fd2973dc..4739881ed70 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -3792,22 +3792,6 @@ sh64_elf64_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - the linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - s = elf_hash_table (info)->srelplt; - if (s != NULL) - dyn.d_un.d_val -= s->size; - bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } @@ -3960,6 +3944,7 @@ static const struct bfd_elf_special_section sh64_elf64_special_sections[]= #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 24 +#define elf_backend_dtrel_excludes_plt 1 #include "elf64-target.h" diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 05a4776c5a2..2e21899f0e5 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -6214,21 +6214,6 @@ elf_x86_64_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; break; - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->elf.srelplt != NULL) - { - s = htab->elf.srelplt->output_section; - dyn.d_un.d_val -= s->size; - } - break; - case DT_TLSDESC_PLT: s = htab->elf.splt; dyn.d_un.d_ptr = s->output_section->vma + s->output_offset @@ -6758,6 +6743,7 @@ static const struct bfd_elf_special_section #define elf_backend_plt_alignment 4 #define elf_backend_extern_protected_data 1 #define elf_backend_caches_rawsize 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_info_to_howto elf_x86_64_info_to_howto diff --git a/bfd/elflink.c b/bfd/elflink.c index daf4b82e947..ddbe80100d7 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11237,15 +11237,16 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) asection *attr_section = NULL; bfd_vma attr_size = 0; const char *std_attrs_section; + struct elf_link_hash_table *htab = elf_hash_table (info); - if (! is_elf_hash_table (info->hash)) + if (!is_elf_hash_table (htab)) return FALSE; if (bfd_link_pic (info)) abfd->flags |= DYNAMIC; - dynamic = elf_hash_table (info)->dynamic_sections_created; - dynobj = elf_hash_table (info)->dynobj; + dynamic = htab->dynamic_sections_created; + dynobj = htab->dynobj; emit_relocs = (bfd_link_relocatable (info) || info->emitrelocations); @@ -11462,8 +11463,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } if (! bfd_link_relocatable (info) && merged) - elf_link_hash_traverse (elf_hash_table (info), - _bfd_elf_link_sec_merge_syms, abfd); + elf_link_hash_traverse (htab, _bfd_elf_link_sec_merge_syms, abfd); /* Figure out the file positions for everything but the symbol table and the relocs. We set symcount to force assign_section_numbers @@ -11526,11 +11526,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (max_sym_count < 20) max_sym_count = 20; - elf_hash_table (info)->strtabsize = max_sym_count; + htab->strtabsize = max_sym_count; amt = max_sym_count * sizeof (struct elf_sym_strtab); - elf_hash_table (info)->strtab - = (struct elf_sym_strtab *) bfd_malloc (amt); - if (elf_hash_table (info)->strtab == NULL) + htab->strtab = (struct elf_sym_strtab *) bfd_malloc (amt); + if (htab->strtab == NULL) goto error_return; /* The real buffer will be allocated in elf_link_swap_symbols_out. */ flinfo.symshndxbuf @@ -11642,12 +11641,12 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) goto error_return; } - if (elf_hash_table (info)->tls_sec) + if (htab->tls_sec) { bfd_vma base, end = 0; asection *sec; - for (sec = elf_hash_table (info)->tls_sec; + for (sec = htab->tls_sec; sec && (sec->flags & SEC_THREAD_LOCAL); sec = sec->next) { @@ -11663,13 +11662,12 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } end = sec->vma + size; } - base = elf_hash_table (info)->tls_sec->vma; + base = htab->tls_sec->vma; /* Only align end of TLS section if static TLS doesn't have special alignment requirements. */ if (bed->static_tls_alignment == 1) - end = align_power (end, - elf_hash_table (info)->tls_sec->alignment_power); - elf_hash_table (info)->tls_size = end - base; + end = align_power (end, htab->tls_sec->alignment_power); + htab->tls_size = end - base; } /* Reorder SHF_LINK_ORDER sections. */ @@ -11817,20 +11815,18 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) symtab_hdr->sh_info = bfd_get_symcount (abfd); if (dynamic - && elf_hash_table (info)->dynsym != NULL - && (elf_hash_table (info)->dynsym->output_section - != bfd_abs_section_ptr)) + && htab->dynsym != NULL + && htab->dynsym->output_section != bfd_abs_section_ptr) { Elf_Internal_Sym sym; - bfd_byte *dynsym = elf_hash_table (info)->dynsym->contents; + bfd_byte *dynsym = htab->dynsym->contents; - o = elf_hash_table (info)->dynsym->output_section; - elf_section_data (o)->this_hdr.sh_info - = elf_hash_table (info)->local_dynsymcount + 1; + o = htab->dynsym->output_section; + elf_section_data (o)->this_hdr.sh_info = htab->local_dynsymcount + 1; /* Write out the section symbols for the output sections. */ if (bfd_link_pic (info) - || elf_hash_table (info)->is_relocatable_executable) + || htab->is_relocatable_executable) { asection *s; @@ -11861,10 +11857,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } /* Write out the local dynsyms. */ - if (elf_hash_table (info)->dynlocal) + if (htab->dynlocal) { struct elf_link_local_dynamic_entry *e; - for (e = elf_hash_table (info)->dynlocal; e ; e = e->next) + for (e = htab->dynlocal; e ; e = e->next) { asection *s; bfd_byte *dest; @@ -12049,8 +12045,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) { struct elf_link_hash_entry *h; - h = elf_link_hash_lookup (elf_hash_table (info), name, - FALSE, FALSE, TRUE); + h = elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE); if (h != NULL && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)) @@ -12172,6 +12167,18 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } } } + if (bed->dtrel_excludes_plt && htab->srelplt != NULL) + { + /* Don't count procedure linkage table relocs in the + overall reloc count. */ + if (dyn.d_tag == DT_RELSZ || dyn.d_tag == DT_RELASZ) + dyn.d_un.d_val -= htab->srelplt->size; + /* If .rela.plt is the first .rela section, exclude + it from DT_RELA. */ + else if (dyn.d_un.d_ptr == (htab->srelplt->output_section->vma + + htab->srelplt->output_offset)) + dyn.d_un.d_ptr += htab->srelplt->size; + } break; } bed->s->swap_dyn_out (dynobj, &dyn, dyncon); @@ -12224,9 +12231,9 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) created by _bfd_elf_link_create_dynamic_sections. */ continue; } - if (elf_hash_table (info)->stab_info.stabstr == o) + if (htab->stab_info.stabstr == o) continue; - if (elf_hash_table (info)->eh_info.hdr_sec == o) + if (htab->eh_info.hdr_sec == o) continue; if (strcmp (o->name, ".dynstr") != 0) { @@ -12245,8 +12252,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) off = elf_section_data (o->output_section)->this_hdr.sh_offset; if (bfd_seek (abfd, off, SEEK_SET) != 0 - || ! _bfd_elf_strtab_emit (abfd, - elf_hash_table (info)->dynstr)) + || !_bfd_elf_strtab_emit (abfd, htab->dynstr)) goto error_return; } } @@ -12262,9 +12268,9 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } /* If we have optimized stabs strings, output them. */ - if (elf_hash_table (info)->stab_info.stabstr != NULL) + if (htab->stab_info.stabstr != NULL) { - if (! _bfd_write_stab_strings (abfd, &elf_hash_table (info)->stab_info)) + if (!_bfd_write_stab_strings (abfd, &htab->stab_info)) goto error_return; } diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 0b5e655e3cd..99b2a04f153 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -9066,21 +9066,6 @@ elfNN_aarch64_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_val = s->size; break; - case DT_RELASZ: - /* The procedure linkage table relocs (DT_JMPREL) should - not be included in the overall relocs (DT_RELA). - Therefore, we override the DT_RELASZ entry here to - make it not include the JMPREL relocs. Since the - linker script arranges for .rela.plt to follow all - other relocation sections, we don't have to worry - about changing the DT_RELA entry. */ - if (htab->root.srelplt != NULL) - { - s = htab->root.srelplt; - dyn.d_un.d_val -= s->size; - } - break; - case DT_TLSDESC_PLT: s = htab->root.splt; dyn.d_un.d_ptr = s->output_section->vma + s->output_offset @@ -9410,6 +9395,7 @@ const struct elf_size_info elfNN_aarch64_size_info = #define elf_backend_may_use_rela_p 1 #define elf_backend_default_use_rela_p 1 #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_got_header_size (GOT_ENTRY_SIZE * 3) #define elf_backend_default_execstack 0 #define elf_backend_extern_protected_data 1 diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c index ef6344728b8..32f94111db7 100644 --- a/bfd/elfnn-ia64.c +++ b/bfd/elfnn-ia64.c @@ -4663,13 +4663,6 @@ elfNN_ia64_finish_dynamic_sections (bfd *abfd, dyn.d_un.d_ptr = (sgotplt->output_section->vma + sgotplt->output_offset); break; - - case DT_RELASZ: - /* Do not have RELASZ include JMPREL. This makes things - easier on ld.so. This is not what the rest of BFD set up. */ - dyn.d_un.d_val -= (ia64_info->minplt_entries - * sizeof (ElfNN_External_Rela)); - break; } bfd_elfNN_swap_dyn_out (abfd, &dyn, dyncon); @@ -5074,6 +5067,7 @@ elfNN_hpux_backend_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, #define elf_backend_fixup_symbol _bfd_elf_link_hash_fixup_symbol #define elf_backend_reloc_type_class elfNN_ia64_reloc_type_class #define elf_backend_rela_normal 1 +#define elf_backend_dtrel_excludes_plt 1 #define elf_backend_special_sections elfNN_ia64_special_sections #define elf_backend_default_execstack 0 diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 029ea1c80d2..0e56ffa361d 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -11714,13 +11714,6 @@ _bfd_mips_elf_finish_dynamic_sections (bfd *output_bfd, dyn.d_un.d_ptr = s->vma; break; - case DT_RELASZ: - BFD_ASSERT (htab->is_vxworks); - /* The count does not include the JUMP_SLOT relocations. */ - if (htab->root.srelplt) - dyn.d_un.d_val -= htab->root.srelplt->size; - break; - case DT_PLTREL: BFD_ASSERT (htab->use_plts_and_copy_relocs); if (htab->is_vxworks) diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index 916d33bc23a..056a4b75507 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -4582,17 +4582,7 @@ sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info, bed->s->swap_dyn_in (dynobj, dyncon, &dyn); - if (htab->is_vxworks && dyn.d_tag == DT_RELASZ) - { - /* On VxWorks, DT_RELASZ should not include the relocations - in .rela.plt. */ - if (htab->elf.srelplt) - { - dyn.d_un.d_val -= htab->elf.srelplt->size; - bed->s->swap_dyn_out (output_bfd, &dyn, dyncon); - } - } - else if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT) + if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT) { /* On VxWorks, DT_PLTGOT should point to the start of the GOT, not to the start of the PLT. */ diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index c6a9466904c..5ff39dd4474 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -632,6 +632,10 @@ #define elf_backend_rela_normal 0 #endif +#ifndef elf_backend_dtrel_excludes_plt +#define elf_backend_dtrel_excludes_plt 0 +#endif + #ifndef elf_backend_plt_sym_val #define elf_backend_plt_sym_val NULL #endif @@ -835,6 +839,7 @@ static struct elf_backend_data elfNN_bed = elf_backend_default_use_rela_p, elf_backend_rela_plts_and_copies_p, elf_backend_rela_normal, + elf_backend_dtrel_excludes_plt, elf_backend_sign_extend_vma, elf_backend_want_got_plt, elf_backend_plt_readonly, -- 2.30.2