Makefile 10.4 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0
2 3 4 5

BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools

6
# List of programs to build
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
tprogs-y := test_lru_dist
tprogs-y += sock_example
tprogs-y += fds_example
tprogs-y += sockex1
tprogs-y += sockex2
tprogs-y += sockex3
tprogs-y += tracex1
tprogs-y += tracex2
tprogs-y += tracex3
tprogs-y += tracex4
tprogs-y += tracex5
tprogs-y += tracex6
tprogs-y += tracex7
tprogs-y += test_probe_write_user
tprogs-y += trace_output
tprogs-y += lathist
tprogs-y += offwaketime
tprogs-y += spintest
tprogs-y += map_perf_test
tprogs-y += test_overhead
tprogs-y += test_cgrp2_array_pin
tprogs-y += test_cgrp2_attach
tprogs-y += test_cgrp2_sock
tprogs-y += test_cgrp2_sock2
tprogs-y += xdp1
tprogs-y += xdp2
tprogs-y += xdp_router_ipv4
tprogs-y += test_current_task_under_cgroup
tprogs-y += trace_event
tprogs-y += sampleip
tprogs-y += tc_l2_redirect
tprogs-y += lwt_len_hist
tprogs-y += xdp_tx_iptunnel
tprogs-y += test_map_in_map
41 42
tprogs-y += per_socket_stats_example
tprogs-y += xdp_redirect
43 44 45 46 47 48 49 50 51 52 53 54 55
tprogs-y += xdp_redirect_map
tprogs-y += xdp_redirect_cpu
tprogs-y += xdp_monitor
tprogs-y += xdp_rxq_info
tprogs-y += syscall_tp
tprogs-y += cpustat
tprogs-y += xdp_adjust_tail
tprogs-y += xdpsock
tprogs-y += xdp_fwd
tprogs-y += task_fd_query
tprogs-y += xdp_sample_pkts
tprogs-y += ibumad
tprogs-y += hbm
56

J
Joe Stringer 已提交
57
# Libbpf dependencies
58 59
LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a

60
CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
61
TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o
J
Joe Stringer 已提交
62

63 64 65
fds_example-objs := fds_example.o
sockex1-objs := sockex1_user.o
sockex2-objs := sockex2_user.o
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
sockex3-objs := bpf_load.o sockex3_user.o
tracex1-objs := bpf_load.o tracex1_user.o
tracex2-objs := bpf_load.o tracex2_user.o
tracex3-objs := bpf_load.o tracex3_user.o
tracex4-objs := bpf_load.o tracex4_user.o
tracex5-objs := bpf_load.o tracex5_user.o
tracex6-objs := bpf_load.o tracex6_user.o
tracex7-objs := bpf_load.o tracex7_user.o
test_probe_write_user-objs := bpf_load.o test_probe_write_user_user.o
trace_output-objs := bpf_load.o trace_output_user.o $(TRACE_HELPERS)
lathist-objs := bpf_load.o lathist_user.o
offwaketime-objs := bpf_load.o offwaketime_user.o $(TRACE_HELPERS)
spintest-objs := bpf_load.o spintest_user.o $(TRACE_HELPERS)
map_perf_test-objs := bpf_load.o map_perf_test_user.o
test_overhead-objs := bpf_load.o test_overhead_user.o
test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o
test_cgrp2_attach-objs := test_cgrp2_attach.o
test_cgrp2_sock-objs := test_cgrp2_sock.o
test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o
xdp1-objs := xdp1_user.o
86
# reuse xdp1 source intentionally
87
xdp2-objs := xdp1_user.o
88
xdp_router_ipv4-objs := xdp_router_ipv4_user.o
89
test_current_task_under_cgroup-objs := bpf_load.o $(CGROUP_HELPERS) \
90
				       test_current_task_under_cgroup_user.o
