Makefile 9.7 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
hostprogs-y := test_lru_dist
8
hostprogs-y += sock_example
9
hostprogs-y += fds_example
10
hostprogs-y += sockex1
11
hostprogs-y += sockex2
12
hostprogs-y += sockex3
13
hostprogs-y += tracex1
14
hostprogs-y += tracex2
15
hostprogs-y += tracex3
16
hostprogs-y += tracex4
17
hostprogs-y += tracex5
18
hostprogs-y += tracex6
19
hostprogs-y += tracex7
20
hostprogs-y += test_probe_write_user
21
hostprogs-y += trace_output
D
Daniel Wagner 已提交
22
hostprogs-y += lathist
23
hostprogs-y += offwaketime
24
hostprogs-y += spintest
25
hostprogs-y += map_perf_test
26
hostprogs-y += test_overhead
27
hostprogs-y += test_cgrp2_array_pin
28
hostprogs-y += test_cgrp2_attach
29
hostprogs-y += test_cgrp2_sock
30
hostprogs-y += test_cgrp2_sock2
31
hostprogs-y += xdp1
32
hostprogs-y += xdp2
33
hostprogs-y += xdp_router_ipv4
34
hostprogs-y += test_current_task_under_cgroup
35
hostprogs-y += trace_event
36
hostprogs-y += sampleip
37
hostprogs-y += tc_l2_redirect
38
hostprogs-y += lwt_len_hist
39
hostprogs-y += xdp_tx_iptunnel
M
Martin KaFai Lau 已提交
40
hostprogs-y += test_map_in_map
41
hostprogs-y += per_socket_stats_example
42
hostprogs-y += xdp_redirect
43
hostprogs-y += xdp_redirect_map
44
hostprogs-y += xdp_redirect_cpu
45
hostprogs-y += xdp_monitor
46
hostprogs-y += xdp_rxq_info
47
hostprogs-y += syscall_tp
48
hostprogs-y += cpustat
49
hostprogs-y += xdp_adjust_tail
50
hostprogs-y += xdpsock
51
hostprogs-y += xdp_fwd
52
hostprogs-y += task_fd_query
53
hostprogs-y += xdp_sample_pkts
54
hostprogs-y += ibumad
B
brakmo 已提交
55
hostprogs-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 114

# Tell kbuild to always build the programs
always := $(hostprogs-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 += cookie_uid_helper_example.o
149
always += tcp_synrto_kern.o
150
always += tcp_rwnd_kern.o
151
always += tcp_bufs_kern.o
152
always += tcp_cong_kern.o
153
always += tcp_iw_kern.o
154
always += tcp_clamp_kern.o
155
always += tcp_basertt_kern.o
156
always += tcp_tos_reflect_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
171

172
KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
173
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
174 175 176
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
177 178

HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
179

180 181 182 183 184 185
KBUILD_HOSTLDLIBS		+= $(LIBBPF) -lelf
HOSTLDLIBS_tracex4		+= -lrt
HOSTLDLIBS_trace_output	+= -lrt
HOSTLDLIBS_map_perf_test	+= -lrt
HOSTLDLIBS_test_overhead	+= -lrt
HOSTLDLIBS_xdpsock		+= -pthread
186

187 188
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
#  make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
189
LLC ?= llc
190
CLANG ?= clang
191 192
LLVM_OBJCOPY ?= llvm-objcopy
BTF_PAHOLE ?= pahole
193

194 195 196
# Detect that we're cross compiling and use the cross compiler
ifdef CROSS_COMPILE
HOSTCC = $(CROSS_COMPILE)gcc
197
CLANG_ARCH_ARGS = -target $(ARCH)
198 199
endif

200 201
# Don't evaluate probes and warnings if we need to run make recursively
ifneq ($(src),)
202 203 204 205 206 207 208 209 210
HDR_PROBE := $(shell echo "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
	$(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
	echo okay)

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

211 212 213
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')
214 215 216 217
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)
218

219 220 221
ifneq ($(BTF_LLVM_PROBE),)
	EXTRA_CFLAGS += -g
else
222 223 224 225 226
ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
	EXTRA_CFLAGS += -g
	LLC_FLAGS += -mattr=dwarfris
	DWARF2BTF = y
endif
227
endif
228
endif
229

230
# Trick to allow make to be run from this directory
231 232
all:
	$(MAKE) -C ../../ $(CURDIR)/ BPF_SAMPLES_PATH=$(CURDIR)
233 234

clean:
235
	$(MAKE) -C ../../ M=$(CURDIR) clean
236 237
	@rm -f *~

238
$(LIBBPF): FORCE
239 240
# Fix up variables inherited from Kbuild that tools/ build system won't like
	$(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
241

242 243 244
$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
	$(call filechk,offsets,__SYSCALL_NRS_H__)

245
targets += syscall_nrs.s
246 247 248 249 250
clean-files += syscall_nrs.h

FORCE:


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

254 255 256 257 258 259 260
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
261

262
verify_target_bpf: verify_cmds
263 264 265 266 267 268
	@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

269 270
$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
$(src)/*.c: verify_target_bpf $(LIBBPF)
271

272
$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
273
$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
B
brakmo 已提交
274
$(obj)/hbm.o: $(src)/hbm.h
275

276 277
# 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
278
# useless for BPF samples.
279
$(obj)/%.o: $(src)/%.c
280 281
	@echo "  CLANG-bpf " $@
	$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
Y
Yonghong Song 已提交
282
		-I$(srctree)/tools/testing/selftests/bpf/ \
283
		-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
284
		-D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
285 286
		-Wno-gnu-variable-sized-type-not-at-end \
		-Wno-address-of-packed-member -Wno-tautological-compare \
287
		-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
288
		-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
289 290 291 292
		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
ifeq ($(DWARF2BTF),y)
	$(BTF_PAHOLE) -J $@
endif