Re: [PATCH v1 08/23] perf perf_regs: Switch from arch string to int e_machine

Mi, Dapeng
2026-01-21T06:58:33Z

On 1/21/2026 2:49 AM, Arnaldo Carvalho de Melo wrote:
> On Fri, Jan 16, 2026 at 09:28:34PM -0800, Ian Rogers wrote:
>> The arch string requires multiple strcmp to identify things like the
>> IP and SP. Switch to passing in an e_machine that in the bulk of cases
>> is computed using a current thread load. The e_machine also allows
>> identification of 32-bit vs 64-bit processes.
>>
>> Signed-off-by: Ian Rogers <irogers@google.com>
>> ---
>> tools/perf/builtin-script.c | 17 ++-
>> tools/perf/util/evsel.c | 14 ++-
>> tools/perf/util/perf_regs.c | 105 +++++++++++-------
> [ Include dwarf-regs.h to get conditional defines for EM_CSKY and EM_LOONGARCH, not available in old distros ]
>
> - Arnaldo

Seems the change would introduce the below building error.

util/perf_regs.c: In function ‘perf_reg_name’:
util/perf_regs.c:48:14: error: ‘EM_LOONGARCH’ undeclared (first use in this
function)
48 |         case EM_LOONGARCH:
|              ^~~~~~~~~~~~
util/perf_regs.c:48:14: note: each undeclared identifier is reported only
once for each function it appears in
util/perf_regs.c: In function ‘perf_arch_reg_ip’:
util/perf_regs.c:114:14: error: ‘EM_LOONGARCH’ undeclared (first use in
this function)
114 |         case EM_LOONGARCH:
|              ^~~~~~~~~~~~
util/perf_regs.c: In function ‘perf_arch_reg_sp’:
util/perf_regs.c:143:14: error: ‘EM_LOONGARCH’ undeclared (first use in
this function)
143 |         case EM_LOONGARCH:
|              ^~~~~~~~~~~~

It looks EM_LOONGARCH is not defined in the <elf.h> header file, not sure
which one is better, include  dwarf-regs.h suggested by Arnaldo or direct
add the define,

diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index b58d59b84fb1..ce839df19fa3 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -6,6 +6,10 @@
#include "util/sample.h"
#include "debug.h"

+#ifndef EM_LOONGARCH
+#define EM_LOONGARCH           258
+#endif
+
int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
char **new_op __maybe_unused)
{

>