91 92 93 94
trace_event-objs := bpf_load.o trace_event_user.o $(TRACE_HELPERS)
sampleip-objs := bpf_load.o sampleip_user.o $(TRACE_HELPERS)
tc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o
lwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o
95
xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o
96 97
test_map_in_map-objs := bpf_load.o test_map_in_map_user.o
per_socket_stats_example-objs := cookie_uid_helper_example.o
98 99
xdp_redirect-objs := xdp_redirect_user.o
xdp_redirect_map-objs := xdp_redirect_map_user.o
100 101 102 103 104 105
xdp_redirect_cpu-objs := bpf_load.o xdp_redirect_cpu_user.o
xdp_monitor-objs := bpf_load.o xdp_monitor_user.o
xdp_rxq_info-objs := xdp_rxq_info_user.o
syscall_tp-objs := bpf_load.o syscall_tp_user.o
cpustat-objs := bpf_load.o cpustat_user.o
xdp_adjust_tail-objs := xdp_adjust_tail_user.o
106
xdpsock-objs := xdpsock_user.o
107
xdp_fwd-objs := xdp_fwd_user.o
108
task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
109
xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
110
ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
B
brakmo 已提交
111
hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
112 113

# Tell kbuild to always build the programs
114
always := $(tprogs-y)
115
always += sockex1_kern.o
116
always += sockex2_kern.o
117
always += sockex3_kern.o
118
always += tracex1_kern.o
119
always += tracex2_kern.o
120
always += tracex3_kern.o
121
always += tracex4_kern.o
122
always += tracex5_kern.o
123
always += tracex6_kern.o
124
always += tracex7_kern.o
125
always += sock_flags_kern.o
126
always += test_probe_write_user_kern.o
127
always += trace_output_kern.o
128
always += tcbpf1_kern.o
129
always += tc_l2_redirect_kern.o
D
Daniel Wagner 已提交
130
always += lathist_kern.o
131
always += offwaketime_kern.o
132
always += spintest_kern.o
133
always += map_perf_test_kern.o
134
always += test_overhead_tp_kern.o
135
always += test_overhead_raw_tp_kern.o
136
always += test_overhead_kprobe_kern.o
137
always += parse_varlen.o parse_simple.o parse_ldabs.o
138
always += test_cgrp2_tc_kern.o
139
always += xdp1_kern.o
140
always += xdp2_kern.o
141
always += xdp_router_ipv4_kern.o
142
always += test_current_task_under_cgroup_kern.o
143
always += trace_event_kern.o
144
always += sampleip_kern.o
145
always += lwt_len_hist_kern.o
146
always += xdp_tx_iptunnel_kern.o
M
Martin KaFai Lau 已提交
147
always += test_map_in_map_kern.o
148
always += tcp_synrto_kern.o
149
always += tcp_rwnd_kern.o
150
always += tcp_bufs_kern.o
151
always += tcp_cong_kern.o
152
always += tcp_iw_kern.o
153
always += tcp_clamp_kern.o
154
always += tcp_basertt_kern.o
155
always += tcp_tos_reflect_kern.o
156
always += tcp_dumpstats_kern.o
157
always += xdp_redirect_kern.o
158
always += xdp_redirect_map_kern.o
159
always += xdp_redirect_cpu_kern.o
160
always += xdp_monitor_kern.o
161
always += xdp_rxq_info_kern.o
162
always += xdp2skb_meta_kern.o
163
always += syscall_tp_kern.o
164
always += cpustat_kern.o
165
always += xdp_adjust_tail_kern.o
166
always += xdp_fwd_kern.o
167
always += task_fd_query_kern.o
168
always += xdp_sample_pkts_kern.o
169
always += ibumad_kern.o
170
always += hbm_out_kern.o
B
brakmo 已提交
171
always += hbm_edt_kern.o
172
always += xdpsock_kern.o
173

174 175 176 177 178
ifeq ($(ARCH), arm)
# Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
# headers when arm instruction set identification is requested.
ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS))
BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR)
179
TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR)
180 181
endif

182 183 184 185
TPROGS_CFLAGS += -Wall -O2
TPROGS_CFLAGS += -Wmissing-prototypes
TPROGS_CFLAGS += -Wstrict-prototypes

186 187 188 189 190 191
TPROGS_CFLAGS += -I$(objtree)/usr/include
TPROGS_CFLAGS += -I$(srctree)/tools/lib/bpf/
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
TPROGS_CFLAGS += -I$(srctree)/tools/lib/
TPROGS_CFLAGS += -I$(srctree)/tools/include
TPROGS_CFLAGS += -I$(srctree)/tools/perf
192
TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0
193

