1 # SPDX-License-Identifier: GPL-2.0 1 # SPDX-License-Identifier: GPL-2.0 2 include ../../../build/Build.include 2 include ../../../build/Build.include 3 include ../../../scripts/Makefile.arch 3 include ../../../scripts/Makefile.arch 4 include ../../../scripts/Makefile.include 4 include ../../../scripts/Makefile.include 5 5 6 CXX ?= $(CROSS_COMPILE)g++ 6 CXX ?= $(CROSS_COMPILE)g++ 7 7 8 CURDIR := $(abspath .) 8 CURDIR := $(abspath .) 9 TOOLSDIR := $(abspath ../../..) 9 TOOLSDIR := $(abspath ../../..) 10 LIBDIR := $(TOOLSDIR)/lib 10 LIBDIR := $(TOOLSDIR)/lib 11 BPFDIR := $(LIBDIR)/bpf 11 BPFDIR := $(LIBDIR)/bpf 12 TOOLSINCDIR := $(TOOLSDIR)/include 12 TOOLSINCDIR := $(TOOLSDIR)/include 13 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool 13 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool 14 APIDIR := $(TOOLSINCDIR)/uapi 14 APIDIR := $(TOOLSINCDIR)/uapi 15 ifneq ($(O),) << 16 GENDIR := $(O)/include/generated << 17 else << 18 GENDIR := $(abspath ../../../../include/genera 15 GENDIR := $(abspath ../../../../include/generated) 19 endif << 20 GENHDR := $(GENDIR)/autoconf.h 16 GENHDR := $(GENDIR)/autoconf.h 21 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config << 22 17 23 ifneq ($(wildcard $(GENHDR)),) 18 ifneq ($(wildcard $(GENHDR)),) 24 GENFLAGS := -DHAVE_GENHDR 19 GENFLAGS := -DHAVE_GENHDR 25 endif 20 endif 26 21 27 BPF_GCC ?= $(shell command -v bpf-gcc; 22 BPF_GCC ?= $(shell command -v bpf-gcc;) 28 SAN_CFLAGS ?= 23 SAN_CFLAGS ?= 29 SAN_LDFLAGS ?= $(SAN_CFLAGS) !! 24 CFLAGS += -g -O0 -rdynamic -Wall -Werror $(GENFLAGS) $(SAN_CFLAGS) \ 30 RELEASE ?= << 31 OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0) << 32 << 33 LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libel << 34 LIBELF_LIBS := $(shell $(PKG_CONFIG) libel << 35 << 36 ifeq ($(srctree),) << 37 srctree := $(patsubst %/,%,$(dir $(CURDIR))) << 38 srctree := $(patsubst %/,%,$(dir $(srctree))) << 39 srctree := $(patsubst %/,%,$(dir $(srctree))) << 40 srctree := $(patsubst %/,%,$(dir $(srctree))) << 41 endif << 42 << 43 CFLAGS += -g $(OPT_FLAGS) -rdynamic << 44 -Wall -Werror -fno-omit-frame-pointe << 45 $(GENFLAGS) $(SAN_CFLAGS) $(LIBELF_C << 46 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GEN 25 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ 47 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUT 26 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT) 48 LDFLAGS += $(SAN_LDFLAGS) !! 27 LDFLAGS += $(SAN_CFLAGS) 49 LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread !! 28 LDLIBS += -lelf -lz -lrt -lpthread 50 << 51 PCAP_CFLAGS := $(shell $(PKG_CONFIG) --cfl << 52 PCAP_LIBS := $(shell $(PKG_CONFIG) --lib << 53 LDLIBS += $(PCAP_LIBS) << 54 CFLAGS += $(PCAP_CFLAGS) << 55 << 56 # The following tests perform type punning and << 57 # aliasing rules, which are exploited by both << 58 # while optimizing. This can lead to broken p << 59 progs/bind4_prog.c-CFLAGS := -fno-strict-alias << 60 progs/bind6_prog.c-CFLAGS := -fno-strict-alias << 61 progs/dynptr_fail.c-CFLAGS := -fno-strict-alia << 62 progs/linked_list_fail.c-CFLAGS := -fno-strict << 63 progs/map_kptr_fail.c-CFLAGS := -fno-strict-al << 64 progs/syscall.c-CFLAGS := -fno-strict-aliasing << 65 progs/test_pkt_md_access.c-CFLAGS := -fno-stri << 66 progs/test_sk_lookup.c-CFLAGS := -fno-strict-a << 67 progs/timer_crash.c-CFLAGS := -fno-strict-alia << 68 progs/test_global_func9.c-CFLAGS := -fno-stric << 69 progs/verifier_nocsr.c-CFLAGS := -fno-strict-a << 70 29 71 # Some utility functions use LLVM libraries << 72 jit_disasm_helpers.c-CFLAGS = $(LLVM_CFLAGS) << 73 << 74 ifneq ($(LLVM),) << 75 # Silence some warnings when compiled with cla 30 # Silence some warnings when compiled with clang >> 31 ifneq ($(LLVM),) 76 CFLAGS += -Wno-unused-command-line-argument 32 CFLAGS += -Wno-unused-command-line-argument 77 endif 33 endif 78 34 79 # Check whether bpf cpu=v4 is supported or not << 80 ifneq ($(shell $(CLANG) --target=bpf -mcpu=hel << 81 CLANG_CPUV4 := 1 << 82 endif << 83 << 84 # Order correspond to 'make run_tests' order 35 # Order correspond to 'make run_tests' order 85 TEST_GEN_PROGS = test_verifier test_tag test_m 36 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 86 test_sock test_sockmap \ !! 37 test_verifier_log test_dev_cgroup \ >> 38 test_sock test_sockmap get_cgroup_id_user \ >> 39 test_cgroup_storage \ 87 test_tcpnotify_user test_sysctl \ 40 test_tcpnotify_user test_sysctl \ 88 test_progs-no_alu32 41 test_progs-no_alu32 89 TEST_INST_SUBDIRS := no_alu32 << 90 42 91 # Also test bpf-gcc, if present 43 # Also test bpf-gcc, if present 92 ifneq ($(BPF_GCC),) 44 ifneq ($(BPF_GCC),) 93 TEST_GEN_PROGS += test_progs-bpf_gcc 45 TEST_GEN_PROGS += test_progs-bpf_gcc 94 TEST_INST_SUBDIRS += bpf_gcc << 95 << 96 # The following tests contain C code that, alt << 97 # triggers GCC warnings that cannot be disable << 98 # anonymous struct types in function parameter << 99 progs/btf_dump_test_case_bitfields.c-bpf_gcc-C << 100 progs/btf_dump_test_case_namespacing.c-bpf_gcc << 101 progs/btf_dump_test_case_packing.c-bpf_gcc-CFL << 102 progs/btf_dump_test_case_padding.c-bpf_gcc-CFL << 103 progs/btf_dump_test_case_syntax.c-bpf_gcc-CFLA << 104 << 105 # The following tests do type-punning, via the << 106 # `struct bpf_insn' to long and then uses the << 107 # "is used uninitialized" warning in GCC due t << 108 # rules. << 109 progs/verifier_ref_tracking.c-bpf_gcc-CFLAGS : << 110 progs/verifier_unpriv.c-bpf_gcc-CFLAGS := -fno << 111 progs/verifier_cgroup_storage.c-bpf_gcc-CFLAGS << 112 progs/verifier_ld_ind.c-bpf_gcc-CFLAGS := -fno << 113 progs/verifier_map_ret_val.c-bpf_gcc-CFLAGS := << 114 progs/verifier_spill_fill.c-bpf_gcc-CFLAGS := << 115 progs/verifier_subprog_precision.c-bpf_gcc-CFL << 116 progs/verifier_uninit.c-bpf_gcc-CFLAGS := -fno << 117 endif << 118 << 119 ifneq ($(CLANG_CPUV4),) << 120 TEST_GEN_PROGS += test_progs-cpuv4 << 121 TEST_INST_SUBDIRS += cpuv4 << 122 endif 46 endif 123 47 124 TEST_GEN_FILES = test_lwt_ip_encap.bpf.o test_ !! 48 TEST_GEN_FILES = test_lwt_ip_encap.o test_tc_edt.o 125 TEST_FILES = xsk_prereqs.sh $(wildcard progs/b 49 TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) 126 50 127 # Order correspond to 'make run_tests' order 51 # Order correspond to 'make run_tests' order 128 TEST_PROGS := test_kmod.sh \ 52 TEST_PROGS := test_kmod.sh \ 129 test_xdp_redirect.sh \ 53 test_xdp_redirect.sh \ 130 test_xdp_redirect_multi.sh \ 54 test_xdp_redirect_multi.sh \ 131 test_xdp_meta.sh \ 55 test_xdp_meta.sh \ >> 56 test_xdp_veth.sh \ >> 57 test_offload.py \ >> 58 test_sock_addr.sh \ 132 test_tunnel.sh \ 59 test_tunnel.sh \ 133 test_lwt_seg6local.sh \ 60 test_lwt_seg6local.sh \ 134 test_lirc_mode2.sh \ 61 test_lirc_mode2.sh \ 135 test_skb_cgroup_id.sh \ 62 test_skb_cgroup_id.sh \ 136 test_flow_dissector.sh \ 63 test_flow_dissector.sh \ 137 test_xdp_vlan_mode_generic.sh \ 64 test_xdp_vlan_mode_generic.sh \ 138 test_xdp_vlan_mode_native.sh \ 65 test_xdp_vlan_mode_native.sh \ 139 test_lwt_ip_encap.sh \ 66 test_lwt_ip_encap.sh \ 140 test_tcp_check_syncookie.sh \ 67 test_tcp_check_syncookie.sh \ 141 test_tc_tunnel.sh \ 68 test_tc_tunnel.sh \ 142 test_tc_edt.sh \ 69 test_tc_edt.sh \ 143 test_xdping.sh \ 70 test_xdping.sh \ 144 test_bpftool_build.sh \ 71 test_bpftool_build.sh \ 145 test_bpftool.sh \ 72 test_bpftool.sh \ 146 test_bpftool_metadata.sh \ 73 test_bpftool_metadata.sh \ 147 test_doc_build.sh \ 74 test_doc_build.sh \ 148 test_xsk.sh \ !! 75 test_xsk.sh 149 test_xdp_features.sh << 150 76 151 TEST_PROGS_EXTENDED := with_addr.sh \ 77 TEST_PROGS_EXTENDED := with_addr.sh \ 152 with_tunnels.sh ima_setup.sh verify_si !! 78 with_tunnels.sh ima_setup.sh \ 153 test_xdp_vlan.sh test_bpftool.py 79 test_xdp_vlan.sh test_bpftool.py 154 80 155 # Compile but not part of 'make run_tests' 81 # Compile but not part of 'make run_tests' 156 TEST_GEN_PROGS_EXTENDED = \ !! 82 TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ 157 flow_dissector_load test_flow_dissecto 83 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ 158 test_lirc_mode2_user xdping test_cpp r 84 test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \ 159 xskxceiver xdp_redirect_multi xdp_synp !! 85 xdpxceiver xdp_redirect_multi 160 xdp_features bpf_test_no_cfi.ko bpf_te << 161 bpf_test_modorder_y.ko << 162 86 163 TEST_GEN_FILES += liburandom_read.so urandom_r !! 87 TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read 164 88 165 ifneq ($(V),1) !! 89 # Emit succinct information message describing current building step >> 90 # $1 - generic step name (e.g., CC, LINK, etc); >> 91 # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor]; >> 92 # $3 - target (assumed to be file); only file name will be emitted; >> 93 # $4 - optional extra arg, emitted as-is, if provided. >> 94 ifeq ($(V),1) >> 95 Q = >> 96 msg = >> 97 else >> 98 Q = @ >> 99 msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))"; >> 100 MAKEFLAGS += --no-print-directory 166 submake_extras := feature_display=0 101 submake_extras := feature_display=0 167 endif 102 endif 168 103 169 # override lib.mk's default rules 104 # override lib.mk's default rules 170 OVERRIDE_TARGETS := 1 105 OVERRIDE_TARGETS := 1 171 override define CLEAN 106 override define CLEAN 172 $(call msg,CLEAN) 107 $(call msg,CLEAN) 173 $(Q)$(RM) -r $(TEST_GEN_PROGS) 108 $(Q)$(RM) -r $(TEST_GEN_PROGS) 174 $(Q)$(RM) -r $(TEST_GEN_PROGS_EXTENDED 109 $(Q)$(RM) -r $(TEST_GEN_PROGS_EXTENDED) 175 $(Q)$(RM) -r $(TEST_GEN_FILES) 110 $(Q)$(RM) -r $(TEST_GEN_FILES) 176 $(Q)$(RM) -r $(EXTRA_CLEAN) 111 $(Q)$(RM) -r $(EXTRA_CLEAN) 177 $(Q)$(MAKE) -C bpf_testmod clean 112 $(Q)$(MAKE) -C bpf_testmod clean 178 $(Q)$(MAKE) docs-clean 113 $(Q)$(MAKE) docs-clean 179 endef 114 endef 180 115 181 include ../lib.mk 116 include ../lib.mk 182 117 183 NON_CHECK_FEAT_TARGETS := clean docs-clean << 184 CHECK_FEAT := $(filter-out $(NON_CHECK_FEAT_TA << 185 ifneq ($(CHECK_FEAT),) << 186 FEATURE_USER := .selftests << 187 FEATURE_TESTS := llvm << 188 FEATURE_DISPLAY := $(FEATURE_TESTS) << 189 << 190 # Makefile.feature expects OUTPUT to end with << 191 ifeq ($(shell expr $(MAKE_VERSION) \>= 4.4), 1 << 192 $(let OUTPUT,$(OUTPUT)/,\ << 193 $(eval include ../../../build/Makefile << 194 else << 195 OUTPUT := $(OUTPUT)/ << 196 $(eval include ../../../build/Makefile.feature << 197 OUTPUT := $(patsubst %/,%,$(OUTPUT)) << 198 endif << 199 endif << 200 << 201 ifeq ($(feature-llvm),1) << 202 LLVM_CFLAGS += -DHAVE_LLVM_SUPPORT << 203 LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler << 204 # both llvm-config and lib.mk add -D_GNU_SOU << 205 LLVM_CFLAGS += $(filter-out -D_GNU_SOURCE,$ << 206 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --lin << 207 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --lin << 208 LLVM_LDLIBS += -lstdc++ << 209 LLVM_LDFLAGS += $(shell $(LLVM_CONFIG) --ldf << 210 endif << 211 << 212 SCRATCH_DIR := $(OUTPUT)/tools 118 SCRATCH_DIR := $(OUTPUT)/tools 213 BUILD_DIR := $(SCRATCH_DIR)/build 119 BUILD_DIR := $(SCRATCH_DIR)/build 214 INCLUDE_DIR := $(SCRATCH_DIR)/include 120 INCLUDE_DIR := $(SCRATCH_DIR)/include 215 BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a 121 BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a 216 ifneq ($(CROSS_COMPILE),) 122 ifneq ($(CROSS_COMPILE),) 217 HOST_BUILD_DIR := $(BUILD_DIR)/host 123 HOST_BUILD_DIR := $(BUILD_DIR)/host 218 HOST_SCRATCH_DIR := $(OUTPUT)/host-tool 124 HOST_SCRATCH_DIR := $(OUTPUT)/host-tools 219 HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR) 125 HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR)/include 220 else 126 else 221 HOST_BUILD_DIR := $(BUILD_DIR) 127 HOST_BUILD_DIR := $(BUILD_DIR) 222 HOST_SCRATCH_DIR := $(SCRATCH_DIR) 128 HOST_SCRATCH_DIR := $(SCRATCH_DIR) 223 HOST_INCLUDE_DIR := $(INCLUDE_DIR) 129 HOST_INCLUDE_DIR := $(INCLUDE_DIR) 224 endif 130 endif 225 HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf 131 HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a 226 RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_bt 132 RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids 227 RUNQSLOWER_OUTPUT := $(BUILD_DIR)/runqslower/ 133 RUNQSLOWER_OUTPUT := $(BUILD_DIR)/runqslower/ 228 134 229 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) 135 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ 230 $(if $(KBUILD_OUTPUT),$(K 136 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ 231 ../../../../vmlinux 137 ../../../../vmlinux \ 232 /sys/kernel/btf/vmlinux 138 /sys/kernel/btf/vmlinux \ 233 /boot/vmlinux-$(shell una 139 /boot/vmlinux-$(shell uname -r) 234 VMLINUX_BTF ?= $(abspath $(firstword $(wildcar 140 VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) 235 ifeq ($(VMLINUX_BTF),) 141 ifeq ($(VMLINUX_BTF),) 236 $(error Cannot find a vmlinux for VMLINUX_BTF 142 $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)") 237 endif 143 endif 238 144 239 # Define simple and short `make test_progs`, ` 145 # Define simple and short `make test_progs`, `make test_sysctl`, etc targets 240 # to build individual tests. 146 # to build individual tests. 241 # NOTE: Semicolon at the end is critical to ov 147 # NOTE: Semicolon at the end is critical to override lib.mk's default static 242 # rule for binaries. 148 # rule for binaries. 243 $(notdir $(TEST_GEN_PROGS) 149 $(notdir $(TEST_GEN_PROGS) \ 244 $(TEST_GEN_PROGS_EXTENDED)): %: $(OUT !! 150 $(TEST_PROGS) \ >> 151 $(TEST_PROGS_EXTENDED) \ >> 152 $(TEST_GEN_PROGS_EXTENDED) \ >> 153 $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ; 245 154 246 # sort removes libbpf duplicates when not cros 155 # sort removes libbpf duplicates when not cross-building 247 MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST !! 156 MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST_BUILD_DIR)/libbpf \ 248 $(BUILD_DIR)/bpftool $(HOST_BUI !! 157 $(HOST_BUILD_DIR)/bpftool $(HOST_BUILD_DIR)/resolve_btfids \ 249 $(HOST_BUILD_DIR)/resolve_btfid << 250 $(RUNQSLOWER_OUTPUT) $(INCLUDE_ 158 $(RUNQSLOWER_OUTPUT) $(INCLUDE_DIR)) 251 $(MAKE_DIRS): 159 $(MAKE_DIRS): 252 $(call msg,MKDIR,,$@) 160 $(call msg,MKDIR,,$@) 253 $(Q)mkdir -p $@ 161 $(Q)mkdir -p $@ 254 162 255 $(OUTPUT)/%.o: %.c 163 $(OUTPUT)/%.o: %.c 256 $(call msg,CC,,$@) 164 $(call msg,CC,,$@) 257 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^ 165 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ 258 166 259 $(OUTPUT)/%:%.c 167 $(OUTPUT)/%:%.c 260 $(call msg,BINARY,,$@) 168 $(call msg,BINARY,,$@) 261 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ 169 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ 262 170 263 # LLVM's ld.lld doesn't support all the archit !! 171 $(OUTPUT)/urandom_read: urandom_read.c 264 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv << 265 LLD := lld << 266 else << 267 LLD := $(shell command -v $(LD)) << 268 endif << 269 << 270 # Filter out -static for liburandom_read.so an << 271 # do not fail. Static builds leave urandom_rea << 272 $(OUTPUT)/liburandom_read.so: urandom_read_lib << 273 $(call msg,LIB,,$@) << 274 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ << 275 $(filter-out -static,$(CF << 276 $(filter %.c,$^) $(filter << 277 -fuse-ld=$(LLD) -Wl,-znos << 278 -Wl,--version-script=libu << 279 -fPIC -shared -o $@ << 280 << 281 $(OUTPUT)/urandom_read: urandom_read.c urandom << 282 $(call msg,BINARY,,$@) 172 $(call msg,BINARY,,$@) 283 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ !! 173 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -Wl,--build-id=sha1 -o $@ 284 $(filter-out -static,$(CF << 285 -lurandom_read $(filter-o << 286 -fuse-ld=$(LLD) -Wl,-znos << 287 -Wl,-rpath=. -o $@ << 288 << 289 $(OUTPUT)/sign-file: ../../../../scripts/sign- << 290 $(call msg,SIGN-FILE,,$@) << 291 $(Q)$(CC) $(shell $(PKG_CONFIG) --cfla << 292 $< -o $@ \ << 293 $(shell $(PKG_CONFIG) --libs << 294 174 295 $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RES !! 175 $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch]) 296 $(call msg,MOD,,$@) 176 $(call msg,MOD,,$@) 297 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # 177 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation 298 $(Q)$(MAKE) $(submake_extras) RESOLVE_ !! 178 $(Q)$(MAKE) $(submake_extras) -C bpf_testmod 299 $(Q)cp bpf_testmod/bpf_testmod.ko $@ 179 $(Q)cp bpf_testmod/bpf_testmod.ko $@ 300 180 301 $(OUTPUT)/bpf_test_no_cfi.ko: $(VMLINUX_BTF) $ << 302 $(call msg,MOD,,$@) << 303 $(Q)$(RM) bpf_test_no_cfi/bpf_test_no_ << 304 $(Q)$(MAKE) $(submake_extras) RESOLVE_ << 305 $(Q)cp bpf_test_no_cfi/bpf_test_no_cfi << 306 << 307 $(OUTPUT)/bpf_test_modorder_x.ko: $(VMLINUX_BT << 308 $(call msg,MOD,,$@) << 309 $(Q)$(RM) bpf_test_modorder_x/bpf_test << 310 $(Q)$(MAKE) $(submake_extras) RESOLVE_ << 311 $(Q)cp bpf_test_modorder_x/bpf_test_mo << 312 << 313 $(OUTPUT)/bpf_test_modorder_y.ko: $(VMLINUX_BT << 314 $(call msg,MOD,,$@) << 315 $(Q)$(RM) bpf_test_modorder_y/bpf_test << 316 $(Q)$(MAKE) $(submake_extras) RESOLVE_ << 317 $(Q)cp bpf_test_modorder_y/bpf_test_mo << 318 << 319 << 320 DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bp 181 DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool 321 ifneq ($(CROSS_COMPILE),) << 322 CROSS_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool << 323 TRUNNER_BPFTOOL := $(CROSS_BPFTOOL) << 324 USE_BOOTSTRAP := "" << 325 else << 326 TRUNNER_BPFTOOL := $(DEFAULT_BPFTOOL) << 327 USE_BOOTSTRAP := "bootstrap/" << 328 endif << 329 182 330 $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BP 183 $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) $(RUNQSLOWER_OUTPUT) 331 $(Q)$(MAKE) $(submake_extras) -C $(TOO 184 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ 332 OUTPUT=$(RUNQSLOWER_OUTPUT 185 OUTPUT=$(RUNQSLOWER_OUTPUT) VMLINUX_BTF=$(VMLINUX_BTF) \ 333 BPFTOOL_OUTPUT=$(HOST_BUIL 186 BPFTOOL_OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ 334 BPFOBJ_OUTPUT=$(BUILD_DIR) !! 187 BPFOBJ_OUTPUT=$(BUILD_DIR)/libbpf \ 335 BPFOBJ=$(BPFOBJ) BPF_INCLU !! 188 BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \ 336 EXTRA_CFLAGS='-g $(OPT_FLA << 337 EXTRA_LDFLAGS='$(SAN_LDFLA << 338 cp $(RUNQSLOWER_OUTPUT)run 189 cp $(RUNQSLOWER_OUTPUT)runqslower $@ 339 190 340 TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL) !! 191 TEST_GEN_PROGS_EXTENDED += $(DEFAULT_BPFTOOL) 341 192 342 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): 193 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ) 343 194 344 TESTING_HELPERS := $(OUTPUT)/testing_helpers.o << 345 CGROUP_HELPERS := $(OUTPUT)/cgroup_helpers.o 195 CGROUP_HELPERS := $(OUTPUT)/cgroup_helpers.o 346 UNPRIV_HELPERS := $(OUTPUT)/unpriv_helpers.o !! 196 TESTING_HELPERS := $(OUTPUT)/testing_helpers.o 347 TRACE_HELPERS := $(OUTPUT)/trace_helpers.o 197 TRACE_HELPERS := $(OUTPUT)/trace_helpers.o 348 JSON_WRITER := $(OUTPUT)/json_writ << 349 CAP_HELPERS := $(OUTPUT)/cap_helpers.o 198 CAP_HELPERS := $(OUTPUT)/cap_helpers.o 350 NETWORK_HELPERS := $(OUTPUT)/network_helpers.o << 351 199 >> 200 $(OUTPUT)/test_dev_cgroup: $(CGROUP_HELPERS) $(TESTING_HELPERS) >> 201 $(OUTPUT)/test_skb_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) 352 $(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTI 202 $(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTING_HELPERS) >> 203 $(OUTPUT)/test_sock_addr: $(CGROUP_HELPERS) $(TESTING_HELPERS) 353 $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TE 204 $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TESTING_HELPERS) 354 $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPER 205 $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) $(TRACE_HELPERS) >> 206 $(OUTPUT)/get_cgroup_id_user: $(CGROUP_HELPERS) $(TESTING_HELPERS) >> 207 $(OUTPUT)/test_cgroup_storage: $(CGROUP_HELPERS) $(TESTING_HELPERS) 355 $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) 208 $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) $(TESTING_HELPERS) 356 $(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TES 209 $(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TESTING_HELPERS) 357 $(OUTPUT)/test_tag: $(TESTING_HELPERS) 210 $(OUTPUT)/test_tag: $(TESTING_HELPERS) 358 $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELP 211 $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS) 359 $(OUTPUT)/xdping: $(TESTING_HELPERS) 212 $(OUTPUT)/xdping: $(TESTING_HELPERS) 360 $(OUTPUT)/flow_dissector_load: $(TESTING_HELPE 213 $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS) 361 $(OUTPUT)/test_maps: $(TESTING_HELPERS) 214 $(OUTPUT)/test_maps: $(TESTING_HELPERS) 362 $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $( !! 215 $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) 363 $(OUTPUT)/xsk.o: $(BPFOBJ) << 364 $(OUTPUT)/test_tcp_check_syncookie_user: $(NET << 365 216 366 BPFTOOL ?= $(DEFAULT_BPFTOOL) 217 BPFTOOL ?= $(DEFAULT_BPFTOOL) 367 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/* 218 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ 368 $(HOST_BPFOBJ) | $(HOST_BU 219 $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool 369 $(Q)$(MAKE) $(submake_extras) -C $(BP 220 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ 370 ARCH= CROSS_COMPILE= CC="$ !! 221 ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \ 371 EXTRA_CFLAGS='-g $(OPT_FLA !! 222 EXTRA_CFLAGS='-g -O0' \ 372 OUTPUT=$(HOST_BUILD_DIR)/b 223 OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \ 373 LIBBPF_OUTPUT=$(HOST_BUILD 224 LIBBPF_OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \ 374 LIBBPF_DESTDIR=$(HOST_SCRA 225 LIBBPF_DESTDIR=$(HOST_SCRATCH_DIR)/ \ 375 prefix= DESTDIR=$(HOST_SCR 226 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install-bin 376 227 377 ifneq ($(CROSS_COMPILE),) << 378 $(CROSS_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ << 379 $(BPFOBJ) | $(BUILD_DIR)/b << 380 $(Q)$(MAKE) $(submake_extras) -C $(BP << 381 ARCH=$(ARCH) CROSS_COMPILE << 382 EXTRA_CFLAGS='-g $(OPT_FLA << 383 OUTPUT=$(BUILD_DIR)/bpftoo << 384 LIBBPF_OUTPUT=$(BUILD_DIR) << 385 LIBBPF_DESTDIR=$(SCRATCH_D << 386 prefix= DESTDIR=$(SCRATCH_ << 387 endif << 388 << 389 all: docs 228 all: docs 390 229 391 docs: 230 docs: 392 $(Q)RST2MAN_OPTS="--exit-status=1" $(M 231 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \ 393 -f Makefile.docs 232 -f Makefile.docs \ 394 prefix= OUTPUT=$(OUTPUT)/ 233 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@ 395 234 396 docs-clean: 235 docs-clean: 397 $(Q)$(MAKE) $(submake_extras) 236 $(Q)$(MAKE) $(submake_extras) \ 398 -f Makefile.docs 237 -f Makefile.docs \ 399 prefix= OUTPUT=$(OUTPUT)/ 238 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@ 400 239 401 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDI 240 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 402 $(APIDIR)/linux/bpf.h 241 $(APIDIR)/linux/bpf.h \ 403 | $(BUILD_DIR)/libbpf 242 | $(BUILD_DIR)/libbpf 404 $(Q)$(MAKE) $(submake_extras) -C $(BPF 243 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ 405 EXTRA_CFLAGS='-g $(OPT_FLA !! 244 EXTRA_CFLAGS='-g -O0' \ 406 EXTRA_LDFLAGS='$(SAN_LDFLA << 407 DESTDIR=$(SCRATCH_DIR) pre 245 DESTDIR=$(SCRATCH_DIR) prefix= all install_headers 408 246 409 ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) 247 ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) 410 $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $( 248 $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 411 $(APIDIR)/linux/bpf.h 249 $(APIDIR)/linux/bpf.h \ 412 | $(HOST_BUILD_DIR)/libbpf 250 | $(HOST_BUILD_DIR)/libbpf 413 $(Q)$(MAKE) $(submake_extras) -C $(BPF 251 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \ 414 EXTRA_CFLAGS='-g $(OPT_FLA !! 252 EXTRA_CFLAGS='-g -O0' ARCH= CROSS_COMPILE= \ 415 OUTPUT=$(HOST_BUILD_DIR)/l !! 253 OUTPUT=$(HOST_BUILD_DIR)/libbpf/ CC=$(HOSTCC) LD=$(HOSTLD) \ 416 CC="$(HOSTCC)" LD="$(HOSTL << 417 DESTDIR=$(HOST_SCRATCH_DIR 254 DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers 418 endif 255 endif 419 256 420 # vmlinux.h is first dumped to a temprorary fi << 421 # the previous version. This helps to avoid un << 422 # $(TRUNNER_BPF_OBJS) << 423 $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPF 257 $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR) 424 ifeq ($(VMLINUX_H),) 258 ifeq ($(VMLINUX_H),) 425 $(call msg,GEN,,$@) 259 $(call msg,GEN,,$@) 426 $(Q)$(BPFTOOL) btf dump file $(VMLINUX !! 260 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ 427 $(Q)cmp -s $(INCLUDE_DIR)/.vmlinux.h.t << 428 else 261 else 429 $(call msg,CP,,$@) 262 $(call msg,CP,,$@) 430 $(Q)cp "$(VMLINUX_H)" $@ 263 $(Q)cp "$(VMLINUX_H)" $@ 431 endif 264 endif 432 265 433 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUI 266 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \ 434 $(TOOLSDIR)/bpf/resolve 267 $(TOOLSDIR)/bpf/resolve_btfids/main.c \ 435 $(TOOLSDIR)/lib/rbtree. 268 $(TOOLSDIR)/lib/rbtree.c \ 436 $(TOOLSDIR)/lib/zalloc. 269 $(TOOLSDIR)/lib/zalloc.c \ 437 $(TOOLSDIR)/lib/string. 270 $(TOOLSDIR)/lib/string.c \ 438 $(TOOLSDIR)/lib/ctype.c 271 $(TOOLSDIR)/lib/ctype.c \ 439 $(TOOLSDIR)/lib/str_err 272 $(TOOLSDIR)/lib/str_error_r.c 440 $(Q)$(MAKE) $(submake_extras) -C $(TOO 273 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \ 441 CC="$(HOSTCC)" LD="$(HOSTLD)" !! 274 CC=$(HOSTCC) LD=$(HOSTLD) AR=$(HOSTAR) \ 442 LIBBPF_INCLUDE=$(HOST_INCLUDE_ 275 LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \ 443 OUTPUT=$(HOST_BUILD_DIR)/resol 276 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ) 444 277 445 # Get Clang's default includes on this system, 278 # Get Clang's default includes on this system, as opposed to those seen by 446 # '--target=bpf'. This fixes "missing" files o !! 279 # '-target bpf'. This fixes "missing" files on some architectures/distros, 447 # such as asm/byteorder.h, asm/socket.h, asm/s 280 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 448 # 281 # 449 # Use '-idirafter': Don't interfere with inclu 282 # Use '-idirafter': Don't interfere with include mechanics except where the 450 # build would have failed anyways. 283 # build would have failed anyways. 451 define get_sys_includes 284 define get_sys_includes 452 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ !! 285 $(shell $(1) -v -E - </dev/null 2>&1 \ 453 | sed -n '/<...> search starts here:/, 286 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ 454 $(shell $(1) $(2) -dM -E - </dev/null | grep ' !! 287 $(shell $(1) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') 455 $(shell $(1) $(2) -dM -E - </dev/null | grep ' << 456 $(shell $(1) $(2) -dM -E - </dev/null | grep - << 457 endef 288 endef 458 289 459 # Determine target endianness. 290 # Determine target endianness. 460 IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </de 291 IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \ 461 grep 'define __BYTE_OR 292 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') 462 MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endi 293 MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) 463 294 464 ifneq ($(CROSS_COMPILE),) !! 295 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) 465 CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_ !! 296 BPF_CFLAGS = -g -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ 466 endif << 467 << 468 CLANG_SYS_INCLUDES = $(call get_sys_includes,$ << 469 BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_ << 470 -I$(INCLUDE_DIR) -I$(CURDIR) -I$( 297 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ 471 -I$(abspath $(OUTPUT)/../usr/incl !! 298 -I$(abspath $(OUTPUT)/../usr/include) 472 -Wno-compare-distinct-pointer-typ << 473 # TODO: enable me -Wsign-compare << 474 299 475 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) !! 300 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ >> 301 -Wno-compare-distinct-pointer-types 476 302 477 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += 303 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline 478 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += - 304 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline 479 305 480 $(OUTPUT)/flow_dissector_load.o: flow_dissecto 306 $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h 481 $(OUTPUT)/cgroup_getset_retval_hooks.o: cgroup << 482 307 483 # Build BPF object using Clang 308 # Build BPF object using Clang 484 # $1 - input .c file 309 # $1 - input .c file 485 # $2 - output .o file 310 # $2 - output .o file 486 # $3 - CFLAGS 311 # $3 - CFLAGS 487 # $4 - binary name << 488 define CLANG_BPF_BUILD_RULE 312 define CLANG_BPF_BUILD_RULE 489 $(call msg,CLNG-BPF,$4,$2) !! 313 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 490 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 !! 314 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v3 -o $2 491 endef 315 endef 492 # Similar to CLANG_BPF_BUILD_RULE, but with di 316 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32 493 define CLANG_NOALU32_BPF_BUILD_RULE 317 define CLANG_NOALU32_BPF_BUILD_RULE 494 $(call msg,CLNG-BPF,$4,$2) !! 318 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) 495 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 !! 319 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -mcpu=v2 -o $2 496 endef << 497 # Similar to CLANG_BPF_BUILD_RULE, but with cp << 498 define CLANG_CPUV4_BPF_BUILD_RULE << 499 $(call msg,CLNG-BPF,$4,$2) << 500 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 << 501 endef 320 endef 502 # Build BPF object using GCC 321 # Build BPF object using GCC 503 define GCC_BPF_BUILD_RULE 322 define GCC_BPF_BUILD_RULE 504 $(call msg,GCC-BPF,$4,$2) !! 323 $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2) 505 $(Q)$(BPF_GCC) $3 -DBPF_NO_PRESERVE_AC !! 324 $(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2 506 endef 325 endef 507 326 508 SKEL_BLACKLIST := btf__% test_pinning_invalid. 327 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c 509 328 510 LINKED_SKELS := test_static_linked.skel.h link 329 LINKED_SKELS := test_static_linked.skel.h linked_funcs.skel.h \ 511 linked_vars.skel.h linked_maps 330 linked_vars.skel.h linked_maps.skel.h \ 512 test_subskeleton.skel.h test_s !! 331 test_subskeleton.skel.h test_subskeleton_lib.skel.h 513 test_usdt.skel.h << 514 332 515 LSKELS := fentry_test.c fexit_test.c fexit_sle !! 333 # In the subskeleton case, we want the test_subskeleton_lib.subskel.h file 516 trace_printk.c trace_vprintk.c map_ptr !! 334 # but that's created as a side-effect of the skel.h generation. 517 core_kern.c core_kern_overflow.c test_ !! 335 test_subskeleton.skel.h-deps := test_subskeleton_lib2.o test_subskeleton_lib.o test_subskeleton.o 518 test_ringbuf_n.c test_ringbuf_map_key. !! 336 test_subskeleton_lib.skel.h-deps := test_subskeleton_lib2.o test_subskeleton_lib.o 519 337 >> 338 LSKELS := kfunc_call_test.c fentry_test.c fexit_test.c fexit_sleep.c \ >> 339 test_ringbuf.c atomics.c trace_printk.c trace_vprintk.c \ >> 340 map_ptr_kern.c core_kern.c core_kern_overflow.c 520 # Generate both light skeleton and libbpf skel 341 # Generate both light skeleton and libbpf skeleton for these 521 LSKELS_EXTRA := test_ksyms_module.c test_ksyms !! 342 LSKELS_EXTRA := test_ksyms_module.c test_ksyms_weak.c kfunc_call_test_subprog.c 522 kfunc_call_test_subprog.c << 523 SKEL_BLACKLIST += $$(LSKELS) 343 SKEL_BLACKLIST += $$(LSKELS) 524 344 525 test_static_linked.skel.h-deps := test_static_ !! 345 test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o 526 linked_funcs.skel.h-deps := linked_funcs1.bpf. !! 346 linked_funcs.skel.h-deps := linked_funcs1.o linked_funcs2.o 527 linked_vars.skel.h-deps := linked_vars1.bpf.o !! 347 linked_vars.skel.h-deps := linked_vars1.o linked_vars2.o 528 linked_maps.skel.h-deps := linked_maps1.bpf.o !! 348 linked_maps.skel.h-deps := linked_maps1.o linked_maps2.o 529 # In the subskeleton case, we want the test_su !! 349 530 # but that's created as a side-effect of the s !! 350 LINKED_BPF_SRCS := $(patsubst %.o,%.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps))) 531 test_subskeleton.skel.h-deps := test_subskelet << 532 test_subskeleton_lib.skel.h-deps := test_subsk << 533 test_usdt.skel.h-deps := test_usdt.bpf.o test_ << 534 xsk_xdp_progs.skel.h-deps := xsk_xdp_progs.bpf << 535 xdp_hw_metadata.skel.h-deps := xdp_hw_metadata << 536 xdp_features.skel.h-deps := xdp_features.bpf.o << 537 << 538 LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKE << 539 LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LI << 540 << 541 HEADERS_FOR_BPF_OBJS := $(wildcard $(BPFDIR)/* << 542 $(addprefix $(BPFDIR)/ << 543 << 544 << 545 << 546 351 547 # Set up extra TRUNNER_XXX "temporary" variabl 352 # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on 548 # $eval()) and pass control to DEFINE_TEST_RUN 353 # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES. 549 # Parameters: 354 # Parameters: 550 # $1 - test runner base binary name (e.g., tes 355 # $1 - test runner base binary name (e.g., test_progs) 551 # $2 - test runner extra "flavor" (e.g., no_al !! 356 # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) 552 define DEFINE_TEST_RUNNER 357 define DEFINE_TEST_RUNNER 553 358 554 TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 359 TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 555 TRUNNER_BINARY := $1$(if $2,-)$2 360 TRUNNER_BINARY := $1$(if $2,-)$2 556 TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNE 361 TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \ 557 $$(notdir $$( 362 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))) 558 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNN 363 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ 559 $$(filter %.c 364 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES))) 560 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_ 365 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES)) 561 TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/test 366 TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h 562 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TR 367 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)) 563 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER !! 368 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS)) 564 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNE 369 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \ 565 $$(filter-out 370 $$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\ 566 371 $$(TRUNNER_BPF_SRCS))) 567 TRUNNER_BPF_LSKELS := $$(patsubst %.c,$$(TRUNN 372 TRUNNER_BPF_LSKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.lskel.h, $$(LSKELS) $$(LSKELS_EXTRA)) 568 TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TR 373 TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TRUNNER_OUTPUT)/,$(LINKED_SKELS)) 569 TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS) 374 TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS) 570 375 571 # Evaluate rules now with extra TRUNNER_XXX va 376 # Evaluate rules now with extra TRUNNER_XXX variables above already defined 572 $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2 377 $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2)) 573 378 574 endef 379 endef 575 380 576 # Using TRUNNER_XXX variables, provided by cal 381 # Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and 577 # set up by DEFINE_TEST_RUNNER itself, create 382 # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with: 578 # $1 - test runner base binary name (e.g., tes 383 # $1 - test runner base binary name (e.g., test_progs) 579 # $2 - test runner extra "flavor" (e.g., no_al !! 384 # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) 580 define DEFINE_TEST_RUNNER_RULES 385 define DEFINE_TEST_RUNNER_RULES 581 386 582 ifeq ($($(TRUNNER_OUTPUT)-dir),) 387 ifeq ($($(TRUNNER_OUTPUT)-dir),) 583 $(TRUNNER_OUTPUT)-dir := y 388 $(TRUNNER_OUTPUT)-dir := y 584 $(TRUNNER_OUTPUT): 389 $(TRUNNER_OUTPUT): 585 $$(call msg,MKDIR,,$$@) 390 $$(call msg,MKDIR,,$$@) 586 $(Q)mkdir -p $$@ 391 $(Q)mkdir -p $$@ 587 endif 392 endif 588 393 589 # ensure we set up BPF objects generation rule 394 # ensure we set up BPF objects generation rule just once for a given 590 # input/output directory combination 395 # input/output directory combination 591 ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-b 396 ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),) 592 $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs : 397 $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y 593 $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.bpf.o !! 398 $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 594 $(TRUNNER_BPF_PROGS_DIR)/ 399 $(TRUNNER_BPF_PROGS_DIR)/%.c \ 595 $(TRUNNER_BPF_PROGS_DIR)/ 400 $(TRUNNER_BPF_PROGS_DIR)/*.h \ 596 $$(INCLUDE_DIR)/vmlinux.h 401 $$(INCLUDE_DIR)/vmlinux.h \ 597 $(HEADERS_FOR_BPF_OBJS) !! 402 $(wildcard $(BPFDIR)/bpf_*.h) \ 598 | $(TRUNNER_OUTPUT) $$(BP 403 | $(TRUNNER_OUTPUT) $$(BPFOBJ) 599 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<, 404 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \ 600 $(TR !! 405 $(TRUNNER_BPF_CFLAGS)) 601 $$($ << 602 $$($ << 603 406 604 $(TRUNNER_BPF_SKELS): %.skel.h: %.bpf.o $(BPFT !! 407 $(TRUNNER_BPF_SKELS): %.skel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT) 605 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) 408 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 606 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li 409 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked1.o) $$< 607 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li 410 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o) 608 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li 411 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o) 609 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=. 412 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o) 610 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=. !! 413 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=)) > $$@ 611 $(Q)$$(BPFTOOL) gen subskeleton $$(<:. !! 414 $(Q)$$(BPFTOOL) gen subskeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=)) > $$(@:.skel.h=.subskel.h) 612 $(Q)rm -f $$(<:.o=.linked1.o) $$(<:.o= << 613 415 614 $(TRUNNER_BPF_LSKELS): %.lskel.h: %.bpf.o $(BP !! 416 $(TRUNNER_BPF_LSKELS): %.lskel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT) 615 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) 417 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 616 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll 418 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked1.o) $$< 617 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll 419 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked2.o) $$(<:.o=.llinked1.o) 618 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll 420 $(Q)$$(BPFTOOL) gen object $$(<:.o=.llinked3.o) $$(<:.o=.llinked2.o) 619 $(Q)diff $$(<:.o=.llinked2.o) $$(<:.o= 421 $(Q)diff $$(<:.o=.llinked2.o) $$(<:.o=.llinked3.o) 620 $(Q)$$(BPFTOOL) gen skeleton -L $$(<:. !! 422 $(Q)$$(BPFTOOL) gen skeleton -L $$(<:.o=.llinked3.o) name $$(notdir $$(<:.o=_lskel)) > $$@ 621 $(Q)rm -f $$(<:.o=.llinked1.o) $$(<:.o << 622 423 623 $(LINKED_BPF_OBJS): %: $(TRUNNER_OUTPUT)/% !! 424 $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT) 624 !! 425 $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o)) 625 # .SECONDEXPANSION here allows to correctly ex << 626 .SECONDEXPANSION: << 627 $(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_OUTPUT) << 628 $$(call msg,LINK-BPF,$(TRUNNER_BINARY) << 629 $(Q)$$(BPFTOOL) gen object $$(@:.skel. 426 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked1.o) $$(addprefix $(TRUNNER_OUTPUT)/,$$($$(@F)-deps)) 630 $(Q)$$(BPFTOOL) gen object $$(@:.skel. 427 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked1.o) 631 $(Q)$$(BPFTOOL) gen object $$(@:.skel. 428 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked3.o) $$(@:.skel.h=.linked2.o) 632 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@ 429 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o) 633 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) 430 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) 634 $(Q)$$(BPFTOOL) gen skeleton $$(@:.ske 431 $(Q)$$(BPFTOOL) gen skeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$@ 635 $(Q)$$(BPFTOOL) gen subskeleton $$(@:. 432 $(Q)$$(BPFTOOL) gen subskeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$(@:.skel.h=.subskel.h) 636 $(Q)rm -f $$(@:.skel.h=.linked1.o) $$( << 637 << 638 # When the compiler generates a %.d file, only << 639 # full paths) are specified as prerequisites f << 640 # file. This target makes %.skel.h basename de << 641 # linking generated %.d dependency with actual << 642 $(notdir %.skel.h): $(TRUNNER_OUTPUT)/%.skel.h << 643 @true << 644 << 645 endif 433 endif 646 434 647 # ensure we set up tests.h header generation r 435 # ensure we set up tests.h header generation rule just once 648 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) 436 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) 649 $(TRUNNER_TESTS_DIR)-tests-hdr := y 437 $(TRUNNER_TESTS_DIR)-tests-hdr := y 650 $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c 438 $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c 651 $$(call msg,TEST-HDR,$(TRUNNER_BINARY) 439 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@) 652 $$(shell (echo '/* Generated header, d 440 $$(shell (echo '/* Generated header, do not edit */'; \ 653 sed -n -E 's/^void (serial_) 441 sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \ 654 $(TRUNNER_TESTS_DIR)/* 442 $(TRUNNER_TESTS_DIR)/*.c | sort ; \ 655 ) > $$@) 443 ) > $$@) 656 endif 444 endif 657 445 658 # compile individual test files 446 # compile individual test files 659 # Note: we cd into output directory to ensure 447 # Note: we cd into output directory to ensure embedded BPF object is found 660 $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test 448 $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ 661 $(TRUNNER_TESTS_DIR)/%.c 449 $(TRUNNER_TESTS_DIR)/%.c \ 662 | $(TRUNNER_OUTPUT)/%.te !! 450 $(TRUNNER_EXTRA_HDRS) \ >> 451 $(TRUNNER_BPF_OBJS) \ >> 452 $(TRUNNER_BPF_SKELS) \ >> 453 $(TRUNNER_BPF_LSKELS) \ >> 454 $(TRUNNER_BPF_SKELS_LINKED) \ >> 455 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 663 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY) 456 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) 664 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) !! 457 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) 665 << 666 $(TRUNNER_TEST_OBJS:.o=.d): $(TRUNNER_OUTPUT)/ << 667 $(TRUNNER_TESTS_DI << 668 $(TRUNNER_EXTRA_HD << 669 $(TRUNNER_BPF_SKEL << 670 $(TRUNNER_BPF_LSKE << 671 $(TRUNNER_BPF_SKEL << 672 $$(BPFOBJ) | $(TRU << 673 << 674 ifeq ($(filter clean docs-clean,$(MAKECMDGOALS << 675 include $(wildcard $(TRUNNER_TEST_OBJS:.o=.d)) << 676 endif << 677 << 678 # add per extra obj CFGLAGS definitions << 679 $(foreach N,$(patsubst $(TRUNNER_OUTPUT)/%.o,% << 680 $(eval $(TRUNNER_OUTPUT)/$(N).o: CFLAG << 681 458 682 $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: 459 $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \ 683 %.c 460 %.c \ 684 $(TRUNNER_EXTRA_HDRS) 461 $(TRUNNER_EXTRA_HDRS) \ 685 $(TRUNNER_TESTS_HDR) 462 $(TRUNNER_TESTS_HDR) \ 686 $$(BPFOBJ) | $(TRUNNER_ 463 $$(BPFOBJ) | $(TRUNNER_OUTPUT) 687 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY), 464 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@) 688 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS 465 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@ 689 466 690 # non-flavored in-srctree builds receive speci 467 # non-flavored in-srctree builds receive special treatment, in particular, we 691 # do not need to copy extra resources (see e.g 468 # do not need to copy extra resources (see e.g. test_btf_dump_case()) 692 $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILE 469 $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) 693 ifneq ($2:$(OUTPUT),:$(shell pwd)) 470 ifneq ($2:$(OUTPUT),:$(shell pwd)) 694 $$(call msg,EXT-COPY,$(TRUNNER_BINARY) 471 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES)) 695 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/ 472 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/ 696 endif 473 endif 697 474 698 $(OUTPUT)/$(TRUNNER_BINARY): LDLIBS += $$(LLVM << 699 $(OUTPUT)/$(TRUNNER_BINARY): LDFLAGS += $$(LLV << 700 << 701 # some X.test.o files have runtime dependencie << 702 $(OUTPUT)/$(TRUNNER_BINARY): | $(TRUNNER_BPF_O << 703 << 704 $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OB 475 $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ 705 $(TRUNNER_EXTRA_O 476 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ 706 $(RESOLVE_BTFIDS) 477 $(RESOLVE_BTFIDS) \ 707 $(TRUNNER_BPFTOOL << 708 | $(TRUNNER_BINAR 478 | $(TRUNNER_BINARY)-extras 709 $$(call msg,BINARY,,$$@) 479 $$(call msg,BINARY,,$$@) 710 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %. !! 480 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@ 711 $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_ !! 481 $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.o $$@ 712 $(Q)ln -sf $(if $2,..,.)/tools/build/b !! 482 $(Q)ln -sf $(if $2,..,.)/tools/build/bpftool/bootstrap/bpftool $(if $2,$2/)bpftool 713 $(OUTPUT)/$(if $2,$2/)bpfto << 714 483 715 endef 484 endef 716 485 717 # Define test_progs test runner. 486 # Define test_progs test runner. 718 TRUNNER_TESTS_DIR := prog_tests 487 TRUNNER_TESTS_DIR := prog_tests 719 TRUNNER_BPF_PROGS_DIR := progs 488 TRUNNER_BPF_PROGS_DIR := progs 720 TRUNNER_EXTRA_SOURCES := test_progs.c !! 489 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \ 721 cgroup_helpers.c !! 490 network_helpers.c testing_helpers.c \ 722 trace_helpers.c !! 491 btf_helpers.c flow_dissector_load.h \ 723 network_helpers.c !! 492 cap_helpers.c 724 testing_helpers.c << 725 btf_helpers.c << 726 cap_helpers.c << 727 unpriv_helpers.c << 728 netlink_helpers.c << 729 jit_disasm_helpers.c << 730 test_loader.c << 731 xsk.c << 732 disasm.c << 733 disasm_helpers.c << 734 json_writer.c << 735 flow_dissector_load.h << 736 ip_check_defrag_frags << 737 TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read 493 TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ 738 $(OUTPUT)/bpf_test_no_c !! 494 ima_setup.sh \ 739 $(OUTPUT)/bpf_test_modo !! 495 $(wildcard progs/btf_dump_test_case_*.c) 740 $(OUTPUT)/bpf_test_modo << 741 $(OUTPUT)/liburandom_re << 742 $(OUTPUT)/xdp_synproxy << 743 $(OUTPUT)/sign-file << 744 $(OUTPUT)/uprobe_multi << 745 ima_setup.sh << 746 verify_sig_setup.sh << 747 $(wildcard progs/btf_du << 748 $(wildcard progs/*.bpf. << 749 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE 496 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE 750 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CF 497 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS 751 $(eval $(call DEFINE_TEST_RUNNER,test_progs)) 498 $(eval $(call DEFINE_TEST_RUNNER,test_progs)) 752 499 753 # Define test_progs-no_alu32 test runner. 500 # Define test_progs-no_alu32 test runner. 754 TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BU 501 TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE 755 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CF 502 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) 756 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no 503 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32)) 757 504 758 # Define test_progs-cpuv4 test runner. << 759 ifneq ($(CLANG_CPUV4),) << 760 TRUNNER_BPF_BUILD_RULE := CLANG_CPUV4_BPF_BUIL << 761 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CF << 762 $(eval $(call DEFINE_TEST_RUNNER,test_progs,cp << 763 endif << 764 << 765 # Define test_progs BPF-GCC-flavored test runn 505 # Define test_progs BPF-GCC-flavored test runner. 766 ifneq ($(BPF_GCC),) 506 ifneq ($(BPF_GCC),) 767 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE 507 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE 768 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get !! 508 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc) 769 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bp 509 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc)) 770 endif 510 endif 771 511 772 # Define test_maps test runner. 512 # Define test_maps test runner. 773 TRUNNER_TESTS_DIR := map_tests 513 TRUNNER_TESTS_DIR := map_tests 774 TRUNNER_BPF_PROGS_DIR := progs 514 TRUNNER_BPF_PROGS_DIR := progs 775 TRUNNER_EXTRA_SOURCES := test_maps.c 515 TRUNNER_EXTRA_SOURCES := test_maps.c 776 TRUNNER_EXTRA_FILES := 516 TRUNNER_EXTRA_FILES := 777 TRUNNER_BPF_BUILD_RULE := $$(error no BPF obje 517 TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built) 778 TRUNNER_BPF_CFLAGS := 518 TRUNNER_BPF_CFLAGS := 779 $(eval $(call DEFINE_TEST_RUNNER,test_maps)) 519 $(eval $(call DEFINE_TEST_RUNNER,test_maps)) 780 520 781 # Define test_verifier test runner. 521 # Define test_verifier test runner. 782 # It is much simpler than test_maps/test_progs 522 # It is much simpler than test_maps/test_progs and sufficiently different from 783 # them (e.g., test.h is using completely patte 523 # them (e.g., test.h is using completely pattern), that it's worth just 784 # explicitly defining all the rules explicitly 524 # explicitly defining all the rules explicitly. 785 verifier/tests.h: verifier/*.c 525 verifier/tests.h: verifier/*.c 786 $(shell ( cd verifier/; \ 526 $(shell ( cd verifier/; \ 787 echo '/* Generated header, d 527 echo '/* Generated header, do not edit */'; \ 788 echo '#ifdef FILL_ARRAY'; \ 528 echo '#ifdef FILL_ARRAY'; \ 789 ls *.c 2> /dev/null | sed -e 529 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \ 790 echo '#endif' \ 530 echo '#endif' \ 791 ) > verifier/tests.h) 531 ) > verifier/tests.h) 792 $(OUTPUT)/test_verifier: test_verifier.c verif 532 $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT) 793 $(call msg,BINARY,,$@) 533 $(call msg,BINARY,,$@) 794 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o % 534 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 795 535 796 # Include find_bit.c to compile xskxceiver. << 797 EXTRA_SRC := $(TOOLSDIR)/lib/find_bit.c << 798 $(OUTPUT)/xskxceiver: $(EXTRA_SRC) xskxceiver. << 799 $(call msg,BINARY,,$@) << 800 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o % << 801 << 802 $(OUTPUT)/xdp_hw_metadata: xdp_hw_metadata.c $ << 803 $(call msg,BINARY,,$@) << 804 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o % << 805 << 806 $(OUTPUT)/xdp_features: xdp_features.c $(OUTPU << 807 $(call msg,BINARY,,$@) << 808 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o % << 809 << 810 # Make sure we are able to include and link li 536 # Make sure we are able to include and link libbpf against c++. 811 $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/tes 537 $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ) 812 $(call msg,CXX,,$@) 538 $(call msg,CXX,,$@) 813 $(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(C !! 539 $(Q)$(CXX) $(CFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@ 814 540 815 # Benchmark runner 541 # Benchmark runner 816 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h 542 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h $(BPFOBJ) 817 $(call msg,CC,,$@) 543 $(call msg,CC,,$@) 818 $(Q)$(CC) $(CFLAGS) -O2 -c $(filter %. 544 $(Q)$(CC) $(CFLAGS) -O2 -c $(filter %.c,$^) $(LDLIBS) -o $@ 819 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overh 545 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h 820 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_b 546 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h 821 $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_ 547 $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \ 822 $(OUTPUT)/perfbuf_ 548 $(OUTPUT)/perfbuf_bench.skel.h 823 $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/ 549 $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/bloom_filter_bench.skel.h 824 $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop 550 $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h 825 $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_b 551 $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h 826 $(OUTPUT)/bench_bpf_hashmap_full_update.o: $(O << 827 $(OUTPUT)/bench_local_storage.o: $(OUTPUT)/loc << 828 $(OUTPUT)/bench_local_storage_rcu_tasks_trace. << 829 $(OUTPUT)/bench_local_storage_create.o: $(OUTP << 830 $(OUTPUT)/bench_bpf_hashmap_lookup.o: $(OUTPUT << 831 $(OUTPUT)/bench_htab_mem.o: $(OUTPUT)/htab_mem << 832 $(OUTPUT)/bench_bpf_crypto.o: $(OUTPUT)/crypto << 833 $(OUTPUT)/bench.o: bench.h testing_helpers.h $ 552 $(OUTPUT)/bench.o: bench.h testing_helpers.h $(BPFOBJ) 834 $(OUTPUT)/bench: LDLIBS += -lm 553 $(OUTPUT)/bench: LDLIBS += -lm 835 $(OUTPUT)/bench: $(OUTPUT)/bench.o \ 554 $(OUTPUT)/bench: $(OUTPUT)/bench.o \ 836 $(TESTING_HELPERS) \ 555 $(TESTING_HELPERS) \ 837 $(TRACE_HELPERS) \ 556 $(TRACE_HELPERS) \ 838 $(CGROUP_HELPERS) \ << 839 $(OUTPUT)/bench_count.o \ 557 $(OUTPUT)/bench_count.o \ 840 $(OUTPUT)/bench_rename.o \ 558 $(OUTPUT)/bench_rename.o \ 841 $(OUTPUT)/bench_trigger.o \ 559 $(OUTPUT)/bench_trigger.o \ 842 $(OUTPUT)/bench_ringbufs.o \ 560 $(OUTPUT)/bench_ringbufs.o \ 843 $(OUTPUT)/bench_bloom_filter_ 561 $(OUTPUT)/bench_bloom_filter_map.o \ 844 $(OUTPUT)/bench_bpf_loop.o \ 562 $(OUTPUT)/bench_bpf_loop.o \ 845 $(OUTPUT)/bench_strncmp.o \ !! 563 $(OUTPUT)/bench_strncmp.o 846 $(OUTPUT)/bench_bpf_hashmap_f << 847 $(OUTPUT)/bench_local_storage << 848 $(OUTPUT)/bench_local_storage << 849 $(OUTPUT)/bench_bpf_hashmap_l << 850 $(OUTPUT)/bench_local_storage << 851 $(OUTPUT)/bench_htab_mem.o \ << 852 $(OUTPUT)/bench_bpf_crypto.o << 853 # << 854 $(call msg,BINARY,,$@) 564 $(call msg,BINARY,,$@) 855 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filte 565 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@ 856 566 857 $(OUTPUT)/veristat.o: $(BPFOBJ) !! 567 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ 858 $(OUTPUT)/veristat: $(OUTPUT)/veristat.o << 859 $(call msg,BINARY,,$@) << 860 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filte << 861 << 862 # Linking uprobe_multi can fail due to relocat << 863 $(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filte << 864 $(OUTPUT)/uprobe_multi: uprobe_multi.c uprobe_ << 865 $(call msg,BINARY,,$@) << 866 $(Q)$(CC) $(CFLAGS) -Wl,-T,uprobe_mult << 867 $(filter-out %.ld,$^) $(LDLIBS << 868 << 869 EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_D << 870 prog_tests/tests.h map_tests/tests.h v 568 prog_tests/tests.h map_tests/tests.h verifier/tests.h \ 871 feature bpftool !! 569 feature bpftool \ 872 $(addprefix $(OUTPUT)/,*.o *.d *.skel. !! 570 $(addprefix $(OUTPUT)/,*.o *.skel.h *.lskel.h *.subskel.h no_alu32 bpf_gcc bpf_testmod.ko) 873 no_alu32 cpuv4 << 874 bpf_test_no_cfi << 875 bpf_test_modord << 876 bpf_test_modord << 877 liburandom_read << 878 $(OUTPUT)/FEATURE-DUMP.selftests << 879 571 880 .PHONY: docs docs-clean 572 .PHONY: docs docs-clean 881 << 882 # Delete partially updated (corrupted) files o << 883 .DELETE_ON_ERROR: << 884 << 885 DEFAULT_INSTALL_RULE := $(INSTALL_RULE) << 886 override define INSTALL_RULE << 887 $(DEFAULT_INSTALL_RULE) << 888 @for DIR in $(TEST_INST_SUBDIRS); do << 889 mkdir -p $(INSTALL_PATH)/$$DIR << 890 rsync -a $(OUTPUT)/$$DIR/*.bpf << 891 done << 892 endef <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.