From 82c1e01f57579f48fddf12447c9e508ed1d4691f Mon Sep 17 00:00:00 2001 From: Eric B Munson Date: Mon, 14 Jun 2010 14:56:33 +0100 Subject: [PATCH] --- yaml --- r: 205263 b: refs/heads/master c: 70c3856b2f1304e0abc65f1b96a8c60ddfc0fb9e h: refs/heads/master i: 205261: cf07e50dec857d2ee04e375671854cdf2e8253c3 205259: d4a724a769df76a18de1c5b4cd3a4bc27d28b6b6 205255: 6954debd5f8ba6d573561b9d4d85690587c33f64 205247: 146a675d26d350cc388465740a2fea314c403631 v: v3 --- [refs] | 2 +- trunk/tools/perf/util/symbol.c | 37 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/[refs] b/[refs] index 42f94b9d4edf..c34147facaf1 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: cf103a14dd2ab23f847e998c8881ea4a5f8090bf +refs/heads/master: 70c3856b2f1304e0abc65f1b96a8c60ddfc0fb9e diff --git a/trunk/tools/perf/util/symbol.c b/trunk/tools/perf/util/symbol.c index b63e5713849f..971d0a05d6b4 100644 --- a/trunk/tools/perf/util/symbol.c +++ b/trunk/tools/perf/util/symbol.c @@ -933,6 +933,25 @@ static bool elf_sec__is_a(GElf_Shdr *self, Elf_Data *secstrs, enum map_type type } } +static size_t elf_addr_to_index(Elf *elf, GElf_Addr addr) +{ + Elf_Scn *sec = NULL; + GElf_Shdr shdr; + size_t cnt = 1; + + while ((sec = elf_nextscn(elf, sec)) != NULL) { + gelf_getshdr(sec, &shdr); + + if ((addr >= shdr.sh_addr) && + (addr < (shdr.sh_addr + shdr.sh_size))) + return cnt; + + ++cnt; + } + + return -1; +} + static int dso__load_sym(struct dso *self, struct map *map, const char *name, int fd, symbol_filter_t filter, int kmodule) { @@ -944,12 +963,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, int err = -1; uint32_t idx; GElf_Ehdr ehdr; - GElf_Shdr shdr; - Elf_Data *syms; + GElf_Shdr shdr, opdshdr; + Elf_Data *syms, *opddata = NULL; GElf_Sym sym; - Elf_Scn *sec, *sec_strndx; + Elf_Scn *sec, *sec_strndx, *opdsec; Elf *elf; int nr = 0; + size_t opdidx = 0; elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); if (elf == NULL) { @@ -969,6 +989,10 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, goto out_elf_end; } + opdsec = elf_section_by_name(elf, &ehdr, &opdshdr, ".opd", &opdidx); + if (opdsec) + opddata = elf_rawdata(opdsec, NULL); + syms = elf_getdata(sec, NULL); if (syms == NULL) goto out_elf_end; @@ -1013,6 +1037,13 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, if (!is_label && !elf_sym__is_a(&sym, map->type)) continue; + if (opdsec && sym.st_shndx == opdidx) { + u32 offset = sym.st_value - opdshdr.sh_addr; + u64 *opd = opddata->d_buf + offset; + sym.st_value = *opd; + sym.st_shndx = elf_addr_to_index(elf, sym.st_value); + } + sec = elf_getscn(elf, sym.st_shndx); if (!sec) goto out_elf_end;