Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf dwarf-regs: Pass accurate disassembly machine to get_dwarf_regnum

Rather than pass 0/EM_NONE, use the value computed in the disasm
struct arch. Switch the EM_NONE case to EM_HOST, rewriting EM_NONE if
it were passed to get_dwarf_regnum. Pass a flags value as
architectures like csky need the flags to determine the ABI variant.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Shenlin Liang <liangshenlin@eswincomputing.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Guilherme Amadio <amadio@gentoo.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Chen Pei <cp0613@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-riscv@lists.infradead.org
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Atish Patra <atishp@rivosinc.com>
Cc: Dima Kogan <dima@secretsauce.net>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: linux-csky@vger.kernel.org
Link: https://lore.kernel.org/r/20241108234606.429459-6-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
9fc4489a cd6c9dca

+12 -7
+3 -3
tools/perf/util/annotate.c
··· 2292 2292 if (regname == NULL) 2293 2293 return -1; 2294 2294 2295 - op_loc->reg1 = get_dwarf_regnum(regname, 0); 2295 + op_loc->reg1 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags); 2296 2296 free(regname); 2297 2297 2298 2298 /* Get the second register */ ··· 2305 2305 if (regname == NULL) 2306 2306 return -1; 2307 2307 2308 - op_loc->reg2 = get_dwarf_regnum(regname, 0); 2308 + op_loc->reg2 = get_dwarf_regnum(regname, arch->e_machine, arch->e_flags); 2309 2309 free(regname); 2310 2310 } 2311 2311 return 0; ··· 2405 2405 return -1; 2406 2406 2407 2407 if (*s == arch->objdump.register_char) 2408 - op_loc->reg1 = get_dwarf_regnum(s, 0); 2408 + op_loc->reg1 = get_dwarf_regnum(s, arch->e_machine, arch->e_flags); 2409 2409 else if (*s == arch->objdump.imm_char) { 2410 2410 op_loc->offset = strtol(s + 1, &p, 0); 2411 2411 if (p && p != s + 1)
+6 -2
tools/perf/util/dwarf-regs.c
··· 70 70 } 71 71 72 72 /* Return DWARF register number from architecture register name */ 73 - int get_dwarf_regnum(const char *name, unsigned int machine) 73 + int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags __maybe_unused) 74 74 { 75 75 char *regname = strdup(name); 76 76 int reg = -1; ··· 84 84 if (p) 85 85 *p = '\0'; 86 86 87 + if (machine == EM_NONE) { 88 + /* Generic arch - use host arch */ 89 + machine = EM_HOST; 90 + } 87 91 switch (machine) { 88 - case EM_NONE: /* Generic arch - use host arch */ 92 + case EM_HOST: 89 93 reg = get_arch_regnum(regname); 90 94 break; 91 95 default:
+3 -2
tools/perf/util/include/dwarf-regs.h
··· 103 103 * name: architecture register name 104 104 * machine: ELF machine signature (EM_*) 105 105 */ 106 - int get_dwarf_regnum(const char *name, unsigned int machine); 106 + int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags); 107 107 108 108 #else /* HAVE_LIBDW_SUPPORT */ 109 109 110 110 static inline int get_dwarf_regnum(const char *name __maybe_unused, 111 - unsigned int machine __maybe_unused) 111 + unsigned int machine __maybe_unused, 112 + unsigned int flags __maybe_unused) 112 113 { 113 114 return -1; 114 115 }