[PATCH v8 09/17] perf arch common: Use perf_env e_machine rather than arch

Ian Rogers
2026-05-02T07:00:11Z

Use the e_machine rather than arch string matching.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/arch/common.c | 55 +++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/tools/perf/arch/common.c b/tools/perf/arch/common.c
index 21836f70f231..e9b5b61feffe 100644
--- a/tools/perf/arch/common.c
+++ b/tools/perf/arch/common.c
@@ -1,12 +1,14 @@
// SPDX-License-Identifier: GPL-2.0
+#include "common.h"
+
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "common.h"
#include "../util/env.h"
#include "../util/debug.h"
+#include <dwarf-regs.h>
#include <linux/zalloc.h>

static const char *const arc_triplets[] = {
@@ -145,7 +147,8 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
const char *name, char **path)
{
int idx;
- const char *arch = perf_env__arch(env), *cross_env;
+ uint16_t e_machine = perf_env__e_machine(env, /*e_flags=*/NULL);
+ const char *cross_env;
const char *const *path_list;
char *buf = NULL;

@@ -153,7 +156,7 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
* We don't need to try to find objdump path for native system.
* Just use default binutils path (e.g.: "objdump").
*/
- if (!strcmp(perf_env__arch(NULL), arch))
+ if (e_machine == EM_HOST)
goto out;

cross_env = getenv("CROSS_COMPILE");
@@ -170,30 +173,42 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
zfree(&buf);
}

- if (!strcmp(arch, "arc"))
+ switch(e_machine) {
+ case EM_ARC:
path_list = arc_triplets;
- else if (!strcmp(arch, "arm"))
+ break;
+ case EM_ARM:
path_list = arm_triplets;
- else if (!strcmp(arch, "arm64"))
+ break;
+ case EM_AARCH64:
path_list = arm64_triplets;
- else if (!strcmp(arch, "powerpc"))
+ break;
+ case EM_PPC:
+ case EM_PPC64:
path_list = powerpc_triplets;
- else if (!strcmp(arch, "riscv32"))
- path_list = riscv32_triplets;
- else if (!strcmp(arch, "riscv64"))
- path_list = riscv64_triplets;
- else if (!strcmp(arch, "sh"))
+ break;
+ case EM_RISCV:
+ path_list = perf_env__kernel_is_64_bit(env) ? riscv64_triplets : riscv32_triplets;
+ break;
+ case EM_SH:
path_list = sh_triplets;
- else if (!strcmp(arch, "s390"))
+ break;
+ case EM_S390:
path_list = s390_triplets;
- else if (!strcmp(arch, "sparc"))
+ break;
+ case EM_SPARC:
+ case EM_SPARCV9:
path_list = sparc_triplets;
- else if (!strcmp(arch, "x86"))
+ break;
+ case EM_X86_64:
+ case EM_386:
path_list = x86_triplets;
- else if (!strcmp(arch, "mips"))
+ break;
+ case EM_MIPS:
path_list = mips_triplets;
- else {
- ui__error("binutils for %s not supported.\n", arch);
+ break;
+ default:
+ ui__error("binutils for %s not supported.\n", perf_env__arch(env));
goto out_error;
}

@@ -202,7 +217,7 @@ static int perf_env__lookup_binutils_path(struct perf_env *env,
ui__error("Please install %s for %s.\n"
"You can add it to PATH, set CROSS_COMPILE or "
"override the default using --%s.\n",
- name, arch, name);
+ name, perf_env__arch(env), name);
goto out_error;
}

@@ -237,5 +252,5 @@ int perf_env__lookup_objdump(struct perf_env *env, char **path)
*/
bool perf_env__single_address_space(struct perf_env *env)
{
- return strcmp(perf_env__arch(env), "sparc");
+ return perf_env__e_machine(env, /*e_flags=*/NULL) == EM_SPARC;
}
--
2.54.0.545.g6539524ca2-goog