Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf disasm: Add e_machine/e_flags to struct arch

Currently functions like get_dwarf_regnum only work with the host
architecture. Carry the elf machine and flags in struct arch so that
in disassembly these can be used to allow cross platform disassembly.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Shenlin Liang <liangshenlin@eswincomputing.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Guilherme Amadio <amadio@gentoo.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Chen Pei <cp0613@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Aditya Gupta <adityag@linux.ibm.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-riscv@lists.infradead.org
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Atish Patra <atishp@rivosinc.com>
Cc: Dima Kogan <dima@secretsauce.net>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: linux-csky@vger.kernel.org
Link: https://lore.kernel.org/r/20241108234606.429459-5-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
cd6c9dca ae894b77

+30 -2
+2
tools/perf/arch/arc/annotate/instructions.c
··· 5 5 { 6 6 arch->initialized = true; 7 7 arch->objdump.comment_char = ';'; 8 + arch->e_machine = EM_ARC; 9 + arch->e_flags = 0; 8 10 return 0; 9 11 }
+2
tools/perf/arch/arm/annotate/instructions.c
··· 53 53 arch->associate_instruction_ops = arm__associate_instruction_ops; 54 54 arch->objdump.comment_char = ';'; 55 55 arch->objdump.skip_functions_char = '+'; 56 + arch->e_machine = EM_ARM; 57 + arch->e_flags = 0; 56 58 return 0; 57 59 58 60 out_free_call:
+2
tools/perf/arch/arm64/annotate/instructions.c
··· 113 113 arch->associate_instruction_ops = arm64__associate_instruction_ops; 114 114 arch->objdump.comment_char = '/'; 115 115 arch->objdump.skip_functions_char = '+'; 116 + arch->e_machine = EM_AARCH64; 117 + arch->e_flags = 0; 116 118 return 0; 117 119 118 120 out_free_call:
+6 -1
tools/perf/arch/csky/annotate/instructions.c
··· 43 43 arch->initialized = true; 44 44 arch->objdump.comment_char = '/'; 45 45 arch->associate_instruction_ops = csky__associate_ins_ops; 46 - 46 + arch->e_machine = EM_CSKY; 47 + #if defined(__CSKYABIV2__) 48 + arch->e_flags = EF_CSKY_ABIV2; 49 + #else 50 + arch->e_flags = EF_CSKY_ABIV1; 51 + #endif 47 52 return 0; 48 53 }
+2
tools/perf/arch/loongarch/annotate/instructions.c
··· 131 131 arch->associate_instruction_ops = loongarch__associate_ins_ops; 132 132 arch->initialized = true; 133 133 arch->objdump.comment_char = '#'; 134 + arch->e_machine = EM_LOONGARCH; 135 + arch->e_flags = 0; 134 136 } 135 137 136 138 return 0;
+2
tools/perf/arch/mips/annotate/instructions.c
··· 40 40 arch->associate_instruction_ops = mips__associate_ins_ops; 41 41 arch->initialized = true; 42 42 arch->objdump.comment_char = '#'; 43 + arch->e_machine = EM_MIPS; 44 + arch->e_flags = 0; 43 45 } 44 46 45 47 return 0;
+2
tools/perf/arch/powerpc/annotate/instructions.c
··· 309 309 arch->associate_instruction_ops = powerpc__associate_instruction_ops; 310 310 arch->objdump.comment_char = '#'; 311 311 annotate_opts.show_asm_raw = true; 312 + arch->e_machine = EM_PPC; 313 + arch->e_flags = 0; 312 314 } 313 315 314 316 return 0;
+2
tools/perf/arch/riscv64/annotate/instructions.c
··· 28 28 arch->associate_instruction_ops = riscv64__associate_ins_ops; 29 29 arch->initialized = true; 30 30 arch->objdump.comment_char = '#'; 31 + arch->e_machine = EM_RISCV; 32 + arch->e_flags = 0; 31 33 } 32 34 33 35 return 0;
+2
tools/perf/arch/s390/annotate/instructions.c
··· 166 166 if (s390__cpuid_parse(arch, cpuid)) 167 167 err = SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; 168 168 } 169 + arch->e_machine = EM_S390; 170 + arch->e_flags = 0; 169 171 } 170 172 171 173 return err;
+2
tools/perf/arch/sparc/annotate/instructions.c
··· 163 163 arch->initialized = true; 164 164 arch->associate_instruction_ops = sparc__associate_instruction_ops; 165 165 arch->objdump.comment_char = '#'; 166 + arch->e_machine = EM_SPARC; 167 + arch->e_flags = 0; 166 168 } 167 169 168 170 return 0;
+2 -1
tools/perf/arch/x86/annotate/instructions.c
··· 202 202 if (x86__cpuid_parse(arch, cpuid)) 203 203 err = SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; 204 204 } 205 - 205 + arch->e_machine = EM_X86_64; 206 + arch->e_flags = 0; 206 207 arch->initialized = true; 207 208 return err; 208 209 }
+4
tools/perf/util/disasm.h
··· 44 44 struct data_loc_info *dloc, Dwarf_Die *cu_die, 45 45 struct disasm_line *dl); 46 46 #endif 47 + /** @e_machine: ELF machine associated with arch. */ 48 + unsigned int e_machine; 49 + /** @e_flags: Optional ELF flags associated with arch. */ 50 + unsigned int e_flags; 47 51 }; 48 52 49 53 struct ins {