readelf: report ARM program and section header types

Reviewed by:	andrew
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7390
This commit is contained in:
emaste 2016-08-02 20:11:04 +00:00
parent 7999df886d
commit d9111a980d

View File

@ -343,7 +343,7 @@ static const char *note_type_openbsd(unsigned int nt);
static const char *note_type_unknown(unsigned int nt); static const char *note_type_unknown(unsigned int nt);
static const char *note_type_xen(unsigned int nt); static const char *note_type_xen(unsigned int nt);
static const char *option_kind(uint8_t kind); static const char *option_kind(uint8_t kind);
static const char *phdr_type(unsigned int ptype); static const char *phdr_type(unsigned int mach, unsigned int ptype);
static const char *ppc_abi_fp(uint64_t fp); static const char *ppc_abi_fp(uint64_t fp);
static const char *ppc_abi_vector(uint64_t vec); static const char *ppc_abi_vector(uint64_t vec);
static void readelf_usage(int status); static void readelf_usage(int status);
@ -622,10 +622,24 @@ elf_ver(unsigned int ver)
} }
static const char * static const char *
phdr_type(unsigned int ptype) phdr_type(unsigned int mach, unsigned int ptype)
{ {
static char s_ptype[32]; static char s_ptype[32];
if (ptype >= PT_LOPROC && ptype <= PT_HIPROC) {
switch (mach) {
case EM_ARM:
switch (ptype) {
case PT_ARM_ARCHEXT: return "ARM_ARCHEXT";
case PT_ARM_EXIDX: return "ARM_EXIDX";
}
break;
}
snprintf(s_ptype, sizeof(s_ptype), "LOPROC+%#x",
ptype - PT_LOPROC);
return (s_ptype);
}
switch (ptype) { switch (ptype) {
case PT_NULL: return "NULL"; case PT_NULL: return "NULL";
case PT_LOAD: return "LOAD"; case PT_LOAD: return "LOAD";
@ -639,10 +653,7 @@ phdr_type(unsigned int ptype)
case PT_GNU_STACK: return "GNU_STACK"; case PT_GNU_STACK: return "GNU_STACK";
case PT_GNU_RELRO: return "GNU_RELRO"; case PT_GNU_RELRO: return "GNU_RELRO";
default: default:
if (ptype >= PT_LOPROC && ptype <= PT_HIPROC) if (ptype >= PT_LOOS && ptype <= PT_HIOS)
snprintf(s_ptype, sizeof(s_ptype), "LOPROC+%#x",
ptype - PT_LOPROC);
else if (ptype >= PT_LOOS && ptype <= PT_HIOS)
snprintf(s_ptype, sizeof(s_ptype), "LOOS+%#x", snprintf(s_ptype, sizeof(s_ptype), "LOOS+%#x",
ptype - PT_LOOS); ptype - PT_LOOS);
else else
@ -659,6 +670,15 @@ section_type(unsigned int mach, unsigned int stype)
if (stype >= SHT_LOPROC && stype <= SHT_HIPROC) { if (stype >= SHT_LOPROC && stype <= SHT_HIPROC) {
switch (mach) { switch (mach) {
case EM_ARM:
switch (stype) {
case SHT_ARM_EXIDX: return "ARM_EXIDX";
case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP";
case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES";
case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY";
case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION";
}
break;
case EM_X86_64: case EM_X86_64:
switch (stype) { switch (stype) {
case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
@ -2273,9 +2293,10 @@ dump_phdr(struct readelf *re)
#define PH_HDR "Type", "Offset", "VirtAddr", "PhysAddr", "FileSiz", \ #define PH_HDR "Type", "Offset", "VirtAddr", "PhysAddr", "FileSiz", \
"MemSiz", "Flg", "Align" "MemSiz", "Flg", "Align"
#define PH_CT phdr_type(phdr.p_type), (uintmax_t)phdr.p_offset, \ #define PH_CT phdr_type(re->ehdr.e_machine, phdr.p_type), \
(uintmax_t)phdr.p_vaddr, (uintmax_t)phdr.p_paddr, \ (uintmax_t)phdr.p_offset, (uintmax_t)phdr.p_vaddr, \
(uintmax_t)phdr.p_filesz, (uintmax_t)phdr.p_memsz, \ (uintmax_t)phdr.p_paddr, (uintmax_t)phdr.p_filesz, \
(uintmax_t)phdr.p_memsz, \
phdr.p_flags & PF_R ? 'R' : ' ', \ phdr.p_flags & PF_R ? 'R' : ' ', \
phdr.p_flags & PF_W ? 'W' : ' ', \ phdr.p_flags & PF_W ? 'W' : ' ', \
phdr.p_flags & PF_X ? 'E' : ' ', \ phdr.p_flags & PF_X ? 'E' : ' ', \