From 7e5c77863093dc650804c26dfef148d5724ac171 Mon Sep 17 00:00:00 2001 From: Wei Li Date: Wed, 20 Feb 2019 22:15:09 +0800 Subject: [PATCH] perf: fix incorrect change in annotate result hulk inclusion category: bugfix bugzilla: 9583 CVE: NA ------------------------------------------------- The output of "perf annotate -l --stdio xxx" changed since commit 425859ff0de33 ("perf annotate: No need to calculate notes->start twice") removed notes->start assignment in symbol__calc_lines(). It will get failed in find_address_in_section() from symbol__tty_annotate() subroutine as the a2l->addr is wrong. So the annotate summary doesn't report the line number of source code correctly. Before fix: [root@localhost tools]# ./perf/perf record -o perf.data /root/common_while_1 ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.261 MB perf.data (6538 samples) ] [root@localhost tools]# ./perf/perf annotate -i perf.data -l -s hotspot_1 --stdio | less Sorted summary for file /root/common_while_1 ---------------------------------------------- 32.53 common_while_1[3c] 32.26 common_while_1[14] 15.59 common_while_1[38] 14.89 common_while_1[2c] 2.48 common_while_1[48] 1.10 common_while_1[c] 0.58 common_while_1[8] Percent | Source code & Disassembly of common_while_1 for cycles:ppp (2457 samples, percent: local period) ---------------------------------------------------------------------------------------------------------------- : : : : Disassembly of section .text: : : 00000000004008b0 : : hotspot_1(): : for(i = 0; i<=100; i++) { : s_cnt2++; : } : } : : void hotspot_1() { 0.00 : 4008b0: stp x29, x30, [sp,#-32]! 0.00 : 4008b4: mov x29, sp : int i; : while(1) { : hotspot_2(); common_while_1[8] 0.58 : 4008b8: bl 400864 : for(i = 0; i<=100; i++) { common_while_1[c] 1.10 : 4008bc: str wzr, [x29,#28] 0.00 : 4008c0: b 4008ec : s_cnt1++; common_while_1[14] 32.26 : 4008c4: adrp x0, 420000 0.00 : 4008c8: add x0, x0, #0x7c 0.16 : 4008cc: ldr w0, [x0] 0.00 : 4008d0: add w1, w0, #0x1 ... After fix: [root@localhost tools]# ./perf/perf record -o perf.data /root/common_while_1 ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.261 MB perf.data (6538 samples) ] [root@localhost tools]# ./perf/perf annotate -i perf.data -l -s hotspot_1 --stdio | less Sorted summary for file /root/common_while_1 ---------------------------------------------- 50.27 common_while_1.c:37 46.46 common_while_1.c:38 2.79 common_while_1.c:36 Percent | Source code & Disassembly of common_while_1 for cycles:ppp (3149 samples, percent: local period) ---------------------------------------------------------------------------------------------------------------- : : : : Disassembly of section .text: : : 00000000004008b0 : : hotspot_1(): : for(i = 0; i<=100; i++) { : s_cnt2++; : } : } : : void hotspot_1() { 0.00 : 4008b0: stp x29, x30, [sp,#-32]! 0.00 : 4008b4: mov x29, sp : int i; : while(1) { : hotspot_2(); common_while_1.c:36 0.82 : 4008b8: bl 400864 : for(i = 0; i<=100; i++) { common_while_1.c:37 1.17 : 4008bc: str wzr, [x29,#28] 0.00 : 4008c0: b 4008ec : s_cnt1++; common_while_1.c:38 31.33 : 4008c4: adrp x0, 420000 0.00 : 4008c8: add x0, x0, #0x7c 0.19 : 4008cc: ldr w0, [x0] 0.00 : 4008d0: add w1, w0, #0x1 ... Fixes: 425859ff0de33 ("perf annotate: No need to calculate notes->start twice") Signed-off-by: Wei Li Signed-off-by: Wei Li Reviewed-by: Li Bin Signed-off-by: Yang Yingliang --- tools/perf/util/annotate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 28cd6a17491b..dfee110b3a58 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1862,6 +1862,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, struct annotation_options *options, struct arch **parch) { + struct annotation *notes = symbol__annotation(sym); struct annotate_args args = { .privsize = privsize, .evsel = evsel, @@ -1892,6 +1893,7 @@ int symbol__annotate(struct symbol *sym, struct map *map, args.ms.map = map; args.ms.sym = sym; + notes->start = map__rip_2objdump(map, sym->start); return symbol__disassemble(sym, &args); } @@ -2746,8 +2748,6 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *ev symbol__calc_percent(sym, evsel); - notes->start = map__rip_2objdump(map, sym->start); - annotation__set_offsets(notes, size); annotation__mark_jump_targets(notes, sym); annotation__compute_ipc(notes, size); -- GitLab