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

perf: build: introduce the libcapstone

Later we will use libcapstone to disassemble instructions of samples.

Signed-off-by: Changbin Du <changbin.du@huawei.com>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: changbin.du@gmail.com
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240217074046.4100789-2-changbin.du@huawei.com

authored by

Changbin Du and committed by
Namhyung Kim
8b767db3 81377de0

+49 -1
+2
tools/build/Makefile.feature
··· 87 87 gtk2-infobar \ 88 88 hello \ 89 89 libbabeltrace \ 90 + libcapstone \ 90 91 libbfd-liberty \ 91 92 libbfd-liberty-z \ 92 93 libopencsd \ ··· 135 134 libcrypto \ 136 135 libunwind \ 137 136 libdw-dwarf-unwind \ 137 + libcapstone \ 138 138 zlib \ 139 139 lzma \ 140 140 get_cpuid \
+4
tools/build/feature/Makefile
··· 54 54 test-timerfd.bin \ 55 55 test-libdw-dwarf-unwind.bin \ 56 56 test-libbabeltrace.bin \ 57 + test-libcapstone.bin \ 57 58 test-compile-32.bin \ 58 59 test-compile-x32.bin \ 59 60 test-zlib.bin \ ··· 286 285 287 286 $(OUTPUT)test-libbabeltrace.bin: 288 287 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 288 + 289 + $(OUTPUT)test-libcapstone.bin: 290 + $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone) 289 291 290 292 $(OUTPUT)test-compile-32.bin: 291 293 $(CC) -m32 -o $@ test-compile.c
+4
tools/build/feature/test-all.c
··· 134 134 #undef main 135 135 #endif 136 136 137 + #define main main_test_libcapstone 138 + # include "test-libcapstone.c" 139 + #undef main 140 + 137 141 #define main main_test_lzma 138 142 # include "test-lzma.c" 139 143 #undef main
+11
tools/build/feature/test-libcapstone.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <capstone/capstone.h> 4 + 5 + int main(void) 6 + { 7 + csh handle; 8 + 9 + cs_open(CS_ARCH_X86, CS_MODE_64, &handle); 10 + return 0; 11 + }
+21
tools/perf/Makefile.config
··· 166 166 FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS) 167 167 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf 168 168 169 + # for linking with debug library, run like: 170 + # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/ 171 + ifdef LIBCAPSTONE_DIR 172 + LIBCAPSTONE_CFLAGS := -I$(LIBCAPSTONE_DIR)/include 173 + LIBCAPSTONE_LDFLAGS := -L$(LIBCAPSTONE_DIR)/ 174 + endif 175 + FEATURE_CHECK_CFLAGS-libcapstone := $(LIBCAPSTONE_CFLAGS) 176 + FEATURE_CHECK_LDFLAGS-libcapstone := $(LIBCAPSTONE_LDFLAGS) -lcapstone 177 + 169 178 ifdef LIBZSTD_DIR 170 179 LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib 171 180 LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib ··· 1081 1072 $(call detected,CONFIG_LIBBABELTRACE) 1082 1073 else 1083 1074 msg := $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev); 1075 + endif 1076 + endif 1077 + 1078 + ifndef NO_CAPSTONE 1079 + $(call feature_check,libcapstone) 1080 + ifeq ($(feature-libcapstone), 1) 1081 + CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS) 1082 + LDFLAGS += $(LICAPSTONE_LDFLAGS) 1083 + EXTLIBS += -lcapstone 1084 + $(call detected,CONFIG_LIBCAPSTONE) 1085 + else 1086 + msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel); 1084 1087 endif 1085 1088 endif 1086 1089
+3
tools/perf/Makefile.perf
··· 84 84 # Define NO_LIBBABELTRACE if you do not want libbabeltrace support 85 85 # for CTF data format. 86 86 # 87 + # Define NO_CAPSTONE if you do not want libcapstone support 88 + # for disasm engine. 89 + # 87 90 # Define NO_LZMA if you do not want to support compressed (xz) kernel modules 88 91 # 89 92 # Define NO_AUXTRACE if you do not want AUX area tracing support
+1
tools/perf/builtin-version.c
··· 73 73 STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto); 74 74 STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind); 75 75 STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind); 76 + STATUS(HAVE_LIBCAPSTONE_SUPPORT, libcapstone); 76 77 STATUS(HAVE_ZLIB_SUPPORT, zlib); 77 78 STATUS(HAVE_LZMA_SUPPORT, lzma); 78 79 STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);
+3 -1
tools/perf/tests/make
··· 83 83 make_no_libunwind := NO_LIBUNWIND=1 84 84 make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1 85 85 make_no_backtrace := NO_BACKTRACE=1 86 + make_no_libcapstone := NO_CAPSTONE=1 86 87 make_no_libnuma := NO_LIBNUMA=1 87 88 make_no_libaudit := NO_LIBAUDIT=1 88 89 make_no_libbionic := NO_LIBBIONIC=1 ··· 123 122 make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 124 123 make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 125 124 make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1 126 - make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1 125 + make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1 NO_CAPSTONE=1 127 126 128 127 # $(run) contains all available tests 129 128 run := make_pure ··· 153 152 run += make_no_libunwind 154 153 run += make_no_libdw_dwarf_unwind 155 154 run += make_no_backtrace 155 + run += make_no_libcapstone 156 156 run += make_no_libnuma 157 157 run += make_no_libaudit 158 158 run += make_no_libbionic