1 # SPDX-License-Identifier: GPL-2.0 1 # SPDX-License-Identifier: GPL-2.0 2 include ../../../build/Build.include !! 2 include ../../../../scripts/Kbuild.include 3 include ../../../scripts/Makefile.arch !! 3 4 include ../../../scripts/Makefile.include !! 4 LIBDIR := ../../../lib 5 << 6 CXX ?= $(CROSS_COMPILE)g++ << 7 << 8 CURDIR := $(abspath .) << 9 TOOLSDIR := $(abspath ../../..) << 10 LIBDIR := $(TOOLSDIR)/lib << 11 BPFDIR := $(LIBDIR)/bpf 5 BPFDIR := $(LIBDIR)/bpf 12 TOOLSINCDIR := $(TOOLSDIR)/include !! 6 APIDIR := ../../../include/uapi 13 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool !! 7 GENDIR := ../../../../include/generated 14 APIDIR := $(TOOLSINCDIR)/uapi << 15 ifneq ($(O),) << 16 GENDIR := $(O)/include/generated << 17 else << 18 GENDIR := $(abspath ../../../../include/genera << 19 endif << 20 GENHDR := $(GENDIR)/autoconf.h 8 GENHDR := $(GENDIR)/autoconf.h 21 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config << 22 9 23 ifneq ($(wildcard $(GENHDR)),) 10 ifneq ($(wildcard $(GENHDR)),) 24 GENFLAGS := -DHAVE_GENHDR 11 GENFLAGS := -DHAVE_GENHDR 25 endif 12 endif 26 13 27 BPF_GCC ?= $(shell command -v bpf-gcc; !! 14 CLANG ?= clang 28 SAN_CFLAGS ?= !! 15 LLC ?= llc 29 SAN_LDFLAGS ?= $(SAN_CFLAGS) !! 16 LLVM_OBJCOPY ?= llvm-objcopy 30 RELEASE ?= !! 17 LLVM_READELF ?= llvm-readelf 31 OPT_FLAGS ?= $(if $(RELEASE),-O2,-O0) !! 18 BTF_PAHOLE ?= pahole 32 !! 19 CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include 33 LIBELF_CFLAGS := $(shell $(PKG_CONFIG) libel !! 20 LDLIBS += -lcap -lelf -lrt -lpthread 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 << 47 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUT << 48 LDFLAGS += $(SAN_LDFLAGS) << 49 LDLIBS += $(LIBELF_LIBS) -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 << 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 << 76 CFLAGS += -Wno-unused-command-line-argument << 77 endif << 78 << 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 21 84 # Order correspond to 'make run_tests' order 22 # Order correspond to 'make run_tests' order 85 TEST_GEN_PROGS = test_verifier test_tag test_m 23 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 86 test_sock test_sockmap \ !! 24 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ 87 test_tcpnotify_user test_sysctl \ !! 25 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \ 88 test_progs-no_alu32 !! 26 test_cgroup_storage test_select_reuseport test_section_names \ 89 TEST_INST_SUBDIRS := no_alu32 !! 27 test_netcnt test_tcpnotify_user test_sock_fields test_sysctl 90 !! 28 91 # Also test bpf-gcc, if present !! 29 BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) 92 ifneq ($(BPF_GCC),) !! 30 TEST_GEN_FILES = $(BPF_OBJ_FILES) 93 TEST_GEN_PROGS += test_progs-bpf_gcc !! 31 94 TEST_INST_SUBDIRS += bpf_gcc !! 32 # Also test sub-register code-gen if LLVM has eBPF v3 processor support which 95 !! 33 # contains both ALU32 and JMP32 instructions. 96 # The following tests contain C code that, alt !! 34 SUBREG_CODEGEN := $(shell echo "int cal(int a) { return a > 0; }" | \ 97 # triggers GCC warnings that cannot be disable !! 35 $(CLANG) -target bpf -O2 -emit-llvm -S -x c - -o - | \ 98 # anonymous struct types in function parameter !! 36 $(LLC) -mattr=+alu32 -mcpu=v3 2>&1 | \ 99 progs/btf_dump_test_case_bitfields.c-bpf_gcc-C !! 37 grep 'if w') 100 progs/btf_dump_test_case_namespacing.c-bpf_gcc !! 38 ifneq ($(SUBREG_CODEGEN),) 101 progs/btf_dump_test_case_packing.c-bpf_gcc-CFL !! 39 TEST_GEN_FILES += $(patsubst %.o,alu32/%.o, $(BPF_OBJ_FILES)) 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 40 endif 123 41 124 TEST_GEN_FILES = test_lwt_ip_encap.bpf.o test_ << 125 TEST_FILES = xsk_prereqs.sh $(wildcard progs/b << 126 << 127 # Order correspond to 'make run_tests' order 42 # Order correspond to 'make run_tests' order 128 TEST_PROGS := test_kmod.sh \ 43 TEST_PROGS := test_kmod.sh \ >> 44 test_libbpf.sh \ 129 test_xdp_redirect.sh \ 45 test_xdp_redirect.sh \ 130 test_xdp_redirect_multi.sh \ << 131 test_xdp_meta.sh \ 46 test_xdp_meta.sh \ >> 47 test_offload.py \ >> 48 test_sock_addr.sh \ 132 test_tunnel.sh \ 49 test_tunnel.sh \ 133 test_lwt_seg6local.sh \ 50 test_lwt_seg6local.sh \ 134 test_lirc_mode2.sh \ 51 test_lirc_mode2.sh \ 135 test_skb_cgroup_id.sh \ 52 test_skb_cgroup_id.sh \ 136 test_flow_dissector.sh \ 53 test_flow_dissector.sh \ 137 test_xdp_vlan_mode_generic.sh \ 54 test_xdp_vlan_mode_generic.sh \ 138 test_xdp_vlan_mode_native.sh \ 55 test_xdp_vlan_mode_native.sh \ 139 test_lwt_ip_encap.sh \ 56 test_lwt_ip_encap.sh \ 140 test_tcp_check_syncookie.sh \ 57 test_tcp_check_syncookie.sh \ 141 test_tc_tunnel.sh \ 58 test_tc_tunnel.sh \ 142 test_tc_edt.sh \ !! 59 test_tc_edt.sh 143 test_xdping.sh \ << 144 test_bpftool_build.sh \ << 145 test_bpftool.sh \ << 146 test_bpftool_metadata.sh \ << 147 test_doc_build.sh \ << 148 test_xsk.sh \ << 149 test_xdp_features.sh << 150 60 151 TEST_PROGS_EXTENDED := with_addr.sh \ 61 TEST_PROGS_EXTENDED := with_addr.sh \ 152 with_tunnels.sh ima_setup.sh verify_si !! 62 with_tunnels.sh \ 153 test_xdp_vlan.sh test_bpftool.py !! 63 tcp_client.py \ >> 64 tcp_server.py \ >> 65 test_xdp_vlan.sh 154 66 155 # Compile but not part of 'make run_tests' 67 # Compile but not part of 'make run_tests' 156 TEST_GEN_PROGS_EXTENDED = \ !! 68 TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr test_skb_cgroup_id_user \ 157 flow_dissector_load test_flow_dissecto 69 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ 158 test_lirc_mode2_user xdping test_cpp r !! 70 test_lirc_mode2_user 159 xskxceiver xdp_redirect_multi xdp_synp << 160 xdp_features bpf_test_no_cfi.ko bpf_te << 161 bpf_test_modorder_y.ko << 162 << 163 TEST_GEN_FILES += liburandom_read.so urandom_r << 164 << 165 ifneq ($(V),1) << 166 submake_extras := feature_display=0 << 167 endif << 168 << 169 # override lib.mk's default rules << 170 OVERRIDE_TARGETS := 1 << 171 override define CLEAN << 172 $(call msg,CLEAN) << 173 $(Q)$(RM) -r $(TEST_GEN_PROGS) << 174 $(Q)$(RM) -r $(TEST_GEN_PROGS_EXTENDED << 175 $(Q)$(RM) -r $(TEST_GEN_FILES) << 176 $(Q)$(RM) -r $(EXTRA_CLEAN) << 177 $(Q)$(MAKE) -C bpf_testmod clean << 178 $(Q)$(MAKE) docs-clean << 179 endef << 180 71 181 include ../lib.mk 72 include ../lib.mk 182 73 183 NON_CHECK_FEAT_TARGETS := clean docs-clean !! 74 # NOTE: $(OUTPUT) won't get default value if used before lib.mk 184 CHECK_FEAT := $(filter-out $(NON_CHECK_FEAT_TA !! 75 TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read 185 ifneq ($(CHECK_FEAT),) !! 76 all: $(TEST_CUSTOM_PROGS) 186 FEATURE_USER := .selftests !! 77 187 FEATURE_TESTS := llvm !! 78 $(OUTPUT)/urandom_read: $(OUTPUT)/%: %.c 188 FEATURE_DISPLAY := $(FEATURE_TESTS) !! 79 $(CC) -o $@ $< -Wl,--build-id 189 !! 80 190 # Makefile.feature expects OUTPUT to end with !! 81 $(OUTPUT)/test_maps: map_tests/*.c 191 ifeq ($(shell expr $(MAKE_VERSION) \>= 4.4), 1 !! 82 192 $(let OUTPUT,$(OUTPUT)/,\ !! 83 BPFOBJ := $(OUTPUT)/libbpf.a 193 $(eval include ../../../build/Makefile !! 84 >> 85 $(TEST_GEN_PROGS): $(BPFOBJ) >> 86 >> 87 $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a >> 88 >> 89 $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c >> 90 $(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c >> 91 $(OUTPUT)/test_sock: cgroup_helpers.c >> 92 $(OUTPUT)/test_sock_addr: cgroup_helpers.c >> 93 $(OUTPUT)/test_socket_cookie: cgroup_helpers.c >> 94 $(OUTPUT)/test_sockmap: cgroup_helpers.c >> 95 $(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c >> 96 $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c >> 97 $(OUTPUT)/test_progs: trace_helpers.c >> 98 $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c >> 99 $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c >> 100 $(OUTPUT)/test_netcnt: cgroup_helpers.c >> 101 $(OUTPUT)/test_sock_fields: cgroup_helpers.c >> 102 $(OUTPUT)/test_sysctl: cgroup_helpers.c >> 103 >> 104 .PHONY: force >> 105 >> 106 # force a rebuild of BPFOBJ when its dependencies are updated >> 107 force: >> 108 >> 109 $(BPFOBJ): force >> 110 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ >> 111 >> 112 PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) >> 113 >> 114 # Let newer LLVM versions transparently probe the kernel for availability >> 115 # of full BPF instruction set. >> 116 ifeq ($(PROBE),) >> 117 CPU ?= probe 194 else 118 else 195 OUTPUT := $(OUTPUT)/ !! 119 CPU ?= generic 196 $(eval include ../../../build/Makefile.feature << 197 OUTPUT := $(patsubst %/,%,$(OUTPUT)) << 198 endif << 199 endif 120 endif 200 121 201 ifeq ($(feature-llvm),1) !! 122 # Get Clang's default includes on this system, as opposed to those seen by 202 LLVM_CFLAGS += -DHAVE_LLVM_SUPPORT !! 123 # '-target bpf'. This fixes "missing" files on some architectures/distros, 203 LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler !! 124 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 204 # both llvm-config and lib.mk add -D_GNU_SOU !! 125 # 205 LLVM_CFLAGS += $(filter-out -D_GNU_SOURCE,$ !! 126 # Use '-idirafter': Don't interfere with include mechanics except where the 206 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --lin !! 127 # build would have failed anyways. 207 LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --lin !! 128 CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \ 208 LLVM_LDLIBS += -lstdc++ !! 129 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') 209 LLVM_LDFLAGS += $(shell $(LLVM_CONFIG) --ldf !! 130 210 endif !! 131 CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \ 211 !! 132 $(CLANG_SYS_INCLUDES) \ 212 SCRATCH_DIR := $(OUTPUT)/tools !! 133 -Wno-compare-distinct-pointer-types 213 BUILD_DIR := $(SCRATCH_DIR)/build !! 134 214 INCLUDE_DIR := $(SCRATCH_DIR)/include !! 135 $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline 215 BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a !! 136 $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline 216 ifneq ($(CROSS_COMPILE),) !! 137 217 HOST_BUILD_DIR := $(BUILD_DIR)/host !! 138 $(OUTPUT)/test_queue_map.o: test_queue_stack_map.h 218 HOST_SCRATCH_DIR := $(OUTPUT)/host-tool !! 139 $(OUTPUT)/test_stack_map.o: test_queue_stack_map.h 219 HOST_INCLUDE_DIR := $(HOST_SCRATCH_DIR) !! 140 220 else !! 141 $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h 221 HOST_BUILD_DIR := $(BUILD_DIR) !! 142 $(OUTPUT)/test_progs.o: flow_dissector_load.h 222 HOST_SCRATCH_DIR := $(SCRATCH_DIR) !! 143 223 HOST_INCLUDE_DIR := $(INCLUDE_DIR) !! 144 BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) 224 endif !! 145 BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) 225 HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf !! 146 BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') 226 RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_bt !! 147 BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \ 227 RUNQSLOWER_OUTPUT := $(BUILD_DIR)/runqslower/ !! 148 $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \ 228 !! 149 $(LLVM_READELF) -S ./llvm_btf_verify.o | grep BTF; \ 229 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) !! 150 /bin/rm -f ./llvm_btf_verify.o) 230 $(if $(KBUILD_OUTPUT),$(K !! 151 231 ../../../../vmlinux !! 152 ifneq ($(BTF_LLVM_PROBE),) 232 /sys/kernel/btf/vmlinux !! 153 CLANG_FLAGS += -g 233 /boot/vmlinux-$(shell una << 234 VMLINUX_BTF ?= $(abspath $(firstword $(wildcar << 235 ifeq ($(VMLINUX_BTF),) << 236 $(error Cannot find a vmlinux for VMLINUX_BTF << 237 endif << 238 << 239 # Define simple and short `make test_progs`, ` << 240 # to build individual tests. << 241 # NOTE: Semicolon at the end is critical to ov << 242 # rule for binaries. << 243 $(notdir $(TEST_GEN_PROGS) << 244 $(TEST_GEN_PROGS_EXTENDED)): %: $(OUT << 245 << 246 # sort removes libbpf duplicates when not cros << 247 MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST << 248 $(BUILD_DIR)/bpftool $(HOST_BUI << 249 $(HOST_BUILD_DIR)/resolve_btfid << 250 $(RUNQSLOWER_OUTPUT) $(INCLUDE_ << 251 $(MAKE_DIRS): << 252 $(call msg,MKDIR,,$@) << 253 $(Q)mkdir -p $@ << 254 << 255 $(OUTPUT)/%.o: %.c << 256 $(call msg,CC,,$@) << 257 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^ << 258 << 259 $(OUTPUT)/%:%.c << 260 $(call msg,BINARY,,$@) << 261 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ << 262 << 263 # LLVM's ld.lld doesn't support all the archit << 264 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv << 265 LLD := lld << 266 else 154 else 267 LLD := $(shell command -v $(LD)) !! 155 ifneq ($(BTF_LLC_PROBE),) >> 156 ifneq ($(BTF_PAHOLE_PROBE),) >> 157 ifneq ($(BTF_OBJCOPY_PROBE),) >> 158 CLANG_FLAGS += -g >> 159 LLC_FLAGS += -mattr=dwarfris >> 160 DWARF2BTF = y >> 161 endif >> 162 endif >> 163 endif 268 endif 164 endif 269 165 270 # Filter out -static for liburandom_read.so an !! 166 TEST_PROGS_CFLAGS := -I. -I$(OUTPUT) 271 # do not fail. Static builds leave urandom_rea !! 167 TEST_VERIFIER_CFLAGS := -I. -I$(OUTPUT) -Iverifier 272 $(OUTPUT)/liburandom_read.so: urandom_read_lib !! 168 273 $(call msg,LIB,,$@) !! 169 ifneq ($(SUBREG_CODEGEN),) 274 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ !! 170 ALU32_BUILD_DIR = $(OUTPUT)/alu32 275 $(filter-out -static,$(CF !! 171 TEST_CUSTOM_PROGS += $(ALU32_BUILD_DIR)/test_progs_32 276 $(filter %.c,$^) $(filter !! 172 $(ALU32_BUILD_DIR): 277 -fuse-ld=$(LLD) -Wl,-znos !! 173 mkdir -p $@ 278 -Wl,--version-script=libu !! 174 279 -fPIC -shared -o $@ !! 175 $(ALU32_BUILD_DIR)/urandom_read: $(OUTPUT)/urandom_read 280 !! 176 cp $< $@ 281 $(OUTPUT)/urandom_read: urandom_read.c urandom !! 177 282 $(call msg,BINARY,,$@) !! 178 $(ALU32_BUILD_DIR)/test_progs_32: test_progs.c $(OUTPUT)/libbpf.a\ 283 $(Q)$(CLANG) $(CLANG_TARGET_ARCH) \ !! 179 $(ALU32_BUILD_DIR) \ 284 $(filter-out -static,$(CF !! 180 $(ALU32_BUILD_DIR)/urandom_read 285 -lurandom_read $(filter-o !! 181 $(CC) $(TEST_PROGS_CFLAGS) $(CFLAGS) \ 286 -fuse-ld=$(LLD) -Wl,-znos !! 182 -o $(ALU32_BUILD_DIR)/test_progs_32 \ 287 -Wl,-rpath=. -o $@ !! 183 test_progs.c trace_helpers.c prog_tests/*.c \ 288 !! 184 $(OUTPUT)/libbpf.a $(LDLIBS) 289 $(OUTPUT)/sign-file: ../../../../scripts/sign- !! 185 290 $(call msg,SIGN-FILE,,$@) !! 186 $(ALU32_BUILD_DIR)/test_progs_32: $(PROG_TESTS_H) 291 $(Q)$(CC) $(shell $(PKG_CONFIG) --cfla !! 187 $(ALU32_BUILD_DIR)/test_progs_32: prog_tests/*.c 292 $< -o $@ \ !! 188 293 $(shell $(PKG_CONFIG) --libs !! 189 $(ALU32_BUILD_DIR)/%.o: progs/%.c $(ALU32_BUILD_DIR) \ 294 !! 190 $(ALU32_BUILD_DIR)/test_progs_32 295 $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(RES !! 191 ($(CLANG) $(CLANG_FLAGS) -O2 -target bpf -emit-llvm -c $< -o - || \ 296 $(call msg,MOD,,$@) !! 192 echo "clang failed") | \ 297 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # !! 193 $(LLC) -march=bpf -mattr=+alu32 -mcpu=$(CPU) $(LLC_FLAGS) \ 298 $(Q)$(MAKE) $(submake_extras) RESOLVE_ !! 194 -filetype=obj -o $@ 299 $(Q)cp bpf_testmod/bpf_testmod.ko $@ !! 195 ifeq ($(DWARF2BTF),y) 300 !! 196 $(BTF_PAHOLE) -J $@ 301 $(OUTPUT)/bpf_test_no_cfi.ko: $(VMLINUX_BTF) $ !! 197 endif 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 << 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 198 endif 329 199 330 $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BP !! 200 # Have one program compiled without "-target bpf" to test whether libbpf loads 331 $(Q)$(MAKE) $(submake_extras) -C $(TOO !! 201 # it successfully 332 OUTPUT=$(RUNQSLOWER_OUTPUT !! 202 $(OUTPUT)/test_xdp.o: progs/test_xdp.c 333 BPFTOOL_OUTPUT=$(HOST_BUIL !! 203 ($(CLANG) $(CLANG_FLAGS) -O2 -emit-llvm -c $< -o - || \ 334 BPFOBJ_OUTPUT=$(BUILD_DIR) !! 204 echo "clang failed") | \ 335 BPFOBJ=$(BPFOBJ) BPF_INCLU !! 205 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ 336 EXTRA_CFLAGS='-g $(OPT_FLA !! 206 ifeq ($(DWARF2BTF),y) 337 EXTRA_LDFLAGS='$(SAN_LDFLA !! 207 $(BTF_PAHOLE) -J $@ 338 cp $(RUNQSLOWER_OUTPUT)run << 339 << 340 TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL) << 341 << 342 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): << 343 << 344 TESTING_HELPERS := $(OUTPUT)/testing_helpers.o << 345 CGROUP_HELPERS := $(OUTPUT)/cgroup_helpers.o << 346 UNPRIV_HELPERS := $(OUTPUT)/unpriv_helpers.o << 347 TRACE_HELPERS := $(OUTPUT)/trace_helpers.o << 348 JSON_WRITER := $(OUTPUT)/json_writ << 349 CAP_HELPERS := $(OUTPUT)/cap_helpers.o << 350 NETWORK_HELPERS := $(OUTPUT)/network_helpers.o << 351 << 352 $(OUTPUT)/test_sock: $(CGROUP_HELPERS) $(TESTI << 353 $(OUTPUT)/test_sockmap: $(CGROUP_HELPERS) $(TE << 354 $(OUTPUT)/test_tcpnotify_user: $(CGROUP_HELPER << 355 $(OUTPUT)/test_sock_fields: $(CGROUP_HELPERS) << 356 $(OUTPUT)/test_sysctl: $(CGROUP_HELPERS) $(TES << 357 $(OUTPUT)/test_tag: $(TESTING_HELPERS) << 358 $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELP << 359 $(OUTPUT)/xdping: $(TESTING_HELPERS) << 360 $(OUTPUT)/flow_dissector_load: $(TESTING_HELPE << 361 $(OUTPUT)/test_maps: $(TESTING_HELPERS) << 362 $(OUTPUT)/test_verifier: $(TESTING_HELPERS) $( << 363 $(OUTPUT)/xsk.o: $(BPFOBJ) << 364 $(OUTPUT)/test_tcp_check_syncookie_user: $(NET << 365 << 366 BPFTOOL ?= $(DEFAULT_BPFTOOL) << 367 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/* << 368 $(HOST_BPFOBJ) | $(HOST_BU << 369 $(Q)$(MAKE) $(submake_extras) -C $(BP << 370 ARCH= CROSS_COMPILE= CC="$ << 371 EXTRA_CFLAGS='-g $(OPT_FLA << 372 OUTPUT=$(HOST_BUILD_DIR)/b << 373 LIBBPF_OUTPUT=$(HOST_BUILD << 374 LIBBPF_DESTDIR=$(HOST_SCRA << 375 prefix= DESTDIR=$(HOST_SCR << 376 << 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 << 390 << 391 docs: << 392 $(Q)RST2MAN_OPTS="--exit-status=1" $(M << 393 -f Makefile.docs << 394 prefix= OUTPUT=$(OUTPUT)/ << 395 << 396 docs-clean: << 397 $(Q)$(MAKE) $(submake_extras) << 398 -f Makefile.docs << 399 prefix= OUTPUT=$(OUTPUT)/ << 400 << 401 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDI << 402 $(APIDIR)/linux/bpf.h << 403 | $(BUILD_DIR)/libbpf << 404 $(Q)$(MAKE) $(submake_extras) -C $(BPF << 405 EXTRA_CFLAGS='-g $(OPT_FLA << 406 EXTRA_LDFLAGS='$(SAN_LDFLA << 407 DESTDIR=$(SCRATCH_DIR) pre << 408 << 409 ifneq ($(BPFOBJ),$(HOST_BPFOBJ)) << 410 $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $( << 411 $(APIDIR)/linux/bpf.h << 412 | $(HOST_BUILD_DIR)/libbpf << 413 $(Q)$(MAKE) $(submake_extras) -C $(BPF << 414 EXTRA_CFLAGS='-g $(OPT_FLA << 415 OUTPUT=$(HOST_BUILD_DIR)/l << 416 CC="$(HOSTCC)" LD="$(HOSTL << 417 DESTDIR=$(HOST_SCRATCH_DIR << 418 endif << 419 << 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 << 424 ifeq ($(VMLINUX_H),) << 425 $(call msg,GEN,,$@) << 426 $(Q)$(BPFTOOL) btf dump file $(VMLINUX << 427 $(Q)cmp -s $(INCLUDE_DIR)/.vmlinux.h.t << 428 else << 429 $(call msg,CP,,$@) << 430 $(Q)cp "$(VMLINUX_H)" $@ << 431 endif 208 endif 432 209 433 $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUI !! 210 $(OUTPUT)/%.o: progs/%.c 434 $(TOOLSDIR)/bpf/resolve !! 211 ($(CLANG) $(CLANG_FLAGS) -O2 -target bpf -emit-llvm -c $< -o - || \ 435 $(TOOLSDIR)/lib/rbtree. !! 212 echo "clang failed") | \ 436 $(TOOLSDIR)/lib/zalloc. !! 213 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ 437 $(TOOLSDIR)/lib/string. !! 214 ifeq ($(DWARF2BTF),y) 438 $(TOOLSDIR)/lib/ctype.c !! 215 $(BTF_PAHOLE) -J $@ 439 $(TOOLSDIR)/lib/str_err !! 216 endif 440 $(Q)$(MAKE) $(submake_extras) -C $(TOO << 441 CC="$(HOSTCC)" LD="$(HOSTLD)" << 442 LIBBPF_INCLUDE=$(HOST_INCLUDE_ << 443 OUTPUT=$(HOST_BUILD_DIR)/resol << 444 217 445 # Get Clang's default includes on this system, !! 218 PROG_TESTS_H := $(OUTPUT)/prog_tests/tests.h 446 # '--target=bpf'. This fixes "missing" files o !! 219 test_progs.c: $(PROG_TESTS_H) 447 # such as asm/byteorder.h, asm/socket.h, asm/s !! 220 $(OUTPUT)/test_progs: CFLAGS += $(TEST_PROGS_CFLAGS) 448 # !! 221 $(OUTPUT)/test_progs: prog_tests/*.c 449 # Use '-idirafter': Don't interfere with inclu << 450 # build would have failed anyways. << 451 define get_sys_includes << 452 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \ << 453 | sed -n '/<...> search starts here:/, << 454 $(shell $(1) $(2) -dM -E - </dev/null | grep ' << 455 $(shell $(1) $(2) -dM -E - </dev/null | grep ' << 456 $(shell $(1) $(2) -dM -E - </dev/null | grep - << 457 endef << 458 << 459 # Determine target endianness. << 460 IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </de << 461 grep 'define __BYTE_OR << 462 MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endi << 463 << 464 ifneq ($(CROSS_COMPILE),) << 465 CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_ << 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$( << 471 -I$(abspath $(OUTPUT)/../usr/incl << 472 -Wno-compare-distinct-pointer-typ << 473 # TODO: enable me -Wsign-compare << 474 222 475 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) !! 223 PROG_TESTS_DIR = $(OUTPUT)/prog_tests >> 224 $(PROG_TESTS_DIR): >> 225 mkdir -p $@ >> 226 >> 227 PROG_TESTS_FILES := $(wildcard prog_tests/*.c) >> 228 $(PROG_TESTS_H): $(PROG_TESTS_DIR) $(PROG_TESTS_FILES) >> 229 $(shell ( cd prog_tests/; \ >> 230 echo '/* Generated header, do not edit */'; \ >> 231 echo '#ifdef DECLARE'; \ >> 232 ls *.c 2> /dev/null | \ >> 233 sed -e 's@\([^\.]*\)\.c@extern void test_\1(void);@'; \ >> 234 echo '#endif'; \ >> 235 echo '#ifdef CALL'; \ >> 236 ls *.c 2> /dev/null | \ >> 237 sed -e 's@\([^\.]*\)\.c@test_\1();@'; \ >> 238 echo '#endif' \ >> 239 ) > $(PROG_TESTS_H)) 476 240 477 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += !! 241 TEST_MAPS_CFLAGS := -I. -I$(OUTPUT) 478 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += - !! 242 MAP_TESTS_DIR = $(OUTPUT)/map_tests >> 243 $(MAP_TESTS_DIR): >> 244 mkdir -p $@ >> 245 MAP_TESTS_H := $(MAP_TESTS_DIR)/tests.h >> 246 test_maps.c: $(MAP_TESTS_H) >> 247 $(OUTPUT)/test_maps: CFLAGS += $(TEST_MAPS_CFLAGS) >> 248 MAP_TESTS_FILES := $(wildcard map_tests/*.c) >> 249 $(MAP_TESTS_H): $(MAP_TESTS_DIR) $(MAP_TESTS_FILES) >> 250 $(shell ( cd map_tests/; \ >> 251 echo '/* Generated header, do not edit */'; \ >> 252 echo '#ifdef DECLARE'; \ >> 253 ls *.c 2> /dev/null | \ >> 254 sed -e 's@\([^\.]*\)\.c@extern void test_\1(void);@'; \ >> 255 echo '#endif'; \ >> 256 echo '#ifdef CALL'; \ >> 257 ls *.c 2> /dev/null | \ >> 258 sed -e 's@\([^\.]*\)\.c@test_\1();@'; \ >> 259 echo '#endif' \ >> 260 ) > $(MAP_TESTS_H)) 479 261 480 $(OUTPUT)/flow_dissector_load.o: flow_dissecto !! 262 VERIFIER_TESTS_H := $(OUTPUT)/verifier/tests.h 481 $(OUTPUT)/cgroup_getset_retval_hooks.o: cgroup !! 263 test_verifier.c: $(VERIFIER_TESTS_H) >> 264 $(OUTPUT)/test_verifier: CFLAGS += $(TEST_VERIFIER_CFLAGS) >> 265 >> 266 VERIFIER_TESTS_DIR = $(OUTPUT)/verifier >> 267 $(VERIFIER_TESTS_DIR): >> 268 mkdir -p $@ 482 269 483 # Build BPF object using Clang !! 270 VERIFIER_TEST_FILES := $(wildcard verifier/*.c) 484 # $1 - input .c file !! 271 $(OUTPUT)/verifier/tests.h: $(VERIFIER_TESTS_DIR) $(VERIFIER_TEST_FILES) 485 # $2 - output .o file << 486 # $3 - CFLAGS << 487 # $4 - binary name << 488 define CLANG_BPF_BUILD_RULE << 489 $(call msg,CLNG-BPF,$4,$2) << 490 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 << 491 endef << 492 # Similar to CLANG_BPF_BUILD_RULE, but with di << 493 define CLANG_NOALU32_BPF_BUILD_RULE << 494 $(call msg,CLNG-BPF,$4,$2) << 495 $(Q)$(CLANG) $3 -O2 --target=bpf -c $1 << 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 << 502 # Build BPF object using GCC << 503 define GCC_BPF_BUILD_RULE << 504 $(call msg,GCC-BPF,$4,$2) << 505 $(Q)$(BPF_GCC) $3 -DBPF_NO_PRESERVE_AC << 506 endef << 507 << 508 SKEL_BLACKLIST := btf__% test_pinning_invalid. << 509 << 510 LINKED_SKELS := test_static_linked.skel.h link << 511 linked_vars.skel.h linked_maps << 512 test_subskeleton.skel.h test_s << 513 test_usdt.skel.h << 514 << 515 LSKELS := fentry_test.c fexit_test.c fexit_sle << 516 trace_printk.c trace_vprintk.c map_ptr << 517 core_kern.c core_kern_overflow.c test_ << 518 test_ringbuf_n.c test_ringbuf_map_key. << 519 << 520 # Generate both light skeleton and libbpf skel << 521 LSKELS_EXTRA := test_ksyms_module.c test_ksyms << 522 kfunc_call_test_subprog.c << 523 SKEL_BLACKLIST += $$(LSKELS) << 524 << 525 test_static_linked.skel.h-deps := test_static_ << 526 linked_funcs.skel.h-deps := linked_funcs1.bpf. << 527 linked_vars.skel.h-deps := linked_vars1.bpf.o << 528 linked_maps.skel.h-deps := linked_maps1.bpf.o << 529 # In the subskeleton case, we want the test_su << 530 # but that's created as a side-effect of the s << 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 << 547 # Set up extra TRUNNER_XXX "temporary" variabl << 548 # $eval()) and pass control to DEFINE_TEST_RUN << 549 # Parameters: << 550 # $1 - test runner base binary name (e.g., tes << 551 # $2 - test runner extra "flavor" (e.g., no_al << 552 define DEFINE_TEST_RUNNER << 553 << 554 TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 << 555 TRUNNER_BINARY := $1$(if $2,-)$2 << 556 TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNE << 557 $$(notdir $$( << 558 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNN << 559 $$(filter %.c << 560 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_ << 561 TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/test << 562 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TR << 563 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER << 564 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNE << 565 $$(filter-out << 566 << 567 TRUNNER_BPF_LSKELS := $$(patsubst %.c,$$(TRUNN << 568 TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TR << 569 TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS) << 570 << 571 # Evaluate rules now with extra TRUNNER_XXX va << 572 $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2 << 573 << 574 endef << 575 << 576 # Using TRUNNER_XXX variables, provided by cal << 577 # set up by DEFINE_TEST_RUNNER itself, create << 578 # $1 - test runner base binary name (e.g., tes << 579 # $2 - test runner extra "flavor" (e.g., no_al << 580 define DEFINE_TEST_RUNNER_RULES << 581 << 582 ifeq ($($(TRUNNER_OUTPUT)-dir),) << 583 $(TRUNNER_OUTPUT)-dir := y << 584 $(TRUNNER_OUTPUT): << 585 $$(call msg,MKDIR,,$$@) << 586 $(Q)mkdir -p $$@ << 587 endif << 588 << 589 # ensure we set up BPF objects generation rule << 590 # input/output directory combination << 591 ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-b << 592 $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs : << 593 $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.bpf.o << 594 $(TRUNNER_BPF_PROGS_DIR)/ << 595 $(TRUNNER_BPF_PROGS_DIR)/ << 596 $$(INCLUDE_DIR)/vmlinux.h << 597 $(HEADERS_FOR_BPF_OBJS) << 598 | $(TRUNNER_OUTPUT) $$(BP << 599 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<, << 600 $(TR << 601 $$($ << 602 $$($ << 603 << 604 $(TRUNNER_BPF_SKELS): %.skel.h: %.bpf.o $(BPFT << 605 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) << 606 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li << 607 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li << 608 $(Q)$$(BPFTOOL) gen object $$(<:.o=.li << 609 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=. << 610 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=. << 611 $(Q)$$(BPFTOOL) gen subskeleton $$(<:. << 612 $(Q)rm -f $$(<:.o=.linked1.o) $$(<:.o= << 613 << 614 $(TRUNNER_BPF_LSKELS): %.lskel.h: %.bpf.o $(BP << 615 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) << 616 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll << 617 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll << 618 $(Q)$$(BPFTOOL) gen object $$(<:.o=.ll << 619 $(Q)diff $$(<:.o=.llinked2.o) $$(<:.o= << 620 $(Q)$$(BPFTOOL) gen skeleton -L $$(<:. << 621 $(Q)rm -f $$(<:.o=.llinked1.o) $$(<:.o << 622 << 623 $(LINKED_BPF_OBJS): %: $(TRUNNER_OUTPUT)/% << 624 << 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. << 630 $(Q)$$(BPFTOOL) gen object $$(@:.skel. << 631 $(Q)$$(BPFTOOL) gen object $$(@:.skel. << 632 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@ << 633 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY) << 634 $(Q)$$(BPFTOOL) gen skeleton $$(@:.ske << 635 $(Q)$$(BPFTOOL) gen subskeleton $$(@:. << 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 << 646 << 647 # ensure we set up tests.h header generation r << 648 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) << 649 $(TRUNNER_TESTS_DIR)-tests-hdr := y << 650 $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c << 651 $$(call msg,TEST-HDR,$(TRUNNER_BINARY) << 652 $$(shell (echo '/* Generated header, d << 653 sed -n -E 's/^void (serial_) << 654 $(TRUNNER_TESTS_DIR)/* << 655 ) > $$@) << 656 endif << 657 << 658 # compile individual test files << 659 # Note: we cd into output directory to ensure << 660 $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test << 661 $(TRUNNER_TESTS_DIR)/%.c << 662 | $(TRUNNER_OUTPUT)/%.te << 663 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY) << 664 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) << 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 << 682 $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: << 683 %.c << 684 $(TRUNNER_EXTRA_HDRS) << 685 $(TRUNNER_TESTS_HDR) << 686 $$(BPFOBJ) | $(TRUNNER_ << 687 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY), << 688 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS << 689 << 690 # non-flavored in-srctree builds receive speci << 691 # do not need to copy extra resources (see e.g << 692 $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILE << 693 ifneq ($2:$(OUTPUT),:$(shell pwd)) << 694 $$(call msg,EXT-COPY,$(TRUNNER_BINARY) << 695 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/ << 696 endif << 697 << 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 << 705 $(TRUNNER_EXTRA_O << 706 $(RESOLVE_BTFIDS) << 707 $(TRUNNER_BPFTOOL << 708 | $(TRUNNER_BINAR << 709 $$(call msg,BINARY,,$$@) << 710 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %. << 711 $(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_ << 712 $(Q)ln -sf $(if $2,..,.)/tools/build/b << 713 $(OUTPUT)/$(if $2,$2/)bpfto << 714 << 715 endef << 716 << 717 # Define test_progs test runner. << 718 TRUNNER_TESTS_DIR := prog_tests << 719 TRUNNER_BPF_PROGS_DIR := progs << 720 TRUNNER_EXTRA_SOURCES := test_progs.c << 721 cgroup_helpers.c << 722 trace_helpers.c << 723 network_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 << 738 $(OUTPUT)/bpf_test_no_c << 739 $(OUTPUT)/bpf_test_modo << 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 << 750 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CF << 751 $(eval $(call DEFINE_TEST_RUNNER,test_progs)) << 752 << 753 # Define test_progs-no_alu32 test runner. << 754 TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BU << 755 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CF << 756 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no << 757 << 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 << 766 ifneq ($(BPF_GCC),) << 767 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE << 768 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get << 769 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bp << 770 endif << 771 << 772 # Define test_maps test runner. << 773 TRUNNER_TESTS_DIR := map_tests << 774 TRUNNER_BPF_PROGS_DIR := progs << 775 TRUNNER_EXTRA_SOURCES := test_maps.c << 776 TRUNNER_EXTRA_FILES := << 777 TRUNNER_BPF_BUILD_RULE := $$(error no BPF obje << 778 TRUNNER_BPF_CFLAGS := << 779 $(eval $(call DEFINE_TEST_RUNNER,test_maps)) << 780 << 781 # Define test_verifier test runner. << 782 # It is much simpler than test_maps/test_progs << 783 # them (e.g., test.h is using completely patte << 784 # explicitly defining all the rules explicitly << 785 verifier/tests.h: verifier/*.c << 786 $(shell ( cd verifier/; \ 272 $(shell ( cd verifier/; \ 787 echo '/* Generated header, d 273 echo '/* Generated header, do not edit */'; \ 788 echo '#ifdef FILL_ARRAY'; \ 274 echo '#ifdef FILL_ARRAY'; \ 789 ls *.c 2> /dev/null | sed -e !! 275 ls *.c 2> /dev/null | \ >> 276 sed -e 's@\(.*\)@#include \"\1\"@'; \ 790 echo '#endif' \ 277 echo '#endif' \ 791 ) > verifier/tests.h) !! 278 ) > $(VERIFIER_TESTS_H)) 792 $(OUTPUT)/test_verifier: test_verifier.c verif !! 279 793 $(call msg,BINARY,,$@) !! 280 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(ALU32_BUILD_DIR) \ 794 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o % !! 281 $(VERIFIER_TESTS_H) $(PROG_TESTS_H) $(MAP_TESTS_H) \ 795 !! 282 feature 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 << 811 $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/tes << 812 $(call msg,CXX,,$@) << 813 $(Q)$(CXX) $(subst -D_GNU_SOURCE=,,$(C << 814 << 815 # Benchmark runner << 816 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h << 817 $(call msg,CC,,$@) << 818 $(Q)$(CC) $(CFLAGS) -O2 -c $(filter %. << 819 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overh << 820 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_b << 821 $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_ << 822 $(OUTPUT)/perfbuf_ << 823 $(OUTPUT)/bench_bloom_filter_map.o: $(OUTPUT)/ << 824 $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop << 825 $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_b << 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 $ << 834 $(OUTPUT)/bench: LDLIBS += -lm << 835 $(OUTPUT)/bench: $(OUTPUT)/bench.o \ << 836 $(TESTING_HELPERS) \ << 837 $(TRACE_HELPERS) \ << 838 $(CGROUP_HELPERS) \ << 839 $(OUTPUT)/bench_count.o \ << 840 $(OUTPUT)/bench_rename.o \ << 841 $(OUTPUT)/bench_trigger.o \ << 842 $(OUTPUT)/bench_ringbufs.o \ << 843 $(OUTPUT)/bench_bloom_filter_ << 844 $(OUTPUT)/bench_bpf_loop.o \ << 845 $(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,,$@) << 855 $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filte << 856 << 857 $(OUTPUT)/veristat.o: $(BPFOBJ) << 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 << 871 feature bpftool << 872 $(addprefix $(OUTPUT)/,*.o *.d *.skel. << 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 << 880 .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.