]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf symbol: Avoid use of machine__is
authorIan Rogers <irogers@google.com>
Tue, 2 Jun 2026 15:25:03 +0000 (08:25 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Jun 2026 19:46:23 +0000 (16:46 -0300)
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@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Honglei Wang <jameshongleiwang@126.com>
Cc: Jan Polensky <japo@linux.ibm.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/symbol.c

index 714b6e6048fa2f95dc2c8d2ca190b2a114e74982..2ce512f08a1d6fea431071105a1e694bd617bcc8 100644 (file)
@@ -851,6 +851,23 @@ 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;
+       /* 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;
+
+       /* Check the global environment next. */
+       if (machine && machine->env && machine->env->e_machine != EM_NONE)
+               return machine->env->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 +883,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 +941,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 +1444,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 +1732,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 && machine_or_dso_e_machine(machine, dso) == EM_X86_64)
                        machine__map_x86_64_entry_trampolines(machine, dso);
                goto out;
        }