blob: b2cdced61090e51ad2691a86b7a8d69fbfe1b081 [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
Alexei Starovoitovffb65f22014-11-13 17:36:48 -08005hostprogs-y := test_verifier test_maps
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 Mackc00662a2016-11-23 16:52:30 +010025hostprogs-y += test_cgrp2_attach
Brenden Blanco86af8b42016-07-19 12:16:51 -070026hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070027hostprogs-y += xdp2
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070028hostprogs-y += test_current_task_under_cgroup
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070029hostprogs-y += trace_event
Brendan Gregg72874412016-09-01 18:37:26 -070030hostprogs-y += sampleip
Martin KaFai Lau90e02892016-11-09 15:36:34 -080031hostprogs-y += tc_l2_redirect
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070032
33test_verifier-objs := test_verifier.o libbpf.o
Alexei Starovoitovffb65f22014-11-13 17:36:48 -080034test_maps-objs := test_maps.o libbpf.o
Alexei Starovoitov03f47232014-12-01 15:06:36 -080035sock_example-objs := sock_example.o libbpf.o
Daniel Borkmann42984d72015-10-29 14:58:10 +010036fds_example-objs := bpf_load.o libbpf.o fds_example.o
Alexei Starovoitova8085782014-12-01 15:06:38 -080037sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080038sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070039sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070040tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070041tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070042tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070043tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070044tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
Kaixu Xia47efb302015-08-06 07:02:36 +000045tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070046test_probe_write_user-objs := bpf_load.o libbpf.o test_probe_write_user_user.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070047trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020048lathist-objs := bpf_load.o libbpf.o lathist_user.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080049offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080050spintest-objs := bpf_load.o libbpf.o spintest_user.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080051map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070052test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070053test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
Daniel Mackc00662a2016-11-23 16:52:30 +010054test_cgrp2_attach-objs := libbpf.o test_cgrp2_attach.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070055xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070056# reuse xdp1 source intentionally
57xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070058test_current_task_under_cgroup-objs := bpf_load.o libbpf.o \
59 test_current_task_under_cgroup_user.o
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070060trace_event-objs := bpf_load.o libbpf.o trace_event_user.o
Brendan Gregg72874412016-09-01 18:37:26 -070061sampleip-objs := bpf_load.o libbpf.o sampleip_user.o
Martin KaFai Lau90e02892016-11-09 15:36:34 -080062tc_l2_redirect-objs := bpf_load.o libbpf.o tc_l2_redirect_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070063
64# Tell kbuild to always build the programs
65always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080066always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080067always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070068always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070069always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070070always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070071always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070072always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070073always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000074always += tracex6_kern.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070075always += test_probe_write_user_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070076always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070077always += tcbpf1_kern.o
William Tu6afb1e22016-08-19 11:55:44 -070078always += tcbpf2_kern.o
Martin KaFai Lau90e02892016-11-09 15:36:34 -080079always += tc_l2_redirect_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020080always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080081always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080082always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080083always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070084always += test_overhead_tp_kern.o
85always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070086always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070087always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070088always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070089always += xdp2_kern.o
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070090always += test_current_task_under_cgroup_kern.o
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070091always += trace_event_kern.o
Brendan Gregg72874412016-09-01 18:37:26 -070092always += sampleip_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070093
94HOSTCFLAGS += -I$(objtree)/usr/include
Alexei Starovoitova8085782014-12-01 15:06:38 -080095
96HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +010097HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080098HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080099HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -0700100HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -0700101HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -0700102HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -0700103HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -0700104HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -0700105HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +0000106HOSTLOADLIBES_tracex6 += -lelf
Sargun Dhilloncf9b1192016-07-25 05:55:02 -0700107HOSTLOADLIBES_test_probe_write_user += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -0700108HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +0200109HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -0800110HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -0800111HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -0800112HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700113HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -0700114HOSTLOADLIBES_xdp1 += -lelf
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700115HOSTLOADLIBES_xdp2 += -lelf
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700116HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700117HOSTLOADLIBES_trace_event += -lelf
Brendan Gregg72874412016-09-01 18:37:26 -0700118HOSTLOADLIBES_sampleip += -lelf
Martin KaFai Lau90e02892016-11-09 15:36:34 -0800119HOSTLOADLIBES_tc_l2_redirect += -l elf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800120
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200121# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
122# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200123LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200124CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200125
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200126# Trick to allow make to be run from this directory
127all:
128 $(MAKE) -C ../../ $$PWD/
129
130clean:
131 $(MAKE) -C ../../ M=$$PWD clean
132 @rm -f *~
133
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200134# Verify LLVM compiler tools are available and bpf target is supported by llc
135.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200136
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200137verify_cmds: $(CLANG) $(LLC)
138 @for TOOL in $^ ; do \
139 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
140 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
141 exit 1; \
142 else true; fi; \
143 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200144
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200145verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200146 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
147 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
148 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
149 exit 2; \
150 else true; fi
151
152$(src)/*.c: verify_target_bpf
153
Naveen N. Rao128d1512016-04-04 22:31:33 +0530154# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
155# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800156# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700157$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200158 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800159 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700160 -Wno-compare-distinct-pointer-types \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200161 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@