xref: /linux/samples/bpf/Makefile (revision af50e4ba34f4c45e92535364133d4deb5931c1c5)
1# SPDX-License-Identifier: GPL-2.0
2# List of programs to build
3hostprogs-y := test_lru_dist
4hostprogs-y += sock_example
5hostprogs-y += fds_example
6hostprogs-y += sockex1
7hostprogs-y += sockex2
8hostprogs-y += sockex3
9hostprogs-y += tracex1
10hostprogs-y += tracex2
11hostprogs-y += tracex3
12hostprogs-y += tracex4
13hostprogs-y += tracex5
14hostprogs-y += tracex6
15hostprogs-y += tracex7
16hostprogs-y += test_probe_write_user
17hostprogs-y += trace_output
18hostprogs-y += lathist
19hostprogs-y += offwaketime
20hostprogs-y += spintest
21hostprogs-y += map_perf_test
22hostprogs-y += test_overhead
23hostprogs-y += test_cgrp2_array_pin
24hostprogs-y += test_cgrp2_attach
25hostprogs-y += test_cgrp2_attach2
26hostprogs-y += test_cgrp2_sock
27hostprogs-y += test_cgrp2_sock2
28hostprogs-y += xdp1
29hostprogs-y += xdp2
30hostprogs-y += xdp_router_ipv4
31hostprogs-y += test_current_task_under_cgroup
32hostprogs-y += trace_event
33hostprogs-y += sampleip
34hostprogs-y += tc_l2_redirect
35hostprogs-y += lwt_len_hist
36hostprogs-y += xdp_tx_iptunnel
37hostprogs-y += test_map_in_map
38hostprogs-y += per_socket_stats_example
39hostprogs-y += load_sock_ops
40hostprogs-y += xdp_redirect
41hostprogs-y += xdp_redirect_map
42hostprogs-y += xdp_redirect_cpu
43hostprogs-y += xdp_monitor
44hostprogs-y += xdp_rxq_info
45hostprogs-y += syscall_tp
46hostprogs-y += cpustat
47
48# Libbpf dependencies
49LIBBPF := ../../tools/lib/bpf/bpf.o ../../tools/lib/bpf/nlattr.o
50CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
51
52test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
53sock_example-objs := sock_example.o $(LIBBPF)
54fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
55sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
56sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
57sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
58tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
59tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
60tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
61tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
62tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
63tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
64tracex7-objs := bpf_load.o $(LIBBPF) tracex7_user.o
65load_sock_ops-objs := bpf_load.o $(LIBBPF) load_sock_ops.o
66test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
67trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
68lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
69offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
70spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
71map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
72test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
73test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
74test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
75test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o $(CGROUP_HELPERS)
76test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
77test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
78xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
79# reuse xdp1 source intentionally
80xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
81xdp_router_ipv4-objs := bpf_load.o $(LIBBPF) xdp_router_ipv4_user.o
82test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) $(CGROUP_HELPERS) \
83				       test_current_task_under_cgroup_user.o
84trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
85sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
86tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
87lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
88xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
89test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
90per_socket_stats_example-objs := $(LIBBPF) cookie_uid_helper_example.o
91xdp_redirect-objs := bpf_load.o $(LIBBPF) xdp_redirect_user.o
92xdp_redirect_map-objs := bpf_load.o $(LIBBPF) xdp_redirect_map_user.o
93xdp_redirect_cpu-objs := bpf_load.o $(LIBBPF) xdp_redirect_cpu_user.o
94xdp_monitor-objs := bpf_load.o $(LIBBPF) xdp_monitor_user.o
95xdp_rxq_info-objs := bpf_load.o $(LIBBPF) xdp_rxq_info_user.o
96syscall_tp-objs := bpf_load.o $(LIBBPF) syscall_tp_user.o
97cpustat-objs := bpf_load.o $(LIBBPF) cpustat_user.o
98
99# Tell kbuild to always build the programs
100always := $(hostprogs-y)
101always += sockex1_kern.o
102always += sockex2_kern.o
103always += sockex3_kern.o
104always += tracex1_kern.o
105always += tracex2_kern.o
106always += tracex3_kern.o
107always += tracex4_kern.o
108always += tracex5_kern.o
109always += tracex6_kern.o
110always += tracex7_kern.o
111always += sock_flags_kern.o
112always += test_probe_write_user_kern.o
113always += trace_output_kern.o
114always += tcbpf1_kern.o
115always += tcbpf2_kern.o
116always += tc_l2_redirect_kern.o
117always += lathist_kern.o
118always += offwaketime_kern.o
119always += spintest_kern.o
120always += map_perf_test_kern.o
121always += test_overhead_tp_kern.o
122always += test_overhead_raw_tp_kern.o
123always += test_overhead_kprobe_kern.o
124always += parse_varlen.o parse_simple.o parse_ldabs.o
125always += test_cgrp2_tc_kern.o
126always += xdp1_kern.o
127always += xdp2_kern.o
128always += xdp_router_ipv4_kern.o
129always += test_current_task_under_cgroup_kern.o
130always += trace_event_kern.o
131always += sampleip_kern.o
132always += lwt_len_hist_kern.o
133always += xdp_tx_iptunnel_kern.o
134always += test_map_in_map_kern.o
135always += cookie_uid_helper_example.o
136always += tcp_synrto_kern.o
137always += tcp_rwnd_kern.o
138always += tcp_bufs_kern.o
139always += tcp_cong_kern.o
140always += tcp_iw_kern.o
141always += tcp_clamp_kern.o
142always += tcp_basertt_kern.o
143always += xdp_redirect_kern.o
144always += xdp_redirect_map_kern.o
145always += xdp_redirect_cpu_kern.o
146always += xdp_monitor_kern.o
147always += xdp_rxq_info_kern.o
148always += xdp2skb_meta_kern.o
149always += syscall_tp_kern.o
150always += cpustat_kern.o
151
152HOSTCFLAGS += -I$(objtree)/usr/include
153HOSTCFLAGS += -I$(srctree)/tools/lib/
154HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
155HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
156HOSTCFLAGS += -I$(srctree)/tools/perf
157
158HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
159HOSTLOADLIBES_fds_example += -lelf
160HOSTLOADLIBES_sockex1 += -lelf
161HOSTLOADLIBES_sockex2 += -lelf
162HOSTLOADLIBES_sockex3 += -lelf
163HOSTLOADLIBES_tracex1 += -lelf
164HOSTLOADLIBES_tracex2 += -lelf
165HOSTLOADLIBES_tracex3 += -lelf
166HOSTLOADLIBES_tracex4 += -lelf -lrt
167HOSTLOADLIBES_tracex5 += -lelf
168HOSTLOADLIBES_tracex6 += -lelf
169HOSTLOADLIBES_tracex7 += -lelf
170HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
171HOSTLOADLIBES_load_sock_ops += -lelf
172HOSTLOADLIBES_test_probe_write_user += -lelf
173HOSTLOADLIBES_trace_output += -lelf -lrt
174HOSTLOADLIBES_lathist += -lelf
175HOSTLOADLIBES_offwaketime += -lelf
176HOSTLOADLIBES_spintest += -lelf
177HOSTLOADLIBES_map_perf_test += -lelf -lrt
178HOSTLOADLIBES_test_overhead += -lelf -lrt
179HOSTLOADLIBES_xdp1 += -lelf
180HOSTLOADLIBES_xdp2 += -lelf
181HOSTLOADLIBES_xdp_router_ipv4 += -lelf
182HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
183HOSTLOADLIBES_trace_event += -lelf
184HOSTLOADLIBES_sampleip += -lelf
185HOSTLOADLIBES_tc_l2_redirect += -l elf
186HOSTLOADLIBES_lwt_len_hist += -l elf
187HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
188HOSTLOADLIBES_test_map_in_map += -lelf
189HOSTLOADLIBES_xdp_redirect += -lelf
190HOSTLOADLIBES_xdp_redirect_map += -lelf
191HOSTLOADLIBES_xdp_redirect_cpu += -lelf
192HOSTLOADLIBES_xdp_monitor += -lelf
193HOSTLOADLIBES_xdp_rxq_info += -lelf
194HOSTLOADLIBES_syscall_tp += -lelf
195HOSTLOADLIBES_cpustat += -lelf
196
197# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
198#  make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
199LLC ?= llc
200CLANG ?= clang
201
202# Detect that we're cross compiling and use the cross compiler
203ifdef CROSS_COMPILE
204HOSTCC = $(CROSS_COMPILE)gcc
205CLANG_ARCH_ARGS = -target $(ARCH)
206endif
207
208# Trick to allow make to be run from this directory
209all: $(LIBBPF)
210	$(MAKE) -C ../../ $(CURDIR)/
211
212clean:
213	$(MAKE) -C ../../ M=$(CURDIR) clean
214	@rm -f *~
215
216$(LIBBPF): FORCE
217	$(MAKE) -C $(dir $@) $(notdir $@)
218
219$(obj)/syscall_nrs.s:	$(src)/syscall_nrs.c
220	$(call if_changed_dep,cc_s_c)
221
222$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
223	$(call filechk,offsets,__SYSCALL_NRS_H__)
224
225clean-files += syscall_nrs.h
226
227FORCE:
228
229
230# Verify LLVM compiler tools are available and bpf target is supported by llc
231.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
232
233verify_cmds: $(CLANG) $(LLC)
234	@for TOOL in $^ ; do \
235		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
236			echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
237			exit 1; \
238		else true; fi; \
239	done
240
241verify_target_bpf: verify_cmds
242	@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
243		echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
244		echo "   NOTICE: LLVM version >= 3.7.1 required" ;\
245		exit 2; \
246	else true; fi
247
248$(src)/*.c: verify_target_bpf
249
250$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
251
252# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
253# But, there is no easy way to fix it, so just exclude it since it is
254# useless for BPF samples.
255$(obj)/%.o: $(src)/%.c
256	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
257		-I$(srctree)/tools/testing/selftests/bpf/ \
258		-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
259		-D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
260		-Wno-gnu-variable-sized-type-not-at-end \
261		-Wno-address-of-packed-member -Wno-tautological-compare \
262		-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
263		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
264