This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

allow 0 for e_shnum, e_shstrndx, e_shoff


This patch against today's CVS allows binutils such as objdump
to work with ELF files that do not have any Elf32_Shdr sections.
Tested on i386.

=====
2001-09-20  John Reiser  <jreiser@BitWagon.com>
	* bfd/elfcode.h: allow for no Shdr at all in non-ET_REL:
	  honor 0 for e_shnum, e_shstrndx, e_shoff

=====
Index: bfd/elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.20
diff -u -r1.20 elfcode.h
--- elfcode.h	2001/09/18 09:57:24	1.20
+++ elfcode.h	2001/09/20 16:09:56
@@ -568,14 +568,14 @@
   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 there is no section header table, and relocatable, 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,6 +634,7 @@
   /* 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.  */
+ 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;
@@ -642,6 +643,7 @@
     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,6 +699,7 @@
      bfd_section_from_shdr with it (since this particular strtab is
      used to find all of the ELF section names.) */
 
+ if (i_ehdrp->e_shstrndx != 0) {
   shstrtab = bfd_elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
   if (!shstrtab)
     goto got_no_match;
@@ -710,6 +713,7 @@
       if (! bfd_section_from_shdr (abfd, shindex))
 	goto got_no_match;
     }
+ }
 
   /* Let the backend double check the format and override global
      information.  */
=====

-- 
John Reiser, jreiser@BitWagon.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]