Skip to content

Commit 8b767db

Browse files
Changbin Dunamhyung
authored andcommitted
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
1 parent 81377de commit 8b767db

File tree

8 files changed

+49
-1
lines changed

8 files changed

+49
-1
lines changed

tools/build/Makefile.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ FEATURE_TESTS_EXTRA := \
8787
gtk2-infobar \
8888
hello \
8989
libbabeltrace \
90+
libcapstone \
9091
libbfd-liberty \
9192
libbfd-liberty-z \
9293
libopencsd \
@@ -134,6 +135,7 @@ FEATURE_DISPLAY ?= \
134135
libcrypto \
135136
libunwind \
136137
libdw-dwarf-unwind \
138+
libcapstone \
137139
zlib \
138140
lzma \
139141
get_cpuid \

tools/build/feature/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ FILES= \
5454
test-timerfd.bin \
5555
test-libdw-dwarf-unwind.bin \
5656
test-libbabeltrace.bin \
57+
test-libcapstone.bin \
5758
test-compile-32.bin \
5859
test-compile-x32.bin \
5960
test-zlib.bin \
@@ -286,6 +287,9 @@ $(OUTPUT)test-libdw-dwarf-unwind.bin:
286287
$(OUTPUT)test-libbabeltrace.bin:
287288
$(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace)
288289

290+
$(OUTPUT)test-libcapstone.bin:
291+
$(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
292+
289293
$(OUTPUT)test-compile-32.bin:
290294
$(CC) -m32 -o $@ test-compile.c
291295

tools/build/feature/test-all.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
#undef main
135135
#endif
136136

137+
#define main main_test_libcapstone
138+
# include "test-libcapstone.c"
139+
#undef main
140+
137141
#define main main_test_lzma
138142
# include "test-lzma.c"
139143
#undef main
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

tools/perf/Makefile.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ endif
166166
FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
167167
FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
168168

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+
169178
ifdef LIBZSTD_DIR
170179
LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
171180
LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
@@ -1075,6 +1084,18 @@ ifndef NO_LIBBABELTRACE
10751084
endif
10761085
endif
10771086

1087+
ifndef NO_CAPSTONE
1088+
$(call feature_check,libcapstone)
1089+
ifeq ($(feature-libcapstone), 1)
1090+
CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS)
1091+
LDFLAGS += $(LICAPSTONE_LDFLAGS)
1092+
EXTLIBS += -lcapstone
1093+
$(call detected,CONFIG_LIBCAPSTONE)
1094+
else
1095+
msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel);
1096+
endif
1097+
endif
1098+
10781099
ifndef NO_AUXTRACE
10791100
ifeq ($(SRCARCH),x86)
10801101
ifeq ($(feature-get_cpuid), 0)

tools/perf/Makefile.perf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ include ../scripts/utilities.mak
8484
# Define NO_LIBBABELTRACE if you do not want libbabeltrace support
8585
# for CTF data format.
8686
#
87+
# Define NO_CAPSTONE if you do not want libcapstone support
88+
# for disasm engine.
89+
#
8790
# Define NO_LZMA if you do not want to support compressed (xz) kernel modules
8891
#
8992
# Define NO_AUXTRACE if you do not want AUX area tracing support

tools/perf/builtin-version.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void library_status(void)
7373
STATUS(HAVE_LIBCRYPTO_SUPPORT, libcrypto);
7474
STATUS(HAVE_LIBUNWIND_SUPPORT, libunwind);
7575
STATUS(HAVE_DWARF_SUPPORT, libdw-dwarf-unwind);
76+
STATUS(HAVE_LIBCAPSTONE_SUPPORT, libcapstone);
7677
STATUS(HAVE_ZLIB_SUPPORT, zlib);
7778
STATUS(HAVE_LZMA_SUPPORT, lzma);
7879
STATUS(HAVE_AUXTRACE_SUPPORT, get_cpuid);

tools/perf/tests/make

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ make_no_libelf := NO_LIBELF=1
8383
make_no_libunwind := NO_LIBUNWIND=1
8484
make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
8585
make_no_backtrace := NO_BACKTRACE=1
86+
make_no_libcapstone := NO_CAPSTONE=1
8687
make_no_libnuma := NO_LIBNUMA=1
8788
make_no_libaudit := NO_LIBAUDIT=1
8889
make_no_libbionic := NO_LIBBIONIC=1
@@ -122,7 +123,7 @@ make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
122123
make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
123124
make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
124125
make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 NO_LIBZSTD=1
125-
make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1
126+
make_minimal += NO_LIBCAP=1 NO_SYSCALL_TABLE=1 NO_CAPSTONE=1
126127

127128
# $(run) contains all available tests
128129
run := make_pure
@@ -152,6 +153,7 @@ run += make_no_libelf
152153
run += make_no_libunwind
153154
run += make_no_libdw_dwarf_unwind
154155
run += make_no_backtrace
156+
run += make_no_libcapstone
155157
run += make_no_libnuma
156158
run += make_no_libaudit
157159
run += make_no_libbionic

0 commit comments

Comments
 (0)