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