History

perf annotate: Fix parsing aarch64 branch instructions after objdump update

Starting with binutils 2.28, aarch64 objdump adds comments to the disassembly output to show the alternative names of a condition code [1]. It is assumed that commas in objdump comments could occur in other arches now or in the future, so this fix is arch-independent. The fix could have been done with arm64 specific jump__parse and jump__scnprintf functions, but the jump__scnprintf instruction would have to have its comment character be a literal, since the scnprintf functions cannot receive a struct arch easily. This inconvenience also applies to the generic jump__scnprintf, which is why we add a raw_comment pointer to struct ins_operands, so the __parse function assigns it to be re-used by its corresponding __scnprintf function. Example differences in 'perf annotate --stdio2' output on an aarch64 perf.data file: BEFORE: → b.cs ffff200008133d1c <unwind_frame+0x18c> // b.hs, dffff7ecc47b AFTER : ↓ b.cs 18c BEFORE: → b.cc ffff200008d8d9cc <get_alloc_profile+0x31c> // b.lo, b.ul, dffff727295b AFTER : ↓ b.cc 31c The branch target labels 18c and 31c also now appear in the output: BEFORE: add x26, x29, #0x80 AFTER : 18c: add x26, x29, #0x80 BEFORE: add x21, x21, #0x8 AFTER : 31c: add x21, x21, #0x8 The Fixes: tag below is added so stable branches will get the update; it doesn't necessarily mean that commit was broken at the time, rather it didn't withstand the aarch64 objdump update. Tested no difference in output for sample x86_64, power arch perf.data files. [1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=bb7eff5206e4795ac79c177a80fe9f4630aaf730

Kim Phillips committed 8 years ago

Commit 4e67b2a1 parent fa694162 files · +22 −1Browse files

Unified · Split

2 files
  1. tools/perf/util/annotate.c +21 −1
  2. tools/perf/util/annotate.h +1 −0
tools/perf/util/annotate.c+21−1
@@ -282,7 +282,19 @@ bool ins__is_call(const struct ins *ins) · 281 unmodified lines
282282 return ins->ops == &call_ops || ins->ops == &s390_call_ops;
283283 }
284284
285−static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms)
285+/*
286+ * Prevents from matching commas in the comment section, e.g.:
287+ * ffff200008446e70: b.cs ffff2000084470f4 <generic_exec_single+0x314> // b.hs, b.nlast
288+ */
289+static inline const char *validate_comma(const char *c, struct ins_operands *ops)
290+{
291+ if (ops->raw_comment && c > ops->raw_comment)
292+ return NULL;
293+
294+ return c;
295+}
296+
297+static int jump__parse(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms)
286298 {
287299 struct map *map = ms->map;
288300 struct symbol *sym = ms->sym;
@@ -291,6 +303,10 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 2 unmodified lines
291303 };
292304 const char *c = strchr(ops->raw, ',');
293305 u64 start, end;
306+
307+ ops->raw_comment = strchr(ops->raw, arch->objdump.comment_char);
308+ c = validate_comma(c, ops);
309+
294310 /*
295311 * Examples of lines to parse for the _cpp_lex_token@@Base
296312 * function:
@@ -310,6 +326,7 @@ static int jump__parse(struct arch *arch __maybe_unused, struct ins_operands *op · 13 unmodified lines
310326 ops->target.addr = strtoull(c, NULL, 16);
311327 if (!ops->target.addr) {
312328 c = strchr(c, ',');
329+ c = validate_comma(c, ops);
313330 if (c++ != NULL)
314331 ops->target.addr = strtoull(c, NULL, 16);
315332 }
@@ -367,9 +384,12 @@ static int jump__scnprintf(struct ins *ins, char *bf, size_t size, · 51 unmodified lines
367384 return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name);
368385
369386 c = strchr(ops->raw, ',');
387+ c = validate_comma(c, ops);
388+
370389 if (c != NULL) {
371390 const char *c2 = strchr(c + 1, ',');
372391
392+ c2 = validate_comma(c2, ops);
373393 /* check for 3-op insn */
374394 if (c2 != NULL)
375395 c = c2;
tools/perf/util/annotate.h+1−0
@@ -22,6 +22,7 @@ struct ins { · 21 unmodified lines
2222
2323 struct ins_operands {
2424 char *raw;
25+ char *raw_comment;
2526 struct {
2627 char *raw;
2728 char *name;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t