aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfcode.h
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2001-09-22 03:16:01 +0000
committerAlan Modra <amodra@gmail.com>2001-09-22 03:16:01 +0000
commit0c35f01ab36dfcbe8f82252db9e08ed51ff9df3f (patch)
treeca74ac120c700b689c61920f0a3c7f8f818fe1aa /bfd/elfcode.h
parent7e6922fd50394b3f802bd6e8dc3010d623103342 (diff)
downloadgdb-0c35f01ab36dfcbe8f82252db9e08ed51ff9df3f.zip
gdb-0c35f01ab36dfcbe8f82252db9e08ed51ff9df3f.tar.gz
gdb-0c35f01ab36dfcbe8f82252db9e08ed51ff9df3f.tar.bz2
* elfcode.h (elf_object_p): Allow for no section header at all in
non-ET_REL files. Honor 0 for e_shnum, e_shstrndx, e_shoff.
Diffstat (limited to 'bfd/elfcode.h')
-rw-r--r--bfd/elfcode.h51
1 files changed, 29 insertions, 22 deletions
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 6e3c2c9..3a76f1a 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -568,14 +568,15 @@ elf_object_p (abfd)
if (i_ehdrp->e_type == ET_CORE)
goto got_wrong_format_error;
- /* If there is no section header table, we're hosed. */
- if (i_ehdrp->e_shoff == 0)
+ /* If this is a relocatable file and there is no section header
+ table, then we're hosed. */
+ if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
goto got_wrong_format_error;
/* As a simple sanity check, verify that the what BFD thinks is the
size of each section header table entry actually matches the size
- recorded in the file. */
- if (i_ehdrp->e_shentsize != sizeof (x_shdr))
+ recorded in the file, but only if there are any sections. */
+ if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
goto got_wrong_format_error;
ebd = get_elf_backend_data (abfd);
@@ -634,14 +635,17 @@ elf_object_p (abfd)
/* Allocate space for a copy of the section header table in
internal form, seek to the section header table in the file,
read it in, and convert it to internal form. */
- amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum;
- i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
- amt = sizeof (i_shdrp) * i_ehdrp->e_shnum;
- elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt);
- if (!i_shdrp || !elf_elfsections (abfd))
- goto got_no_match;
- if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0)
- goto got_no_match;
+ if (i_ehdrp->e_shnum != 0)
+ {
+ amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum;
+ i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
+ amt = sizeof (i_shdrp) * i_ehdrp->e_shnum;
+ elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt);
+ if (!i_shdrp || !elf_elfsections (abfd))
+ goto got_no_match;
+ if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0)
+ goto got_no_match;
+ }
for (shindex = 0; shindex < i_ehdrp->e_shnum; shindex++)
{
if (bfd_bread ((PTR) & x_shdr, (bfd_size_type) sizeof x_shdr, abfd)
@@ -697,18 +701,21 @@ elf_object_p (abfd)
bfd_section_from_shdr with it (since this particular strtab is
used to find all of the ELF section names.) */
- shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
- if (!shstrtab)
- goto got_no_match;
-
- /* Once all of the section headers have been read and converted, we
- can start processing them. Note that the first section header is
- a dummy placeholder entry, so we ignore it. */
-
- for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
+ if (i_ehdrp->e_shstrndx != 0)
{
- if (! bfd_section_from_shdr (abfd, shindex))
+ shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
+ if (!shstrtab)
goto got_no_match;
+
+ /* Once all of the section headers have been read and converted, we
+ can start processing them. Note that the first section header is
+ a dummy placeholder entry, so we ignore it. */
+
+ for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
+ {
+ if (! bfd_section_from_shdr (abfd, shindex))
+ goto got_no_match;
+ }
}
/* Let the backend double check the format and override global