Date: Mon, 25 Jan 2016 04:22:01 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r294699 - head/usr.bin/elfdump Message-ID: <201601250422.u0P4M1iI037337@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Mon Jan 25 04:22:01 2016 New Revision: 294699 URL: https://svnweb.freebsd.org/changeset/base/294699 Log: 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 Modified: head/usr.bin/elfdump/elfdump.c Modified: head/usr.bin/elfdump/elfdump.c ============================================================================== --- head/usr.bin/elfdump/elfdump.c Mon Jan 25 00:24:57 2016 (r294698) +++ head/usr.bin/elfdump/elfdump.c Mon Jan 25 04:22:01 2016 (r294699) @@ -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 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 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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601250422.u0P4M1iI037337>