Page MenuHomeFreeBSD

Copy the e_machine and e_flags fields from the binary into an ELF core dump.
ClosedPublic

Authored by jhb on Jan 31 2017, 1:38 AM.
Tags
None
Referenced Files
F83733839: D9392.diff
Tue, May 14, 4:42 AM
Unknown Object (File)
Nov 19 2023, 12:06 PM
Unknown Object (File)
Nov 15 2023, 8:33 AM
Unknown Object (File)
Nov 8 2023, 1:59 AM
Unknown Object (File)
Oct 14 2023, 7:36 AM
Unknown Object (File)
Oct 9 2023, 12:18 AM
Unknown Object (File)
Oct 7 2023, 12:55 AM
Unknown Object (File)
May 30 2023, 2:59 AM
Subscribers
None

Details

Summary

In the kernel, cache the machine and flags fields from ELF header to use in
the ELF header of a core dump. For gcore, the copy these fields over from
the ELF header in the binary.

This matters for platforms which encode ABI information in the flags field
(such as o32 vs n32 on MIPS).

Test Plan
  • Generate core dumps on mips64 and verify ELF flags via readelf -h.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb retitled this revision from to Copy the e_machine and e_flags fields from the binary into an ELF core dump..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
jhb added a reviewer: kib.
kib edited edge metadata.
kib added inline comments.
usr.bin/gcore/elfcore.c
433 ↗(On Diff #24585)

I think that the short read there is a normal error, and not an exception. I.e. I suggest using errx() instead of assert().

This revision is now accepted and ready to land.Jan 31 2017, 1:47 AM
usr.bin/gcore/elfcore.c
433 ↗(On Diff #24585)

The reason I had made it an assert is that we just read that same header earlier from
the file in elf_ident(). Presumably re-reading the header a second time cannot fail? (I thought about changing the code so that elf_ident() wrote the header into a global variable that that elf_puthdr() could then read rather than re-reading it, but that seemed kind of gross)

usr.bin/gcore/elfcore.c
433 ↗(On Diff #24585)

Indeed it should not fail because mapped for execution vnode get VV_TEXT flag set. Unless the binary is on a filesystem where it can, e.g. nfs.

usr.bin/gcore/elfcore.c
433 ↗(On Diff #24585)

Humm, NFS is unpleasant like that. err() it is.

This revision was automatically updated to reflect the committed changes.