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