summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2016-01-25 04:22:01 +0000
committeremaste <emaste@FreeBSD.org>2016-01-25 04:22:01 +0000
commitaa1ae9936261cc033254821a7064bcf4f2325a66 (patch)
tree769d217e9bf45d509dce7262a4290cd14cac9b94 /usr.bin
parent246c221ba317dc51a5f4c1d17a91f86e1542ad61 (diff)
downloadFreeBSD-src-aa1ae9936261cc033254821a7064bcf4f2325a66.zip
FreeBSD-src-aa1ae9936261cc033254821a7064bcf4f2325a66.tar.gz
elfdump: handle STT_SPARC_REGISTER
STT_SPARC_REGISTER is a SPARC-specific symbol type specified by the Sparcv9 ABI to provide some information on register use by the object. Also rework st_info type lookup to avoid out-of-bounds array access. MFC after: 1 week Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/elfdump/elfdump.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/usr.bin/elfdump/elfdump.c b/usr.bin/elfdump/elfdump.c
index 908c699..e42727a 100644
--- a/usr.bin/elfdump/elfdump.c
+++ b/usr.bin/elfdump/elfdump.c
@@ -408,9 +408,27 @@ static const char *sh_flags[] = {
"SHF_WRITE|SHF_ALLOC|SHF_EXECINSTR"
};
-static const char *st_types[] = {
- "STT_NOTYPE", "STT_OBJECT", "STT_FUNC", "STT_SECTION", "STT_FILE"
-};
+static const char *
+st_type(unsigned int mach, unsigned int type)
+{
+ static char s_type[32];
+
+ switch (type) {
+ case STT_NOTYPE: return "STT_NOTYPE";
+ case STT_OBJECT: return "STT_OBJECT";
+ case STT_FUNC: return "STT_FUNC";
+ case STT_SECTION: return "STT_SECTION";
+ case STT_FILE: return "STT_FILE";
+ case STT_COMMON: return "STT_COMMON";
+ case STT_TLS: return "STT_TLS";
+ case 13:
+ if (mach == EM_SPARCV9)
+ return "STT_SPARC_REGISTER";
+ break;
+ }
+ snprintf(s_type, sizeof(s_type), "<unknown: %#x>", type);
+ return (s_type);
+}
static const char *st_bindings[] = {
"STB_LOCAL", "STB_GLOBAL", "STB_WEAK"
@@ -824,6 +842,7 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh)
static void
elf_print_symtab(Elf32_Ehdr *e, void *sh, char *str)
{
+ u_int64_t machine;
u_int64_t offset;
u_int64_t entsize;
u_int64_t size;
@@ -835,6 +854,7 @@ elf_print_symtab(Elf32_Ehdr *e, void *sh, char *str)
int len;
int i;
+ machine = elf_get_quarter(e, e, E_MACHINE);
offset = elf_get_off(e, sh, SH_OFFSET);
entsize = elf_get_size(e, sh, SH_ENTSIZE);
size = elf_get_size(e, sh, SH_SIZE);
@@ -854,7 +874,7 @@ elf_print_symtab(Elf32_Ehdr *e, void *sh, char *str)
fprintf(out, "\tst_value: %#jx\n", value);
fprintf(out, "\tst_size: %jd\n", (intmax_t)size);
fprintf(out, "\tst_info: %s %s\n",
- st_types[ELF32_ST_TYPE(info)],
+ st_type(machine, ELF32_ST_TYPE(info)),
st_bindings[ELF32_ST_BIND(info)]);
fprintf(out, "\tst_shndx: %jd\n", (intmax_t)shndx);
}
OpenPOWER on IntegriCloud