From 947216bf8f343c1440e85633b5bf2f2394f87bc4 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 28 Nov 2002 11:55:43 +0000 Subject: include/elf/ChangeLog * internal.h (elf32_internal_ehdr, Elf32_Internal_Ehdr, elf64_internal_ehdr, Elf64_Internal_Ehdr, elf32_internal_phdr, Elf32_Internal_Phdr, elf64_internal_phdr, Elf64_Internal_Phdr, elf32_internal_shdr, Elf32_Internal_Shdr, elf64_internal_shdr, Elf64_Internal_Shdr, elf32_internal_sym, elf64_internal_sym, Elf32_Internal_Sym, Elf64_Internal_Sym, Elf32_Internal_Note, elf32_internal_note, elf32_internal_rel, Elf32_Internal_Rel, elf64_internal_rel, Elf64_Internal_Rel, elf32_internal_rela, elf64_internal_rela, Elf32_Internal_Rela, Elf64_Internal_Rela, elf32_internal_dyn, elf64_internal_dyn, Elf32_Internal_Dyn, Elf64_Internal_Dyn, elf32_internal_verdef, elf64_internal_verdef, elf32_internal_verdaux, elf64_internal_verdaux, elf32_internal_verneed, elf64_internal_verneed, elf32_internal_vernaux, elf64_internal_vernaux, elf32_internal_versym, elf64_internal_versym, Elf32_Internal_Verdef, Elf64_Internal_Verdef, Elf32_Internal_Verdaux, Elf64_Internal_Verdaux, Elf32_Internal_Verneed, Elf64_Internal_Verneed, Elf32_Internal_Vernaux, Elf64_Internal_Vernaux, Elf32_Internal_Versym, Elf64_Internal_Versym, Elf32_Internal_Syminfo, Elf64_Internal_Syminfo): Delete. (Elf_Internal_Rel): Delete. bfd/ChangeLog * elf-bfd.h: Replace occurrences of Elf32_Internal_* and Elf64_Internal_* with Elf_Internal_*. Replace Elf_Internal_Rel with Elf_Internal_Rela. * elf-hppa.h, elf-m10200.c, elf-m10300.c, elf32-arc.c, elf32-arm.h, elf32-avr.c, elf32-cris.c, elf32-d10v.c, elf32-d30v.c, elf32-dlx.c, elf32-fr30.c, elf32-frv.c, elf32-gen.c, elf32-h8300.c, elf32-hppa.c, elf32-i370.c, elf32-i386.c, elf32-i860.c, elf32-i960.c, elf32-ip2k.c, elf32-m32r.c, elf32-m68hc11.c, elf32-m68hc12.c, elf32-m68k.c, elf32-mcore.c, elf32-mips.c, elf32-openrisc.c, elf32-or32.c, elf32-ppc.c, elf32-s390.c, elf32-sh.c, elf32-v850.c, elf32-vax.c, elf32-xstormy16.c, elf64-alpha.c, elf64-gen.c, elf64-hppa.c, elf64-mips.c, elf64-mmix.c, elf64-ppc.c, elf64-s390.c, elf64-sh64.c, elf64-sparc.c, elf64-x86-64.c, elfarm-nabi.c, elfarm-oabi.c, elfcode.h, elflink.h, elfn32-mips.c, elfxx-ia64.c, elfxx-mips.c: Ditto. * elf-hppa.h (elf_hppa_internal_shdr): Delete. Use Elf_Internal_Shdr throughout instead. * elf.c (_bfd_elf_no_info_to_howto_rel): Delete. * elfcode.h (elf_swap_reloca_in): Pass source operand as a bfd_byte *. Remove INLINE keyword. (elf_swap_reloc_in): Likewise. Also clear r_addend. (elf_swap_reloc_out, elf_swap_reloca_out): Pass destination operand as a bfd_byte *. (elf_write_relocs): Consolidate REL and RELA code. (elf_slurp_reloc_table_from_section): Simplify REL code. (NAME(_bfd_elf,size_info)): Populate reloc swap entries. * elf-bfd.h (MAX_INT_RELS_PER_EXT_REL): Define. * elflink.h (elf_link_read_relocs_from_section): Consolidate REL and RELA code. (elf_link_adjust_relocs): Likewise. Don't malloc space for temp reloc array, use a fixed size of MAX_INT_RELS_PER_EXT_REL. (elf_link_output_relocs): Likewise. (elf_reloc_link_order): Likewise. (elf_finish_pointer_linker_section): Likewise. (struct elf_link_sort_rela): Remove union. (elf_link_sort_cmp1): Update to suit. (elf_link_sort_cmp2): Here too. (elf_link_sort_relocs): Consolidate REL and RELA code. Fix memory over-allocation for int_rels_per_ext_rel != 1 case. * elf32-arm.h: Update all bfd_elf32_swap_reloc_out calls. * elf32-i386.c: Likewise. * elf32-cris.c: Likewise for bfd_elf32_swap_reloca_out. * elf32-hppa.c, elf32-i370.c, elf32-m68k.c, elf32-ppc.c, elf32-s390.c, elf32-sh.c, elf32-vax.c, elfxx-mips.c: Likewise. * elf64-alpha.c: Likewise for bfd_elf64_swap_reloca_out. * elf64-hppa.c, elf64-mips.c, elf64-ppc.c, elf64-s390.c, elf64-sh64.c, elf64-sparc.c, elf64-x86-64.c: Likewise. * elfxx-ia64.c: Likewise for bfd_elfNN_swap_reloca_out. * elfxx-mips.c (sort_dynamic_relocs): Likewise for bfd_elf32_swap_reloc_in. * elf32-arm.h: Update elf32_arm_info_to_howto calls. * elf32-mips.c: Likewise for mips_info_to_howto_rel. (mips_elf64_swap_reloc_in): Zero r_addend. (mips_elf64_be_swap_reloc_in): Likewise. (mips_elf64_slurp_one_reloc_table): Simplify. * elf64-alpha.c (alpha_elf_size_info): Populate reloc swap entries. * elf64-hppa.c (hppa64_elf_size_info): Likewise. * elf64-sparc.c (sparc64_elf_size_info): Likewise. --- bfd/elfcode.h | 209 ++++++++++++++++++++++------------------------------------ 1 file changed, 78 insertions(+), 131 deletions(-) (limited to 'bfd/elfcode.h') diff --git a/bfd/elfcode.h b/bfd/elfcode.h index f523972..c1ef912 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -421,44 +421,49 @@ elf_swap_phdr_out (abfd, src, dst) } /* Translate an ELF reloc from external format to internal format. */ -INLINE void -elf_swap_reloc_in (abfd, src, dst) +void +elf_swap_reloc_in (abfd, s, dst) bfd *abfd; - const Elf_External_Rel *src; - Elf_Internal_Rel *dst; + const bfd_byte *s; + Elf_Internal_Rela *dst; { + const Elf_External_Rel *src = (const Elf_External_Rel *) s; dst->r_offset = H_GET_WORD (abfd, src->r_offset); dst->r_info = H_GET_WORD (abfd, src->r_info); + dst->r_addend = 0; } -INLINE void -elf_swap_reloca_in (abfd, src, dst) +void +elf_swap_reloca_in (abfd, s, dst) bfd *abfd; - const Elf_External_Rela *src; + const bfd_byte *s; Elf_Internal_Rela *dst; { + const Elf_External_Rela *src = (const Elf_External_Rela *) s; dst->r_offset = H_GET_WORD (abfd, src->r_offset); dst->r_info = H_GET_WORD (abfd, src->r_info); dst->r_addend = H_GET_SIGNED_WORD (abfd, src->r_addend); } /* Translate an ELF reloc from internal format to external format. */ -INLINE void -elf_swap_reloc_out (abfd, src, dst) +void +elf_swap_reloc_out (abfd, src, d) bfd *abfd; - const Elf_Internal_Rel *src; - Elf_External_Rel *dst; + const Elf_Internal_Rela *src; + bfd_byte *d; { + Elf_External_Rel *dst = (Elf_External_Rel *) d; H_PUT_WORD (abfd, src->r_offset, dst->r_offset); H_PUT_WORD (abfd, src->r_info, dst->r_info); } -INLINE void -elf_swap_reloca_out (abfd, src, dst) +void +elf_swap_reloca_out (abfd, src, d) bfd *abfd; const Elf_Internal_Rela *src; - Elf_External_Rela *dst; + bfd_byte *d; { + Elf_External_Rela *dst = (Elf_External_Rela *) d; H_PUT_WORD (abfd, src->r_offset, dst->r_offset); H_PUT_WORD (abfd, src->r_info, dst->r_info); H_PUT_SIGNED_WORD (abfd, src->r_addend, dst->r_addend); @@ -858,12 +863,13 @@ elf_write_relocs (abfd, sec, data) { boolean *failedp = (boolean *) data; Elf_Internal_Shdr *rela_hdr; - Elf_External_Rela *outbound_relocas; - Elf_External_Rel *outbound_relocs; + bfd_vma addr_offset; + void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *)); + size_t extsize; + bfd_byte *dst_rela; unsigned int idx; - int use_rela_p; - asymbol *last_sym = 0; - int last_sym_idx = 0; + asymbol *last_sym; + int last_sym_idx; /* If we have already failed, don't do anything. */ if (*failedp) @@ -891,122 +897,69 @@ elf_write_relocs (abfd, sec, data) /* Figure out whether the relocations are RELA or REL relocations. */ if (rela_hdr->sh_type == SHT_RELA) - use_rela_p = true; + { + swap_out = elf_swap_reloca_out; + extsize = sizeof (Elf_External_Rela); + } else if (rela_hdr->sh_type == SHT_REL) - use_rela_p = false; + { + swap_out = elf_swap_reloc_out; + extsize = sizeof (Elf_External_Rel); + } else /* Every relocation section should be either an SHT_RELA or an SHT_REL section. */ abort (); + /* The address of an ELF reloc is section relative for an object + file, and absolute for an executable file or shared library. + The address of a BFD reloc is always section relative. */ + addr_offset = 0; + if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) + addr_offset = sec->vma; + /* orelocation has the data, reloc_count has the count... */ - if (use_rela_p) - { - outbound_relocas = (Elf_External_Rela *) rela_hdr->contents; + last_sym = 0; + last_sym_idx = 0; + dst_rela = rela_hdr->contents; - for (idx = 0; idx < sec->reloc_count; idx++) + for (idx = 0; idx < sec->reloc_count; idx++, dst_rela += extsize) + { + Elf_Internal_Rela src_rela; + arelent *ptr; + asymbol *sym; + int n; + + ptr = sec->orelocation[idx]; + sym = *ptr->sym_ptr_ptr; + if (sym == last_sym) + n = last_sym_idx; + else if (bfd_is_abs_section (sym->section) && sym->value == 0) + n = STN_UNDEF; + else { - Elf_Internal_Rela dst_rela; - Elf_External_Rela *src_rela; - arelent *ptr; - asymbol *sym; - int n; - - ptr = sec->orelocation[idx]; - src_rela = outbound_relocas + idx; - - /* The address of an ELF reloc is section relative for an object - file, and absolute for an executable file or shared library. - The address of a BFD reloc is always section relative. */ - if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) - dst_rela.r_offset = ptr->address; - else - dst_rela.r_offset = ptr->address + sec->vma; - - sym = *ptr->sym_ptr_ptr; - if (sym == last_sym) - n = last_sym_idx; - else if (bfd_is_abs_section (sym->section) && sym->value == 0) - n = STN_UNDEF; - else - { - last_sym = sym; - n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); - if (n < 0) - { - *failedp = true; - return; - } - last_sym_idx = n; - } - - if ((*ptr->sym_ptr_ptr)->the_bfd != NULL - && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec - && ! _bfd_elf_validate_reloc (abfd, ptr)) + last_sym = sym; + n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); + if (n < 0) { *failedp = true; return; } - - dst_rela.r_info = ELF_R_INFO (n, ptr->howto->type); - - dst_rela.r_addend = ptr->addend; - elf_swap_reloca_out (abfd, &dst_rela, src_rela); + last_sym_idx = n; } - } - else - /* REL relocations */ - { - outbound_relocs = (Elf_External_Rel *) rela_hdr->contents; - for (idx = 0; idx < sec->reloc_count; idx++) + if ((*ptr->sym_ptr_ptr)->the_bfd != NULL + && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec + && ! _bfd_elf_validate_reloc (abfd, ptr)) { - Elf_Internal_Rel dst_rel; - Elf_External_Rel *src_rel; - arelent *ptr; - int n; - asymbol *sym; - - ptr = sec->orelocation[idx]; - sym = *ptr->sym_ptr_ptr; - src_rel = outbound_relocs + idx; - - /* The address of an ELF reloc is section relative for an object - file, and absolute for an executable file or shared library. - The address of a BFD reloc is always section relative. */ - if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0) - dst_rel.r_offset = ptr->address; - else - dst_rel.r_offset = ptr->address + sec->vma; - - if (sym == last_sym) - n = last_sym_idx; - else if (bfd_is_abs_section (sym->section) && sym->value == 0) - n = STN_UNDEF; - else - { - last_sym = sym; - n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym); - if (n < 0) - { - *failedp = true; - return; - } - last_sym_idx = n; - } - - if ((*ptr->sym_ptr_ptr)->the_bfd != NULL - && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec - && ! _bfd_elf_validate_reloc (abfd, ptr)) - { - *failedp = true; - return; - } - - dst_rel.r_info = ELF_R_INFO (n, ptr->howto->type); - - elf_swap_reloc_out (abfd, &dst_rel, src_rel); + *failedp = true; + return; } + + src_rela.r_offset = ptr->address + addr_offset; + src_rela.r_info = ELF_R_INFO (n, ptr->howto->type); + src_rela.r_addend = ptr->addend; + (*swap_out) (abfd, &src_rela, dst_rela); } } @@ -1372,17 +1325,11 @@ elf_slurp_reloc_table_from_section (abfd, asect, rel_hdr, reloc_count, i++, relent++, native_relocs += entsize) { Elf_Internal_Rela rela; - Elf_Internal_Rel rel; if (entsize == sizeof (Elf_External_Rela)) - elf_swap_reloca_in (abfd, (Elf_External_Rela *) native_relocs, &rela); + elf_swap_reloca_in (abfd, native_relocs, &rela); else - { - elf_swap_reloc_in (abfd, (Elf_External_Rel *) native_relocs, &rel); - rela.r_offset = rel.r_offset; - rela.r_info = rel.r_info; - rela.r_addend = 0; - } + elf_swap_reloc_in (abfd, native_relocs, &rela); /* The address of an ELF reloc is section relative for an object file, and absolute for an executable file or shared library. @@ -1421,7 +1368,7 @@ elf_slurp_reloc_table_from_section (abfd, asect, rel_hdr, reloc_count, if (entsize == sizeof (Elf_External_Rela)) (*ebd->elf_info_to_howto) (abfd, relent, &rela); else - (*ebd->elf_info_to_howto_rel) (abfd, relent, &rel); + (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela); } if (allocated != NULL) @@ -1649,8 +1596,8 @@ const struct elf_size_info NAME(_bfd_elf,size_info) = { elf_slurp_symbol_table, elf_swap_dyn_in, elf_swap_dyn_out, - NULL, - NULL, - NULL, - NULL + elf_swap_reloc_in, + elf_swap_reloc_out, + elf_swap_reloca_in, + elf_swap_reloca_out }; -- cgit v1.1