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]

[RFA:] save/restore bug for elf_core_file_p


This patch correspond to the elf_object_p changes in
<URL:http://sources.redhat.com/ml/binutils/2000-09/msg00449.html> and
<URL:http://sources.redhat.com/ml/binutils/2000-12/msg00242.html>.

Without it, the elf32-cris target, coming after the
elf32-us-cris target in the target vector, will encounter a
"wild pointer" to a section by the same name as the first one it
tries to add, "note0", and the core file will not be recognized.
With it, the core file can be parsed, though I need to add the
note-parsers that Daniel Jacobowitz mentioned.

Ok to commit?

	* elfcore.h (elf_core_file_p): Preserve and clear abfd section
	information.  Save bfd arch and mach values.  Restore on error.

Index: elfcore.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcore.h,v
retrieving revision 1.9
diff -p -c -r1.9 elfcore.h
*** elfcore.h	2001/09/18 09:57:24	1.9
--- elfcore.h	2001/11/02 05:44:13
*************** elf_core_file_p (abfd)
*** 85,93 ****
--- 85,102 ----
    unsigned int phindex;
    struct elf_backend_data *ebd;
    struct elf_obj_tdata *preserved_tdata = elf_tdata (abfd);
+   struct sec *preserved_sections = abfd->sections;
+   unsigned int preserved_section_count = abfd->section_count;
+   enum bfd_architecture previous_arch = bfd_get_arch (abfd);
+   unsigned long previous_mach = bfd_get_mach (abfd);
    struct elf_obj_tdata *new_tdata = NULL;
    bfd_size_type amt;
  
+   /* Clear section information, since there might be a recognized bfd that
+      we now check if we can replace, and we don't want to append to it.  */
+   abfd->sections = NULL;
+   abfd->section_count = 0;
+ 
    /* Read in the ELF header in external format.  */
    if (bfd_bread ((PTR) &x_ehdr, (bfd_size_type) sizeof (x_ehdr), abfd)
        != sizeof (x_ehdr))
*************** elf_core_file_p (abfd)
*** 234,239 ****
--- 243,258 ----
    return abfd->xvec;
  
  wrong:
+   /* There is way too much undoing of half-known state here.  The caller,
+      bfd_check_format_matches, really shouldn't iterate on live bfd's to
+      check match/no-match like it does.  We have to rely on that a call to
+      bfd_default_set_arch_mach with the previously known mach, undoes what
+      was done by the first bfd_default_set_arch_mach (with mach 0) here.
+      For this to work, only elf-data and the mach may be changed by the
+      target-specific elf_backend_object_p function.  Note that saving the
+      whole bfd here and restoring it would be even worse; the first thing
+      you notice is that the cached bfd file position gets out of sync.  */
+   bfd_default_set_arch_mach (abfd, previous_arch, previous_mach);
    bfd_set_error (bfd_error_wrong_format);
  fail:
    if (i_phdrp != NULL)
*************** fail:
*** 241,245 ****
--- 260,266 ----
    if (new_tdata != NULL)
      bfd_release (abfd, new_tdata);
    elf_tdata (abfd) = preserved_tdata;
+   abfd->sections = preserved_sections;
+   abfd->section_count = preserved_section_count;
    return NULL;
  }

brgds, H-P


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