[PATCH] sh: handle Linux core notes in the generic ELF vector

Matt Turner mattst88@gmail.com
Wed Sep 30 20:38:09 GMT 2026


On Tue, Sep 29, 2026 at 10:26 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Sat, Sep 26, 2026 at 12:16:03AM -0400, Matt Turner wrote:
> > A Linux sh core file matches elf32-shl, elf32-sh-linux, elf32-shl-nbsd
> > and elf32-shl-vxworks with equal priority, and bfd_check_format_matches
> > picks the first, elf32-shl. Only the Linux vector handled NT_PRSTATUS
> > and NT_PRPSINFO notes, so the core had no .reg section and gdb found no
> > registers.
> >
> > Handle the notes in the generic vector, which the NetBSD, Linux and
> > FDPIC vectors inherit. VxWorks still undefines them.
> >
> >       PR 34676
>
> This seems a hack to me, despite being used elsewhere.  Ideally we'd
> choose the correct target.  Please test the following.

Thanks, that works. With --enable-targets=all on x86_64, and your
patch instead of mine, a qemu-sh4 Linux core is now recognized as
elf32-sh-linux, has a .reg section, and gdb reads the registers and
gives a full backtrace.

A few small things I noticed:

- The associated vector loop and the "first of the best matches" loop
  only compare best_match >> 16, so if more than one target shares
  the best priority and section count, they can still pick a target
  with fewer sections.

- (0xffff - abfd->section_count) & 0xffff wraps for files with more
  than 65535 sections. Probably harmless?

- If the default vector matches, we return before any of this, so an
  sh-elf toolchain opening a Linux core still gets elf32-shl. That
  seems unlikely to matter in practice.

Anyway, this looks good to me. Thank you!


More information about the Binutils mailing list