diff options
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 42 | ||||
-rw-r--r-- | bfd/elf-bfd.h | 2 | ||||
-rw-r--r-- | bfd/elf-hppa.h | 4 | ||||
-rw-r--r-- | bfd/elf.c | 82 | ||||
-rw-r--r-- | bfd/elf32-arm.c | 4 | ||||
-rw-r--r-- | bfd/elf32-avr.c | 17 | ||||
-rw-r--r-- | bfd/elf32-hppa.c | 18 | ||||
-rw-r--r-- | bfd/elf32-m68hc1x.c | 9 | ||||
-rw-r--r-- | bfd/elf64-hppa.c | 14 | ||||
-rw-r--r-- | bfd/elfcode.h | 69 | ||||
-rw-r--r-- | bfd/elflink.c | 22 |
11 files changed, 139 insertions, 144 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 1dca4b7..2171dc9 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,47 @@ 2008-03-12 Alan Modra <amodra@bigpond.net.au> + PR 5900 + * elf-bfd.h: Include elf/internal.h after elf/external.h. + * elfcode.h (elf_swap_symbol_in): Map reserved shndx range. + (elf_swap_symbol_out): Adjust SHN_XINDEX test. + (elf_swap_ehdr_out): Mask SHN_LORESERVE and SHN_XINDEX to values + seen in external structs. + (valid_section_index_p): Delete. + (elf_object_p): Don't increment section numbers over reserved range. + Simplify test for valid sh_link, sh_info and e_shstrndx fields. + (elf_write_shdrs_and_ehdr): Mask SHN_LORESERVE and SHN_XINDEX to values + seen in external structs. Don't increment section numbers over + reserved range. + * elf.c (bfd_elf_sym_name): Remove redundant tests on st_shndx. + (bfd_section_from_shdr): Likewise. + (group_signature): Range check before accessing elf_elfsections. + (_bfd_elf_setup_sections): Likewise. + (bfd_section_from_shdr): Likewise. + (bfd_section_from_shdr): Don't increment section number over + reserved sections. + (assign_file_positions_for_non_load_sections): Likewise. + (assign_file_positions_except_relocs): Likewise. + (_bfd_elf_write_object_contents): Likewise. + (assign_section_numbers): Likewise. Adjust for changed SHN_*. + (prep_headers): Delete unused variable. + * elflink.c (bfd_elf_link_record_local_dynamic_symbol): Adjust + for changed SHN_* values. + (check_dynsym, elf_link_input_bfd): Likewise. + (bfd_elf_final_link): Likewise. Don't skip over reserved section + range. + (elf_fixup_link_order): Check that sh_link field is valid. + * elf-hppa.h (elf_hppa_add_symbol_hook): Make "index" unsigned. + * elf32-arm.c (elf32_arm_gc_mark_extra_sections): Range check before + accesssing elf_elfsections. + * elf32-avr.c (elf32_avr_size_stubs): Likewise. + * elf32-hppa.c (elf32_hppa_size_stubs): Likewise. + * elf32-m68hc1x.c (elf32_m68hc11_size_stubs): Likewise. + * elf64-hppa.c (elf64_hppa_check_relocs): Adjust for changed + SHN_* defines. Test for SHN_BAD return from + _bfd_elf_section_from_bfd_section + +2008-03-12 Alan Modra <amodra@bigpond.net.au> + * 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. diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index b3d1d38..8732710 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -24,8 +24,8 @@ #define _LIBELF_H_ 1 #include "elf/common.h" -#include "elf/internal.h" #include "elf/external.h" +#include "elf/internal.h" #include "bfdlink.h" /* The number of entries in a section is its size divided by the size diff --git a/bfd/elf-hppa.h b/bfd/elf-hppa.h index c82264b..d2b5dfd 100644 --- a/bfd/elf-hppa.h +++ b/bfd/elf-hppa.h @@ -1,5 +1,5 @@ /* Common code for PA ELF implementations. - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -1193,7 +1193,7 @@ elf_hppa_add_symbol_hook (bfd *abfd, asection **secp, bfd_vma *valp) { - int index = sym->st_shndx; + unsigned int index = sym->st_shndx; switch (index) { @@ -457,8 +457,7 @@ bfd_elf_sym_name (bfd *abfd, if (iname == 0 && ELF_ST_TYPE (isym->st_info) == STT_SECTION /* Check for a bogus st_shndx to avoid crashing. */ - && isym->st_shndx < elf_numsections (abfd) - && !(isym->st_shndx >= SHN_LORESERVE && isym->st_shndx <= SHN_HIRESERVE)) + && isym->st_shndx < elf_numsections (abfd)) { iname = elf_elfsections (abfd)[isym->st_shndx]->sh_name; shindex = elf_elfheader (abfd)->e_shstrndx; @@ -495,6 +494,8 @@ group_signature (bfd *abfd, Elf_Internal_Shdr *ghdr) /* First we need to ensure the symbol table is available. Make sure that it is a symbol table section. */ + if (ghdr->sh_link >= elf_numsections (abfd)) + return NULL; hdr = elf_elfsections (abfd) [ghdr->sh_link]; if (hdr->sh_type != SHT_SYMTAB || ! bfd_section_from_shdr (abfd, ghdr->sh_link)) @@ -713,8 +714,7 @@ _bfd_elf_setup_sections (bfd *abfd) get the situation where elfsec is 0. */ if (elfsec == 0) { - const struct elf_backend_data *bed - = get_elf_backend_data (abfd); + const struct elf_backend_data *bed = get_elf_backend_data (abfd); if (bed->link_order_error_handler) bed->link_order_error_handler (_("%B: warning: sh_link not set for section `%A'"), @@ -722,14 +722,17 @@ _bfd_elf_setup_sections (bfd *abfd) } else { - asection *link; + asection *link = NULL; - this_hdr = elf_elfsections (abfd)[elfsec]; + if (elfsec < elf_numsections (abfd)) + { + this_hdr = elf_elfsections (abfd)[elfsec]; + link = this_hdr->bfd_section; + } /* PR 1991, 2008: Some strip/objcopy may leave an incorrect value in sh_link. We don't want to proceed. */ - link = this_hdr->bfd_section; if (link == NULL) { (*_bfd_error_handler) @@ -1518,17 +1521,22 @@ _bfd_elf_stringtab_init (void) bfd_boolean bfd_section_from_shdr (bfd *abfd, unsigned int shindex) { - Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[shindex]; - Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd); - const struct elf_backend_data *bed = get_elf_backend_data (abfd); + Elf_Internal_Shdr *hdr; + Elf_Internal_Ehdr *ehdr; + const struct elf_backend_data *bed; const char *name; - name = bfd_elf_string_from_elf_section (abfd, - elf_elfheader (abfd)->e_shstrndx, + if (shindex >= elf_numsections (abfd)) + return FALSE; + + hdr = elf_elfsections (abfd)[shindex]; + ehdr = elf_elfheader (abfd); + name = bfd_elf_string_from_elf_section (abfd, ehdr->e_shstrndx, hdr->sh_name); if (name == NULL) return FALSE; + bed = get_elf_backend_data (abfd); switch (hdr->sh_type) { case SHT_NULL: @@ -1729,8 +1737,7 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex) return FALSE; /* Check for a bogus link to avoid crashing. */ - if ((hdr->sh_link >= SHN_LORESERVE && hdr->sh_link <= SHN_HIRESERVE) - || hdr->sh_link >= num_sec) + if (hdr->sh_link >= num_sec) { ((*_bfd_error_handler) (_("%B: invalid link %lu for reloc section %s (index %u)"), @@ -1784,7 +1791,6 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex) section, an invalid section, or another reloc section. */ if (hdr->sh_link != elf_onesymtab (abfd) || hdr->sh_info == SHN_UNDEF - || (hdr->sh_info >= SHN_LORESERVE && hdr->sh_info <= SHN_HIRESERVE) || hdr->sh_info >= num_sec || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA) @@ -2771,11 +2777,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) abfd->section_count--; } else - { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; - d->this_idx = section_number++; - } + d->this_idx = section_number++; } } } @@ -2785,26 +2787,18 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) d = elf_section_data (sec); if (d->this_hdr.sh_type != SHT_GROUP) - { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; - d->this_idx = section_number++; - } + d->this_idx = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name); if ((sec->flags & SEC_RELOC) == 0) d->rel_idx = 0; else { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; d->rel_idx = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr.sh_name); } if (d->rel_hdr2) { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; d->rel_idx2 = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr2->sh_name); } @@ -2812,22 +2806,16 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) d->rel_idx2 = 0; } - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; t->shstrtab_section = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->shstrtab_hdr.sh_name); elf_elfheader (abfd)->e_shstrndx = t->shstrtab_section; if (bfd_get_symcount (abfd) > 0) { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; t->symtab_section = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name); - if (section_number > SHN_LORESERVE - 2) + if (section_number > ((SHN_LORESERVE - 2) & 0xFFFF)) { - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; t->symtab_shndx_section = section_number++; t->symtab_shndx_hdr.sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), @@ -2835,8 +2823,6 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) if (t->symtab_shndx_hdr.sh_name == (unsigned int) -1) return FALSE; } - if (section_number == SHN_LORESERVE) - section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE; t->strtab_section = section_number++; _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name); } @@ -2846,8 +2832,6 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) elf_numsections (abfd) = section_number; elf_elfheader (abfd)->e_shnum = section_number; - if (section_number > SHN_LORESERVE) - elf_elfheader (abfd)->e_shnum -= SHN_HIRESERVE + 1 - SHN_LORESERVE; /* Set up the list of section header pointers, in agreement with the indices. */ @@ -2868,7 +2852,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) if (bfd_get_symcount (abfd) > 0) { i_shdrp[t->symtab_section] = &t->symtab_hdr; - if (elf_numsections (abfd) > SHN_LORESERVE) + if (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF)) { i_shdrp[t->symtab_shndx_section] = &t->symtab_shndx_hdr; t->symtab_shndx_hdr.sh_link = t->symtab_section; @@ -4560,12 +4544,6 @@ assign_file_positions_for_non_load_sections (bfd *abfd, hdr->sh_offset = -1; else off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); - - if (i == SHN_LORESERVE - 1) - { - i += SHN_HIRESERVE + 1 - SHN_LORESERVE; - hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE; - } } /* Now that we have set the section file positions, we can set up @@ -4762,12 +4740,6 @@ assign_file_positions_except_relocs (bfd *abfd, } else off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE); - - if (i == SHN_LORESERVE - 1) - { - i += SHN_HIRESERVE + 1 - SHN_LORESERVE; - hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE; - } } } else @@ -4813,12 +4785,10 @@ prep_headers (bfd *abfd) { Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */ Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */ - Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */ struct elf_strtab_hash *shstrtab; const struct elf_backend_data *bed = get_elf_backend_data (abfd); i_ehdrp = elf_elfheader (abfd); - i_shdrp = elf_elfsections (abfd); shstrtab = _bfd_elf_strtab_init (); if (shstrtab == NULL) @@ -4963,8 +4933,6 @@ _bfd_elf_write_object_contents (bfd *abfd) || bfd_bwrite (i_shdrp[count]->contents, amt, abfd) != amt) return FALSE; } - if (count == SHN_LORESERVE - 1) - count += SHN_HIRESERVE + 1 - SHN_LORESERVE; } /* Write out the section header names. */ diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 1be3346..580d590 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -8043,7 +8043,9 @@ elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info, Elf_Internal_Shdr *hdr; hdr = &elf_section_data (o)->this_hdr; - if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link + if (hdr->sh_type == SHT_ARM_EXIDX + && hdr->sh_link + && hdr->sh_link < elf_numsections (sub) && !o->gc_mark && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark) { diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c index 5cebbaa..3cbfb75 100644 --- a/bfd/elf32-avr.c +++ b/bfd/elf32-avr.c @@ -1,5 +1,5 @@ /* AVR-specific support for 32-bit ELF - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007 + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. Contributed by Denis Chertykov <denisc@overta.ru> @@ -2757,15 +2757,20 @@ elf32_avr_size_stubs (bfd *output_bfd, /* It's a local symbol. */ Elf_Internal_Sym *sym; Elf_Internal_Shdr *hdr; + unsigned int shndx; sym = local_syms + r_indx; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) sym_value = sym->st_value; - destination = (sym_value + irela->r_addend - + sym_sec->output_offset - + sym_sec->output_section->vma); + shndx = sym->st_shndx; + if (shndx < elf_numsections (input_bfd)) + { + hdr = elf_elfsections (input_bfd)[shndx]; + sym_sec = hdr->bfd_section; + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } } else { diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 20b16be..7707060 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -1,6 +1,7 @@ /* BFD back-end for HP PA-RISC ELF files. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2002, 2003, 2004, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. Original code by Center for Software Science @@ -2976,15 +2977,20 @@ elf32_hppa_size_stubs /* It's a local symbol. */ Elf_Internal_Sym *sym; Elf_Internal_Shdr *hdr; + unsigned int shndx; sym = local_syms + r_indx; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) sym_value = sym->st_value; - destination = (sym_value + irela->r_addend - + sym_sec->output_offset - + sym_sec->output_section->vma); + shndx = sym->st_shndx; + if (shndx < elf_numsections (input_bfd)) + { + hdr = elf_elfsections (input_bfd)[shndx]; + sym_sec = hdr->bfd_section; + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } } else { diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c index 9ad82b6..2660c89 100644 --- a/bfd/elf32-m68hc1x.c +++ b/bfd/elf32-m68hc1x.c @@ -450,8 +450,13 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, if (!is_far) continue; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; + if (sym->st_shndx >= elf_numsections (input_bfd)) + sym_sec = NULL; + else + { + hdr = elf_elfsections (input_bfd)[sym->st_shndx]; + sym_sec = hdr->bfd_section; + } stub_name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name)); diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index b203205..982d45f 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -1,5 +1,5 @@ /* Support for HPPA 64-bit ELF - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -625,7 +625,7 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs) asection *dlt, *plt, *stubs; char *buf; size_t buf_len; - int sec_symndx; + unsigned int sec_symndx; if (info->relocatable) return TRUE; @@ -677,7 +677,8 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs) isymend = local_syms + symtab_hdr->sh_info; for (isym = local_syms; isym < isymend; isym++) { - if (isym->st_shndx > highest_shndx) + if (isym->st_shndx > highest_shndx + && isym->st_shndx < SHN_LORESERVE) highest_shndx = isym->st_shndx; } @@ -723,10 +724,13 @@ elf64_hppa_check_relocs (abfd, info, sec, relocs) /* If we did not find a section symbol for this section, then something went terribly wrong above. */ - if (sec_symndx == -1) + if (sec_symndx == SHN_BAD) return FALSE; - sec_symndx = hppa_info->section_syms[sec_symndx]; + if (sec_symndx < SHN_LORESERVE) + sec_symndx = hppa_info->section_syms[sec_symndx]; + else + sec_symndx = 0; } else sec_symndx = 0; diff --git a/bfd/elfcode.h b/bfd/elfcode.h index bbbffe1..c356638 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -189,12 +189,14 @@ elf_swap_symbol_in (bfd *abfd, dst->st_info = H_GET_8 (abfd, src->st_info); dst->st_other = H_GET_8 (abfd, src->st_other); dst->st_shndx = H_GET_16 (abfd, src->st_shndx); - if (dst->st_shndx == SHN_XINDEX) + if (dst->st_shndx == (SHN_XINDEX & 0xffff)) { if (shndx == NULL) return FALSE; dst->st_shndx = H_GET_32 (abfd, shndx->est_shndx); } + else if (dst->st_shndx >= (SHN_LORESERVE & 0xffff)) + dst->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); return TRUE; } @@ -215,12 +217,12 @@ elf_swap_symbol_out (bfd *abfd, H_PUT_8 (abfd, src->st_info, dst->st_info); H_PUT_8 (abfd, src->st_other, dst->st_other); tmp = src->st_shndx; - if (tmp > SHN_HIRESERVE) + if (tmp >= (SHN_LORESERVE & 0xffff) && tmp < SHN_LORESERVE) { if (shndx == NULL) abort (); H_PUT_32 (abfd, tmp, shndx); - tmp = SHN_XINDEX; + tmp = SHN_XINDEX & 0xffff; } H_PUT_16 (abfd, tmp, dst->st_shndx); } @@ -280,12 +282,12 @@ elf_swap_ehdr_out (bfd *abfd, H_PUT_16 (abfd, src->e_phnum, dst->e_phnum); H_PUT_16 (abfd, src->e_shentsize, dst->e_shentsize); tmp = src->e_shnum; - if (tmp >= SHN_LORESERVE) + if (tmp >= (SHN_LORESERVE & 0xffff)) tmp = SHN_UNDEF; H_PUT_16 (abfd, tmp, dst->e_shnum); tmp = src->e_shstrndx; - if (tmp >= SHN_LORESERVE) - tmp = SHN_XINDEX; + if (tmp >= (SHN_LORESERVE & 0xffff)) + tmp = SHN_XINDEX & 0xffff; H_PUT_16 (abfd, tmp, dst->e_shstrndx); } @@ -470,25 +472,6 @@ elf_file_p (Elf_External_Ehdr *x_ehdrp) && (x_ehdrp->e_ident[EI_MAG3] == ELFMAG3)); } -/* Determines if a given section index is valid. */ - -static inline bfd_boolean -valid_section_index_p (unsigned index, unsigned num_sections) -{ - /* Note: We allow SHN_UNDEF as a valid section index. */ - if (index < SHN_LORESERVE || index > SHN_HIRESERVE) - return index < num_sections; - - /* We disallow the use of reserved indcies, except for those - with OS or Application specific meaning. The test make use - of the knowledge that: - SHN_LORESERVE == SHN_LOPROC - and - SHN_HIPROC == SHN_LOOS - 1 */ - /* XXX - Should we allow SHN_XINDEX as a valid index here ? */ - return (index >= SHN_LOPROC && index <= SHN_HIOS); -} - /* Check to see if the file associated with ABFD matches the target vector that ABFD points to. @@ -707,7 +690,7 @@ elf_object_p (bfd *abfd) } /* And similarly for the string table index. */ - if (i_ehdrp->e_shstrndx == SHN_XINDEX) + if (i_ehdrp->e_shstrndx == (SHN_XINDEX & 0xffff)) { i_ehdrp->e_shstrndx = i_shdr.sh_link; if (i_ehdrp->e_shstrndx != i_shdr.sh_link) @@ -753,8 +736,6 @@ elf_object_p (bfd *abfd) if (!i_shdrp) goto got_no_match; num_sec = i_ehdrp->e_shnum; - if (num_sec > SHN_LORESERVE) - num_sec += SHN_HIRESERVE + 1 - SHN_LORESERVE; elf_numsections (abfd) = num_sec; amt = sizeof (i_shdrp) * num_sec; elf_elfsections (abfd) = bfd_alloc (abfd, amt); @@ -762,16 +743,7 @@ elf_object_p (bfd *abfd) goto got_no_match; memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp)); - shdrp = i_shdrp; - shindex = 0; - if (num_sec > SHN_LORESERVE) - { - for ( ; shindex < SHN_LORESERVE; shindex++) - elf_elfsections (abfd)[shindex] = shdrp++; - for ( ; shindex < SHN_HIRESERVE + 1; shindex++) - elf_elfsections (abfd)[shindex] = i_shdrp; - } - for ( ; shindex < num_sec; shindex++) + for (shdrp = i_shdrp, shindex = 0; shindex < num_sec; shindex++) elf_elfsections (abfd)[shindex] = shdrp++; /* Read in the rest of the section header table and convert it @@ -783,13 +755,13 @@ elf_object_p (bfd *abfd) elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex); /* Sanity check sh_link and sh_info. */ - if (! valid_section_index_p (i_shdrp[shindex].sh_link, num_sec)) + if (i_shdrp[shindex].sh_link >= num_sec) goto got_wrong_format_error; if (((i_shdrp[shindex].sh_flags & SHF_INFO_LINK) || i_shdrp[shindex].sh_type == SHT_RELA || i_shdrp[shindex].sh_type == SHT_REL) - && ! valid_section_index_p (i_shdrp[shindex].sh_info, num_sec)) + && i_shdrp[shindex].sh_info >= num_sec) goto got_wrong_format_error; /* If the section is loaded, but not page aligned, clear @@ -807,7 +779,7 @@ elf_object_p (bfd *abfd) /* A further sanity check. */ if (i_ehdrp->e_shnum != 0) { - if (! valid_section_index_p (i_ehdrp->e_shstrndx, elf_numsections (abfd))) + if (i_ehdrp->e_shstrndx >= elf_numsections (abfd)) { /* PR 2257: We used to just goto got_wrong_format_error here @@ -856,12 +828,8 @@ elf_object_p (bfd *abfd) a dummy placeholder entry, so we ignore it. */ num_sec = elf_numsections (abfd); for (shindex = 1; shindex < num_sec; shindex++) - { - if (! bfd_section_from_shdr (abfd, shindex)) - goto got_no_match; - if (shindex == SHN_LORESERVE - 1) - shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE; - } + if (!bfd_section_from_shdr (abfd, shindex)) + goto got_no_match; /* Set up ELF sections for SHF_GROUP and SHF_LINK_ORDER. */ if (! _bfd_elf_setup_sections (abfd)) @@ -1081,9 +1049,9 @@ elf_write_shdrs_and_ehdr (bfd *abfd) /* Some fields in the first section header handle overflow of ehdr fields. */ - if (i_ehdrp->e_shnum >= SHN_LORESERVE) + if (i_ehdrp->e_shnum >= (SHN_LORESERVE & 0xffff)) i_shdrp[0]->sh_size = i_ehdrp->e_shnum; - if (i_ehdrp->e_shstrndx >= SHN_LORESERVE) + if (i_ehdrp->e_shstrndx >= (SHN_LORESERVE & 0xffff)) i_shdrp[0]->sh_link = i_ehdrp->e_shstrndx; /* at this point we've concocted all the ELF sections... */ @@ -1099,9 +1067,6 @@ elf_write_shdrs_and_ehdr (bfd *abfd) elf_debug_section (count, *i_shdrp); #endif elf_swap_shdr_out (abfd, *i_shdrp, x_shdrp + count); - - if (count == SHN_LORESERVE - 1) - i_shdrp += SHN_HIRESERVE + 1 - SHN_LORESERVE; } if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0 || bfd_bwrite (x_shdrp, amt, abfd) != amt) diff --git a/bfd/elflink.c b/bfd/elflink.c index ed99a5d..0e42da7 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -618,8 +618,7 @@ bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info *info, } if (entry->isym.st_shndx != SHN_UNDEF - && (entry->isym.st_shndx < SHN_LORESERVE - || entry->isym.st_shndx > SHN_HIRESERVE)) + && entry->isym.st_shndx < SHN_LORESERVE) { asection *s; @@ -8201,13 +8200,14 @@ elf_link_output_sym (struct elf_final_link_info *finfo, static bfd_boolean check_dynsym (bfd *abfd, Elf_Internal_Sym *sym) { - if (sym->st_shndx > SHN_HIRESERVE) + if (sym->st_shndx >= (SHN_LORESERVE & 0xffff) + && sym->st_shndx < SHN_LORESERVE) { /* The gABI doesn't support dynamic symbols in output sections beyond 64k. */ (*_bfd_error_handler) (_("%B: Too many sections: %d (>= %d)"), - abfd, bfd_count_sections (abfd), SHN_LORESERVE); + abfd, bfd_count_sections (abfd), SHN_LORESERVE & 0xffff); bfd_set_error (bfd_error_nonrepresentable_section); return FALSE; } @@ -8951,10 +8951,9 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd) /* If this symbol is defined in a section which we are discarding, we don't need to keep it. */ if (isym->st_shndx != SHN_UNDEF - && (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE) - && (isec == NULL - || bfd_section_removed_from_list (output_bfd, - isec->output_section))) + && isym->st_shndx < SHN_LORESERVE + && bfd_section_removed_from_list (output_bfd, + isec->output_section)) continue; /* Get the name of the symbol. */ @@ -9778,7 +9777,8 @@ elf_fixup_link_order (bfd *abfd, asection *o) && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass && (elfsec = _bfd_elf_section_from_bfd_section (sub, s)) && elfsec < elf_numsections (sub) - && elf_elfsections (sub)[elfsec]->sh_flags & SHF_LINK_ORDER) + && elf_elfsections (sub)[elfsec]->sh_flags & SHF_LINK_ORDER + && elf_elfsections (sub)[elfsec]->sh_link < elf_numsections (sub)) { seen_linkorder++; linkorder_sec = s; @@ -10186,7 +10186,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) finfo.symbuf = bfd_malloc (amt); if (finfo.symbuf == NULL) goto error_return; - if (elf_numsections (abfd) > SHN_LORESERVE) + if (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF)) { /* Wild guess at number of output symbols. realloc'd as needed. */ amt = 2 * max_sym_count + elf_numsections (abfd) + 1000; @@ -10236,8 +10236,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (!elf_link_output_sym (&finfo, NULL, &elfsym, o, NULL)) goto error_return; } - if (i == SHN_LORESERVE - 1) - i += SHN_HIRESERVE + 1 - SHN_LORESERVE; } } |