From 7325306f39112471924c0f2bf92734473686ae58 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Sat, 25 Feb 2006 09:23:30 +0000 Subject: bfd/ * elf-bfd.h (elf_link_hash_table): Add hplt field. * elflink.c (_bfd_elf_create_dynamic_sections): Initialize it. * elf-m10300.c (_bfd_mn10300_elf_create_got_section): Likewise. * elf32-frv.c (_frv_create_got_section): Likewise. * elf32-m32r.c (m32r_elf_create_dynamic_sections): Likewise. * elf32-sh.c (sh_elf_create_dynamic_sections): Likewise. * elf64-alpha.c (elf64_alpha_create_dynamic_sections): Likewise. * elf64-sh64.c (sh64_elf64_create_dynamic_sections): Likewise. * elf32-i386.c (elf_i386_link_hash_table): Remove hgot and hplt. (elf_i386_link_hash_table_create): Don't initialize them. (elf_i386_size_dynamic_sections): Use the generic ELF hplt and hgot fields. (elf_i386_finish_dynamic_symbol): Likewise. * elf32-ppc.c (ppc_elf_link_hash_table): Remove hplt. (ppc_elf_size_dynamic_sections): Use the generic ELF hplt fields. (ppc_elf_finish_dynamic_symbol): Likewise. --- bfd/ChangeLog | 19 +++++++++++++++++++ bfd/elf-bfd.h | 3 +++ bfd/elf-m10300.c | 12 ++++++++---- bfd/elf32-frv.c | 12 ++++++++---- bfd/elf32-i386.c | 56 +++++++++++++++++++------------------------------------ bfd/elf32-m32r.c | 1 + bfd/elf32-ppc.c | 29 +++++++++++----------------- bfd/elf32-sh.c | 1 + bfd/elf64-alpha.c | 6 ++++-- bfd/elf64-sh64.c | 1 + bfd/elflink.c | 13 +++++++++---- 11 files changed, 84 insertions(+), 69 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 646a849..f7cbecb 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,22 @@ +2006-02-25 Richard Sandiford + + * elf-bfd.h (elf_link_hash_table): Add hplt field. + * elflink.c (_bfd_elf_create_dynamic_sections): Initialize it. + * elf-m10300.c (_bfd_mn10300_elf_create_got_section): Likewise. + * elf32-frv.c (_frv_create_got_section): Likewise. + * elf32-m32r.c (m32r_elf_create_dynamic_sections): Likewise. + * elf32-sh.c (sh_elf_create_dynamic_sections): Likewise. + * elf64-alpha.c (elf64_alpha_create_dynamic_sections): Likewise. + * elf64-sh64.c (sh64_elf64_create_dynamic_sections): Likewise. + * elf32-i386.c (elf_i386_link_hash_table): Remove hgot and hplt. + (elf_i386_link_hash_table_create): Don't initialize them. + (elf_i386_size_dynamic_sections): Use the generic ELF hplt and + hgot fields. + (elf_i386_finish_dynamic_symbol): Likewise. + * elf32-ppc.c (ppc_elf_link_hash_table): Remove hplt. + (ppc_elf_size_dynamic_sections): Use the generic ELF hplt fields. + (ppc_elf_finish_dynamic_symbol): Likewise. + 2006-02-24 DJ Delorie * elf32-m32c.c (m32c_elf_howto_table): Add relaxation relocs. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 4181e36..76be811 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -378,6 +378,9 @@ struct elf_link_hash_table /* The _GLOBAL_OFFSET_TABLE_ symbol. */ struct elf_link_hash_entry *hgot; + /* The _PROCEDURE_LINKAGE_TABLE_ symbol. */ + struct elf_link_hash_entry *hplt; + /* A pointer to information used to merge SEC_MERGE sections. */ void *merge_info; diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index 86ffb78..5b14e92 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -582,10 +582,14 @@ _bfd_mn10300_elf_create_got_section (abfd, info) /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. */ - if (bed->want_plt_sym - && !_bfd_elf_define_linkage_sym (abfd, info, s, - "_PROCEDURE_LINKAGE_TABLE_")) - return FALSE; + if (bed->want_plt_sym) + { + h = _bfd_elf_define_linkage_sym (abfd, info, s, + "_PROCEDURE_LINKAGE_TABLE_"); + elf_hash_table (info)->hplt = h; + if (h == NULL) + return FALSE; + } s = bfd_make_section_with_flags (abfd, ".got", flags); if (s == NULL diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c index e0c5120..7126ed4 100644 --- a/bfd/elf32-frv.c +++ b/bfd/elf32-frv.c @@ -4398,10 +4398,14 @@ _frv_create_got_section (bfd *abfd, struct bfd_link_info *info) /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. */ - if (bed->want_plt_sym - && !_bfd_elf_define_linkage_sym (abfd, info, s, - "_PROCEDURE_LINKAGE_TABLE_")) - return FALSE; + if (bed->want_plt_sym) + { + h = _bfd_elf_define_linkage_sym (abfd, info, s, + "_PROCEDURE_LINKAGE_TABLE_"); + elf_hash_table (info)->hplt = h; + if (h == NULL) + return FALSE; + } /* FRV-specific: we want rel relocations for the plt. */ s = bfd_make_section_with_flags (abfd, ".rel.plt", diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 64e5fb0..eb701a1 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -647,9 +647,6 @@ struct elf_i386_link_hash_table /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. */ asection *srelplt2; - /* Short-cuts to frequently used symbols for VxWorks targets. */ - struct elf_link_hash_entry *hgot, *hplt; - /* True if the target system is VxWorks. */ int is_vxworks; @@ -739,8 +736,6 @@ elf_i386_link_hash_table_create (bfd *abfd) ret->sym_sec.abfd = NULL; ret->is_vxworks = 0; ret->srelplt2 = NULL; - ret->hgot = NULL; - ret->hplt = NULL; ret->plt0_pad_byte = 0; return &ret->elf.root; @@ -2003,23 +1998,17 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (htab->is_vxworks) { - /* Save the GOT and PLT symbols in the hash table for easy access. - Mark them as having relocations; they might not, but we won't - know for sure until we build the GOT in finish_dynamic_symbol. */ - - htab->hgot = elf_link_hash_lookup (elf_hash_table (info), - "_GLOBAL_OFFSET_TABLE_", - FALSE, FALSE, FALSE); - if (htab->hgot) - htab->hgot->indx = -2; - htab->hplt = elf_link_hash_lookup (elf_hash_table (info), - "_PROCEDURE_LINKAGE_TABLE_", - FALSE, FALSE, FALSE); - if (htab->hplt) - htab->hplt->indx = -2; - - if (htab->is_vxworks && htab->hplt && htab->splt->flags & SEC_CODE) - htab->hplt->type = STT_FUNC; + /* Mark the GOT and PLT symbols as having relocations; they might + not, but we won't know for sure until we build the GOT in + finish_dynamic_symbol. */ + if (htab->elf.hgot) + htab->elf.hgot->indx = -2; + if (htab->elf.hplt) + { + htab->elf.hplt->indx = -2; + if (htab->splt->flags & SEC_CODE) + htab->elf.hplt->type = STT_FUNC; + } } /* Allocate global sym .plt and .got entries, and space for global @@ -2055,7 +2044,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, we've exported dynamic symbols from them we must leave them. It's too late to tell BFD to get rid of the symbols. */ - if (htab->hplt != NULL) + if (htab->elf.hplt != NULL) strip_section = FALSE; } else if (strncmp (bfd_get_section_name (dynobj, s), ".rel", 4) == 0) @@ -3524,7 +3513,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd, rel.r_offset = (htab->splt->output_section->vma + htab->splt->output_offset + h->plt.offset + 2), - rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); /* Create the R_386_32 relocation referencing the beginning of @@ -3532,7 +3521,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd, rel.r_offset = (htab->sgotplt->output_section->vma + htab->sgotplt->output_offset + got_offset); - rel.r_info = ELF32_R_INFO (htab->hplt->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, loc + sizeof (Elf32_External_Rel)); } @@ -3786,28 +3775,21 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, if (htab->is_vxworks) { Elf_Internal_Rela rel; - struct elf_link_hash_entry *hgot; - - /* The VxWorks GOT is relocated by the dynamic linker. - Therefore, we must emit relocations rather than - simply computing the values now. */ - hgot = elf_link_hash_lookup (elf_hash_table (info), - "_GLOBAL_OFFSET_TABLE_", - FALSE, FALSE, FALSE); + /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 4. On IA32 we use REL relocations so the addend goes in the PLT directly. */ rel.r_offset = (htab->splt->output_section->vma + htab->splt->output_offset + 2); - rel.r_info = ELF32_R_INFO (hgot->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, htab->srelplt2->contents); /* Generate a relocation for _GLOBAL_OFFSET_TABLE_ + 8. */ rel.r_offset = (htab->splt->output_section->vma + htab->splt->output_offset + 8); - rel.r_info = ELF32_R_INFO (hgot->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, htab->srelplt2->contents + sizeof (Elf32_External_Rel)); @@ -3835,12 +3817,12 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, { Elf_Internal_Rela rel; bfd_elf32_swap_reloc_in (output_bfd, p, &rel); - rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, p); p += sizeof (Elf32_External_Rel); bfd_elf32_swap_reloc_in (output_bfd, p, &rel); - rel.r_info = ELF32_R_INFO (htab->hplt->indx, R_386_32); + rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_386_32); bfd_elf32_swap_reloc_out (output_bfd, &rel, p); p += sizeof (Elf32_External_Rel); } diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 6a8c5bf..672d5f4 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -1668,6 +1668,7 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) h = (struct elf_link_hash_entry *) bh; h->def_regular = 1; h->type = STT_OBJECT; + htab->root.hplt = h; if (info->shared && ! bfd_elf_link_record_dynamic_symbol (info, h)) diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 134b960..ec407fd 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -2365,9 +2365,6 @@ struct ppc_elf_link_hash_table /* The .got.plt section (VxWorks only)*/ asection *sgotplt; - /* Short-cuts to frequently used symbols on VxWorks targets. */ - struct elf_link_hash_entry *hplt; - /* True if the target system is VxWorks. */ int is_vxworks; @@ -4762,21 +4759,17 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (htab->is_vxworks) { - /* Save the PLT symbol in the hash table for easy access. - Mark GOT and PLT syms as having relocations; they might not, - but we won't know for sure until we build the GOT in + /* Mark the GOT and PLT symbols as having relocations; they might + not, but we won't know for sure until we build the GOT in finish_dynamic_symbol. */ - if (htab->elf.hgot) htab->elf.hgot->indx = -2; - htab->hplt = elf_link_hash_lookup (elf_hash_table (info), - "_PROCEDURE_LINKAGE_TABLE_", - FALSE, FALSE, FALSE); - if (htab->hplt) - htab->hplt->indx = -2; - /* If the PLT is executable then give the symbol function type. */ - if (htab->hplt && htab->plt->flags & SEC_CODE) - htab->hplt->type = STT_FUNC; + if (htab->elf.hplt) + { + htab->elf.hplt->indx = -2; + if (htab->plt->flags & SEC_CODE) + htab->elf.hplt->type = STT_FUNC; + } } /* Allocate space for global sym dynamic relocs. */ @@ -4867,7 +4860,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* We'd like to strip these sections if they aren't needed, but if we've exported dynamic symbols from them we must leave them. It's too late to tell BFD to get rid of the symbols. */ - if ((s == htab->plt || s == htab->got) && htab->hplt != NULL) + if ((s == htab->plt || s == htab->got) && htab->elf.hplt != NULL) strip_section = FALSE; /* Strip this section if we don't need it; see the comment below. */ @@ -6880,7 +6873,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd, rela.r_offset = (htab->sgotplt->output_section->vma + htab->sgotplt->output_offset + got_offset); - rela.r_info = ELF32_R_INFO (htab->hplt->indx, + rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); rela.r_addend = ent->plt.offset + 16; bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); @@ -7248,7 +7241,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd, loc += sizeof (Elf32_External_Rela); bfd_elf32_swap_reloc_in (output_bfd, loc, &rel); - rel.r_info = ELF32_R_INFO (htab->hplt->indx, R_PPC_ADDR32); + rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32); bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); loc += sizeof (Elf32_External_Rela); } diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index fbd0470..25077cc 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -3726,6 +3726,7 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) h = (struct elf_link_hash_entry *) bh; h->def_regular = 1; h->type = STT_OBJECT; + htab->root.hplt = h; if (info->shared && ! bfd_elf_link_record_dynamic_symbol (info, h)) diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 0472d7f..b6cbf23 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -1244,8 +1244,10 @@ elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. */ - if (!_bfd_elf_define_linkage_sym (abfd, info, s, - "_PROCEDURE_LINKAGE_TABLE_")) + h = _bfd_elf_define_linkage_sym (abfd, info, s, + "_PROCEDURE_LINKAGE_TABLE_"); + elf_hash_table (info)->hplt = h; + if (h == NULL) return FALSE; flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index df15723..d915478 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -3240,6 +3240,7 @@ sh64_elf64_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) h = (struct elf_link_hash_entry *) bh; h->def_regular = 1; h->type = STT_OBJECT; + elf_hash_table (info)->hplt = h; if (info->shared && ! bfd_elf_link_record_dynamic_symbol (info, h)) diff --git a/bfd/elflink.c b/bfd/elflink.c index 9a99b06..a95ac44 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -263,6 +263,7 @@ bfd_boolean _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) { flagword flags, pltflags; + struct elf_link_hash_entry *h; asection *s; const struct elf_backend_data *bed = get_elf_backend_data (abfd); @@ -288,10 +289,14 @@ _bfd_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the .plt section. */ - if (bed->want_plt_sym - && !_bfd_elf_define_linkage_sym (abfd, info, s, - "_PROCEDURE_LINKAGE_TABLE_")) - return FALSE; + if (bed->want_plt_sym) + { + h = _bfd_elf_define_linkage_sym (abfd, info, s, + "_PROCEDURE_LINKAGE_TABLE_"); + elf_hash_table (info)->hplt = h; + if (h == NULL) + return FALSE; + } s = bfd_make_section_with_flags (abfd, (bed->default_use_rela_p -- cgit v1.1