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

perf disasm: Define stubs for the LLVM and capstone disassemblers

This reduces the number of ifdefs in the main symbol__disassemble()
method and paves the way for allowing the user to configure the
disassemblers of preference.

Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Aditya Bodkhe <Aditya.Bodkhe1@ibm.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Steinar H. Gunderson <sesse@google.com>
Link: https://lore.kernel.org/r/20241111151734.1018476-3-acme@kernel.org
[ Applied fixes from Masami Hiramatsu and Aditya Bodkhe for when capstone devel files are not available ]
Link: https://lore.kernel.org/r/B78FB6DF-24E9-4A3C-91C9-535765EC0E2A@ibm.com
Link: https://lore.kernel.org/r/173145729034.2747044.453926054000880254.stgit@mhiramat.roam.corp.google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+35 -8
+35 -8
tools/perf/util/disasm.c
··· 1424 1424 } 1425 1425 #endif 1426 1426 1427 + #if !defined(HAVE_LIBCAPSTONE_SUPPORT) || !defined(HAVE_LIBLLVM_SUPPORT) 1428 + static void symbol__disassembler_missing(const char *disassembler, const char *filename, 1429 + struct symbol *sym) 1430 + { 1431 + pr_debug("The %s disassembler isn't linked in for %s in %s\n", 1432 + disassembler, sym->name, filename); 1433 + } 1434 + #endif 1435 + 1427 1436 #ifdef HAVE_LIBCAPSTONE_SUPPORT 1428 1437 static void print_capstone_detail(cs_insn *insn, char *buf, size_t len, 1429 1438 struct annotate_args *args, u64 addr) ··· 1724 1715 count = -1; 1725 1716 goto out; 1726 1717 } 1727 - #endif 1718 + #else // HAVE_LIBCAPSTONE_SUPPORT 1719 + static int symbol__disassemble_capstone(char *filename, struct symbol *sym, 1720 + struct annotate_args *args __maybe_unused) 1721 + { 1722 + symbol__disassembler_missing("capstone", filename, sym); 1723 + return -1; 1724 + } 1725 + 1726 + static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *sym, 1727 + struct annotate_args *args __maybe_unused) 1728 + { 1729 + symbol__disassembler_missing("capstone powerpc", filename, sym); 1730 + return -1; 1731 + } 1732 + #endif // HAVE_LIBCAPSTONE_SUPPORT 1728 1733 1729 1734 static int symbol__disassemble_raw(char *filename, struct symbol *sym, 1730 1735 struct annotate_args *args) ··· 2006 1983 free(line_storage); 2007 1984 return ret; 2008 1985 } 2009 - #endif 1986 + #else // HAVE_LIBLLVM_SUPPORT 1987 + static int symbol__disassemble_llvm(char *filename, struct symbol *sym, 1988 + struct annotate_args *args __maybe_unused) 1989 + { 1990 + symbol__disassembler_missing("LLVM", filename, sym); 1991 + return -1; 1992 + } 1993 + #endif // HAVE_LIBLLVM_SUPPORT 2010 1994 2011 1995 /* 2012 1996 * Possibly create a new version of line with tabs expanded. Returns the ··· 2272 2242 err = symbol__disassemble_raw(symfs_filename, sym, args); 2273 2243 if (err == 0) 2274 2244 goto out_remove_tmp; 2275 - #ifdef HAVE_LIBCAPSTONE_SUPPORT 2245 + 2276 2246 err = symbol__disassemble_capstone_powerpc(symfs_filename, sym, args); 2277 2247 if (err == 0) 2278 2248 goto out_remove_tmp; 2279 - #endif 2280 2249 } 2281 2250 } 2282 2251 2283 - #ifdef HAVE_LIBLLVM_SUPPORT 2284 2252 err = symbol__disassemble_llvm(symfs_filename, sym, args); 2285 2253 if (err == 0) 2286 2254 goto out_remove_tmp; 2287 - #endif 2288 - #ifdef HAVE_LIBCAPSTONE_SUPPORT 2255 + 2289 2256 err = symbol__disassemble_capstone(symfs_filename, sym, args); 2290 2257 if (err == 0) 2291 2258 goto out_remove_tmp; 2292 - #endif 2259 + 2293 2260 err = symbol__disassemble_objdump(symfs_filename, sym, args); 2294 2261 2295 2262 out_remove_tmp: