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

perf riscv: Remove dwarf-regs.c and add dwarf-regs-table.h

The file just provides the function get_arch_regstr, however, if in
the only caller get_dwarf_regstr EM_HOST is used for the EM_NONE case,
and the register table is provided in a header file, the function can
never be called. So remove as dead code. Tidy up the EM_NONE cases for
riscv in dwarf-regs.c.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.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-15-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
a90c4519 285b523c

+12 -30
-1
tools/perf/arch/riscv/util/Build
··· 2 2 perf-util-y += header.o 3 3 4 4 perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o 5 - perf-util-$(CONFIG_LIBDW) += dwarf-regs.o 6 5 perf-util-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
+6 -26
tools/perf/arch/riscv/util/dwarf-regs.c tools/perf/arch/riscv/include/dwarf-regs-table.h
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. 4 - * Mapping of DWARF debug register numbers into register names. 5 - */ 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifdef DEFINE_DWARF_REGSTR_TABLE 3 + /* This is included in perf/util/dwarf-regs.c */ 6 4 7 - #include <stddef.h> 8 - #include <errno.h> /* for EINVAL */ 9 - #include <string.h> /* for strcmp */ 10 - #include <dwarf-regs.h> 5 + #define REG_DWARFNUM_NAME(reg, idx) [idx] = "%" #reg 11 6 12 - struct regs_dwarfnum { 13 - const char *name; 14 - unsigned int dwarfnum; 15 - }; 16 - 17 - #define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num} 18 - #define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0} 19 - 20 - struct regs_dwarfnum riscv_dwarf_regs_table[] = { 7 + static const char * const riscv_regstr_tbl[] = { 21 8 REG_DWARFNUM_NAME("%zero", 0), 22 9 REG_DWARFNUM_NAME("%ra", 1), 23 10 REG_DWARFNUM_NAME("%sp", 2), ··· 37 50 REG_DWARFNUM_NAME("%t4", 29), 38 51 REG_DWARFNUM_NAME("%t5", 30), 39 52 REG_DWARFNUM_NAME("%t6", 31), 40 - REG_DWARFNUM_END, 41 53 }; 42 54 43 - #define RISCV_MAX_REGS ((sizeof(riscv_dwarf_regs_table) / \ 44 - sizeof(riscv_dwarf_regs_table[0])) - 1) 45 - 46 - const char *get_arch_regstr(unsigned int n) 47 - { 48 - return (n < RISCV_MAX_REGS) ? riscv_dwarf_regs_table[n].name : NULL; 49 - } 55 + #endif
+5 -2
tools/perf/util/dwarf-regs.c
··· 20 20 #include "../arch/arm64/include/dwarf-regs-table.h" 21 21 #include "../arch/sh/include/dwarf-regs-table.h" 22 22 #include "../arch/powerpc/include/dwarf-regs-table.h" 23 + #include "../arch/riscv/include/dwarf-regs-table.h" 23 24 #include "../arch/s390/include/dwarf-regs-table.h" 24 25 #include "../arch/sparc/include/dwarf-regs-table.h" 25 26 #include "../arch/xtensa/include/dwarf-regs-table.h" ··· 34 33 { 35 34 #if EM_HOST == EM_X86_64 || EM_HOST == EM_386 || EM_HOST == EM_AARCH64 || EM_HOST == EM_ARM \ 36 35 || EM_HOST == EM_CSKY || EM_HOST == EM_LOONGARCH || EM_HOST == EM_MIPS || EM_HOST == EM_PPC \ 37 - || EM_HOST == EM_PPC64 36 + || EM_HOST == EM_PPC64 || EM_HOST == EM_RISCV 38 37 if (machine == EM_NONE) { 39 38 /* Generic arch - use host arch */ 40 39 machine = EM_HOST; ··· 43 42 switch (machine) { 44 43 #if EM_HOST != EM_X86_64 && EM_HOST != EM_386 && EM_HOST != EM_AARCH64 && EM_HOST != EM_ARM \ 45 44 && EM_HOST != EM_CSKY && EM_HOST != EM_LOONGARCH && EM_HOST != EM_MIPS && EM_HOST != EM_PPC \ 46 - && EM_HOST != EM_PPC64 45 + && EM_HOST != EM_PPC64 && EM_HOST != EM_RISCV 47 46 case EM_NONE: /* Generic arch - use host arch */ 48 47 return get_arch_regstr(n); 49 48 #endif ··· 64 63 case EM_PPC: 65 64 case EM_PPC64: 66 65 return __get_dwarf_regstr(powerpc_regstr_tbl, n); 66 + case EM_RISCV: 67 + return __get_dwarf_regstr(riscv_regstr_tbl, n); 67 68 case EM_SPARC: 68 69 case EM_SPARCV9: 69 70 return __get_dwarf_regstr(sparc_regstr_tbl, n);
+1 -1
tools/perf/util/include/dwarf-regs.h
··· 91 91 #ifdef HAVE_LIBDW_SUPPORT 92 92 #if !defined(__x86_64__) && !defined(__i386__) && !defined(__aarch64__) && !defined(__arm__) \ 93 93 && !defined(__loongarch__) && !defined(__mips__) && !defined(__powerpc__) \ 94 - && !defined(__powerpc64__) 94 + && !defined(__powerpc64__) && !defined(__riscv__) 95 95 const char *get_arch_regstr(unsigned int n); 96 96 #endif 97 97