diff --git a/bfd/ChangeLog b/bfd/ChangeLog index fbadc555827..a067412ce86 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,19 @@ +2001-05-23 Nick Clifton + + * elf-bfd.h (NUM_SHDR_ENTRIES): New macro: compute the number + of entries in a structured section. + * elf.c: Use new macro. + * elf32-i386.c: Use new macro. + * elf32-mips.c: Use new macro. + * elf64-alpha.c: Use new macro. + * elf64-sparc.c: Use new macro. + * elfcode.h: Use new macro. + * elflink.h: Use new macro. + +2001-05-23 Nick Clifton + + * bfdint.texi: Replace -oformat with --oformat. + 2001-05-21 Andreas Jaeger * dwarf2.c (decode_line_info): Fix error message. diff --git a/bfd/doc/bfdint.texi b/bfd/doc/bfdint.texi index 1b08c6f77a8..5aa8ed376f8 100644 --- a/bfd/doc/bfdint.texi +++ b/bfd/doc/bfdint.texi @@ -296,7 +296,7 @@ The target vector starts with a set of constants. @item name The name of the target vector. This is an arbitrary string. This is how the target vector is named in command line options for tools which -use BFD, such as the @samp{-oformat} linker option. +use BFD, such as the @samp{--oformat} linker option. @item flavour A general description of the type of target. The following flavours are diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index fd3f347aef4..f5b74e93dc9 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -27,6 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "elf/external.h" #include "bfdlink.h" +/* The number of entries in a section is its size divided by the size + of a single entry. This is normally only applicaable to reloc and + symbol table sections. */ +#define NUM_SHDR_ENTRIES(shdr) ((shdr)->sh_size / (shdr)->sh_entsize) + /* If size isn't specified as 64 or 32, NAME macro should fail. */ #ifndef NAME #if ARCH_SIZE==64 diff --git a/bfd/elf.c b/bfd/elf.c index e424ce8d10e..fc31cdc8e1f 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1449,7 +1449,7 @@ bfd_section_from_shdr (abfd, shindex) } *hdr2 = *hdr; elf_elfsections (abfd)[shindex] = hdr2; - target_sect->reloc_count += hdr->sh_size / hdr->sh_entsize; + target_sect->reloc_count += NUM_SHDR_ENTRIES (hdr); target_sect->flags |= SEC_RELOC; target_sect->relocation = NULL; target_sect->rel_filepos = hdr->sh_offset; diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index f4e1e500c32..f43adcd85eb 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -501,7 +501,7 @@ elf_i386_check_relocs (abfd, info, sec, relocs) r_symndx = ELF32_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_size / symtab_hdr->sh_entsize) + if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) { if (abfd->my_archive) (*_bfd_error_handler) (_("%s(%s): bad symbol index: %d"), diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index c2dd84785a2..70e9dc9e4df 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -3071,7 +3071,7 @@ _bfd_mips_elf_fake_sections (abfd, hdr, sec) boolean _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval) - bfd *abfd; + bfd *abfd ATTRIBUTE_UNUSED; Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED; asection *sec; int *retval; @@ -6822,8 +6822,7 @@ _bfd_mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, REL_HDR is read before its REL_HDR2. */ rel_hdr = &elf_section_data (input_section)->rel_hdr; if ((size_t) (rel - relocs) - >= (rel_hdr->sh_size / rel_hdr->sh_entsize - * bed->s->int_rels_per_ext_rel)) + >= (NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel)) rel_hdr = elf_section_data (input_section)->rel_hdr2; if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd)) { @@ -7592,7 +7591,7 @@ _bfd_mips_elf_check_relocs (abfd, info, sec, relocs) asection **n; if (elf_bad_symtab (abfd)) - symcount = symtab_hdr->sh_size / symtab_hdr->sh_entsize; + symcount = NUM_SHDR_ENTRIES (symtab_hdr); else symcount = symtab_hdr->sh_info; n = (asection **) bfd_zalloc (abfd, @@ -7707,7 +7706,7 @@ _bfd_mips_elf_check_relocs (abfd, info, sec, relocs) if (r_symndx < extsymoff) h = NULL; - else if (r_symndx >= extsymoff + (symtab_hdr->sh_size / symtab_hdr->sh_entsize)) + else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr)) { (*_bfd_error_handler) (_("Malformed reloc detected for section %s"), name); diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c index 06891d3e0e5..bd89a7b8053 100644 --- a/bfd/elf64-alpha.c +++ b/bfd/elf64-alpha.c @@ -2831,7 +2831,7 @@ elf64_alpha_can_merge_gots (a, b) Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr; int i, n; - n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info; + n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; for (i = 0; i < n; ++i) { struct alpha_elf_got_entry *ae, *be; @@ -2903,7 +2903,7 @@ elf64_alpha_merge_gots (a, b) hashes = alpha_elf_sym_hashes (bsub); symtab_hdr = &elf_tdata (bsub)->symtab_hdr; - n = symtab_hdr->sh_size / symtab_hdr->sh_entsize - symtab_hdr->sh_info; + n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; for (i = 0; i < n; ++i) { struct alpha_elf_got_entry *ae, *be, **pbe, **start; diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c index dc393b30295..295bd2f5439 100644 --- a/bfd/elf64-sparc.c +++ b/bfd/elf64-sparc.c @@ -396,7 +396,7 @@ sparc64_elf_slurp_reloc_table (abfd, asect, symbols, dynamic) return true; rel_hdr = &d->this_hdr; - asect->reloc_count = rel_hdr->sh_size / rel_hdr->sh_entsize; + asect->reloc_count = NUM_SHDR_ENTRIES (rel_hdr); rel_hdr2 = NULL; } @@ -996,8 +996,7 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs) srelgot = NULL; sreloc = NULL; - rel_end = relocs + elf_section_data (sec)->rel_hdr.sh_size - / elf_section_data (sec)->rel_hdr.sh_entsize; + rel_end = relocs + NUM_SHDR_ENTRIES (& elf_section_data (sec)->rel_hdr); for (rel = relocs; rel < rel_end; rel++) { unsigned long r_symndx; @@ -1903,8 +1902,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section, sgot = splt = sreloc = NULL; rel = relocs; - relend = relocs + elf_section_data (input_section)->rel_hdr.sh_size - / elf_section_data (input_section)->rel_hdr.sh_entsize; + relend = relocs + NUM_SHDR_ENTIRES (& elf_section_data (input_section)->rel_hdr); for (; rel < relend; rel++) { int r_type; diff --git a/bfd/elfcode.h b/bfd/elfcode.h index c5e9821b899..d9f3e059dcb 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1373,11 +1373,9 @@ elf_slurp_reloc_table (abfd, asect, symbols, dynamic) return true; rel_hdr = &d->rel_hdr; - reloc_count = rel_hdr->sh_size / rel_hdr->sh_entsize; + reloc_count = NUM_SHDR_ENTRIES (rel_hdr); rel_hdr2 = d->rel_hdr2; - reloc_count2 = (rel_hdr2 - ? (rel_hdr2->sh_size / rel_hdr2->sh_entsize) - : 0); + reloc_count2 = (rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0); BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2); BFD_ASSERT (asect->rel_filepos == rel_hdr->sh_offset @@ -1394,7 +1392,7 @@ elf_slurp_reloc_table (abfd, asect, symbols, dynamic) return true; rel_hdr = &d->this_hdr; - reloc_count = rel_hdr->sh_size / rel_hdr->sh_entsize; + reloc_count = NUM_SHDR_ENTRIES (rel_hdr); rel_hdr2 = NULL; reloc_count2 = 0; } diff --git a/bfd/elflink.h b/bfd/elflink.h index c43f1125452..0f5c7125203 100644 --- a/bfd/elflink.h +++ b/bfd/elflink.h @@ -2465,7 +2465,7 @@ elf_link_read_relocs_from_section (abfd, shdr, external_relocs, Elf_Internal_Rel *irel; erel = (Elf_External_Rel *) external_relocs; - erelend = erel + shdr->sh_size / shdr->sh_entsize; + erelend = erel + NUM_SHDR_ENTRIES (shdr); irela = internal_relocs; irel = bfd_alloc (abfd, (bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rel))); @@ -2495,7 +2495,7 @@ elf_link_read_relocs_from_section (abfd, shdr, external_relocs, BFD_ASSERT (shdr->sh_entsize == sizeof (Elf_External_Rela)); erela = (Elf_External_Rela *) external_relocs; - erelaend = erela + shdr->sh_size / shdr->sh_entsize; + erelaend = erela + NUM_SHDR_ENTRIES (shdr); irela = internal_relocs; for (; erela < erelaend; erela++, irela += bed->s->int_rels_per_ext_rel) { @@ -2575,7 +2575,7 @@ NAME(_bfd_elf,link_read_relocs) (abfd, o, external_relocs, internal_relocs, (abfd, elf_section_data (o)->rel_hdr2, ((bfd_byte *) external_relocs) + rel_hdr->sh_size, - internal_relocs + (rel_hdr->sh_size / rel_hdr->sh_entsize + internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel))) goto error_return; @@ -4413,11 +4413,9 @@ elf_bfd_final_link (abfd, info) rel_count2 = &esdo->rel_count; } - *rel_count += (esdi->rel_hdr.sh_size - / esdi->rel_hdr.sh_entsize); + *rel_count += NUM_SHDR_ENTRIES (& esdi->rel_hdr); if (esdi->rel_hdr2) - *rel_count2 += (esdi->rel_hdr2->sh_size - / esdi->rel_hdr2->sh_entsize); + *rel_count2 += NUM_SHDR_ENTRIES (esdi->rel_hdr2); } } @@ -5442,7 +5440,7 @@ elf_link_output_relocs (output_bfd, input_section, input_rel_hdr, bed = get_elf_backend_data (output_bfd); irela = internal_relocs; - irelaend = irela + input_rel_hdr->sh_size / input_rel_hdr->sh_entsize; + irelaend = irela + NUM_SHDR_ENTRIES (input_rel_hdr); if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel)) { Elf_External_Rel *erel; @@ -5477,7 +5475,7 @@ elf_link_output_relocs (output_bfd, input_section, input_rel_hdr, /* Bump the counter, so that we know where to add the next set of relocations. */ - *rel_countp += input_rel_hdr->sh_size / input_rel_hdr->sh_entsize; + *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr); } /* Link an input file into the linker output file. This function @@ -5939,8 +5937,7 @@ elf_link_input_bfd (finfo, input_bfd) elf_link_output_relocs (output_bfd, o, input_rel_hdr, internal_relocs); - internal_relocs - += input_rel_hdr->sh_size / input_rel_hdr->sh_entsize; + internal_relocs += NUM_SHDR_ENTRIES (input_rel_hdr); input_rel_hdr = elf_section_data (o)->rel_hdr2; if (input_rel_hdr) elf_link_output_relocs (output_bfd, o,