Teach readelf about some OpenBSD ELF program headers

- Add constants for OpenBSD wxneeded, bootdata and randomize to the
  FreeBSD elf_common.h file. This is the file that gets used by the
  elftoolchain library.
- Update readelf and elfdump utilities to decode these program headers
  if they are encountered.

Note: FreeBSD has it's own version of elfdump(1), which will be updated
in a subsequent commit. I am adding it here anyway because this diff is
going to be submitted upstream.

Discussed with:	emaste
Reviewed by:	imp
MFC afer:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20548

M    contrib/elftoolchain/elfdump/elfdump.c
M    contrib/elftoolchain/readelf/readelf.c
M    sys/sys/elf_common.h
This commit is contained in:
Christian S.J. Peron 2019-06-07 14:51:55 +00:00
parent cb1ee1bf9b
commit ca3075599a
3 changed files with 21 additions and 11 deletions

View File

@ -343,17 +343,20 @@ elf_phdr_type_str(unsigned int type)
static char s_type[32];
switch (type) {
case PT_NULL: return "PT_NULL";
case PT_LOAD: return "PT_LOAD";
case PT_DYNAMIC: return "PT_DYNAMIC";
case PT_INTERP: return "PT_INTERP";
case PT_NOTE: return "PT_NOTE";
case PT_SHLIB: return "PT_SHLIB";
case PT_PHDR: return "PT_PHDR";
case PT_TLS: return "PT_TLS";
case PT_GNU_EH_FRAME: return "PT_GNU_EH_FRAME";
case PT_GNU_STACK: return "PT_GNU_STACK";
case PT_GNU_RELRO: return "PT_GNU_RELRO";
case PT_NULL: return "PT_NULL";
case PT_LOAD: return "PT_LOAD";
case PT_DYNAMIC: return "PT_DYNAMIC";
case PT_INTERP: return "PT_INTERP";
case PT_NOTE: return "PT_NOTE";
case PT_SHLIB: return "PT_SHLIB";
case PT_PHDR: return "PT_PHDR";
case PT_TLS: return "PT_TLS";
case PT_GNU_EH_FRAME: return "PT_GNU_EH_FRAME";
case PT_GNU_STACK: return "PT_GNU_STACK";
case PT_GNU_RELRO: return "PT_GNU_RELRO";
case PT_OPENBSD_RANDOMIZE: return "PT_OPENBSD_RANDOMIZE";
case PT_OPENBSD_WXNEEDED: return "PT_OPENBSD_WXNEEDED";
case PT_OPENBSD_BOOTDATA: return "PT_OPENBSD_BOOTDATA";
}
snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
return (s_type);

View File

@ -674,6 +674,9 @@ phdr_type(unsigned int mach, unsigned int ptype)
case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
case PT_GNU_STACK: return "GNU_STACK";
case PT_GNU_RELRO: return "GNU_RELRO";
case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE";
case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED";
case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA";
default:
if (ptype >= PT_LOOS && ptype <= PT_HIOS)
snprintf(s_ptype, sizeof(s_ptype), "LOOS+%#x",

View File

@ -535,6 +535,10 @@ typedef struct {
#define PT_ARM_EXIDX 0x70000001 /* ARM exception unwind tables. */
#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */
#define PT_OPENBSD_RANDOMIZE 0x65A3DBE6 /* OpenBSD random data segment */
#define PT_OPENBSD_WXNEEDED 0x65A3DBE7 /* OpenBSD EXEC/WRITE pages needed */
#define PT_OPENBSD_BOOTDATA 0x65A41BE6 /* OpenBSD section for boot args */
/* Values for p_flags. */
#define PF_X 0x1 /* Executable. */
#define PF_W 0x2 /* Writable. */