Skip to content

Commit 1cb7944

Browse files
committed
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
1 parent 8ebeb68 commit 1cb7944

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

contrib/elftoolchain/elfdump/elfdump.c

+14-11
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,20 @@ elf_phdr_type_str(unsigned int type)
343343
static char s_type[32];
344344

345345
switch (type) {
346-
case PT_NULL: return "PT_NULL";
347-
case PT_LOAD: return "PT_LOAD";
348-
case PT_DYNAMIC: return "PT_DYNAMIC";
349-
case PT_INTERP: return "PT_INTERP";
350-
case PT_NOTE: return "PT_NOTE";
351-
case PT_SHLIB: return "PT_SHLIB";
352-
case PT_PHDR: return "PT_PHDR";
353-
case PT_TLS: return "PT_TLS";
354-
case PT_GNU_EH_FRAME: return "PT_GNU_EH_FRAME";
355-
case PT_GNU_STACK: return "PT_GNU_STACK";
356-
case PT_GNU_RELRO: return "PT_GNU_RELRO";
346+
case PT_NULL: return "PT_NULL";
347+
case PT_LOAD: return "PT_LOAD";
348+
case PT_DYNAMIC: return "PT_DYNAMIC";
349+
case PT_INTERP: return "PT_INTERP";
350+
case PT_NOTE: return "PT_NOTE";
351+
case PT_SHLIB: return "PT_SHLIB";
352+
case PT_PHDR: return "PT_PHDR";
353+
case PT_TLS: return "PT_TLS";
354+
case PT_GNU_EH_FRAME: return "PT_GNU_EH_FRAME";
355+
case PT_GNU_STACK: return "PT_GNU_STACK";
356+
case PT_GNU_RELRO: return "PT_GNU_RELRO";
357+
case PT_OPENBSD_RANDOMIZE: return "PT_OPENBSD_RANDOMIZE";
358+
case PT_OPENBSD_WXNEEDED: return "PT_OPENBSD_WXNEEDED";
359+
case PT_OPENBSD_BOOTDATA: return "PT_OPENBSD_BOOTDATA";
357360
}
358361
snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
359362
return (s_type);

contrib/elftoolchain/readelf/readelf.c

+3
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ phdr_type(unsigned int mach, unsigned int ptype)
674674
case PT_GNU_EH_FRAME: return "GNU_EH_FRAME";
675675
case PT_GNU_STACK: return "GNU_STACK";
676676
case PT_GNU_RELRO: return "GNU_RELRO";
677+
case PT_OPENBSD_RANDOMIZE: return "OPENBSD_RANDOMIZE";
678+
case PT_OPENBSD_WXNEEDED: return "OPENBSD_WXNEEDED";
679+
case PT_OPENBSD_BOOTDATA: return "OPENBSD_BOOTDATA";
677680
default:
678681
if (ptype >= PT_LOOS && ptype <= PT_HIOS)
679682
snprintf(s_ptype, sizeof(s_ptype), "LOOS+%#x",

sys/sys/elf_common.h

+4
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,10 @@ typedef struct {
535535
#define PT_ARM_EXIDX 0x70000001 /* ARM exception unwind tables. */
536536
#define PT_HIPROC 0x7fffffff /* Last processor-specific type. */
537537

538+
#define PT_OPENBSD_RANDOMIZE 0x65A3DBE6 /* OpenBSD random data segment */
539+
#define PT_OPENBSD_WXNEEDED 0x65A3DBE7 /* OpenBSD EXEC/WRITE pages needed */
540+
#define PT_OPENBSD_BOOTDATA 0x65A41BE6 /* OpenBSD section for boot args */
541+
538542
/* Values for p_flags. */
539543
#define PF_X 0x1 /* Executable. */
540544
#define PF_W 0x2 /* Writable. */

0 commit comments

Comments
 (0)