]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - bfd/elf.c
Use the ELF class to determine the word size for FreeBSD core notes.
authorJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Jun 2017 16:40:46 +0000 (09:40 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Jun 2017 16:40:46 +0000 (09:40 -0700)
commitb5430a3ced5fe5ba484bd9b3215b9ae19ced0160
tree9f9a9f46e37d3f6f48b534fbd8e1d44c0bfd57ce
parentf378ab099d535f5540f292fed07fcf4b1fabd314
Use the ELF class to determine the word size for FreeBSD core notes.

FreeBSD ELF cores contain data structures with that have two different
layouts: one for ILP32 platforms and a second for LP64 platforms.
Previously, the code used 'bits_per_word' from 'arch_info', but this
field is not a reliable indicator of the format for FreeBSD MIPS cores
in particular.

I had originally posted this patch back in November because process
cores for FreeBSD MIPS contained an e_flags value of 0 in the header
which resulted in a bfd_arch which always had 'bits_per_word' set to
32.  This permitted reading o32 cores, but not n64 cores.  The feedback
I received then was to try to change n64 cores to use a different
default bfd_arch that had a 64-bit 'bits_per_word' when e_flags was zero.
I submitted a patch to that effect but it was never approved.  Instead,
I changed FreeBSD's kernel and gcore commands to preserve the e_flags
field from an executable when generating process cores.  With a proper
e_flags field in process cores, n64 cores now use a 64-bit bfd_arch and
now work fine.  However, the change to include e_flags in the process
cores had the unintended side effect of breaking handling of o32
process cores.  Specifically, FreeBSD MIPS builds o32 with a default
MIPS architecture of 'mips3', thus FreeBSD process cores with a non-zero
e_flags match the 'mips3' bfd_arch which has 64 'bits_per_word'.

From this, it seems that 'bits_per_word' for FreeBSD MIPS is not likely
to ever be completely correct.  However, FreeBSD core dumps do
reliably set the ELF class to ELFCLASS32 for cores using ILP32 and
ELFCLASS64 for cores using LP64.  As such, I think my original patch of
using the ELF class instead of 'bits_per_word' is probably the simplest
and most reliable approach for detecting the note structure layout.

bfd/ChangeLog:

* elf.c (elfcore_grok_freebsd_psinfo): Use ELF header class to
determine structure sizes.
(elfcore_grok_freebsd_prstatus): Likewise.
bfd/ChangeLog
bfd/elf.c