xref: /openbmc/linux/samples/bpf/Makefile (revision 9dae47aba0a055f761176d9297371d5bb24289ec)
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
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 += syscall_tp_kern.o
146
147HOSTCFLAGS += -I$(objtree)/usr/include
148HOSTCFLAGS += -I$(srctree)/tools/lib/
149HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
150HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
151HOSTCFLAGS += -I$(srctree)/tools/perf
152
153HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
154HOSTLOADLIBES_fds_example += -lelf
155HOSTLOADLIBES_sockex1 += -lelf
156HOSTLOADLIBES_sockex2 += -lelf
157HOSTLOADLIBES_sockex3 += -lelf
158HOSTLOADLIBES_tracex1 += -lelf
159HOSTLOADLIBES_tracex2 += -lelf
160HOSTLOADLIBES_tracex3 += -lelf
161HOSTLOADLIBES_tracex4 += -lelf -lrt
162HOSTLOADLIBES_tracex5 += -lelf
163HOSTLOADLIBES_tracex6 += -lelf
164HOSTLOADLIBES_tracex7 += -lelf
165HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
166HOSTLOADLIBES_load_sock_ops += -lelf
167HOSTLOADLIBES_test_probe_write_user += -lelf
168HOSTLOADLIBES_trace_output += -lelf -lrt
169HOSTLOADLIBES_lathist += -lelf
170HOSTLOADLIBES_offwaketime += -lelf
171HOSTLOADLIBES_spintest += -lelf
172HOSTLOADLIBES_map_perf_test += -lelf -lrt
173HOSTLOADLIBES_test_overhead += -lelf -lrt
174HOSTLOADLIBES_xdp1 += -lelf
175HOSTLOADLIBES_xdp2 += -lelf
176HOSTLOADLIBES_xdp_router_ipv4 += -lelf
177HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
178HOSTLOADLIBES_trace_event += -lelf
179HOSTLOADLIBES_sampleip += -lelf
180HOSTLOADLIBES_tc_l2_redirect += -l elf
181HOSTLOADLIBES_lwt_len_hist += -l elf
182HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
183HOSTLOADLIBES_test_map_in_map += -lelf
184HOSTLOADLIBES_xdp_redirect += -lelf
185HOSTLOADLIBES_xdp_redirect_map += -lelf
186HOSTLOADLIBES_xdp_redirect_cpu += -lelf
187HOSTLOADLIBES_xdp_monitor += -lelf
188HOSTLOADLIBES_xdp_rxq_info += -lelf
189HOSTLOADLIBES_syscall_tp += -lelf
190
191# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
192#  make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
193LLC ?= llc
194CLANG ?= clang
195
196# Detect that we're cross compiling and use the cross compiler
197ifdef CROSS_COMPILE
198HOSTCC = $(CROSS_COMPILE)gcc
199CLANG_ARCH_ARGS = -target $(ARCH)
200endif
201
202# Trick to allow make to be run from this directory
203all:
204	$(MAKE) -C ../../ $(CURDIR)/
205
206clean:
207	$(MAKE) -C ../../ M=$(CURDIR) clean
208	@rm -f *~
209
210$(obj)/syscall_nrs.s:	$(src)/syscall_nrs.c
211	$(call if_changed_dep,cc_s_c)
212
213$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
214	$(call filechk,offsets,__SYSCALL_NRS_H__)
215
216clean-files += syscall_nrs.h
217
218FORCE:
219
220
221# Verify LLVM compiler tools are available and bpf target is supported by llc
222.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
223
224verify_cmds: $(CLANG) $(LLC)
225	@for TOOL in $^ ; do \
226		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
227			echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
228			exit 1; \
229		else true; fi; \
230	done
231
232verify_target_bpf: verify_cmds
233	@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
234		echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
235		echo "   NOTICE: LLVM version >= 3.7.1 required" ;\
236		exit 2; \
237	else true; fi
238
239$(src)/*.c: verify_target_bpf
240
241$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
242
243# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
244# But, there is no easy way to fix it, so just exclude it since it is
245# useless for BPF samples.
246$(obj)/%.o: $(src)/%.c
247	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
248		-I$(srctree)/tools/testing/selftests/bpf/ \
249		-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
250		-D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
251		-Wno-gnu-variable-sized-type-not-at-end \
252		-Wno-address-of-packed-member -Wno-tautological-compare \
253		-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
254		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
255