aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-04-07 06:24:30 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-08 08:58:14 -0400
commita58f7033ba892b7d299954b94471450d72623039 (patch)
treed04a4d8230b6231447ad736465429be145b2e489 /tools/perf
parent1b700c9975008615ad470cf79acc8455ce60a695 (diff)
perf symbols: Record text offset in dso to calculate objdump address
In this patch, the offset of '.text' section is stored into dso and used here to re-calculate address to objdump. In most of the cases, executable code is in '.text' section, so the adjustment made to a symbol in dso__load_sym (using sym.st_value -= shdr.sh_addr - shdr.sh_offset) should equal to 'sym.st_value -= dso->text_offset'. Therefore, adding text_offset back get objdump address from symbol address (rip). However, it is not true for kernel and kernel module since there could be multiple executable sections with different offset. Exclude kernel for this reason. After this patch, even dso->adjust_symbols is set to true for shared objects, map__rip_2objdump() and map__objdump_2mem() would return correct result, so perf behavior of annotate won't be changed. Signed-off-by: Wang Nan <wangnan0@huawei.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Cody P Schafer <dev@codyps.com> Cc: He Kuang <hekuang@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kirill Smelkov <kirr@nexedi.com> Cc: Li Zefan <lizefan@huawei.com> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1460024671-64774-2-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/map.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 171b6d10a04b..02c31865648b 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -431,6 +431,13 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
431 if (map->dso->rel) 431 if (map->dso->rel)
432 return rip - map->pgoff; 432 return rip - map->pgoff;
433 433
434 /*
435 * kernel modules also have DSO_TYPE_USER in dso->kernel,
436 * but all kernel modules are ET_REL, so won't get here.
437 */
438 if (map->dso->kernel == DSO_TYPE_USER)
439 return rip + map->dso->text_offset;
440
434 return map->unmap_ip(map, rip) - map->reloc; 441 return map->unmap_ip(map, rip) - map->reloc;
435} 442}
436 443
@@ -454,6 +461,13 @@ u64 map__objdump_2mem(struct map *map, u64 ip)
454 if (map->dso->rel) 461 if (map->dso->rel)
455 return map->unmap_ip(map, ip + map->pgoff); 462 return map->unmap_ip(map, ip + map->pgoff);
456 463
464 /*
465 * kernel modules also have DSO_TYPE_USER in dso->kernel,
466 * but all kernel modules are ET_REL, so won't get here.
467 */
468 if (map->dso->kernel == DSO_TYPE_USER)
469 return map->unmap_ip(map, ip - map->dso->text_offset);
470
457 return ip + map->reloc; 471 return ip + map->reloc;
458} 472}
459 473