[PATCH v8 08/17] perf symbol: Avoid use of machine__is

From: Ian Rogers

Date: Sat May 02 2026 - 03:01:57 EST


Switch to using the ELF machine from the dso or running machine rather
than the machine perf_env arch that may fall back on EM_HOST. This
also avoids potentially imprecise string comparisons.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/symbol.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index fcaeeddbbb6b..8aaaab0ad4b7 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -851,6 +851,24 @@ static int maps__split_kallsyms_for_kcore(struct maps *kmaps, struct dso *dso)
return count;
}

+static uint16_t machine_or_dso_e_machine(struct machine *machine, struct dso *dso)
+{
+ uint16_t e_machine = EM_NONE;
+
+ /* Check for a cached value first. */
+ if (machine && machine->env && machine->env->e_machine != EM_NONE)
+ return machine->env->e_machine;
+
+ /* DSO should be most accurate */
+ if (dso)
+ e_machine = dso__e_machine(dso, machine, /*e_flags=*/NULL);
+
+ if (e_machine != EM_NONE)
+ return e_machine;
+
+ return perf_env__e_machine(machine ? machine->env : NULL, /*e_flags=*/NULL);
+}
+
/*
* Split the symbols into maps, making sure there are no overlaps, i.e. the
* kernel range is broken in several maps, named [kernel].N, as we don't have
@@ -866,14 +884,13 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
struct rb_root_cached *root = dso__symbols(dso);
struct rb_node *next = rb_first_cached(root);
int kernel_range = 0;
- bool x86_64;
+ uint16_t e_machine = EM_NONE;

if (!kmaps)
return -1;

machine = maps__machine(kmaps);
-
- x86_64 = machine__is(machine, "x86_64");
+ e_machine = machine_or_dso_e_machine(machine, dso);

while (next) {
char *module;
@@ -925,7 +942,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
*/
pos->start = map__map_ip(curr_map, pos->start);
pos->end = map__map_ip(curr_map, pos->end);
- } else if (x86_64 && is_entry_trampoline(pos->name)) {
+ } else if (e_machine == EM_X86_64 && is_entry_trampoline(pos->name)) {
/*
* These symbols are not needed anymore since the
* trampoline maps refer to the text section and it's
@@ -1428,7 +1445,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
free(new_node);
}

- if (machine__is(machine, "x86_64")) {
+ if (machine_or_dso_e_machine(machine, dso) == EM_X86_64) {
u64 addr;

/*
@@ -1716,7 +1733,7 @@ int dso__load(struct dso *dso, struct map *map)
ret = dso__load_guest_kernel_sym(dso, map);

machine = maps__machine(map__kmaps(map));
- if (machine__is(machine, "x86_64"))
+ if (machine_or_dso_e_machine(machine, dso) == EM_X86_64)
machine__map_x86_64_entry_trampolines(machine, dso);
goto out;
}
--
2.54.0.545.g6539524ca2-goog