]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - samples/bpf/Makefile
samples/bpf: fix a build problem
[mirror_ubuntu-bionic-kernel.git] / samples / bpf / Makefile
CommitLineData
3c731eba
AS
1# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
5db58faf 5hostprogs-y := test_lru_dist
03f4723e 6hostprogs-y += sock_example
42984d7c 7hostprogs-y += fds_example
a8085782 8hostprogs-y += sockex1
fbe33108 9hostprogs-y += sockex2
530b2c86 10hostprogs-y += sockex3
b896c4f9 11hostprogs-y += tracex1
d822a192 12hostprogs-y += tracex2
5c7fc2d2 13hostprogs-y += tracex3
9811e353 14hostprogs-y += tracex4
5bacd780 15hostprogs-y += tracex5
47efb302 16hostprogs-y += tracex6
cf9b1199 17hostprogs-y += test_probe_write_user
39111695 18hostprogs-y += trace_output
0fb1170e 19hostprogs-y += lathist
a6ffe7b9 20hostprogs-y += offwaketime
9d8b612d 21hostprogs-y += spintest
26e90931 22hostprogs-y += map_perf_test
e3edfdec 23hostprogs-y += test_overhead
a3f74617 24hostprogs-y += test_cgrp2_array_pin
d8c5b17f 25hostprogs-y += test_cgrp2_attach
9b474ece 26hostprogs-y += test_cgrp2_attach2
ad2805dc 27hostprogs-y += test_cgrp2_sock
554ae6e7 28hostprogs-y += test_cgrp2_sock2
86af8b41 29hostprogs-y += xdp1
764cbcce 30hostprogs-y += xdp2
9e6e60ec 31hostprogs-y += test_current_task_under_cgroup
1c47910e 32hostprogs-y += trace_event
72874418 33hostprogs-y += sampleip
90e02896 34hostprogs-y += tc_l2_redirect
f74599f7 35hostprogs-y += lwt_len_hist
12d8bb64 36hostprogs-y += xdp_tx_iptunnel
fb30d4b7 37hostprogs-y += test_map_in_map
51570a5a 38hostprogs-y += per_socket_stats_example
3c731eba 39
43371c83 40# Libbpf dependencies
9899694a 41LIBBPF := ../../tools/lib/bpf/bpf.o
43371c83
JS
42
43test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
44sock_example-objs := sock_example.o $(LIBBPF)
45fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
46sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
47sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
48sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
49tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
50tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
51tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
52tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
53tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
54tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
55test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
56trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
57lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
58offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
59spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
60map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
61test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
62test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
63test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
64test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
65test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
66test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
67xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
764cbcce 68# reuse xdp1 source intentionally
43371c83
JS
69xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
70test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
9e6e60ec 71 test_current_task_under_cgroup_user.o
43371c83
JS
72trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
73sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
74tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
75lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
76xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
fb30d4b7 77test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
51570a5a 78per_socket_stats_example-objs := $(LIBBPF) cookie_uid_helper_example.o
3c731eba
AS
79
80# Tell kbuild to always build the programs
81always := $(hostprogs-y)
a8085782 82always += sockex1_kern.o
fbe33108 83always += sockex2_kern.o
530b2c86 84always += sockex3_kern.o
b896c4f9 85always += tracex1_kern.o
d822a192 86always += tracex2_kern.o
5c7fc2d2 87always += tracex3_kern.o
9811e353 88always += tracex4_kern.o
5bacd780 89always += tracex5_kern.o
47efb302 90always += tracex6_kern.o
554ae6e7 91always += sock_flags_kern.o
cf9b1199 92always += test_probe_write_user_kern.o
39111695 93always += trace_output_kern.o
91bc4822 94always += tcbpf1_kern.o
6afb1e28 95always += tcbpf2_kern.o
90e02896 96always += tc_l2_redirect_kern.o
0fb1170e 97always += lathist_kern.o
a6ffe7b9 98always += offwaketime_kern.o
9d8b612d 99always += spintest_kern.o
26e90931 100always += map_perf_test_kern.o
e3edfdec
AS
101always += test_overhead_tp_kern.o
102always += test_overhead_kprobe_kern.o
65d472fb 103always += parse_varlen.o parse_simple.o parse_ldabs.o
a3f74617 104always += test_cgrp2_tc_kern.o
86af8b41 105always += xdp1_kern.o
764cbcce 106always += xdp2_kern.o
9e6e60ec 107always += test_current_task_under_cgroup_kern.o
1c47910e 108always += trace_event_kern.o
72874418 109always += sampleip_kern.o
f74599f7 110always += lwt_len_hist_kern.o
12d8bb64 111always += xdp_tx_iptunnel_kern.o
fb30d4b7 112always += test_map_in_map_kern.o
51570a5a 113always += cookie_uid_helper_example.o
3c731eba
AS
114
115HOSTCFLAGS += -I$(objtree)/usr/include
43371c83 116HOSTCFLAGS += -I$(srctree)/tools/lib/
9bee294f 117HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
205c8ada
JS
118HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
119HOSTCFLAGS += -I$(srctree)/tools/perf
a8085782
AS
120
121HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
42984d7c 122HOSTLOADLIBES_fds_example += -lelf
a8085782 123HOSTLOADLIBES_sockex1 += -lelf
fbe33108 124HOSTLOADLIBES_sockex2 += -lelf
530b2c86 125HOSTLOADLIBES_sockex3 += -lelf
b896c4f9 126HOSTLOADLIBES_tracex1 += -lelf
d822a192 127HOSTLOADLIBES_tracex2 += -lelf
5c7fc2d2 128HOSTLOADLIBES_tracex3 += -lelf
9811e353 129HOSTLOADLIBES_tracex4 += -lelf -lrt
5bacd780 130HOSTLOADLIBES_tracex5 += -lelf
47efb302 131HOSTLOADLIBES_tracex6 += -lelf
554ae6e7 132HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
cf9b1199 133HOSTLOADLIBES_test_probe_write_user += -lelf
39111695 134HOSTLOADLIBES_trace_output += -lelf -lrt
0fb1170e 135HOSTLOADLIBES_lathist += -lelf
a6ffe7b9 136HOSTLOADLIBES_offwaketime += -lelf
9d8b612d 137HOSTLOADLIBES_spintest += -lelf
26e90931 138HOSTLOADLIBES_map_perf_test += -lelf -lrt
e3edfdec 139HOSTLOADLIBES_test_overhead += -lelf -lrt
86af8b41 140HOSTLOADLIBES_xdp1 += -lelf
764cbcce 141HOSTLOADLIBES_xdp2 += -lelf
9e6e60ec 142HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
1c47910e 143HOSTLOADLIBES_trace_event += -lelf
72874418 144HOSTLOADLIBES_sampleip += -lelf
90e02896 145HOSTLOADLIBES_tc_l2_redirect += -l elf
f74599f7 146HOSTLOADLIBES_lwt_len_hist += -l elf
12d8bb64 147HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
fb30d4b7 148HOSTLOADLIBES_test_map_in_map += -lelf
a8085782 149
bdefbbf2
JDB
150# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
151# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
6ccfba75 152LLC ?= llc
bdefbbf2 153CLANG ?= clang
6ccfba75 154
b62a796c
JDB
155# Trick to allow make to be run from this directory
156all:
e19b7cee 157 $(MAKE) -C ../../ $(CURDIR)/
b62a796c
JDB
158
159clean:
e19b7cee 160 $(MAKE) -C ../../ M=$(CURDIR) clean
b62a796c
JDB
161 @rm -f *~
162
4b7190e8
DD
163$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
164 $(call if_changed_dep,cc_s_c)
165
166$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
167 $(call filechk,offsets,__SYSCALL_NRS_H__)
168
169clean-files += syscall_nrs.h
170
171FORCE:
172
173
bdefbbf2
JDB
174# Verify LLVM compiler tools are available and bpf target is supported by llc
175.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
7b01dd57 176
bdefbbf2
JDB
177verify_cmds: $(CLANG) $(LLC)
178 @for TOOL in $^ ; do \
179 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
180 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
181 exit 1; \
182 else true; fi; \
183 done
7b01dd57 184
bdefbbf2 185verify_target_bpf: verify_cmds
7b01dd57
JDB
186 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
187 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
188 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
189 exit 2; \
190 else true; fi
191
192$(src)/*.c: verify_target_bpf
193
4b7190e8
DD
194$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
195
128d1514
NR
196# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
197# But, there is no easy way to fix it, so just exclude it since it is
30b50aa6 198# useless for BPF samples.
b88c06e3 199$(obj)/%.o: $(src)/%.c
00a3855d 200 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
30b50aa6 201 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
65d472fb 202 -Wno-compare-distinct-pointer-types \
69a9d09b
AS
203 -Wno-gnu-variable-sized-type-not-at-end \
204 -Wno-address-of-packed-member -Wno-tautological-compare \
69b6a7f7 205 -Wno-unknown-warning-option \
6ccfba75 206 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@