I'm trying to cross-compile a BPF program for OpenWrt using the Linux kernel headers from the SDK and clang. However, I keep running into issues with the #include
s. This is my Makefile:
OBJS:= bpfprog.o
LINUXINCLUDE := -I${LINUX_DIR}/arch/${LINUX_KARCH}/include/generated/${LINUX_UAPI_DIR}
LINUXINCLUDE += -I${LINUX_DIR}/arch/${LINUX_KARCH}/include/${LINUX_UAPI_DIR}
LINUXINCLUDE += -I${LINUX_DIR}/arch/${LINUX_KARCH}/include
LINUXINCLUDE += -I${LINUX_DIR}/include/generated/${LINUX_UAPI_DIR}
LINUXINCLUDE += -I${LINUX_DIR}/include/${LINUX_UAPI_DIR}
LINUXINCLUDE += -I${LINUX_DIR}/include
CLANG ?= clang
LLC ?= llc
INC_FLAGS = -nostdinc
EXTRA_CFLAGS = -O2
$(OBJS): %.o:%.c
$(CLANG) $(INC_FLAGS) \
-D__KERNEL__ -D__ASM_SYSREG_H \
-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 \
-target bpfel $(LINUXINCLUDE) \
$(EXTRA_CFLAGS) -c $< -o $@
[...]
The error du jour is openwrt-sdk-x86-64_gcc-8.4.0_musl.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/linux-5.4.80/arch/x86/include/asm/alternative.h:59:2: error: unknown type name 's32'
but I've had many like this one before.
Is there fundamentally wrong with how I'm approaching this? How does one compile against the kernel headers correctly?