From cb33740c88ad5fd9e07f243332c511275c15219f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 11 Mar 2008 23:23:23 +0000 Subject: [PATCH] * elf-bfd.h (_bfd_elf_section_from_bfd_section): Update prototype. * elf.c (_bfd_elf_section_from_bfd_section): Return unsigned int, SHN_BAD on error. (_bfd_elf_print_private_bfd_data): Test for SHN_BAD result from _bfd_elf_section_from_bfd_section, not -1. (swap_out_syms): Likewise. * elflink.c (elf_link_add_object_symbols): Likewise. (bfd_elf_get_bfd_needed_list): Likewise. (bfd_elf_match_symbols_in_sections): Likewise. (elf_link_add_object_symbols): Don't bother testing for symbols using normal sections before calling bfd_section_from_elf_index. (elf_link_input_bfd, bfd_elf_final_link): Likewise. (bfd_elf_reloc_symbol_deleted_p): Likewise. * elfcode.h (elf_slurp_symbol_table): Likewise. * elf32-spu.c (get_sym_h): Likewise. * elf32-xtensa.c (get_elf_r_symndx_section): Likewise. * elf64-ppc.c (opd_entry_value, get_sym_h, ppc64_elf_edit_toc): Ditto. * elf64-sh64.c (sh_elf64_get_relocated_section_contents): Likewise. --- bfd/ChangeLog | 21 ++++++++++++ bfd/elf-bfd.h | 2 +- bfd/elf.c | 18 +++++----- bfd/elf32-spu.c | 9 +---- bfd/elf32-xtensa.c | 5 +-- bfd/elf64-ppc.c | 20 ++--------- bfd/elf64-sh64.c | 9 ++--- bfd/elfcode.h | 27 +++++++-------- bfd/elflink.c | 97 +++++++++++++++++++++++------------------------------- 9 files changed, 92 insertions(+), 116 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 936b729..1dca4b7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,24 @@ +2008-03-12 Alan Modra + + * elf-bfd.h (_bfd_elf_section_from_bfd_section): Update prototype. + * elf.c (_bfd_elf_section_from_bfd_section): Return unsigned int, + SHN_BAD on error. + (_bfd_elf_print_private_bfd_data): Test for SHN_BAD result from + _bfd_elf_section_from_bfd_section, not -1. + (swap_out_syms): Likewise. + * elflink.c (elf_link_add_object_symbols): Likewise. + (bfd_elf_get_bfd_needed_list): Likewise. + (bfd_elf_match_symbols_in_sections): Likewise. + (elf_link_add_object_symbols): Don't bother testing for symbols + using normal sections before calling bfd_section_from_elf_index. + (elf_link_input_bfd, bfd_elf_final_link): Likewise. + (bfd_elf_reloc_symbol_deleted_p): Likewise. + * elfcode.h (elf_slurp_symbol_table): Likewise. + * elf32-spu.c (get_sym_h): Likewise. + * elf32-xtensa.c (get_elf_r_symndx_section): Likewise. + * elf64-ppc.c (opd_entry_value, get_sym_h, ppc64_elf_edit_toc): Ditto. + * elf64-sh64.c (sh_elf64_get_relocated_section_contents): Likewise. + 2008-03-11 Alan Modra * elf32-spu.c (spu_elf_relocate_section): Test identical conditions diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 164cbde..b3d1d38 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1636,7 +1636,7 @@ extern void _bfd_elf_swap_versym_in extern void _bfd_elf_swap_versym_out (bfd *, const Elf_Internal_Versym *, Elf_External_Versym *); -extern int _bfd_elf_section_from_bfd_section +extern unsigned int _bfd_elf_section_from_bfd_section (bfd *, asection *); extern char *bfd_elf_string_from_elf_section (bfd *, unsigned, unsigned); diff --git a/bfd/elf.c b/bfd/elf.c index 54375c2..c697e9e 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1180,7 +1180,7 @@ _bfd_elf_print_private_bfd_data (bfd *abfd, void *farg) s = bfd_get_section_by_name (abfd, ".dynamic"); if (s != NULL) { - int elfsec; + unsigned int elfsec; unsigned long shlink; bfd_byte *extdyn, *extdynend; size_t extdynsize; @@ -1192,7 +1192,7 @@ _bfd_elf_print_private_bfd_data (bfd *abfd, void *farg) goto error_return; elfsec = _bfd_elf_section_from_bfd_section (abfd, s); - if (elfsec == -1) + if (elfsec == SHN_BAD) goto error_return; shlink = elf_elfsections (abfd)[elfsec]->sh_link; @@ -4996,11 +4996,11 @@ _bfd_elf_write_corefile_contents (bfd *abfd) /* Given a section, search the header to find them. */ -int +unsigned int _bfd_elf_section_from_bfd_section (bfd *abfd, struct bfd_section *asect) { const struct elf_backend_data *bed; - int index; + unsigned int index; if (elf_section_data (asect) != NULL && elf_section_data (asect)->this_idx != 0) @@ -5013,7 +5013,7 @@ _bfd_elf_section_from_bfd_section (bfd *abfd, struct bfd_section *asect) else if (bfd_is_und_section (asect)) index = SHN_UNDEF; else - index = -1; + index = SHN_BAD; bed = get_elf_backend_data (abfd); if (bed->elf_backend_section_from_bfd_section) @@ -5024,7 +5024,7 @@ _bfd_elf_section_from_bfd_section (bfd *abfd, struct bfd_section *asect) return retval; } - if (index == -1) + if (index == SHN_BAD) bfd_set_error (bfd_error_nonrepresentable_section); return index; @@ -6277,7 +6277,7 @@ swap_out_syms (bfd *abfd, else { asection *sec = syms[idx]->section; - int shndx; + unsigned int shndx; if (sec->output_section) { @@ -6324,7 +6324,7 @@ swap_out_syms (bfd *abfd, { shndx = _bfd_elf_section_from_bfd_section (abfd, sec); - if (shndx == -1) + if (shndx == SHN_BAD) { asection *sec2; @@ -6348,7 +6348,7 @@ Unable to find equivalent output section for symbol '%s' from section '%s'"), } shndx = _bfd_elf_section_from_bfd_section (abfd, sec2); - BFD_ASSERT (shndx != -1); + BFD_ASSERT (shndx != SHN_BAD); } } diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c index 99b1b61..93fe0a4 100644 --- a/bfd/elf32-spu.c +++ b/bfd/elf32-spu.c @@ -409,14 +409,7 @@ get_sym_h (struct elf_link_hash_entry **hp, *symp = sym; if (symsecp != NULL) - { - asection *symsec = NULL; - if ((sym->st_shndx != SHN_UNDEF - && sym->st_shndx < SHN_LORESERVE) - || sym->st_shndx > SHN_HIRESERVE) - symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); - *symsecp = symsec; - } + *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx); } return TRUE; diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index ec6d463..0d744c2 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -9503,15 +9503,12 @@ get_elf_r_symndx_section (bfd *abfd, unsigned long r_symndx) if (section_index == SHN_UNDEF) target_sec = bfd_und_section_ptr; - else if (section_index > 0 && section_index < SHN_LORESERVE) - target_sec = bfd_section_from_elf_index (abfd, section_index); else if (section_index == SHN_ABS) target_sec = bfd_abs_section_ptr; else if (section_index == SHN_COMMON) target_sec = bfd_com_section_ptr; else - /* Who knows? */ - target_sec = NULL; + target_sec = bfd_section_from_elf_index (abfd, section_index); } else { diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index a196824..8aabad7 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -5026,11 +5026,7 @@ opd_entry_value (asection *opd_sec, sym += symndx; val = sym->st_value; - sec = NULL; - if ((sym->st_shndx != SHN_UNDEF - && sym->st_shndx < SHN_LORESERVE) - || sym->st_shndx > SHN_HIRESERVE) - sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx); + sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx); BFD_ASSERT ((sec->flags & SEC_MERGE) == 0); } else @@ -6060,14 +6056,7 @@ get_sym_h (struct elf_link_hash_entry **hp, *symp = sym; if (symsecp != NULL) - { - asection *symsec = NULL; - if ((sym->st_shndx != SHN_UNDEF - && sym->st_shndx < SHN_LORESERVE) - || sym->st_shndx > SHN_HIRESERVE) - symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx); - *symsecp = symsec; - } + *symsecp = bfd_section_from_elf_index (ibfd, sym->st_shndx); if (tls_maskp != NULL) { @@ -7577,10 +7566,7 @@ ppc64_elf_edit_toc (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) for (sym = local_syms; sym < local_syms + symtab_hdr->sh_info; ++sym) - if (sym->st_shndx != SHN_UNDEF - && (sym->st_shndx < SHN_LORESERVE - || sym->st_shndx > SHN_HIRESERVE) - && sym->st_value != 0 + if (sym->st_value != 0 && bfd_section_from_elf_index (ibfd, sym->st_shndx) == toc) { if (skip[sym->st_value >> 3] != (unsigned long) -1) diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index fb5e8c9..a390025 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -1,5 +1,5 @@ /* SuperH SH64-specific support for 64-bit ELF - Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -2195,17 +2195,12 @@ sh_elf64_get_relocated_section_contents (bfd *output_bfd, if (isymp->st_shndx == SHN_UNDEF) isec = bfd_und_section_ptr; - else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE) - isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); else if (isymp->st_shndx == SHN_ABS) isec = bfd_abs_section_ptr; else if (isymp->st_shndx == SHN_COMMON) isec = bfd_com_section_ptr; else - { - /* Who knows? */ - isec = NULL; - } + isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx); *secpp = isec; } diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 969c25a..bbbffe1 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1,6 +1,6 @@ /* ELF executable support for BFD. Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003, 2004, 2005, 2006, 2007 + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support, from information published @@ -1270,19 +1270,6 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) { sym->symbol.section = bfd_und_section_ptr; } - else if (isym->st_shndx < SHN_LORESERVE - || isym->st_shndx > SHN_HIRESERVE) - { - sym->symbol.section = bfd_section_from_elf_index (abfd, - isym->st_shndx); - if (sym->symbol.section == NULL) - { - /* This symbol is in a section for which we did not - create a BFD section. Just use bfd_abs_section, - although it is wrong. FIXME. */ - sym->symbol.section = bfd_abs_section_ptr; - } - } else if (isym->st_shndx == SHN_ABS) { sym->symbol.section = bfd_abs_section_ptr; @@ -1297,7 +1284,17 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) sym->symbol.value = isym->st_size; } else - sym->symbol.section = bfd_abs_section_ptr; + { + sym->symbol.section + = bfd_section_from_elf_index (abfd, isym->st_shndx); + if (sym->symbol.section == NULL) + { + /* This symbol is in a section for which we did not + create a BFD section. Just use bfd_abs_section, + although it is wrong. FIXME. */ + sym->symbol.section = bfd_abs_section_ptr; + } + } /* If this is a relocatable file, then the symbol value is already section relative. */ diff --git a/bfd/elflink.c b/bfd/elflink.c index 5139799..ed99a5d 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -3472,14 +3472,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) { bfd_byte *dynbuf; bfd_byte *extdyn; - int elfsec; + unsigned int elfsec; unsigned long shlink; if (!bfd_malloc_and_get_section (abfd, s, &dynbuf)) goto error_free_dyn; elfsec = _bfd_elf_section_from_bfd_section (abfd, s); - if (elfsec == -1) + if (elfsec == SHN_BAD) goto error_free_dyn; shlink = elf_elfsections (abfd)[elfsec]->sh_link; @@ -3820,8 +3820,16 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) if (isym->st_shndx == SHN_UNDEF) sec = bfd_und_section_ptr; - else if (isym->st_shndx < SHN_LORESERVE - || isym->st_shndx > SHN_HIRESERVE) + else if (isym->st_shndx == SHN_ABS) + sec = bfd_abs_section_ptr; + else if (isym->st_shndx == SHN_COMMON) + { + sec = bfd_com_section_ptr; + /* What ELF calls the size we call the value. What ELF + calls the value we call the alignment. */ + value = isym->st_size; + } + else { sec = bfd_section_from_elf_index (abfd, isym->st_shndx); if (sec == NULL) @@ -3836,19 +3844,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) else if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) value -= sec->vma; } - else if (isym->st_shndx == SHN_ABS) - sec = bfd_abs_section_ptr; - else if (isym->st_shndx == SHN_COMMON) - { - sec = bfd_com_section_ptr; - /* What ELF calls the size we call the value. What ELF - calls the value we call the alignment. */ - value = isym->st_size; - } - else - { - /* Leave it up to the processor backend. */ - } name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, isym->st_name); @@ -6750,7 +6745,7 @@ bfd_elf_get_bfd_needed_list (bfd *abfd, { asection *s; bfd_byte *dynbuf = NULL; - int elfsec; + unsigned int elfsec; unsigned long shlink; bfd_byte *extdyn, *extdynend; size_t extdynsize; @@ -6770,7 +6765,7 @@ bfd_elf_get_bfd_needed_list (bfd *abfd, goto error_return; elfsec = _bfd_elf_section_from_bfd_section (abfd, s); - if (elfsec == -1) + if (elfsec == SHN_BAD) goto error_return; shlink = elf_elfsections (abfd)[elfsec]->sh_link; @@ -6942,7 +6937,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, Elf_Internal_Sym *isym, *isymend; struct elf_symbol *symtable1 = NULL, *symtable2 = NULL; bfd_size_type count1, count2, i; - int shndx1, shndx2; + unsigned int shndx1, shndx2; bfd_boolean result; bfd1 = sec1->owner; @@ -6958,7 +6953,7 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, shndx1 = _bfd_elf_section_from_bfd_section (bfd1, sec1); shndx2 = _bfd_elf_section_from_bfd_section (bfd2, sec2); - if (shndx1 == -1 || shndx2 == -1) + if (shndx1 == SHN_BAD || shndx2 == SHN_BAD) return FALSE; bed1 = get_elf_backend_data (bfd1); @@ -7015,9 +7010,9 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, while (lo < hi) { mid = (lo + hi) / 2; - if ((unsigned int) shndx1 < ssymbuf1[mid].st_shndx) + if (shndx1 < ssymbuf1[mid].st_shndx) hi = mid; - else if ((unsigned int) shndx1 > ssymbuf1[mid].st_shndx) + else if (shndx1 > ssymbuf1[mid].st_shndx) lo = mid + 1; else { @@ -7034,9 +7029,9 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, while (lo < hi) { mid = (lo + hi) / 2; - if ((unsigned int) shndx2 < ssymbuf2[mid].st_shndx) + if (shndx2 < ssymbuf2[mid].st_shndx) hi = mid; - else if ((unsigned int) shndx2 > ssymbuf2[mid].st_shndx) + else if (shndx2 > ssymbuf2[mid].st_shndx) lo = mid + 1; else { @@ -7099,12 +7094,12 @@ bfd_elf_match_symbols_in_sections (asection *sec1, asection *sec2, /* Count definitions in the section. */ count1 = 0; for (isym = isymbuf1, isymend = isym + symcount1; isym < isymend; isym++) - if (isym->st_shndx == (unsigned int) shndx1) + if (isym->st_shndx == shndx1) symtable1[count1++].u.isym = isym; count2 = 0; for (isym = isymbuf2, isymend = isym + symcount2; isym < isymend; isym++) - if (isym->st_shndx == (unsigned int) shndx2) + if (isym->st_shndx == shndx2) symtable2[count2++].u.isym = isym; if (count1 == 0 || count2 == 0 || count1 != count2) @@ -8904,28 +8899,26 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) if (isym->st_shndx == SHN_UNDEF) isec = bfd_und_section_ptr; - else if (isym->st_shndx < SHN_LORESERVE - || isym->st_shndx > SHN_HIRESERVE) - { - isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); - if (isec - && isec->sec_info_type == ELF_INFO_TYPE_MERGE - && ELF_ST_TYPE (isym->st_info) != STT_SECTION) - isym->st_value = - _bfd_merged_section_offset (output_bfd, &isec, - elf_section_data (isec)->sec_info, - isym->st_value); - } else if (isym->st_shndx == SHN_ABS) isec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) isec = bfd_com_section_ptr; else { - /* Don't attempt to output symbols with st_shnx in the - reserved range other than SHN_ABS and SHN_COMMON. */ - *ppsection = NULL; - continue; + isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); + if (isec == NULL) + { + /* Don't attempt to output symbols with st_shnx in the + reserved range other than SHN_ABS and SHN_COMMON. */ + *ppsection = NULL; + continue; + } + else if (isec->sec_info_type == ELF_INFO_TYPE_MERGE + && ELF_ST_TYPE (isym->st_info) != STT_SECTION) + isym->st_value = + _bfd_merged_section_offset (output_bfd, &isec, + elf_section_data (isec)->sec_info, + isym->st_value); } *ppsection = isec; @@ -10491,13 +10484,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) the original st_name with the dynstr_index. */ sym = e->isym; - if (e->isym.st_shndx != SHN_UNDEF - && (e->isym.st_shndx < SHN_LORESERVE - || e->isym.st_shndx > SHN_HIRESERVE)) + s = bfd_section_from_elf_index (e->input_bfd, + e->isym.st_shndx); + if (s != NULL) { - s = bfd_section_from_elf_index (e->input_bfd, - e->isym.st_shndx); - sym.st_shndx = elf_section_data (s->output_section)->this_idx; if (! check_dynsym (abfd, &sym)) @@ -11864,12 +11854,9 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie) /* Need to: get the symbol; get the section. */ isym = &rcookie->locsyms[r_symndx]; - if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE) - { - isec = bfd_section_from_elf_index (rcookie->abfd, isym->st_shndx); - if (isec != NULL && elf_discarded_section (isec)) - return TRUE; - } + isec = bfd_section_from_elf_index (rcookie->abfd, isym->st_shndx); + if (isec != NULL && elf_discarded_section (isec)) + return TRUE; } return FALSE; } -- 2.7.4