Changeset View
Changeset View
Standalone View
Standalone View
readelf/readelf.c
Show First 20 Lines • Show All 991 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
dump_rel(struct readelf *re, struct section *s, Elf_Data *d) | dump_rel(struct readelf *re, struct section *s, Elf_Data *d) | ||||
{ | { | ||||
GElf_Rel r; | GElf_Rel r; | ||||
const char *symname; | const char *symname; | ||||
uint64_t symval; | uint64_t symval; | ||||
int i, len; | int i, len; | ||||
uint32_t type; | |||||
uint8_t type2, type3; | |||||
if (s->link >= re->shnum) | if (s->link >= re->shnum) | ||||
return; | return; | ||||
#define REL_HDR "r_offset", "r_info", "r_type", "st_value", "st_name" | #define REL_HDR "r_offset", "r_info", "r_type", "st_value", "st_name" | ||||
#define REL_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | #define REL_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | ||||
elftc_reloc_type_str(re->ehdr.e_machine, \ | elftc_reloc_type_str(re->ehdr.e_machine, \ | ||||
ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname | ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname | ||||
#define REL_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | #define REL_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | ||||
elftc_reloc_type_str(re->ehdr.e_machine, \ | elftc_reloc_type_str(re->ehdr.e_machine, type), \ | ||||
ELF64_R_TYPE(r.r_info)), (uintmax_t)symval, symname | (uintmax_t)symval, symname | ||||
printf("\nRelocation section (%s):\n", s->name); | printf("\nRelocation section (%s):\n", s->name); | ||||
if (re->ec == ELFCLASS32) | if (re->ec == ELFCLASS32) | ||||
printf("%-8s %-8s %-19s %-8s %s\n", REL_HDR); | printf("%-8s %-8s %-19s %-8s %s\n", REL_HDR); | ||||
else { | else { | ||||
if (re->options & RE_WW) | if (re->options & RE_WW) | ||||
printf("%-16s %-16s %-24s %-16s %s\n", REL_HDR); | printf("%-16s %-16s %-24s %-16s %s\n", REL_HDR); | ||||
else | else | ||||
Show All 9 Lines | |||||
} | } | ||||
symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); | symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); | ||||
symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); | symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); | ||||
if (re->ec == ELFCLASS32) { | if (re->ec == ELFCLASS32) { | ||||
r.r_info = ELF32_R_INFO(ELF64_R_SYM(r.r_info), | r.r_info = ELF32_R_INFO(ELF64_R_SYM(r.r_info), | ||||
ELF64_R_TYPE(r.r_info)); | ELF64_R_TYPE(r.r_info)); | ||||
printf("%8.8jx %8.8jx %-19.19s %8.8jx %s\n", REL_CT32); | printf("%8.8jx %8.8jx %-19.19s %8.8jx %s\n", REL_CT32); | ||||
} else { | } else { | ||||
type = ELF64_R_TYPE(r.r_info); | |||||
if (re->ehdr.e_machine == EM_MIPS) { | |||||
type2 = (type >> 8) & 0xFF; | |||||
type3 = (type >> 16) & 0xFF; | |||||
type = type & 0xFF; | |||||
} | |||||
if (re->options & RE_WW) | if (re->options & RE_WW) | ||||
printf("%16.16jx %16.16jx %-24.24s" | printf("%16.16jx %16.16jx %-24.24s" | ||||
" %16.16jx %s\n", REL_CT64); | " %16.16jx %s\n", REL_CT64); | ||||
else | else | ||||
printf("%12.12jx %12.12jx %-19.19s" | printf("%12.12jx %12.12jx %-19.19s" | ||||
" %16.16jx %s\n", REL_CT64); | " %16.16jx %s\n", REL_CT64); | ||||
if (re->ehdr.e_machine == EM_MIPS) { | |||||
if (re->options & RE_WW) { | |||||
printf("%32s: %s\n", "Type2", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type2)); | |||||
printf("%32s: %s\n", "Type3", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type3)); | |||||
} else { | |||||
printf("%24s: %s\n", "Type2", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type2)); | |||||
printf("%24s: %s\n", "Type3", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type3)); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
#undef REL_HDR | #undef REL_HDR | ||||
#undef REL_CT | #undef REL_CT | ||||
} | } | ||||
static void | static void | ||||
dump_rela(struct readelf *re, struct section *s, Elf_Data *d) | dump_rela(struct readelf *re, struct section *s, Elf_Data *d) | ||||
{ | { | ||||
GElf_Rela r; | GElf_Rela r; | ||||
const char *symname; | const char *symname; | ||||
uint64_t symval; | uint64_t symval; | ||||
int i, len; | int i, len; | ||||
uint32_t type; | |||||
uint8_t type2, type3; | |||||
if (s->link >= re->shnum) | if (s->link >= re->shnum) | ||||
return; | return; | ||||
#define RELA_HDR "r_offset", "r_info", "r_type", "st_value", \ | #define RELA_HDR "r_offset", "r_info", "r_type", "st_value", \ | ||||
"st_name + r_addend" | "st_name + r_addend" | ||||
#define RELA_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | #define RELA_CT32 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | ||||
elftc_reloc_type_str(re->ehdr.e_machine, \ | elftc_reloc_type_str(re->ehdr.e_machine, \ | ||||
ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname | ELF32_R_TYPE(r.r_info)), (uintmax_t)symval, symname | ||||
#define RELA_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | #define RELA_CT64 (uintmax_t)r.r_offset, (uintmax_t)r.r_info, \ | ||||
elftc_reloc_type_str(re->ehdr.e_machine, \ | elftc_reloc_type_str(re->ehdr.e_machine, type), \ | ||||
ELF64_R_TYPE(r.r_info)), (uintmax_t)symval, symname | (uintmax_t)symval, symname | ||||
printf("\nRelocation section with addend (%s):\n", s->name); | printf("\nRelocation section with addend (%s):\n", s->name); | ||||
if (re->ec == ELFCLASS32) | if (re->ec == ELFCLASS32) | ||||
printf("%-8s %-8s %-19s %-8s %s\n", RELA_HDR); | printf("%-8s %-8s %-19s %-8s %s\n", RELA_HDR); | ||||
else { | else { | ||||
if (re->options & RE_WW) | if (re->options & RE_WW) | ||||
printf("%-16s %-16s %-24s %-16s %s\n", RELA_HDR); | printf("%-16s %-16s %-24s %-16s %s\n", RELA_HDR); | ||||
else | else | ||||
Show All 10 Lines | |||||
symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); | symname = get_symbol_name(re, s->link, GELF_R_SYM(r.r_info)); | ||||
symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); | symval = get_symbol_value(re, s->link, GELF_R_SYM(r.r_info)); | ||||
if (re->ec == ELFCLASS32) { | if (re->ec == ELFCLASS32) { | ||||
r.r_info = ELF32_R_INFO(ELF64_R_SYM(r.r_info), | r.r_info = ELF32_R_INFO(ELF64_R_SYM(r.r_info), | ||||
ELF64_R_TYPE(r.r_info)); | ELF64_R_TYPE(r.r_info)); | ||||
printf("%8.8jx %8.8jx %-19.19s %8.8jx %s", RELA_CT32); | printf("%8.8jx %8.8jx %-19.19s %8.8jx %s", RELA_CT32); | ||||
printf(" + %x\n", (uint32_t) r.r_addend); | printf(" + %x\n", (uint32_t) r.r_addend); | ||||
} else { | } else { | ||||
type = ELF64_R_TYPE(r.r_info); | |||||
if (re->ehdr.e_machine == EM_MIPS) { | |||||
type2 = (type >> 8) & 0xFF; | |||||
type3 = (type >> 16) & 0xFF; | |||||
type = type & 0xFF; | |||||
} | |||||
if (re->options & RE_WW) | if (re->options & RE_WW) | ||||
printf("%16.16jx %16.16jx %-24.24s" | printf("%16.16jx %16.16jx %-24.24s" | ||||
" %16.16jx %s", RELA_CT64); | " %16.16jx %s", RELA_CT64); | ||||
else | else | ||||
printf("%12.12jx %12.12jx %-19.19s" | printf("%12.12jx %12.12jx %-19.19s" | ||||
" %16.16jx %s", RELA_CT64); | " %16.16jx %s", RELA_CT64); | ||||
printf(" + %jx\n", (uintmax_t) r.r_addend); | printf(" + %jx\n", (uintmax_t) r.r_addend); | ||||
if (re->ehdr.e_machine == EM_MIPS) { | |||||
if (re->options & RE_WW) { | |||||
printf("%32s: %s\n", "Type2", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type2)); | |||||
printf("%32s: %s\n", "Type3", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type3)); | |||||
} else { | |||||
printf("%24s: %s\n", "Type2", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type2)); | |||||
printf("%24s: %s\n", "Type3", | |||||
elftc_reloc_type_str(EM_MIPS, | |||||
type3)); | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
#undef RELA_HDR | #undef RELA_HDR | ||||
#undef RELA_CT | #undef RELA_CT | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 991 Lines • Show Last 20 Lines |