mirror of
				https://github.com/Ysurac/openmptcprouter.git
				synced 2025-03-09 15:40:20 +00:00 
			
		
		
		
	Update LLVM-BPF and a script to compile BPF MPTCP scheduler
This commit is contained in:
		
							parent
							
								
									b2a933513f
								
							
						
					
					
						commit
						e975d7197b
					
				
					 1 changed files with 94 additions and 0 deletions
				
			
		
							
								
								
									
										94
									
								
								common/include/bpf_mptcp.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								common/include/bpf_mptcp.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| include $(INCLUDE_DIR)/kernel.mk | ||||
| 
 | ||||
| BPF_DEPENDS := @HAS_BPF_TOOLCHAIN | ||||
| LLVM_VER:= | ||||
| 
 | ||||
| CLANG_MIN_VER:=12 | ||||
| 
 | ||||
| ifneq ($(CONFIG_USE_LLVM_HOST),) | ||||
|   BPF_TOOLCHAIN_HOST_PATH:=$(call qstrip,$(CONFIG_BPF_TOOLCHAIN_HOST_PATH)) | ||||
|   ifneq ($(BPF_TOOLCHAIN_HOST_PATH),) | ||||
|     BPF_PATH:=$(BPF_TOOLCHAIN_HOST_PATH)/bin:$(PATH) | ||||
|   else | ||||
|     BPF_PATH:=$(PATH) | ||||
|   endif | ||||
|   CLANG:=$(firstword $(shell PATH='$(BPF_PATH)' command -v clang clang-16 clang-13 clang-12 clang-11)) | ||||
|   LLVM_VER:=$(subst clang,,$(notdir $(CLANG))) | ||||
| endif | ||||
| ifneq ($(CONFIG_USE_LLVM_PREBUILT),) | ||||
|   CLANG:=$(TOPDIR)/llvm-bpf/bin/clang | ||||
| endif | ||||
| ifneq ($(CONFIG_USE_LLVM_BUILD),) | ||||
|   CLANG:=$(STAGING_DIR_HOST)/llvm-bpf/bin/clang | ||||
| endif | ||||
| 
 | ||||
| LLVM_PATH:=$(dir $(CLANG)) | ||||
| LLVM_LLC:=$(LLVM_PATH)/llc$(LLVM_VER) | ||||
| LLVM_DIS:=$(LLVM_PATH)/llvm-dis$(LLVM_VER) | ||||
| LLVM_OPT:=$(LLVM_PATH)/opt$(LLVM_VER) | ||||
| LLVM_STRIP:=$(LLVM_PATH)/llvm-strip$(LLVM_VER) | ||||
| 
 | ||||
| BPF_KARCH:=mips | ||||
| #BPF_KARCH:=$(LINUX_KARCH)
 | ||||
| BPF_ARCH:=mips$(if $(CONFIG_ARCH_64BIT),64)$(if $(CONFIG_BIG_ENDIAN),,el) | ||||
| #BPF_ARCH:=$(ARCH)
 | ||||
| BPF_TARGET:=bpf$(if $(CONFIG_BIG_ENDIAN),eb,el) | ||||
| 
 | ||||
| BPF_HEADERS_DIR:=$(STAGING_DIR)/bpf-headers | ||||
| #BPF_HEADERS_DIR:=$(LINUX_DIR)
 | ||||
| 
 | ||||
| BPF_KERNEL_INCLUDE := \
 | ||||
|         -nostdinc -isystem $(TOOLCHAIN_DIR)/include \
 | ||||
|         -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/generated \
 | ||||
|         -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/uapi \
 | ||||
|         -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/generated/uapi \
 | ||||
|         -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include \
 | ||||
|         -I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/asm/mach-generic \
 | ||||
|         -I$(BPF_HEADERS_DIR)/include/uapi \
 | ||||
|         -I$(BPF_HEADERS_DIR)/include/generated/uapi \
 | ||||
|         -I$(BPF_HEADERS_DIR)/tools/lib \
 | ||||
