This is the mail archive of the 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 section info in elf_object_p.

Consider a target (meaning port triple) with more than one ELF bfd_target,
and processing a file where elf_backend_object_p matches one, but not the
default bfd_target.  For example, bfd_targets (aout, elf1, elf2), where
the file matches elf1 and aout is the default target.  The generic ELF
targets don't count here, as they are handled as special cases, giving an
early no-match if there's an e_machine match for another ELF target.

bfd_check_format_matches will try *all* targets, not just loop until a
match is found, unless the default target matches, which it will settle
for.  It's checking for ambiguous format recognition, as stated in that

However, elf_object_p has bugs when getting no-match signalled as late as
from elf_backend_object_p, visible when it is called multiple times, both
with failure-then-success and vice versa.  It boils down to that sections
are blindly linked into abfd, and are not restored on error.  Note that
with and without this patch, there is a perceived memory leak in case of
multiple recognized formats, but as mentioned, that'd be ambiguous format
recognition, an error situation.

Browsing config.bfd, I have not been able to locate a target triple with
this situation.  Remember, this only happens if the tested target is ELF
but not if it's the default target.

It happens for me because I'm having separate ELF bfd_targets that reject
or accept through elf_backend_object_p looking at header flags, rather
than just e_machine, size and endianness.  (I'm just doing the recommended
route of different-bfd_targets-per-symbol_leading_char as previously
discussed.)  With this patch the testsuite passes (with usual tweaks to
test ELF) for CRIS with the mentioned changes, which I'll commit
separately after some more work and testsuite additions.

Ok to commit?

2000-09-26  Hans-Peter Nilsson  <>

	* elfcode.h (elf_object_p): Preserve and clear abfd section
 	information.  Restore at error.

Index: elfcode.h
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.13
diff -p -c -r1.13 elfcode.h
*** elfcode.h	2000/07/11 06:08:19	1.13
--- elfcode.h	2000/09/26 15:13:44
*************** elf_object_p (abfd)
*** 500,508 ****
--- 500,515 ----
    char *shstrtab;		/* Internal copy of section header stringtab */
    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;
    struct elf_obj_tdata *new_tdata = NULL;
    asection *s;
+   /* 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_read ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
*************** elf_object_p (abfd)
*** 745,750 ****
--- 752,759 ----
    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]