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:
parent
c14beb6822
commit
b385405966
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=269092
@ -303,7 +303,10 @@ static const char *p_flags[] = {
|
||||
|
||||
/* http://www.sco.com/developers/gabi/latest/ch4.sheader.html#sh_type */
|
||||
static const char *
|
||||
sh_types(u_int64_t sht) {
|
||||
sh_types(uint64_t machine, uint64_t sht) {
|
||||
static char unknown_buf[64];
|
||||
|
||||
if (sht < 0x60000000) {
|
||||
switch (sht) {
|
||||
case 0: return "SHT_NULL";
|
||||
case 1: return "SHT_PROGBITS";
|
||||
@ -322,7 +325,13 @@ sh_types(u_int64_t sht) {
|
||||
case 16: return "SHT_PREINIT_ARRAY";
|
||||
case 17: return "SHT_GROUP";
|
||||
case 18: return "SHT_SYMTAB_SHNDX";
|
||||
/* 0x60000000 - 0x6fffffff operating system-specific semantics */
|
||||
}
|
||||
snprintf(unknown_buf, sizeof(unknown_buf),
|
||||
"ERROR: SHT %ju NOT DEFINED", (uintmax_t)sht);
|
||||
return (unknown_buf);
|
||||
} else if (sht < 0x70000000) {
|
||||
/* 0x60000000-0x6fffffff operating system-specific semantics */
|
||||
switch (sht) {
|
||||
case 0x6ffffff0: return "XXX:VERSYM";
|
||||
case 0x6ffffff4: return "SHT_SUNW_dof";
|
||||
case 0x6ffffff7: return "SHT_GNU_LIBLIST";
|
||||
@ -330,13 +339,40 @@ sh_types(u_int64_t sht) {
|
||||
case 0x6ffffffd: return "SHT_SUNW(GNU)_verdef";
|
||||
case 0x6ffffffe: return "SHT_SUNW(GNU)_verneed";
|
||||
case 0x6fffffff: return "SHT_SUNW(GNU)_versym";
|
||||
/* 0x70000000 - 0x7fffffff processor-specific semantics */
|
||||
}
|
||||
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";
|
||||
/* 0x80000000 - 0xffffffff application programs */
|
||||
default: return "ERROR: SHT NOT DEFINED";
|
||||
}
|
||||
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 addralign;
|
||||
u_int64_t entsize;
|
||||
u_int64_t machine;
|
||||
void *v;
|
||||
int i;
|
||||
|
||||
@ -712,6 +749,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
|
||||
return;
|
||||
}
|
||||
|
||||
machine = elf_get_quarter(e, e, E_MACHINE);
|
||||
shentsize = elf_get_quarter(e, e, E_SHENTSIZE);
|
||||
shnum = elf_get_shnum(e, sh);
|
||||
fprintf(out, "\nsection header:\n");
|
||||
@ -730,7 +768,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
|
||||
fprintf(out, "\n");
|
||||
fprintf(out, "entry: %d\n", i);
|
||||
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_addr: %#jx\n", addr);
|
||||
fprintf(out, "\tsh_offset: %jd\n", (intmax_t)offset);
|
||||
|
Loading…
Reference in New Issue
Block a user