[PATCH v8 04/17] perf print_insn: Use e_machine for fallback IP length check

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

Avoid string comparisons with perf_env arch, switch to using the more
precise ELF machine.

Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/print_insn.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c
index 02e6fbb8ca04..5e36344174d6 100644
--- a/tools/perf/util/print_insn.c
+++ b/tools/perf/util/print_insn.c
@@ -9,6 +9,7 @@
#include <stdbool.h>
#include "capstone.h"
#include "debug.h"
+#include "env.h"
#include "sample.h"
#include "symbol.h"
#include "machine.h"
@@ -17,6 +18,7 @@
#include "dump-insn.h"
#include "map.h"
#include "dso.h"
+#include <elf.h>

size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
{
@@ -33,13 +35,13 @@ size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
static bool is64bitip(struct machine *machine, struct addr_location *al)
{
const struct dso *dso = al->map ? map__dso(al->map) : NULL;
+ uint16_t e_machine;

if (dso)
return dso__is_64_bit(dso);

- return machine__is(machine, "x86_64") ||
- machine__normalized_is(machine, "arm64") ||
- machine__normalized_is(machine, "s390");
+ e_machine = perf_env__e_machine(machine->env, /*e_flags=*/NULL);
+ return e_machine == EM_X86_64 || e_machine == EM_AARCH64 || e_machine == EM_S390;
}

ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u8 cpumode,
--
2.54.0.545.g6539524ca2-goog