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