elfdump: Improve section type reporting

The SHT range 0x70000000-0x7fffffff is processor-specific.  Pass the
ELF machine type header to sh_types so the section header type name can
be reported correctly for the given processor.

For all ranges report the actual value for unknown types.

Add MIPS-specific type SHT_MIPS_OPTIONS.

CR:		D483
Reviewed by:	sbruno, marcel
Sponsored by:	DARPA, AFRL
This commit is contained in:
Ed Maste 2014-07-25 18:20:56 +00:00
parent c14beb6822
commit b385405966
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269092

View File

@ -303,40 +303,76 @@ static const char *p_flags[] = {
/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */ /* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */
static const char * static const char *
sh_types(u_int64_t sht) { sh_types(uint64_t machine, uint64_t sht) {
switch (sht) { static char unknown_buf[64];
case 0: return "SHT_NULL";
case 1: return "SHT_PROGBITS"; if (sht < 0x60000000) {
case 2: return "SHT_SYMTAB"; switch (sht) {
case 3: return "SHT_STRTAB"; case 0: return "SHT_NULL";
case 4: return "SHT_RELA"; case 1: return "SHT_PROGBITS";
case 5: return "SHT_HASH"; case 2: return "SHT_SYMTAB";
case 6: return "SHT_DYNAMIC"; case 3: return "SHT_STRTAB";
case 7: return "SHT_NOTE"; case 4: return "SHT_RELA";
case 8: return "SHT_NOBITS"; case 5: return "SHT_HASH";
case 9: return "SHT_REL"; case 6: return "SHT_DYNAMIC";
case 10: return "SHT_SHLIB"; case 7: return "SHT_NOTE";
case 11: return "SHT_DYNSYM"; case 8: return "SHT_NOBITS";
case 14: return "SHT_INIT_ARRAY"; case 9: return "SHT_REL";
case 15: return "SHT_FINI_ARRAY"; case 10: return "SHT_SHLIB";
case 16: return "SHT_PREINIT_ARRAY"; case 11: return "SHT_DYNSYM";
case 17: return "SHT_GROUP"; case 14: return "SHT_INIT_ARRAY";
case 18: return "SHT_SYMTAB_SHNDX"; case 15: return "SHT_FINI_ARRAY";
/* 0x60000000 - 0x6fffffff operating system-specific semantics */ case 16: return "SHT_PREINIT_ARRAY";
case 0x6ffffff0: return "XXX:VERSYM"; case 17: return "SHT_GROUP";
case 0x6ffffff4: return "SHT_SUNW_dof"; case 18: return "SHT_SYMTAB_SHNDX";
case 0x6ffffff7: return "SHT_GNU_LIBLIST"; }
case 0x6ffffffc: return "XXX:VERDEF"; snprintf(unknown_buf, sizeof(unknown_buf),
case 0x6ffffffd: return "SHT_SUNW(GNU)_verdef"; "ERROR: SHT %ju NOT DEFINED", (uintmax_t)sht);
case 0x6ffffffe: return "SHT_SUNW(GNU)_verneed"; return (unknown_buf);
case 0x6fffffff: return "SHT_SUNW(GNU)_versym"; } else if (sht < 0x70000000) {
/* 0x70000000 - 0x7fffffff processor-specific semantics */ /* 0x60000000-0x6fffffff operating system-specific semantics */
case 0x70000000: return "SHT_IA_64_EXT"; switch (sht) {
case 0x70000001: return "SHT_IA_64_UNWIND"; case 0x6ffffff0: return "XXX:VERSYM";
case 0x7ffffffd: return "XXX:AUXILIARY"; case 0x6ffffff4: return "SHT_SUNW_dof";
case 0x7fffffff: return "XXX:FILTER"; case 0x6ffffff7: return "SHT_GNU_LIBLIST";
/* 0x80000000 - 0xffffffff application programs */ case 0x6ffffffc: return "XXX:VERDEF";
default: return "ERROR: SHT NOT DEFINED"; case 0x6ffffffd: return "SHT_SUNW(GNU)_verdef";
case 0x6ffffffe: return "SHT_SUNW(GNU)_verneed";
case 0x6fffffff: return "SHT_SUNW(GNU)_versym";
}
snprintf(unknown_buf, sizeof(unknown_buf),
"ERROR: OS-SPECIFIC SHT 0x%jx NOT DEFINED",
(uintmax_t)sht);
return (unknown_buf);
} else if (sht < 0x80000000) {
/* 0x70000000-0x7fffffff processor-specific semantics */
switch (machine) {
case EM_MIPS:
switch (sht) {
case 0x7000000d: return "SHT_MIPS_OPTIONS";
}
break;
case EM_IA_64:
switch (sht) {
case 0x70000000: return "SHT_IA_64_EXT";
case 0x70000001: return "SHT_IA_64_UNWIND";
}
break;
}
switch (sht) {
case 0x7ffffffd: return "XXX:AUXILIARY";
case 0x7fffffff: return "XXX:FILTER";
}
snprintf(unknown_buf, sizeof(unknown_buf),
"ERROR: PROCESSOR-SPECIFIC SHT 0x%jx NOT DEFINED",
(uintmax_t)sht);
return (unknown_buf);
} else {
/* 0x80000000-0xffffffff application programs */
snprintf(unknown_buf, sizeof(unknown_buf),
"ERROR: SHT 0x%jx NOT DEFINED",
(uintmax_t)sht);
return (unknown_buf);
} }
} }
@ -704,6 +740,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
u_int64_t info; u_int64_t info;
u_int64_t addralign; u_int64_t addralign;
u_int64_t entsize; u_int64_t entsize;
u_int64_t machine;
void *v; void *v;
int i; int i;
@ -712,6 +749,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
return; return;
} }
machine = elf_get_quarter(e, e, E_MACHINE);
shentsize = elf_get_quarter(e, e, E_SHENTSIZE); shentsize = elf_get_quarter(e, e, E_SHENTSIZE);
shnum = elf_get_shnum(e, sh); shnum = elf_get_shnum(e, sh);
fprintf(out, "\nsection header:\n"); fprintf(out, "\nsection header:\n");
@ -730,7 +768,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
fprintf(out, "\n"); fprintf(out, "\n");
fprintf(out, "entry: %d\n", i); fprintf(out, "entry: %d\n", i);
fprintf(out, "\tsh_name: %s\n", shstrtab + name); fprintf(out, "\tsh_name: %s\n", shstrtab + name);
fprintf(out, "\tsh_type: %s\n", sh_types(type)); fprintf(out, "\tsh_type: %s\n", sh_types(machine, type));
fprintf(out, "\tsh_flags: %s\n", sh_flags[flags & 0x7]); fprintf(out, "\tsh_flags: %s\n", sh_flags[flags & 0x7]);
fprintf(out, "\tsh_addr: %#jx\n", addr); fprintf(out, "\tsh_addr: %#jx\n", addr);
fprintf(out, "\tsh_offset: %jd\n", (intmax_t)offset); fprintf(out, "\tsh_offset: %jd\n", (intmax_t)offset);