diff options
author | Nick Clifton <nickc@redhat.com> | 2009-03-13 11:34:43 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2009-03-13 11:34:43 +0000 |
commit | ce98a316e9018523f263417f3948fed63a1ba1db (patch) | |
tree | 328e6f758f98e96ba4d3df6b1434c3d082ca98f2 /bfd/elflink.c | |
parent | f7c60c5e2b07932c2b73b687083b254cbe0dd5de (diff) | |
download | gdb-ce98a316e9018523f263417f3948fed63a1ba1db.zip gdb-ce98a316e9018523f263417f3948fed63a1ba1db.tar.gz gdb-ce98a316e9018523f263417f3948fed63a1ba1db.tar.bz2 |
PR 9934
* elf-bfd.h (NUM_SHDR_ENTRIES): Cope with an empty section.
* elflink.c (elf_link_read_relocs_from_section): Use
NUM_SHDR_ENTRIES. Gracefully handle the case where there are
relocs but no symbol table.
* elf32-arm.c (elf32_arm_check_relocs): Likewise.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index d0e4534..c635cb0 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2202,7 +2202,7 @@ elf_link_read_relocs_from_section (bfd *abfd, return FALSE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - nsyms = symtab_hdr->sh_size / symtab_hdr->sh_entsize; + nsyms = NUM_SHDR_ENTRIES (symtab_hdr); bed = get_elf_backend_data (abfd); @@ -2228,11 +2228,24 @@ elf_link_read_relocs_from_section (bfd *abfd, r_symndx = ELF32_R_SYM (irela->r_info); if (bed->s->arch_size == 64) r_symndx >>= 24; - if ((size_t) r_symndx >= nsyms) + if (nsyms > 0) + { + if ((size_t) r_symndx >= nsyms) + { + (*_bfd_error_handler) + (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)" + " for offset 0x%lx in section `%A'"), + abfd, sec, + (unsigned long) r_symndx, (unsigned long) nsyms, irela->r_offset); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + } + else if (r_symndx != 0) { (*_bfd_error_handler) - (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)" - " for offset 0x%lx in section `%A'"), + (_("%B: non-zero symbol index (0x%lx) for offset 0x%lx in section `%A'" + " when the object file has no symbol table"), abfd, sec, (unsigned long) r_symndx, (unsigned long) nsyms, irela->r_offset); bfd_set_error (bfd_error_bad_value); |