blob: 81b0ef2f7994005e726f75cd258158388a433a0e [file] [log] [blame]
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -07001# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
Martin KaFai Lau5db58fa2016-11-11 10:55:11 -08005hostprogs-y := test_lru_dist
Alexei Starovoitov03f47232014-12-01 15:06:36 -08006hostprogs-y += sock_example
Daniel Borkmann42984d72015-10-29 14:58:10 +01007hostprogs-y += fds_example
Alexei Starovoitova8085782014-12-01 15:06:38 -08008hostprogs-y += sockex1
Alexei Starovoitovfbe33102014-12-01 15:06:39 -08009hostprogs-y += sockex2
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070010hostprogs-y += sockex3
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070011hostprogs-y += tracex1
Alexei Starovoitovd822a192015-03-25 12:49:24 -070012hostprogs-y += tracex2
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070013hostprogs-y += tracex3
Alexei Starovoitov9811e352015-03-25 12:49:26 -070014hostprogs-y += tracex4
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070015hostprogs-y += tracex5
Kaixu Xia47efb302015-08-06 07:02:36 +000016hostprogs-y += tracex6
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070017hostprogs-y += test_probe_write_user
Alexei Starovoitov39111692015-10-20 20:02:35 -070018hostprogs-y += trace_output
Daniel Wagner0fb11702015-06-19 16:00:44 +020019hostprogs-y += lathist
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080020hostprogs-y += offwaketime
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080021hostprogs-y += spintest
Alexei Starovoitov26e90932016-03-08 15:07:54 -080022hostprogs-y += map_perf_test
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070023hostprogs-y += test_overhead
Martin KaFai Laua3f74612016-06-30 10:28:45 -070024hostprogs-y += test_cgrp2_array_pin
Daniel Mackd8c5b172016-11-23 16:52:30 +010025hostprogs-y += test_cgrp2_attach
Sargun Dhillon9b474ec2016-12-02 02:42:32 -080026hostprogs-y += test_cgrp2_attach2
David Ahernad2805d2016-12-01 08:48:05 -080027hostprogs-y += test_cgrp2_sock
David Ahern554ae6e2016-12-01 08:48:08 -080028hostprogs-y += test_cgrp2_sock2
Brenden Blanco86af8b42016-07-19 12:16:51 -070029hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070030hostprogs-y += xdp2
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070031hostprogs-y += test_current_task_under_cgroup
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070032hostprogs-y += trace_event
Brendan Gregg72874412016-09-01 18:37:26 -070033hostprogs-y += sampleip
Martin KaFai Lau90e02892016-11-09 15:36:34 -080034hostprogs-y += tc_l2_redirect
Thomas Graff74599f2016-11-30 17:10:11 +010035hostprogs-y += lwt_len_hist
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -080036hostprogs-y += xdp_tx_iptunnel
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070037
Joe Stringer43371c82016-12-14 14:43:39 -080038# Libbpf dependencies
39LIBBPF := libbpf.o ../../tools/lib/bpf/bpf.o
40
41test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
42sock_example-objs := sock_example.o $(LIBBPF)
43fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
44sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
45sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
46sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
47tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
48tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
49tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
50tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
51tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
52tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
53test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
54trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
55lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
56offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
57spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
58map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
59test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
60test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
61test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
62test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
63test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
64test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
65xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070066# reuse xdp1 source intentionally
Joe Stringer43371c82016-12-14 14:43:39 -080067xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
68test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070069 test_current_task_under_cgroup_user.o
Joe Stringer43371c82016-12-14 14:43:39 -080070trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
71sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
72tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
73lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
74xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070075
76# Tell kbuild to always build the programs
77always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080078always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080079always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070080always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070081always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070082always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070083always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070084always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070085always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000086always += tracex6_kern.o
David Ahern554ae6e2016-12-01 08:48:08 -080087always += sock_flags_kern.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070088always += test_probe_write_user_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070089always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070090always += tcbpf1_kern.o
William Tu6afb1e22016-08-19 11:55:44 -070091always += tcbpf2_kern.o
Martin KaFai Lau90e02892016-11-09 15:36:34 -080092always += tc_l2_redirect_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020093always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080094always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080095always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080096always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070097always += test_overhead_tp_kern.o
98always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070099always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -0700100always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -0700101always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700102always += xdp2_kern.o
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700103always += test_current_task_under_cgroup_kern.o
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700104always += trace_event_kern.o
Brendan Gregg72874412016-09-01 18:37:26 -0700105always += sampleip_kern.o
Thomas Graff74599f2016-11-30 17:10:11 +0100106always += lwt_len_hist_kern.o
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -0800107always += xdp_tx_iptunnel_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -0700108
109HOSTCFLAGS += -I$(objtree)/usr/include
Joe Stringer43371c82016-12-14 14:43:39 -0800110HOSTCFLAGS += -I$(srctree)/tools/lib/
Alexei Starovoitov9bee2942016-11-28 22:07:22 -0800111HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
Alexei Starovoitova8085782014-12-01 15:06:38 -0800112
113HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +0100114HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800115HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -0800116HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -0700117HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -0700118HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -0700119HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -0700120HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -0700121HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -0700122HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +0000123HOSTLOADLIBES_tracex6 += -lelf
David Ahern554ae6e2016-12-01 08:48:08 -0800124HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
Sargun Dhilloncf9b1192016-07-25 05:55:02 -0700125HOSTLOADLIBES_test_probe_write_user += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -0700126HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +0200127HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -0800128HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -0800129HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -0800130HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700131HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -0700132HOSTLOADLIBES_xdp1 += -lelf
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700133HOSTLOADLIBES_xdp2 += -lelf
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700134HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700135HOSTLOADLIBES_trace_event += -lelf
Brendan Gregg72874412016-09-01 18:37:26 -0700136HOSTLOADLIBES_sampleip += -lelf
Martin KaFai Lau90e02892016-11-09 15:36:34 -0800137HOSTLOADLIBES_tc_l2_redirect += -l elf
Thomas Graff74599f2016-11-30 17:10:11 +0100138HOSTLOADLIBES_lwt_len_hist += -l elf
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -0800139HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800140
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200141# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
142# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200143LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200144CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200145
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200146# Trick to allow make to be run from this directory
147all:
148 $(MAKE) -C ../../ $$PWD/
149
150clean:
151 $(MAKE) -C ../../ M=$$PWD clean
152 @rm -f *~
153
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200154# Verify LLVM compiler tools are available and bpf target is supported by llc
155.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200156
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200157verify_cmds: $(CLANG) $(LLC)
158 @for TOOL in $^ ; do \
159 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
160 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
161 exit 1; \
162 else true; fi; \
163 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200164
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200165verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200166 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
167 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
168 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
169 exit 2; \
170 else true; fi
171
172$(src)/*.c: verify_target_bpf
173
Naveen N. Rao128d1512016-04-04 22:31:33 +0530174# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
175# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800176# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700177$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200178 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800179 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700180 -Wno-compare-distinct-pointer-types \
Alexei Starovoitov69a9d092016-12-01 18:31:12 -0800181 -Wno-gnu-variable-sized-type-not-at-end \
182 -Wno-address-of-packed-member -Wno-tautological-compare \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200183 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@