[PATCH users/roland/tolerant-elf_object_p] Don't let a single unrecognized ELF section break target matching.

Roland McGrath mcgrathr@google.com
Wed Jul 29 18:31:48 GMT 2020


When an input file uses a novel section type that BFD doesn't
recognize, `objdump -d` refuses to work on the file at all.
This is quite annoying.  This change seems to fix it and causes no
regressions I can see.
(The change is also on branch users/roland/tolerant-elf_object_p for
your convenience.  Sorry if my MUA mangles it.)

OK for trunk?
Maybe for 2.35 too?

Thanks,
Roland

bfd/
2020-07-29  Roland McGrath  <mcgrathr@google.com>

        * elfcode.h (elf_object_p): Ignore errors from individual
        bfd_section_from_shdr calls so a novel section type appearing in
        the input doesn't break target-matching.

diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 2e2c5343f2..f65160ca38 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -816,8 +816,11 @@ elf_object_p (bfd *abfd)
         a dummy placeholder entry, so we ignore it.  */
       num_sec = elf_numsections (abfd);
       for (shindex = 1; shindex < num_sec; shindex++)
-       if (!bfd_section_from_shdr (abfd, shindex))
-         goto got_no_match;
+        /* Ignore the return value here since an unrecognized section type
+           doesn't make the entire file unusable.  The unrecognized section
+           simply won't be examined, and bfd_section_from_shdr will have
+           emitted an error message.  */
+       bfd_section_from_shdr (abfd, shindex);

       /* Set up ELF sections for SHF_GROUP and SHF_LINK_ORDER.  */
       if (! _bfd_elf_setup_sections (abfd))


More information about the Binutils mailing list