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