1# SPDX-License-Identifier: GPL-2.0 2include ../../../build/Build.include 3include ../../../scripts/Makefile.arch 4include ../../../scripts/Makefile.include 5 6CXX ?= $(CROSS_COMPILE)g++ 7 8CURDIR := $(abspath .) 9TOOLSDIR := $(abspath ../../..) 10LIBDIR := $(TOOLSDIR)/lib 11BPFDIR := $(LIBDIR)/bpf 12TOOLSINCDIR := $(TOOLSDIR)/include 13BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool 14APIDIR := $(TOOLSINCDIR)/uapi 15ifneq ($(O),) 16GENDIR := $(O)/include/generated 17else 18GENDIR := $(abspath ../../../../include/generated) 19endif 20GENHDR := $(GENDIR)/autoconf.h 21PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 22 23ifneq ($(wildcard $(GENHDR)),) 24 GENFLAGS := -DHAVE_GENHDR 25endif 26 27BPF_GCC ?= $(shell command -v bpf-gcc;) 28SAN_CFLAGS ?= 29SAN_LDFLAGS ?= $(SAN_CFLAGS) 30RELEASE ?= 31OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0) 32 33LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libelf --cflags 2>/dev/null) 34LIBELF_LIBS := $(shell $(PKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) 35 36CFLAGS += -g $(OPT_FLAGS) -rdynamic \ 37 -Wall -Werror -fno-omit-frame-pointer \ 38 $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_CFLAGS) \ 39 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ 40 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT) 41LDFLAGS += $(SAN_LDFLAGS) 42LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread 43 44# The following tests perform type punning and they may break strict 45# aliasing rules, which are exploited by both GCC and clang by default 46# while optimizing. This can lead to broken programs. 47progs/bind4_prog.c-CFLAGS := -fno-strict-aliasing 48progs/bind6_prog.c-CFLAGS := -fno-strict-aliasing 49progs/dynptr_fail.c-CFLAGS := -fno-strict-aliasing 50progs/linked_list_fail.c-CFLAGS := -fno-strict-aliasing 51progs/map_kptr_fail.c-CFLAGS := -fno-strict-aliasing 52progs/syscall.c-CFLAGS := -fno-strict-aliasing 53progs/test_pkt_md_access.c-CFLAGS := -fno-strict-aliasing 54progs/test_sk_lookup.c-CFLAGS := -fno-strict-aliasing 55progs/timer_crash.c-CFLAGS := -fno-strict-aliasing 56 57ifneq ($(LLVM),) 58# Silence some warnings when compiled with clang 59CFLAGS += -Wno-unused-command-line-argument 60endif 61 62# Check whether bpf cpu=v4 is supported or not by clang 63ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),) 64CLANG_CPUV4 := 1 65endif 66 67# Order correspond to 'make run_tests' order 68TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 69 test_dev_cgroup \ 70 test_sock test_sockmap get_cgroup_id_user \ 71 test_cgroup_storage \ 72 test_tcpnotify_user test_sysctl \ 73 test_progs-no_alu32 74TEST_INST_SUBDIRS := no_alu32 75 76# Also test bpf-gcc, if present 77ifneq ($(BPF_GCC),) 78TEST_GEN_PROGS += test_progs-bpf_gcc 79TEST_INST_SUBDIRS += bpf_gcc 80 81# The following tests contain C code that, although technically legal, 82# triggers GCC warnings that cannot be disabled: declaration of 83# anonymous struct types in function parameter lists. 84progs/btf_dump_test_case_bitfields.c-CFLAGS := -Wno-error 85progs/btf_dump_test_case_namespacing.c-CFLAGS := -Wno-error 86progs/btf_dump_test_case_packing.c-CFLAGS := -Wno-error 87progs/btf_dump_test_case_padding.c-CFLAGS := -Wno-error 88progs/btf_dump_test_case_syntax.c-CFLAGS := -Wno-error 89endif 90 91ifneq ($(CLANG_CPUV4),) 92TEST_GEN_PROGS += test_progs-cpuv4 93TEST_INST_SUBDIRS += cpuv4 94endif 95 96TEST_GEN_FILES = test_lwt_ip_encap.bpf.o test_tc_edt.bpf.o 97TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) 98 99# Order correspond to 'make run_tests' order 100TEST_PROGS := test_kmod.sh \ 101 test_xdp_redirect.sh \ 102 test_xdp_redirect_multi.sh \ 103 test_xdp_meta.sh \ 104 test_xdp_veth.sh \ 105 test_offload.py \ 106 test_sock_addr.sh \ 107 test_tunnel.sh \ 108 test_lwt_seg6local.sh \ 109 test_lirc_mode2.sh \ 110 test_skb_cgroup_id.sh \ 111 test_flow_dissector.sh \ 112 test_xdp_vlan_mode_generic.sh \ 113 test_xdp_vlan_mode_native.sh \ 114 test_lwt_ip_encap.sh \ 115 test_tcp_check_syncookie.sh \ 116 test_tc_tunnel.sh \ 117 test_tc_edt.sh \ 118 test_xdping.sh \ 119 test_bpftool_build.sh \ 120 test_bpftool.sh \ 121 test_bpftool_metadata.sh \ 122 test_doc_build.sh \ 123 test_xsk.sh \ 124 test_xdp_features.sh 125 126TEST_PROGS_EXTENDED := with_addr.sh \ 127 with_tunnels.sh ima_setup.sh verify_sig_setup.sh \ 128 test_xdp_vlan.sh test_bpftool.py 129 130# Compile but not part of 'make run_tests' 131TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ 132 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ 133 test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ 134 xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ 135 xdp_features bpf_test_no_cfi.ko 136 137TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi 138 139# Emit succinct information message describing current building step 140# $1 - generic step name (e.g., CC, LINK, etc); 141# $2 - optional "flavor" specifier; if provided, will be emitted as [flavor]; 142# $3 - target (assumed to be file); only file name will be emitted; 143# $4 - optional extra arg, emitted as-is, if provided. 144ifeq ($(V),1) 145Q = 146msg = 147else 148Q = @ 149msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))"; 150MAKEFLAGS += --no-print-directory 151submake_extras := feature_display=0 152endif 153 154# override lib.mk's default rules 155OVERRIDE_TARGETS := 1 156override define CLEAN 157 $(call msg,CLEAN) 158 $(Q)$(RM) -r $(TEST_GEN_PROGS) 159 $(Q)$(RM) -r $(TEST_GEN_PROGS_EXTENDED) 160 $(Q)$(RM) -r $(TEST_GEN_FILES) 161 $(Q)$(RM) -r $(EXTRA_CLEAN) 162 $(Q)$(MAKE) -C bpf_testmod clean 163 $(Q)$(MAKE) docs-clean 164endef 165 166include ../lib.mk 167 168SCRATCH_DIR := $(OUTPUT)/tools 169BUILD_DIR := $(SCRATCH_DIR)/build 170INCLUDE_DIR := $(SCRATCH_DIR)/include 171BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a 172ifneq ($(CROSS_COMPILE),) 173HOST_BUILD_DIR := $(BUILD_DIR)/host 174HOST_SCRATCH_DIR := $(OUTPUT)/host-tools 175HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR)/include 176else 177HOST_BUILD_DIR := $(BUILD_DIR) 178HOST_SCRATCH_DIR := $(SCRATCH_DIR) 179HOST_INCLUDE_DIR := $(INCLUDE_DIR) 180endif 181HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a 182RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids 183RUNQSLOWER_OUTPUT := $(BUILD_DIR)/runqslower/ 184 185VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ 186 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ 187 ../../../../vmlinux \ 188 /sys/kernel/btf/vmlinux \ 189 /boot/vmlinux-$(shell uname -r) 190VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) 191ifeq ($(VMLINUX_BTF),) 192$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") 193endif 194 195# Define simple and short `make test_progs`, `make test_sysctl`, etc targets 196# to build individual tests. 197# NOTE: Semicolon at the end is critical to override lib.mk's default static 198# rule for binaries. 199$(notdir $(TEST_GEN_PROGS) \ 200 $(TEST_GEN_PROGS_EXTENDED)): %: $(OUTPUT)/% ; 201 202# sort removes libbpf duplicates when not cross-building 203MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST_BUILD_DIR)/libbpf \ 204 $(BUILD_DIR)/bpftool $(HOST_BUILD_DIR)/bpftool \ 205 $(HOST_BUILD_DIR)/resolve_btfids \ 206 $(RUNQSLOWER_OUTPUT) $(INCLUDE_DIR)) 207$(MAKE_DIRS): 208 $(call msg,MKDIR,,$@) 209 $(Q)mkdir -p $@ 210 211$(OUTPUT)/%.o: %.c 212 $(call msg,CC,,$@) 213 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ 214 215$(OUTPUT)/%:%.c 216 $(call msg,BINARY,,$@) 217 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ 218 219# LLVM's ld.lld doesn't support all the architectures, so use it only on x86 220ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv)) 221LLD := lld 222else 223LLD := ld 224endif 225 226# Filter out -static for liburandom_read.so and its dependent targets so that static builds 227# do not fail. Static builds leave urandom_read relying on system-wide shared libraries. 228$(OUTPUT)/liburandom_read.so: urandom_read_lib1.c urandom_read_lib2.c liburandom_read.map 229 $(call msg,LIB,,$@) 230 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ 231 $(filter-out -static,$(CFLAGS) $(LDFLAGS)) \ 232 $(filter %.c,$^) $(filter-out -static,$(LDLIBS)) \ 233 -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \ 234 -Wl,--version-script=liburandom_read.map \ 235 -fPIC -shared -o $@ 236 237$(OUTPUT)/urandom_read: urandom_read.c urandom_read_aux.c $(OUTPUT)/liburandom_read.so 238 $(call msg,BINARY,,$@) 239 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ 240 $(filter-out -static,$(CFLAGS) $(LDFLAGS)) $(filter %.c,$^) \ 241 -lurandom_read $(filter-out -static,$(LDLIBS)) -L$(OUTPUT) \ 242 -fuse-ld=$(LLD) -Wl,-znoseparate-code -Wl,--build-id=sha1 \ 243 -Wl,-rpath=. -o $@ 244 245$(OUTPUT)/sign-file: ../../../../scripts/sign-file.c 246 $(call msg,SIGN-FILE,,$@) 247 $(Q)$(CC) $(shell $(PKG_CONFIG) --cflags libcrypto 2> /dev/null) \ 248 $< -o $@ \ 249 $(shell $(PKG_CONFIG) --libs libcrypto 2> /dev/null || echo -lcrypto) 250 251$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch]) 252 $(call msg,MOD,,$@) 253 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation 254 $(Q)$(MAKE) $(submake_extras) RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) -C bpf_testmod 255 $(Q)cp bpf_testmod/bpf_testmod.ko $@ 256 257$(OUTPUT)/bpf_test_no_cfi.ko: $(VMLINUX_BTF) $(RESOLVE_BTFIDS) $(wildcard bpf_test_no_cfi/Makefile bpf_test_no_cfi/*.[ch]) 258 $(call msg,MOD,,$@) 259 $(Q)$(RM) bpf_test_no_cfi/bpf_test_no_cfi.ko # force re-compilation 260 $(Q)$(MAKE) $(submake_extras) RESOLVE_BTFIDS=$(RESOLVE_BTFIDS) -C bpf_test_no_cfi 261 $(Q)cp bpf_test_no_cfi/bpf_test_no_cfi.ko $@ 262 263DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool 264ifneq ($(CROSS_COMPILE),) 265CROSS_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool 266TRUNNER_BPFTOOL := $(CROSS_BPFTOOL) 267USE_BOOTSTRAP := "" 268else 269TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) 270USE_BOOTSTRAP := "bootstrap/" 271endif 272 273$(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) 274 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ 275 OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ 276 BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ 277 BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ 278 BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) \ 279 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS)' \ 280 EXTRA_LDFLAGS='$(SAN_LDFLAGS)' && \ 281 cp $(RUNQSLOWER_OUTPUT)runqslower $@ 282 283TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL) 284 285$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ) 286 287TESTING_HELPERS := $(OUTPUT)/testing_helpers.o 288CGROUP_HELPERS := $(OUTPUT)/cgroup_helpers.o 289UNPRIV_HELPERS := $(OUTPUT)/unpriv_helpers.o 290TRACE_HELPERS := $(OUTPUT)/trace_helpers.o 291JSON_WRITER := $(OUTPUT)/json_writer.o 292CAP_HELPERS := $(OUTPUT)/cap_helpers.o 293 294$(OUTPUT)/test_dev_cgroup: $(CGROUP_HELPERS) $(TESTING_HELPERS) 295$(OUTPUT)/test_skb_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) 296$(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTING_HELPERS) 297$(OUTPUT)/test_sock_addr: $(CGROUP_HELPERS) $(TESTING_HELPERS) 298$(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS) 299$(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS) 300$(OUTPUT)/get_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) 301$(OUTPUT)/test_cgroup_storage: $(CGROUP_HELPERS) $(TESTING_HELPERS) 302$(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS) 303$(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS) 304$(OUTPUT)/test_tag: $(TESTING_HELPERS) 305$(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS) 306$(OUTPUT)/xdping: $(TESTING_HELPERS) 307$(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS) 308$(OUTPUT)/test_maps: $(TESTING_HELPERS) 309$(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS) 310$(OUTPUT)/xsk.o: $(BPFOBJ) 311 312BPFTOOL ?= $(DEFAULT_BPFTOOL) 313$(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ 314 $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool 315 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ 316 ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" \ 317 EXTRA_CFLAGS='-g $(OPT_FLAGS)' \ 318 OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ 319 LIBBPF_OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \ 320 LIBBPF_DESTDIR=$(HOST_SCRATCH_DIR)/ \ 321 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install-bin 322 323ifneq ($(CROSS_COMPILE),) 324$(CROSS_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ 325 $(BPFOBJ) | $(BUILD_DIR)/bpftool 326 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ 327 ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) \ 328 EXTRA_CFLAGS='-g $(OPT_FLAGS)' \ 329 OUTPUT=$(BUILD_DIR)/bpftool/ \ 330 LIBBPF_OUTPUT=$(BUILD_DIR)/libbpf/ \ 331 LIBBPF_DESTDIR=$(SCRATCH_DIR)/ \ 332 prefix= DESTDIR=$(SCRATCH_DIR)/ install-bin 333endif 334 335all: docs 336 337docs: 338 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \ 339 -f Makefile.docs \ 340 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@ 341 342docs-clean: 343 $(Q)$(MAKE) $(submake_extras) \ 344 -f Makefile.docs \ 345 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@ 346 347$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 348 $(APIDIR)/linux/bpf.h \ 349 | $(BUILD_DIR)/libbpf 350 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ 351 EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS)' \ 352 EXTRA_LDFLAGS='$(SAN_LDFLAGS)' \ 353 DESTDIR=$(SCRATCH_DIR) prefix= all install_headers 354 355ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) 356$(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 357 $(APIDIR)/linux/bpf.h \ 358 | $(HOST_BUILD_DIR)/libbpf 359 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \ 360 EXTRA_CFLAGS='-g $(OPT_FLAGS)' ARCH= CROSS_COMPILE= \ 361 OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \ 362 CC="$(HOSTCC)" LD="$(HOSTLD)" \ 363 DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers 364endif 365 366$(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR) 367ifeq ($(VMLINUX_H),) 368 $(call msg,GEN,,$@) 369 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ 370else 371 $(call msg,CP,,$@) 372 $(Q)cp "$(VMLINUX_H)" $@ 373endif 374 375$(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ 376 $(TOOLSDIR)/bpf/resolve_btfids/main.c \ 377 $(TOOLSDIR)/lib/rbtree.c \ 378 $(TOOLSDIR)/lib/zalloc.c \ 379 $(TOOLSDIR)/lib/string.c \ 380 $(TOOLSDIR)/lib/ctype.c \ 381 $(TOOLSDIR)/lib/str_error_r.c 382 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \ 383 CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \ 384 LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \ 385 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) 386 387# Get Clang's default includes on this system, as opposed to those seen by 388# '--target=bpf'. This fixes "missing" files on some architectures/distros, 389# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 390# 391# Use '-idirafter': Don't interfere with include mechanics except where the 392# build would have failed anyways. 393define get_sys_includes 394$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ 395 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ 396$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') \ 397$(shell $(1) $(2) -dM -E - </dev/null | grep '__loongarch_grlen ' | awk '{printf("-D__BITS_PER_LONG=%d", $$3)}') 398endef 399 400# Determine target endianness. 401IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \ 402 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') 403MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) 404 405ifneq ($(CROSS_COMPILE),) 406CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) 407endif 408 409CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) 410BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ 411 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ 412 -I$(abspath $(OUTPUT)/../usr/include) \ 413 -Wno-compare-distinct-pointer-types 414# TODO: enable me -Wsign-compare 415 416CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) 417 418$(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline 419$(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline 420 421$(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h 422$(OUTPUT)/cgroup_getset_retval_hooks.o: cgroup_getset_retval_hooks.h 423 424# Build BPF object using Clang 425# $1 - input .c file 426# $2 - output .o file 427# $3 - CFLAGS 428define CLANG_BPF_BUILD_RULE 429 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 430 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v3 -o $2 431endef 432# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32 433define CLANG_NOALU32_BPF_BUILD_RULE 434 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 435 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v2 -o $2 436endef 437# Similar to CLANG_BPF_BUILD_RULE, but with cpu-v4 438define CLANG_CPUV4_BPF_BUILD_RULE 439 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 440 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 -mcpu=v4 -o $2 441endef 442# Build BPF object using GCC 443define GCC_BPF_BUILD_RULE 444 $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2) 445 $(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2 446endef 447 448SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c 449 450LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \ 451 linked_vars.skel.h linked_maps.skel.h \ 452 test_subskeleton.skel.h test_subskeleton_lib.skel.h \ 453 test_usdt.skel.h 454 455LSKELS := fentry_test.c fexit_test.c fexit_sleep.c atomics.c \ 456 trace_printk.c trace_vprintk.c map_ptr_kern.c \ 457 core_kern.c core_kern_overflow.c test_ringbuf.c \ 458 test_ringbuf_map_key.c 459 460# Generate both light skeleton and libbpf skeleton for these 461LSKELS_EXTRA := test_ksyms_module.c test_ksyms_weak.c kfunc_call_test.c \ 462 kfunc_call_test_subprog.c 463SKEL_BLACKLIST += $$(LSKELS) 464 465test_static_linked.skel.h-deps := test_static_linked1.bpf.o test_static_linked2.bpf.o 466linked_funcs.skel.h-deps := linked_funcs1.bpf.o linked_funcs2.bpf.o 467linked_vars.skel.h-deps := linked_vars1.bpf.o linked_vars2.bpf.o 468linked_maps.skel.h-deps := linked_maps1.bpf.o linked_maps2.bpf.o 469# In the subskeleton case, we want the test_subskeleton_lib.subskel.h file 470# but that's created as a side-effect of the skel.h generation. 471test_subskeleton.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o test_subskeleton.bpf.o 472test_subskeleton_lib.skel.h-deps := test_subskeleton_lib2.bpf.o test_subskeleton_lib.bpf.o 473test_usdt.skel.h-deps := test_usdt.bpf.o test_usdt_multispec.bpf.o 474xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf.o 475xdp_hw_metadata.skel.h-deps := xdp_hw_metadata.bpf.o 476xdp_features.skel.h-deps := xdp_features.bpf.o 477 478LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps))) 479 480# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on 481# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES. 482# Parameters: 483# $1 - test runner base binary name (e.g., test_progs) 484# $2 - test runner extra "flavor" (e.g., no_alu32, cpuv4, gcc-bpf, etc) 485define DEFINE_TEST_RUNNER 486 487TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 488TRUNNER_BINARY := $1$(if $2,-)$2 489TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \ 490 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))) 491TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ 492 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES))) 493TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES)) 494TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h 495TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)) 496TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS)) 497TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \ 498 $$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\ 499 $$(TRUNNER_BPF_SRCS))) 500TRUNNER_BPF_LSKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.lskel.h, $$(LSKELS) $$(LSKELS_EXTRA)) 501TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TRUNNER_OUTPUT)/,$(LINKED_SKELS)) 502TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS) 503 504# Evaluate rules now with extra TRUNNER_XXX variables above already defined 505$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2)) 506 507endef 508 509# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and 510# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with: 511# $1 - test runner base binary name (e.g., test_progs) 512# $2 - test runner extra "flavor" (e.g., no_alu32, cpuv4, gcc-bpf, etc) 513define DEFINE_TEST_RUNNER_RULES 514 515ifeq ($($(TRUNNER_OUTPUT)-dir),) 516$(TRUNNER_OUTPUT)-dir := y 517$(TRUNNER_OUTPUT): 518 $$(call msg,MKDIR,,$$@) 519 $(Q)mkdir -p $$@ 520endif 521 522# ensure we set up BPF objects generation rule just once for a given 523# input/output directory combination 524ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),) 525$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y 526$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.bpf.o: \ 527 $(TRUNNER_BPF_PROGS_DIR)/%.c \ 528 $(TRUNNER_BPF_PROGS_DIR)/*.h \ 529 $$(INCLUDE_DIR)/vmlinux.h \ 530 $(wildcard $(BPFDIR)/bpf_*.h) \ 531 $(wildcard $(BPFDIR)/*.bpf.h) \ 532 | $(TRUNNER_OUTPUT) $$(BPFOBJ) 533 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \ 534 $(TRUNNER_BPF_CFLAGS) \ 535 $$($$<-CFLAGS)) 536 537$(TRUNNER_BPF_SKELS): %.skel.h: %.bpf.o $(BPFTOOL) | $(TRUNNER_OUTPUT) 538 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 539 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked1.o) $$< 540 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o) 541 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o) 542 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o) 543 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.bpf.o=)) > $$@ 544 $(Q)$$(BPFTOOL) gen subskeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.bpf.o=)) > $$(@:.skel.h=.subskel.h) 545 $(Q)rm -f $$(<:.o=.linked1.o) $$(<:.o=.linked2.o) $$(<:.o=.linked3.o) 546 547$(TRUNNER_BPF_LSKELS): %.lskel.h: %.bpf.o $(BPFTOOL) | $(TRUNNER_OUTPUT) 548 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 549 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked1.o) $$< 550 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked2.o) $$(<:.o=.llinked1.o) 551 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked3.o) $$(<:.o=.llinked2.o) 552 $(Q)diff $$(<:.o=.llinked2.o) $$(<:.o=.llinked3.o) 553 $(Q)$$(BPFTOOL) gen skeleton -L $$(<:.o=.llinked3.o) name $$(notdir $$(<:.bpf.o=_lskel)) > $$@ 554 $(Q)rm -f $$(<:.o=.llinked1.o) $$(<:.o=.llinked2.o) $$(<:.o=.llinked3.o) 555 556$(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT) 557 $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.bpf.o)) 558 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked1.o) $$(addprefix $(TRUNNER_OUTPUT)/,$$($$(@F)-deps)) 559 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked1.o) 560 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked3.o) $$(@:.skel.h=.linked2.o) 561 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o) 562 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 563 $(Q)$$(BPFTOOL) gen skeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$@ 564 $(Q)$$(BPFTOOL) gen subskeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$(@:.skel.h=.subskel.h) 565 $(Q)rm -f $$(@:.skel.h=.linked1.o) $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o) 566endif 567 568# ensure we set up tests.h header generation rule just once 569ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) 570$(TRUNNER_TESTS_DIR)-tests-hdr := y 571$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c 572 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@) 573 $$(shell (echo '/* Generated header, do not edit */'; \ 574 sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \ 575 $(TRUNNER_TESTS_DIR)/*.c | sort ; \ 576 ) > $$@) 577endif 578 579# compile individual test files 580# Note: we cd into output directory to ensure embedded BPF object is found 581$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ 582 $(TRUNNER_TESTS_DIR)/%.c \ 583 $(TRUNNER_EXTRA_HDRS) \ 584 $(TRUNNER_BPF_OBJS) \ 585 $(TRUNNER_BPF_SKELS) \ 586 $(TRUNNER_BPF_LSKELS) \ 587 $(TRUNNER_BPF_SKELS_LINKED) \ 588 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 589 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) 590 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) 591 592$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 593 %.c \ 594 $(TRUNNER_EXTRA_HDRS) \ 595 $(TRUNNER_TESTS_HDR) \ 596 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 597 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@) 598 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@ 599 600# non-flavored in-srctree builds receive special treatment, in particular, we 601# do not need to copy extra resources (see e.g. test_btf_dump_case()) 602$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) 603ifneq ($2:$(OUTPUT),:$(shell pwd)) 604 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES)) 605 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/ 606endif 607 608$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ 609 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ 610 $(RESOLVE_BTFIDS) \ 611 $(TRUNNER_BPFTOOL) \ 612 | $(TRUNNER_BINARY)-extras 613 $$(call msg,BINARY,,$$@) 614 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@ 615 $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.bpf.o $$@ 616 $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/$(USE_BOOTSTRAP)bpftool \ 617 $(OUTPUT)/$(if $2,$2/)bpftool 618 619endef 620 621# Define test_progs test runner. 622TRUNNER_TESTS_DIR := prog_tests 623TRUNNER_BPF_PROGS_DIR := progs 624TRUNNER_EXTRA_SOURCES := test_progs.c \ 625 cgroup_helpers.c \ 626 trace_helpers.c \ 627 network_helpers.c \ 628 testing_helpers.c \ 629 btf_helpers.c \ 630 cap_helpers.c \ 631 unpriv_helpers.c \ 632 netlink_helpers.c \ 633 test_loader.c \ 634 xsk.c \ 635 disasm.c \ 636 json_writer.c \ 637 flow_dissector_load.h \ 638 ip_check_defrag_frags.h 639TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ 640 $(OUTPUT)/bpf_test_no_cfi.ko \ 641 $(OUTPUT)/liburandom_read.so \ 642 $(OUTPUT)/xdp_synproxy \ 643 $(OUTPUT)/sign-file \ 644 $(OUTPUT)/uprobe_multi \ 645 ima_setup.sh \ 646 verify_sig_setup.sh \ 647 $(wildcard progs/btf_dump_test_case_*.c) \ 648 $(wildcard progs/*.bpf.o) 649TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE 650TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS 651$(eval $(call DEFINE_TEST_RUNNER,test_progs)) 652 653# Define test_progs-no_alu32 test runner. 654TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE 655TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) 656$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32)) 657 658# Define test_progs-cpuv4 test runner. 659ifneq ($(CLANG_CPUV4),) 660TRUNNER_BPF_BUILD_RULE := CLANG_CPUV4_BPF_BUILD_RULE 661TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) 662$(eval $(call DEFINE_TEST_RUNNER,test_progs,cpuv4)) 663endif 664 665# Define test_progs BPF-GCC-flavored test runner. 666ifneq ($(BPF_GCC),) 667TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE 668TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc,) 669$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc)) 670endif 671 672# Define test_maps test runner. 673TRUNNER_TESTS_DIR := map_tests 674TRUNNER_BPF_PROGS_DIR := progs 675TRUNNER_EXTRA_SOURCES := test_maps.c 676TRUNNER_EXTRA_FILES := 677TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built) 678TRUNNER_BPF_CFLAGS := 679$(eval $(call DEFINE_TEST_RUNNER,test_maps)) 680 681# Define test_verifier test runner. 682# It is much simpler than test_maps/test_progs and sufficiently different from 683# them (e.g., test.h is using completely pattern), that it's worth just 684# explicitly defining all the rules explicitly. 685verifier/tests.h: verifier/*.c 686 $(shell ( cd verifier/; \ 687 echo '/* Generated header, do not edit */'; \ 688 echo '#ifdef FILL_ARRAY'; \ 689 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \ 690 echo '#endif' \ 691 ) > verifier/tests.h) 692$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT) 693 $(call msg,BINARY,,$@) 694 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 695 696# Include find_bit.c to compile xskxceiver. 697EXTRA_SRC := $(TOOLSDIR)/lib/find_bit.c 698$(OUTPUT)/xskxceiver: $(EXTRA_SRC) xskxceiver.c xskxceiver.h $(OUTPUT)/xsk.o $(OUTPUT)/xsk_xdp_progs.skel.h $(BPFOBJ) | $(OUTPUT) 699 $(call msg,BINARY,,$@) 700 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 701 702$(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xsk.o $(OUTPUT)/xdp_hw_metadata.skel.h | $(OUTPUT) 703 $(call msg,BINARY,,$@) 704 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 705 706$(OUTPUT)/xdp_features: xdp_features.c $(OUTPUT)/network_helpers.o $(OUTPUT)/xdp_features.skel.h | $(OUTPUT) 707 $(call msg,BINARY,,$@) 708 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 709 710# Make sure we are able to include and link libbpf against c++. 711$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ) 712 $(call msg,CXX,,$@) 713 $(Q)$(CXX) $(CFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@ 714 715# Benchmark runner 716$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ) 717 $(call msg,CC,,$@) 718 $(Q)$(CC) $(CFLAGS) -O2 -c $(filter %.c,$^) $(LDLIBS) -o $@ 719$(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h 720$(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h 721$(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \ 722 $(OUTPUT)/perfbuf_bench.skel.h 723$(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h 724$(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h 725$(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h 726$(OUTPUT)/bench_bpf_hashmap_full_update.o: $(OUTPUT)/bpf_hashmap_full_update_bench.skel.h 727$(OUTPUT)/bench_local_storage.o: $(OUTPUT)/local_storage_bench.skel.h 728$(OUTPUT)/bench_local_storage_rcu_tasks_trace.o: $(OUTPUT)/local_storage_rcu_tasks_trace_bench.skel.h 729$(OUTPUT)/bench_local_storage_create.o: $(OUTPUT)/bench_local_storage_create.skel.h 730$(OUTPUT)/bench_bpf_hashmap_lookup.o: $(OUTPUT)/bpf_hashmap_lookup.skel.h 731$(OUTPUT)/bench_htab_mem.o: $(OUTPUT)/htab_mem_bench.skel.h 732$(OUTPUT)/bench.o: bench.h testing_helpers.h $(BPFOBJ) 733$(OUTPUT)/bench: LDLIBS += -lm 734$(OUTPUT)/bench: $(OUTPUT)/bench.o \ 735 $(TESTING_HELPERS) \ 736 $(TRACE_HELPERS) \ 737 $(CGROUP_HELPERS) \ 738 $(OUTPUT)/bench_count.o \ 739 $(OUTPUT)/bench_rename.o \ 740 $(OUTPUT)/bench_trigger.o \ 741 $(OUTPUT)/bench_ringbufs.o \ 742 $(OUTPUT)/bench_bloom_filter_map.o \ 743 $(OUTPUT)/bench_bpf_loop.o \ 744 $(OUTPUT)/bench_strncmp.o \ 745 $(OUTPUT)/bench_bpf_hashmap_full_update.o \ 746 $(OUTPUT)/bench_local_storage.o \ 747 $(OUTPUT)/bench_local_storage_rcu_tasks_trace.o \ 748 $(OUTPUT)/bench_bpf_hashmap_lookup.o \ 749 $(OUTPUT)/bench_local_storage_create.o \ 750 $(OUTPUT)/bench_htab_mem.o \ 751 # 752 $(call msg,BINARY,,$@) 753 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@ 754 755$(OUTPUT)/veristat.o: $(BPFOBJ) 756$(OUTPUT)/veristat: $(OUTPUT)/veristat.o 757 $(call msg,BINARY,,$@) 758 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@ 759 760$(OUTPUT)/uprobe_multi: uprobe_multi.c 761 $(call msg,BINARY,,$@) 762 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@ 763 764EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ 765 prog_tests/tests.h map_tests/tests.h verifier/tests.h \ 766 feature bpftool \ 767 $(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h *.subskel.h \ 768 no_alu32 cpuv4 bpf_gcc bpf_testmod.ko \ 769 bpf_test_no_cfi.ko \ 770 liburandom_read.so) 771 772.PHONY: docs docs-clean 773 774# Delete partially updated (corrupted) files on error 775.DELETE_ON_ERROR: 776 777DEFAULT_INSTALL_RULE := $(INSTALL_RULE) 778override define INSTALL_RULE 779 $(DEFAULT_INSTALL_RULE) 780 @for DIR in $(TEST_INST_SUBDIRS); do \ 781 mkdir -p $(INSTALL_PATH)/$$DIR; \ 782 rsync -a $(OUTPUT)/$$DIR/*.bpf.o $(INSTALL_PATH)/$$DIR;\ 783 done 784endef 785