|         -I$(BPF_HEADERS_DIR)/tools/testing/selftests \
 | ||||
|         -I$(BPF_HEADERS_DIR)/samples/bpf \
 | ||||
|         -I$(BPF_HEADERS_DIR)/include \
 | ||||
|         -include asm-generic/int-ll64.h \
 | ||||
|         -include linux/kconfig.h | ||||
| #	-include asm_goto_workaround.h
 | ||||
| 
 | ||||
| BPF_CFLAGS := \
 | ||||
| 	$(BPF_KERNEL_INCLUDE) -I$(PKG_BUILD_DIR) \
 | ||||
| 	-D__KERNEL__ -D__BPF_TRACING__ -DCONFIG_GENERIC_CSUM -DCONFIG_PAGE_SIZE_64KB \
 | ||||
| 	-D__TARGET_ARCH_${BPF_KARCH} \
 | ||||
| 	-D$(if $(CONFIG_BIG_ENDIAN),__MIPSEB__,__MIPSEL__) \
 | ||||
| 	-m$(if $(CONFIG_BIG_ENDIAN),big,little)-endian \
 | ||||
| 	-fno-stack-protector -Wall \
 | ||||
| 	-Wno-unused-value -Wno-pointer-sign \
 | ||||
| 	-Wno-compare-distinct-pointer-types \
 | ||||
| 	-Wno-gnu-variable-sized-type-not-at-end \
 | ||||
| 	-Wno-address-of-packed-member -Wno-tautological-compare \
 | ||||
| 	-Wno-unknown-warning-option \
 | ||||
| 	-fno-asynchronous-unwind-tables \
 | ||||
| 	-Wno-uninitialized -Wno-unused-variable \
 | ||||
| 	-Wno-unused-label \
 | ||||
| 	-O2 -emit-llvm -Xclang -disable-llvm-passes | ||||
| 
 | ||||
| ifneq ($(CONFIG_HAS_BPF_TOOLCHAIN),) | ||||
| ifeq ($(DUMP)$(filter download refresh,$(MAKECMDGOALS)),) | ||||
| #  CLANG_VER:=$(shell $(CLANG) -dM -E - < /dev/null | grep __clang_major__ | cut -d' ' -f3)
 | ||||
|   CLANG_VER:=$(shell $(CLANG) --version - < /dev/null | grep -oE '[0-9]+' | head -n 1) | ||||
|   CLANG_VER_VALID:=$(shell [ "$(CLANG_VER)" -ge "$(CLANG_MIN_VER)" ] && echo 1 ) | ||||
|   ifeq ($(CLANG_VER_VALID),) | ||||
|     $(error ERROR: LLVM/clang version too old. Minimum required: $(CLANG_MIN_VER), found: $(CLANG_VER)) | ||||
|   endif | ||||
| endif | ||||
| endif | ||||
| 
 | ||||
| define CompileBPF | ||||
| 	$(CLANG) -g --target=bpf $(BPF_CFLAGS) $(2) \
 | ||||
| 		-c $(1) -o $(patsubst %.c,%.bc,$(1)) | ||||
| 	$(LLVM_OPT) -O2 -mtriple=$(BPF_TARGET) < $(patsubst %.c,%.bc,$(1)) > $(patsubst %.c,%.opt,$(1)) | ||||
| 	$(LLVM_DIS) < $(patsubst %.c,%.opt,$(1)) > $(patsubst %.c,%.S,$(1)) | ||||
| 	$(LLVM_LLC) -march=$(BPF_TARGET) -mcpu=v3 -filetype=obj -o $(patsubst %.c,%.o,$(1)) < $(patsubst %.c,%.S,$(1)) | ||||
| 	$(CP) $(patsubst %.c,%.o,$(1)) $(patsubst %.c,%.debug.o,$(1)) | ||||
| 	$(LLVM_STRIP) --strip-debug $(patsubst %.c,%.o,$(1)) | ||||
| endef | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue