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

perf dwarf-regs: Pass ELF flags to get_dwarf_regstr

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-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
a784847c 9fc4489a

+17 -13
+2 -1
tools/perf/util/dwarf-regs.c
··· 29 29 #define __get_dwarf_regstr(tbl, n) (((n) < ARRAY_SIZE(tbl)) ? (tbl)[(n)] : NULL) 30 30 31 31 /* Return architecture dependent register string (for kprobe-tracer) */ 32 - const char *get_dwarf_regstr(unsigned int n, unsigned int machine) 32 + const char *get_dwarf_regstr(unsigned int n, unsigned int machine, 33 + unsigned int flags __maybe_unused) 33 34 { 34 35 switch (machine) { 35 36 case EM_NONE: /* Generic arch - use host arch */
+6 -5
tools/perf/util/include/dwarf-regs.h
··· 90 90 91 91 #ifdef HAVE_LIBDW_SUPPORT 92 92 const char *get_arch_regstr(unsigned int n); 93 - /* 94 - * get_dwarf_regstr - Returns ftrace register string from DWARF regnum 95 - * n: DWARF register number 96 - * machine: ELF machine signature (EM_*) 93 + /** 94 + * get_dwarf_regstr() - Returns ftrace register string from DWARF regnum. 95 + * @n: DWARF register number. 96 + * @machine: ELF machine signature (EM_*). 97 + * @flags: ELF flags for things like ABI differences. 97 98 */ 98 - const char *get_dwarf_regstr(unsigned int n, unsigned int machine); 99 + const char *get_dwarf_regstr(unsigned int n, unsigned int machine, unsigned int flags); 99 100 100 101 int get_arch_regnum(const char *name); 101 102 /*
+7 -6
tools/perf/util/probe-finder.c
··· 56 56 */ 57 57 static int convert_variable_location(Dwarf_Die *vr_die, Dwarf_Addr addr, 58 58 Dwarf_Op *fb_ops, Dwarf_Die *sp_die, 59 - unsigned int machine, 59 + const struct probe_finder *pf, 60 60 struct probe_trace_arg *tvar) 61 61 { 62 62 Dwarf_Attribute attr; ··· 166 166 if (!tvar) 167 167 return ret2; 168 168 169 - regs = get_dwarf_regstr(regn, machine); 169 + regs = get_dwarf_regstr(regn, pf->e_machine, pf->e_flags); 170 170 if (!regs) { 171 171 /* This should be a bug in DWARF or this tool */ 172 172 pr_warning("Mapping for the register number %u " ··· 451 451 dwarf_diename(vr_die)); 452 452 453 453 ret = convert_variable_location(vr_die, pf->addr, pf->fb_ops, 454 - &pf->sp_die, pf->machine, pf->tvar); 454 + &pf->sp_die, pf, pf->tvar); 455 455 if (ret == -ENOENT && pf->skip_empty_arg) 456 456 /* This can be found in other place. skip it */ 457 457 return 0; ··· 1134 1134 if (gelf_getehdr(elf, &ehdr) == NULL) 1135 1135 return -EINVAL; 1136 1136 1137 - pf->machine = ehdr.e_machine; 1137 + pf->e_machine = ehdr.e_machine; 1138 + pf->e_flags = ehdr.e_flags; 1138 1139 1139 1140 do { 1140 1141 GElf_Shdr shdr; ··· 1172 1171 (tag == DW_TAG_variable && vf->vars)) { 1173 1172 if (convert_variable_location(die_mem, vf->pf->addr, 1174 1173 vf->pf->fb_ops, &pf->sp_die, 1175 - pf->machine, NULL) == 0) { 1174 + pf, /*tvar=*/NULL) == 0) { 1176 1175 vf->args[vf->nargs].var = (char *)dwarf_diename(die_mem); 1177 1176 if (vf->args[vf->nargs].var == NULL) { 1178 1177 vf->ret = -ENOMEM; ··· 1403 1402 tag == DW_TAG_variable) { 1404 1403 ret = convert_variable_location(die_mem, af->pf.addr, 1405 1404 af->pf.fb_ops, &af->pf.sp_die, 1406 - af->pf.machine, NULL); 1405 + &af->pf, /*tvar=*/NULL); 1407 1406 if (ret == 0 || ret == -ERANGE) { 1408 1407 int ret2; 1409 1408 bool externs = !af->child;
+2 -1
tools/perf/util/probe-finder.h
··· 68 68 /* Call Frame Information from .debug_frame. Not owned. */ 69 69 Dwarf_CFI *cfi_dbg; 70 70 Dwarf_Op *fb_ops; /* Frame base attribute */ 71 - unsigned int machine; /* Target machine arch */ 71 + unsigned int e_machine; /* ELF target machine arch */ 72 + unsigned int e_flags; /* ELF target machine flags */ 72 73 struct perf_probe_arg *pvar; /* Current target variable */ 73 74 struct probe_trace_arg *tvar; /* Current result variable */ 74 75 bool skip_empty_arg; /* Skip non-exist args */