Skip to content

Commit bf4e799

Browse files
captain5050namhyung
authored andcommitted
perf dwarf-regs: Move x86 dwarf-regs out of arch
Move arch/x86/util/dwarf-regs.c to util/dwarf-regs-x86.c and compile in unconditionally. To avoid get_arch_regnum being duplicated, rename to get_x86_regnum and add to get_dwarf_regnum switch. For get_arch_regstr, this was unused on x86 unless the machine type was EM_NONE. Map that case to EM_HOST and remove get_arch_regstr from dwarf-regs-x86.c. Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Cc: Anup Patel <[email protected]> Cc: Yang Jihong <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: David S. Miller <[email protected]> Cc: Albert Ou <[email protected]> Cc: Shenlin Liang <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Guilherme Amadio <[email protected]> Cc: Steinar H. Gunderson <[email protected]> Cc: Changbin Du <[email protected]> Cc: Alexander Lobakin <[email protected]> Cc: Przemek Kitszel <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Guo Ren <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Will Deacon <[email protected]> Cc: James Clark <[email protected]> Cc: Mike Leach <[email protected]> Cc: Chen Pei <[email protected]> Cc: Leo Yan <[email protected]> Cc: Oliver Upton <[email protected]> Cc: Aditya Gupta <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Bibo Mao <[email protected]> Cc: John Garry <[email protected]> Cc: Atish Patra <[email protected]> Cc: Dima Kogan <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent a784847 commit bf4e799

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

tools/perf/arch/x86/util/Build

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ perf-util-y += mem-events.o
1111
perf-util-y += evsel.o
1212
perf-util-y += iostat.o
1313

14-
perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
15-
perf-util-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
16-
1714
perf-util-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
1815
perf-util-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
1916

tools/perf/util/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ endif
204204
perf-util-$(CONFIG_LIBDW) += probe-finder.o
205205
perf-util-$(CONFIG_LIBDW) += dwarf-aux.o
206206
perf-util-$(CONFIG_LIBDW) += dwarf-regs.o
207+
perf-util-$(CONFIG_LIBDW) += dwarf-regs-x86.o
207208
perf-util-$(CONFIG_LIBDW) += debuginfo.o
208209
perf-util-$(CONFIG_LIBDW) += annotate-data.o
209210

tools/perf/arch/x86/util/dwarf-regs.c renamed to tools/perf/util/dwarf-regs-x86.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@
1111
#include <linux/kernel.h> /* for ARRAY_SIZE */
1212
#include <dwarf-regs.h>
1313

14-
#define DEFINE_DWARF_REGSTR_TABLE 1
15-
#include "dwarf-regs-table.h"
16-
17-
/* Return architecture dependent register string (for kprobe-tracer) */
18-
const char *get_arch_regstr(unsigned int n)
19-
{
20-
#if defined(__i386__)
21-
size_t len = ARRAY_SIZE(x86_32_regstr_tbl);
22-
#else
23-
size_t len = ARRAY_SIZE(x86_64_regstr_tbl);
24-
#endif
25-
26-
if (n >= len)
27-
return NULL;
28-
29-
#if defined(__i386__)
30-
return x86_32_regstr_tbl[n];
31-
#else
32-
return x86_64_regstr_tbl[n];
33-
#endif
34-
}
35-
3614
struct dwarf_regs_idx {
3715
const char *name;
3816
int idx;
@@ -58,7 +36,7 @@ static const struct dwarf_regs_idx x86_regidx_table[] = {
5836
{ "rip", DWARF_REG_PC },
5937
};
6038

61-
int get_arch_regnum(const char *name)
39+
int get_x86_regnum(const char *name)
6240
{
6341
unsigned int i;
6442

tools/perf/util/dwarf-regs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,17 @@
3232
const char *get_dwarf_regstr(unsigned int n, unsigned int machine,
3333
unsigned int flags __maybe_unused)
3434
{
35+
#if EM_HOST == EM_X86_64 || EM_HOST == EM_386
36+
if (machine == EM_NONE) {
37+
/* Generic arch - use host arch */
38+
machine = EM_HOST;
39+
}
40+
#endif
3541
switch (machine) {
42+
#if EM_HOST != EM_X86_64 && EM_HOST != EM_386
3643
case EM_NONE: /* Generic arch - use host arch */
3744
return get_arch_regstr(n);
45+
#endif
3846
case EM_386:
3947
return __get_dwarf_regstr(x86_32_regstr_tbl, n);
4048
case EM_X86_64:
@@ -65,10 +73,12 @@ const char *get_dwarf_regstr(unsigned int n, unsigned int machine,
6573
return NULL;
6674
}
6775

76+
#if EM_HOST != EM_X86_64 && EM_HOST != EM_386
6877
__weak int get_arch_regnum(const char *name __maybe_unused)
6978
{
7079
return -ENOTSUP;
7180
}
81+
#endif
7282

7383
/* Return DWARF register number from architecture register name */
7484
int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags __maybe_unused)
@@ -90,9 +100,16 @@ int get_dwarf_regnum(const char *name, unsigned int machine, unsigned int flags
90100
machine = EM_HOST;
91101
}
92102
switch (machine) {
103+
#if EM_HOST != EM_X86_64 && EM_HOST != EM_386
93104
case EM_HOST:
94105
reg = get_arch_regnum(regname);
95106
break;
107+
#endif
108+
case EM_X86_64:
109+
fallthrough;
110+
case EM_386:
111+
reg = get_x86_regnum(regname);
112+
break;
96113
default:
97114
pr_err("ELF MACHINE %x is not supported.\n", machine);
98115
}

tools/perf/util/include/dwarf-regs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@
8989
#define DWARF_REG_FB 0xd3affb /* random number */
9090

9191
#ifdef HAVE_LIBDW_SUPPORT
92+
#if !defined(__x86_64__) && !defined(__i386__)
9293
const char *get_arch_regstr(unsigned int n);
94+
#endif
95+
9396
/**
9497
* get_dwarf_regstr() - Returns ftrace register string from DWARF regnum.
9598
* @n: DWARF register number.
@@ -98,7 +101,12 @@ const char *get_arch_regstr(unsigned int n);
98101
*/
99102
const char *get_dwarf_regstr(unsigned int n, unsigned int machine, unsigned int flags);
100103

104+
int get_x86_regnum(const char *name);
105+
106+
#if !defined(__x86_64__) && !defined(__i386__)
101107
int get_arch_regnum(const char *name);
108+
#endif
109+
102110
/*
103111
* get_dwarf_regnum - Returns DWARF regnum from register name
104112
* name: architecture register name

0 commit comments

Comments
 (0)