18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciBPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src)) 48c2ecf20Sopenharmony_ciTOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# List of programs to build 78c2ecf20Sopenharmony_citprogs-y := test_lru_dist 88c2ecf20Sopenharmony_citprogs-y += sock_example 98c2ecf20Sopenharmony_citprogs-y += fds_example 108c2ecf20Sopenharmony_citprogs-y += sockex1 118c2ecf20Sopenharmony_citprogs-y += sockex2 128c2ecf20Sopenharmony_citprogs-y += sockex3 138c2ecf20Sopenharmony_citprogs-y += tracex1 148c2ecf20Sopenharmony_citprogs-y += tracex2 158c2ecf20Sopenharmony_citprogs-y += tracex3 168c2ecf20Sopenharmony_citprogs-y += tracex4 178c2ecf20Sopenharmony_citprogs-y += tracex5 188c2ecf20Sopenharmony_citprogs-y += tracex6 198c2ecf20Sopenharmony_citprogs-y += tracex7 208c2ecf20Sopenharmony_citprogs-y += test_probe_write_user 218c2ecf20Sopenharmony_citprogs-y += trace_output 228c2ecf20Sopenharmony_citprogs-y += lathist 238c2ecf20Sopenharmony_citprogs-y += offwaketime 248c2ecf20Sopenharmony_citprogs-y += spintest 258c2ecf20Sopenharmony_citprogs-y += map_perf_test 268c2ecf20Sopenharmony_citprogs-y += test_overhead 278c2ecf20Sopenharmony_citprogs-y += test_cgrp2_array_pin 288c2ecf20Sopenharmony_citprogs-y += test_cgrp2_attach 298c2ecf20Sopenharmony_citprogs-y += test_cgrp2_sock 308c2ecf20Sopenharmony_citprogs-y += test_cgrp2_sock2 318c2ecf20Sopenharmony_citprogs-y += xdp1 328c2ecf20Sopenharmony_citprogs-y += xdp2 338c2ecf20Sopenharmony_citprogs-y += xdp_router_ipv4 348c2ecf20Sopenharmony_citprogs-y += test_current_task_under_cgroup 358c2ecf20Sopenharmony_citprogs-y += trace_event 368c2ecf20Sopenharmony_citprogs-y += sampleip 378c2ecf20Sopenharmony_citprogs-y += tc_l2_redirect 388c2ecf20Sopenharmony_citprogs-y += lwt_len_hist 398c2ecf20Sopenharmony_citprogs-y += xdp_tx_iptunnel 408c2ecf20Sopenharmony_citprogs-y += test_map_in_map 418c2ecf20Sopenharmony_citprogs-y += per_socket_stats_example 428c2ecf20Sopenharmony_citprogs-y += xdp_redirect 438c2ecf20Sopenharmony_citprogs-y += xdp_redirect_map 448c2ecf20Sopenharmony_citprogs-y += xdp_redirect_cpu 458c2ecf20Sopenharmony_citprogs-y += xdp_monitor 468c2ecf20Sopenharmony_citprogs-y += xdp_rxq_info 478c2ecf20Sopenharmony_citprogs-y += syscall_tp 488c2ecf20Sopenharmony_citprogs-y += cpustat 498c2ecf20Sopenharmony_citprogs-y += xdp_adjust_tail 508c2ecf20Sopenharmony_citprogs-y += xdpsock 518c2ecf20Sopenharmony_citprogs-y += xsk_fwd 528c2ecf20Sopenharmony_citprogs-y += xdp_fwd 538c2ecf20Sopenharmony_citprogs-y += task_fd_query 548c2ecf20Sopenharmony_citprogs-y += xdp_sample_pkts 558c2ecf20Sopenharmony_citprogs-y += ibumad 568c2ecf20Sopenharmony_citprogs-y += hbm 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci# Libbpf dependencies 598c2ecf20Sopenharmony_ciLIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciCGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o 628c2ecf20Sopenharmony_ciTRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cifds_example-objs := fds_example.o 658c2ecf20Sopenharmony_cisockex1-objs := sockex1_user.o 668c2ecf20Sopenharmony_cisockex2-objs := sockex2_user.o 678c2ecf20Sopenharmony_cisockex3-objs := sockex3_user.o 688c2ecf20Sopenharmony_citracex1-objs := tracex1_user.o $(TRACE_HELPERS) 698c2ecf20Sopenharmony_citracex2-objs := tracex2_user.o 708c2ecf20Sopenharmony_citracex3-objs := tracex3_user.o 718c2ecf20Sopenharmony_citracex4-objs := tracex4_user.o 728c2ecf20Sopenharmony_citracex5-objs := tracex5_user.o $(TRACE_HELPERS) 738c2ecf20Sopenharmony_citracex6-objs := tracex6_user.o 748c2ecf20Sopenharmony_citracex7-objs := tracex7_user.o 758c2ecf20Sopenharmony_citest_probe_write_user-objs := test_probe_write_user_user.o 768c2ecf20Sopenharmony_citrace_output-objs := trace_output_user.o $(TRACE_HELPERS) 778c2ecf20Sopenharmony_cilathist-objs := lathist_user.o 788c2ecf20Sopenharmony_cioffwaketime-objs := offwaketime_user.o $(TRACE_HELPERS) 798c2ecf20Sopenharmony_cispintest-objs := spintest_user.o $(TRACE_HELPERS) 808c2ecf20Sopenharmony_cimap_perf_test-objs := map_perf_test_user.o 818c2ecf20Sopenharmony_citest_overhead-objs := bpf_load.o test_overhead_user.o 828c2ecf20Sopenharmony_citest_cgrp2_array_pin-objs := test_cgrp2_array_pin.o 838c2ecf20Sopenharmony_citest_cgrp2_attach-objs := test_cgrp2_attach.o 848c2ecf20Sopenharmony_citest_cgrp2_sock-objs := test_cgrp2_sock.o 858c2ecf20Sopenharmony_citest_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o 868c2ecf20Sopenharmony_cixdp1-objs := xdp1_user.o 878c2ecf20Sopenharmony_ci# reuse xdp1 source intentionally 888c2ecf20Sopenharmony_cixdp2-objs := xdp1_user.o 898c2ecf20Sopenharmony_cixdp_router_ipv4-objs := xdp_router_ipv4_user.o 908c2ecf20Sopenharmony_citest_current_task_under_cgroup-objs := $(CGROUP_HELPERS) \ 918c2ecf20Sopenharmony_ci test_current_task_under_cgroup_user.o 928c2ecf20Sopenharmony_citrace_event-objs := trace_event_user.o $(TRACE_HELPERS) 938c2ecf20Sopenharmony_cisampleip-objs := sampleip_user.o $(TRACE_HELPERS) 948c2ecf20Sopenharmony_citc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o 958c2ecf20Sopenharmony_cilwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o 968c2ecf20Sopenharmony_cixdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o 978c2ecf20Sopenharmony_citest_map_in_map-objs := test_map_in_map_user.o 988c2ecf20Sopenharmony_ciper_socket_stats_example-objs := cookie_uid_helper_example.o 998c2ecf20Sopenharmony_cixdp_redirect-objs := xdp_redirect_user.o 1008c2ecf20Sopenharmony_cixdp_redirect_map-objs := xdp_redirect_map_user.o 1018c2ecf20Sopenharmony_cixdp_redirect_cpu-objs := xdp_redirect_cpu_user.o 1028c2ecf20Sopenharmony_cixdp_monitor-objs := xdp_monitor_user.o 1038c2ecf20Sopenharmony_cixdp_rxq_info-objs := xdp_rxq_info_user.o 1048c2ecf20Sopenharmony_cisyscall_tp-objs := syscall_tp_user.o 1058c2ecf20Sopenharmony_cicpustat-objs := cpustat_user.o 1068c2ecf20Sopenharmony_cixdp_adjust_tail-objs := xdp_adjust_tail_user.o 1078c2ecf20Sopenharmony_cixdpsock-objs := xdpsock_user.o 1088c2ecf20Sopenharmony_cixsk_fwd-objs := xsk_fwd.o 1098c2ecf20Sopenharmony_cixdp_fwd-objs := xdp_fwd_user.o 1108c2ecf20Sopenharmony_citask_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS) 1118c2ecf20Sopenharmony_cixdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS) 1128c2ecf20Sopenharmony_ciibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS) 1138c2ecf20Sopenharmony_cihbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci# Tell kbuild to always build the programs 1168c2ecf20Sopenharmony_cialways-y := $(tprogs-y) 1178c2ecf20Sopenharmony_cialways-y += sockex1_kern.o 1188c2ecf20Sopenharmony_cialways-y += sockex2_kern.o 1198c2ecf20Sopenharmony_cialways-y += sockex3_kern.o 1208c2ecf20Sopenharmony_cialways-y += tracex1_kern.o 1218c2ecf20Sopenharmony_cialways-y += tracex2_kern.o 1228c2ecf20Sopenharmony_cialways-y += tracex3_kern.o 1238c2ecf20Sopenharmony_cialways-y += tracex4_kern.o 1248c2ecf20Sopenharmony_cialways-y += tracex5_kern.o 1258c2ecf20Sopenharmony_cialways-y += tracex6_kern.o 1268c2ecf20Sopenharmony_cialways-y += tracex7_kern.o 1278c2ecf20Sopenharmony_cialways-y += sock_flags_kern.o 1288c2ecf20Sopenharmony_cialways-y += test_probe_write_user_kern.o 1298c2ecf20Sopenharmony_cialways-y += trace_output_kern.o 1308c2ecf20Sopenharmony_cialways-y += tcbpf1_kern.o 1318c2ecf20Sopenharmony_cialways-y += tc_l2_redirect_kern.o 1328c2ecf20Sopenharmony_cialways-y += lathist_kern.o 1338c2ecf20Sopenharmony_cialways-y += offwaketime_kern.o 1348c2ecf20Sopenharmony_cialways-y += spintest_kern.o 1358c2ecf20Sopenharmony_cialways-y += map_perf_test_kern.o 1368c2ecf20Sopenharmony_cialways-y += test_overhead_tp_kern.o 1378c2ecf20Sopenharmony_cialways-y += test_overhead_raw_tp_kern.o 1388c2ecf20Sopenharmony_cialways-y += test_overhead_kprobe_kern.o 1398c2ecf20Sopenharmony_cialways-y += parse_varlen.o parse_simple.o parse_ldabs.o 1408c2ecf20Sopenharmony_cialways-y += test_cgrp2_tc_kern.o 1418c2ecf20Sopenharmony_cialways-y += xdp1_kern.o 1428c2ecf20Sopenharmony_cialways-y += xdp2_kern.o 1438c2ecf20Sopenharmony_cialways-y += xdp_router_ipv4_kern.o 1448c2ecf20Sopenharmony_cialways-y += test_current_task_under_cgroup_kern.o 1458c2ecf20Sopenharmony_cialways-y += trace_event_kern.o 1468c2ecf20Sopenharmony_cialways-y += sampleip_kern.o 1478c2ecf20Sopenharmony_cialways-y += lwt_len_hist_kern.o 1488c2ecf20Sopenharmony_cialways-y += xdp_tx_iptunnel_kern.o 1498c2ecf20Sopenharmony_cialways-y += test_map_in_map_kern.o 1508c2ecf20Sopenharmony_cialways-y += tcp_synrto_kern.o 1518c2ecf20Sopenharmony_cialways-y += tcp_rwnd_kern.o 1528c2ecf20Sopenharmony_cialways-y += tcp_bufs_kern.o 1538c2ecf20Sopenharmony_cialways-y += tcp_cong_kern.o 1548c2ecf20Sopenharmony_cialways-y += tcp_iw_kern.o 1558c2ecf20Sopenharmony_cialways-y += tcp_clamp_kern.o 1568c2ecf20Sopenharmony_cialways-y += tcp_basertt_kern.o 1578c2ecf20Sopenharmony_cialways-y += tcp_tos_reflect_kern.o 1588c2ecf20Sopenharmony_cialways-y += tcp_dumpstats_kern.o 1598c2ecf20Sopenharmony_cialways-y += xdp_redirect_kern.o 1608c2ecf20Sopenharmony_cialways-y += xdp_redirect_map_kern.o 1618c2ecf20Sopenharmony_cialways-y += xdp_redirect_cpu_kern.o 1628c2ecf20Sopenharmony_cialways-y += xdp_monitor_kern.o 1638c2ecf20Sopenharmony_cialways-y += xdp_rxq_info_kern.o 1648c2ecf20Sopenharmony_cialways-y += xdp2skb_meta_kern.o 1658c2ecf20Sopenharmony_cialways-y += syscall_tp_kern.o 1668c2ecf20Sopenharmony_cialways-y += cpustat_kern.o 1678c2ecf20Sopenharmony_cialways-y += xdp_adjust_tail_kern.o 1688c2ecf20Sopenharmony_cialways-y += xdp_fwd_kern.o 1698c2ecf20Sopenharmony_cialways-y += task_fd_query_kern.o 1708c2ecf20Sopenharmony_cialways-y += xdp_sample_pkts_kern.o 1718c2ecf20Sopenharmony_cialways-y += ibumad_kern.o 1728c2ecf20Sopenharmony_cialways-y += hbm_out_kern.o 1738c2ecf20Sopenharmony_cialways-y += hbm_edt_kern.o 1748c2ecf20Sopenharmony_cialways-y += xdpsock_kern.o 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ciifeq ($(ARCH), arm) 1778c2ecf20Sopenharmony_ci# Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux 1788c2ecf20Sopenharmony_ci# headers when arm instruction set identification is requested. 1798c2ecf20Sopenharmony_ciARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS)) 1808c2ecf20Sopenharmony_ciBPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR) 1818c2ecf20Sopenharmony_ciTPROGS_CFLAGS += $(ARM_ARCH_SELECTOR) 1828c2ecf20Sopenharmony_ciendif 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -Wall -O2 1858c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -Wmissing-prototypes 1868c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -Wstrict-prototypes 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -I$(objtree)/usr/include 1898c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/ 1908c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -I$(srctree)/tools/lib/ 1918c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -I$(srctree)/tools/include 1928c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -I$(srctree)/tools/perf 1938c2ecf20Sopenharmony_ciTPROGS_CFLAGS += -DHAVE_ATTR_TEST=0 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ciifdef SYSROOT 1968c2ecf20Sopenharmony_ciTPROGS_CFLAGS += --sysroot=$(SYSROOT) 1978c2ecf20Sopenharmony_ciTPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib 1988c2ecf20Sopenharmony_ciendif 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ciTPROGCFLAGS_bpf_load.o += -Wno-unused-variable 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ciTPROGS_LDLIBS += $(LIBBPF) -lelf -lz 2038c2ecf20Sopenharmony_ciTPROGLDLIBS_tracex4 += -lrt 2048c2ecf20Sopenharmony_ciTPROGLDLIBS_trace_output += -lrt 2058c2ecf20Sopenharmony_ciTPROGLDLIBS_map_perf_test += -lrt 2068c2ecf20Sopenharmony_ciTPROGLDLIBS_test_overhead += -lrt 2078c2ecf20Sopenharmony_ciTPROGLDLIBS_xdpsock += -pthread 2088c2ecf20Sopenharmony_ciTPROGLDLIBS_xsk_fwd += -pthread 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: 2118c2ecf20Sopenharmony_ci# make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang 2128c2ecf20Sopenharmony_ciLLC ?= llc 2138c2ecf20Sopenharmony_ciCLANG ?= clang 2148c2ecf20Sopenharmony_ciOPT ?= opt 2158c2ecf20Sopenharmony_ciLLVM_DIS ?= llvm-dis 2168c2ecf20Sopenharmony_ciLLVM_OBJCOPY ?= llvm-objcopy 2178c2ecf20Sopenharmony_ciBTF_PAHOLE ?= pahole 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci# Detect that we're cross compiling and use the cross compiler 2208c2ecf20Sopenharmony_ciifdef CROSS_COMPILE 2218c2ecf20Sopenharmony_ciCLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%)) 2228c2ecf20Sopenharmony_ciendif 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci# Don't evaluate probes and warnings if we need to run make recursively 2258c2ecf20Sopenharmony_ciifneq ($(src),) 2268c2ecf20Sopenharmony_ciHDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \ 2278c2ecf20Sopenharmony_ci $(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \ 2288c2ecf20Sopenharmony_ci -o /dev/null 2>/dev/null && echo okay) 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ciifeq ($(HDR_PROBE),) 2318c2ecf20Sopenharmony_ci$(warning WARNING: Detected possible issues with include path.) 2328c2ecf20Sopenharmony_ci$(warning WARNING: Please install kernel headers locally (make headers_install).) 2338c2ecf20Sopenharmony_ciendif 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ciBTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) 2368c2ecf20Sopenharmony_ciBTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) 2378c2ecf20Sopenharmony_ciBTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') 2388c2ecf20Sopenharmony_ciBTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ 2398c2ecf20Sopenharmony_ci $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 2408c2ecf20Sopenharmony_ci readelf -S ./llvm_btf_verify.o | grep BTF; \ 2418c2ecf20Sopenharmony_ci /bin/rm -f ./llvm_btf_verify.o) 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ciBPF_EXTRA_CFLAGS += -fno-stack-protector 2448c2ecf20Sopenharmony_ciifneq ($(BTF_LLVM_PROBE),) 2458c2ecf20Sopenharmony_ci BPF_EXTRA_CFLAGS += -g 2468c2ecf20Sopenharmony_cielse 2478c2ecf20Sopenharmony_ciifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),) 2488c2ecf20Sopenharmony_ci BPF_EXTRA_CFLAGS += -g 2498c2ecf20Sopenharmony_ci LLC_FLAGS += -mattr=dwarfris 2508c2ecf20Sopenharmony_ci DWARF2BTF = y 2518c2ecf20Sopenharmony_ciendif 2528c2ecf20Sopenharmony_ciendif 2538c2ecf20Sopenharmony_ciendif 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci# Trick to allow make to be run from this directory 2568c2ecf20Sopenharmony_ciall: 2578c2ecf20Sopenharmony_ci $(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR) 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ciclean: 2608c2ecf20Sopenharmony_ci $(MAKE) -C ../../ M=$(CURDIR) clean 2618c2ecf20Sopenharmony_ci @find $(CURDIR) -type f -name '*~' -delete 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci$(LIBBPF): FORCE 2648c2ecf20Sopenharmony_ci# Fix up variables inherited from Kbuild that tools/ build system won't like 2658c2ecf20Sopenharmony_ci $(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \ 2668c2ecf20Sopenharmony_ci LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O= 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE 2698c2ecf20Sopenharmony_ci $(call filechk,offsets,__SYSCALL_NRS_H__) 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_citargets += syscall_nrs.s 2728c2ecf20Sopenharmony_ciclean-files += syscall_nrs.h 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ciFORCE: 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci# Verify LLVM compiler tools are available and bpf target is supported by llc 2788c2ecf20Sopenharmony_ci.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_civerify_cmds: $(CLANG) $(LLC) 2818c2ecf20Sopenharmony_ci @for TOOL in $^ ; do \ 2828c2ecf20Sopenharmony_ci if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \ 2838c2ecf20Sopenharmony_ci echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\ 2848c2ecf20Sopenharmony_ci exit 1; \ 2858c2ecf20Sopenharmony_ci else true; fi; \ 2868c2ecf20Sopenharmony_ci done 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_civerify_target_bpf: verify_cmds 2898c2ecf20Sopenharmony_ci @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ 2908c2ecf20Sopenharmony_ci echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ 2918c2ecf20Sopenharmony_ci echo " NOTICE: LLVM version >= 3.7.1 required" ;\ 2928c2ecf20Sopenharmony_ci exit 2; \ 2938c2ecf20Sopenharmony_ci else true; fi 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF) 2968c2ecf20Sopenharmony_ci$(src)/*.c: verify_target_bpf $(LIBBPF) 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h 2998c2ecf20Sopenharmony_ci$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h 3008c2ecf20Sopenharmony_ci$(obj)/hbm.o: $(src)/hbm.h 3018c2ecf20Sopenharmony_ci$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci-include $(BPF_SAMPLES_PATH)/Makefile.target 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci# asm/sysreg.h - inline assembly used by it is incompatible with llvm. 3068c2ecf20Sopenharmony_ci# But, there is no easy way to fix it, so just exclude it since it is 3078c2ecf20Sopenharmony_ci# useless for BPF samples. 3088c2ecf20Sopenharmony_ci# below we use long chain of commands, clang | opt | llvm-dis | llc, 3098c2ecf20Sopenharmony_ci# to generate final object file. 'clang' compiles the source into IR 3108c2ecf20Sopenharmony_ci# with native target, e.g., x64, arm64, etc. 'opt' does bpf CORE IR builtin 3118c2ecf20Sopenharmony_ci# processing (llvm12) and IR optimizations. 'llvm-dis' converts 3128c2ecf20Sopenharmony_ci# 'opt' output to IR, and finally 'llc' generates bpf byte code. 3138c2ecf20Sopenharmony_ci$(obj)/%.o: $(src)/%.c 3148c2ecf20Sopenharmony_ci @echo " CLANG-bpf " $@ 3158c2ecf20Sopenharmony_ci $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \ 3168c2ecf20Sopenharmony_ci -I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \ 3178c2ecf20Sopenharmony_ci -I$(srctree)/tools/lib/ \ 3188c2ecf20Sopenharmony_ci -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \ 3198c2ecf20Sopenharmony_ci -D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \ 3208c2ecf20Sopenharmony_ci -Wno-gnu-variable-sized-type-not-at-end \ 3218c2ecf20Sopenharmony_ci -Wno-address-of-packed-member -Wno-tautological-compare \ 3228c2ecf20Sopenharmony_ci -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \ 3238c2ecf20Sopenharmony_ci -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \ 3248c2ecf20Sopenharmony_ci -O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \ 3258c2ecf20Sopenharmony_ci $(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \ 3268c2ecf20Sopenharmony_ci $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@ 3278c2ecf20Sopenharmony_ciifeq ($(DWARF2BTF),y) 3288c2ecf20Sopenharmony_ci $(BTF_PAHOLE) -J $@ 3298c2ecf20Sopenharmony_ciendif 330