aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKirill Smelkov <kirr@landau.phys.spbu.ru>2010-02-03 13:52:07 -0500
committerIngo Molnar <mingo@elte.hu>2010-02-04 03:33:27 -0500
commit7a2b6209863626cf8362e5ff4653491558f91e67 (patch)
tree76c8c3b92577033814c7bf4dce1858fc682fbf32 /tools
parent29a9f66d703cb9464e24084e09edab5683e1b6b8 (diff)
perf annotate: Fix it for non-prelinked *.so
The problem was we were incorrectly calculating objdump addresses for sym->start and sym->end, look: For simple ET_DYN type DSO (*.so) with one function, objdump -dS output is something like this: 000004ac <my_strlen>: int my_strlen(const char *s) 4ac: 55 push %ebp 4ad: 89 e5 mov %esp,%ebp 4af: 83 ec 10 sub $0x10,%esp { i.e. we have relative-to-dso-mapping IPs (=RIP) there. For ET_EXEC type and probably for prelinked libs as well (sorry can't test - I don't use prelink) objdump outputs absolute IPs, e.g. 08048604 <zz_strlen>: extern "C" int zz_strlen(const char *s) 8048604: 55 push %ebp 8048605: 89 e5 mov %esp,%ebp 8048607: 83 ec 10 sub $0x10,%esp { So, if sym->start is always relative to dso mapping(*), we'll have to unmap it for ET_EXEC like cases, and leave as is for ET_DYN cases. (*) and it is - we've explicitely made it relative. Look for adjust_symbols handling in dso__load_sym() Previously we were always unmapping sym->start and for ET_DYN dsos resulting addresses were wrong, and so objdump output was empty. The end result was that perf annotate output for symbols from non-prelinked *.so had always 0.00% percents only, which is wrong. To fix it, let's introduce a helper for converting rip to objdump address, and also let's document what map_ip() and unmap_ip() do -- I had to study sources for several hours to understand it. Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <1265223128-11786-8-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-annotate.c5
-rw-r--r--tools/perf/util/map.c12
-rw-r--r--tools/perf/util/map.h9
3 files changed, 24 insertions, 2 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 4fc3899bf83a..28ea4e0c3658 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -189,7 +189,7 @@ static int parse_line(FILE *file, struct hist_entry *he, u64 len)
189 line_ip = -1; 189 line_ip = -1;
190 } 190 }
191 191
192 start = he->map->unmap_ip(he->map, sym->start); 192 start = map__rip_2objdump(he->map, sym->start);
193 193
194 if (line_ip != -1) { 194 if (line_ip != -1) {
195 const char *path = NULL; 195 const char *path = NULL;
@@ -397,7 +397,8 @@ static void annotate_sym(struct hist_entry *he)
397 dso, dso->long_name, sym, sym->name); 397 dso, dso->long_name, sym, sym->name);
398 398
399 sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s", 399 sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
400 map->unmap_ip(map, sym->start), map->unmap_ip(map, sym->end), 400 map__rip_2objdump(map, sym->start),
401 map__rip_2objdump(map, sym->end),
401 filename, filename); 402 filename, filename);
402 403
403 if (verbose >= 3) 404 if (verbose >= 3)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f6626cc3df2e..af5805f51314 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -210,3 +210,15 @@ size_t map__fprintf(struct map *self, FILE *fp)
210 return fprintf(fp, " %Lx-%Lx %Lx %s\n", 210 return fprintf(fp, " %Lx-%Lx %Lx %s\n",
211 self->start, self->end, self->pgoff, self->dso->name); 211 self->start, self->end, self->pgoff, self->dso->name);
212} 212}
213
214/*
215 * objdump wants/reports absolute IPs for ET_EXEC, and RIPs for ET_DYN.
216 * map->dso->adjust_symbols==1 for ET_EXEC-like cases.
217 */
218u64 map__rip_2objdump(struct map *map, u64 rip)
219{
220 u64 addr = map->dso->adjust_symbols ?
221 map->unmap_ip(map, rip) : /* RIP -> IP */
222 rip;
223 return addr;
224}
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index de048399d776..9cee9c788dbf 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -26,8 +26,12 @@ struct map {
26 u64 end; 26 u64 end;
27 enum map_type type; 27 enum map_type type;
28 u64 pgoff; 28 u64 pgoff;
29
30 /* ip -> dso rip */
29 u64 (*map_ip)(struct map *, u64); 31 u64 (*map_ip)(struct map *, u64);
32 /* dso rip -> ip */
30 u64 (*unmap_ip)(struct map *, u64); 33 u64 (*unmap_ip)(struct map *, u64);
34
31 struct dso *dso; 35 struct dso *dso;
32}; 36};
33 37
@@ -56,6 +60,11 @@ static inline u64 identity__map_ip(struct map *map __used, u64 ip)
56 return ip; 60 return ip;
57} 61}
58 62
63
64/* rip -> addr suitable for passing to `objdump --start-address=` */
65u64 map__rip_2objdump(struct map *map, u64 rip);
66
67
59struct symbol; 68struct symbol;
60struct mmap_event; 69struct mmap_event;
61 70