From ceca8c72bfc921bdfc339ad82bcbb56affa10b2d Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 25 Aug 2015 01:49:09 +0200 Subject: [PATCH] nixprof: make it work with ELF64 --- core/deps/libelf/elf.h | 9 +++++++++ core/linux/nixprof/nixprof.cpp | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/deps/libelf/elf.h b/core/deps/libelf/elf.h index 4b574234d..5c1e79256 100644 --- a/core/deps/libelf/elf.h +++ b/core/deps/libelf/elf.h @@ -116,6 +116,15 @@ struct elf_symbol { uint16_t st_shndx; // Section index }; +struct elf64_symbol { + uint32_t st_name; + unsigned char st_info; + unsigned char st_other; + uint16_t st_shndx; + uint64_t st_value; + uint64_t st_size; +}; + /* * constants for Elf32_Phdr.p_flags */ diff --git a/core/linux/nixprof/nixprof.cpp b/core/linux/nixprof/nixprof.cpp index c5eb4e9c6..7b2934a36 100644 --- a/core/linux/nixprof/nixprof.cpp +++ b/core/linux/nixprof/nixprof.cpp @@ -3,6 +3,7 @@ #if FEAT_HAS_NIXPROF #include "cfg/cfg.h" +#include #include #include @@ -178,16 +179,24 @@ static void elf_syms(FILE* out,const char* libfile) prof_head(out,"libsym",libfile); // printf("Found dymsym %d, and dynstr %d!\n",dynsym,dynstr); elf_symbol* sym=(elf_symbol*)elf_getSection(data,dynsym); - int symcnt=elf_getSectionSize(data,dynsym)/sizeof(elf_symbol); + elf64_symbol* sym64 = (elf64_symbol*) sym; - for (int i=0;ie_ident[EI_CLASS] == ELFCLASS32; + size_t symbol_size = elf32 ? sizeof(elf_symbol) : sizeof(elf64_symbol); + int symcnt = elf_getSectionSize(data,dynsym) / symbol_size; + + for (int i=0; i < symcnt; i++) { - if (sym[i].st_value && sym[i].st_name && sym[i].st_shndx) + uint64_t st_value = elf32 ? sym[i].st_value : sym64[i].st_value; + uint32_t st_name = elf32 ? sym[i].st_name : sym64[i].st_name; + uint16_t st_shndx = elf32 ? sym[i].st_shndx : sym64[i].st_shndx; + uint64_t st_size = elf32 ? sym[i].st_size : sym64[i].st_size; + if (st_value && st_name && st_shndx) { char* name=(char*)elf_getSection(data,dynstr);// sym[i].st_shndx - - // printf("Symbol %d: %s, %08X, %d bytes\n",i,name+sym[i].st_name,sym[i].st_value,sym[i].st_size); - fprintf(out,"%08X %d %s\n",sym[i].st_value,sym[i].st_size,name+sym[i].st_name); + // printf("Symbol %d: %s, %08" PRIx64 ", % " PRIi64 " bytes\n", + // i, name + st_name, st_value, st_size); + fprintf(out,"%08" PRIX64 "%" PRIi64 " %s\n", st_value, st_size, name + st_name); } } }