I
Ivan Khoronzhuk 已提交
194 195 196 197 198
ifdef SYSROOT
TPROGS_CFLAGS += --sysroot=$(SYSROOT)
TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib
endif

199 200
TPROGCFLAGS_bpf_load.o += -Wno-unused-variable

201
TPROGS_LDLIBS			+= $(LIBBPF) -lelf -lz
202 203 204 205 206 207
TPROGLDLIBS_tracex4		+= -lrt
TPROGLDLIBS_trace_output	+= -lrt
TPROGLDLIBS_map_perf_test	+= -lrt
TPROGLDLIBS_test_overhead	+= -lrt
TPROGLDLIBS_xdpsock		+= -pthread

208
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
209
#  make M=samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
210
LLC ?= llc
211
CLANG ?= clang
212 213
LLVM_OBJCOPY ?= llvm-objcopy
BTF_PAHOLE ?= pahole
214

215 216
# Detect that we're cross compiling and use the cross compiler
ifdef CROSS_COMPILE
217
CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
218 219
endif

220 221
# Don't evaluate probes and warnings if we need to run make recursively
ifneq ($(src),)
222
HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
223 224
	$(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \
	-o /dev/null 2>/dev/null && echo okay)
225 226 227 228 229 230

ifeq ($(HDR_PROBE),)
$(warning WARNING: Detected possible issues with include path.)
$(warning WARNING: Please install kernel headers locally (make headers_install).)
endif

231 232 233
BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
234 235 236 237
BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
			  $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
			  readelf -S ./llvm_btf_verify.o | grep BTF; \
			  /bin/rm -f ./llvm_btf_verify.o)
238

239
ifneq ($(BTF_LLVM_PROBE),)
240
	BPF_EXTRA_CFLAGS += -g
241
else
242
ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
243
	BPF_EXTRA_CFLAGS += -g
244 245 246
	LLC_FLAGS += -mattr=dwarfris
	DWARF2BTF = y
endif
247
endif
248
endif
249

250
# Trick to allow make to be run from this directory
251
all:
252
	$(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR)
253 254

clean:
255
	$(MAKE) -C ../../ M=$(CURDIR) clean
256 257
	@rm -f *~

258
$(LIBBPF): FORCE
259
# Fix up variables inherited from Kbuild that tools/ build system won't like
260 261
	$(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \
		LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O=
262

263 264 265
$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
	$(call filechk,offsets,__SYSCALL_NRS_H__)

266
targets += syscall_nrs.s
267 268 269 270 271
clean-files += syscall_nrs.h

FORCE:


272 273
# Verify LLVM compiler tools are available and bpf target is supported by llc
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
274

275 276 277 278 279 280 281
verify_cmds: $(CLANG) $(LLC)
	@for TOOL in $^ ; do \
		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
			echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
			exit 1; \
		else true; fi; \
	done
282

283
verify_target_bpf: verify_cmds
284 285 286 287 288 289
	@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
		echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
		echo "   NOTICE: LLVM version >= 3.7.1 required" ;\
		exit 2; \
	else true; fi

290 291
$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
$(src)/*.c: verify_target_bpf $(LIBBPF)
292

293
$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
294
$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
B
brakmo 已提交
295
$(obj)/hbm.o: $(src)/hbm.h
B
brakmo 已提交
296
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
297

298 299
-include $(BPF_SAMPLES_PATH)/Makefile.target

300 301
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is
302
# useless for BPF samples.
303
$(obj)/%.o: $(src)/%.c
304
	@echo "  CLANG-bpf " $@
305 306 307
	$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
		-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
		-I$(srctree)/tools/lib/bpf/ \
308
		-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
309
		-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
310 311
		-Wno-gnu-variable-sized-type-not-at-end \
		-Wno-address-of-packed-member -Wno-tautological-compare \
312
		-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
313
		-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
314 315 316 317
		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
ifeq ($(DWARF2BTF),y)
	$(BTF_PAHOLE) -J $@
endif