From: Jesper Dangaard Brouer Date: Wed, 7 Feb 2018 22:21:24 +0000 (+0100) Subject: epf: improving the ebpf makefile X-Git-Tag: suricata-4.1.0-beta1~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39754a976a0c969552df4ff8024bb8fa29907fef;p=thirdparty%2Fsuricata.git epf: improving the ebpf makefile The current ebpf/Makefile.am have the problem that clang compile errors still result in an ELF .bpf output file. This is obviously problematic as the problem is first seen runtime when loading the bpf-prog. This is caused by the uses of a pipe from clang to llc. To address this problem, split up the clang and llc invocations up into two separate commands, to get proper reaction based on the compiler exit code. The clang compiler is used as a frontend (+ optimizer) and instructed (via -S -emit-llvm) to generate LLVM IR (Intermediate Representation) with suffix .ll. The LLVM llc command is used as a compiler backend taking IR and producing BPF machine bytecode, and storing this into a ELF object. In the last step the IR .ll suffix code it removed. The official documentation of the IR language: http://llvm.org/docs/LangRef.html Also fix the previous make portability warning: '%-style pattern rules are a GNU make extension' I instead use some static pattern rules: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html Signed-off-by: Jesper Dangaard Brouer --- diff --git a/ebpf/Makefile.am b/ebpf/Makefile.am index d0dc0b214f..bfa99dc2df 100644 --- a/ebpf/Makefile.am +++ b/ebpf/Makefile.am @@ -3,11 +3,26 @@ if BUILD_EBPF # Maintaining a local copy of UAPI linux/bpf.h BPF_CFLAGS = -Iinclude -all: lb.bpf filter.bpf bypass_filter.bpf xdp_filter.bpf vlan_filter.bpf +CLANG = ${CC} -%.bpf: %.c - ${CC} -Wall $(BPF_CFLAGS) -O2 -I/usr/include/$(build_cpu)-$(build_os)/ -D__KERNEL__ -D__ASM_SYSREG_H -target bpf -emit-llvm -c $< -o - | ${LLC} -march=bpf -filetype=obj -o $@ +BPF_TARGETS = lb.bpf +BPF_TARGETS += filter.bpf +BPF_TARGETS += bypass_filter.bpf +BPF_TARGETS += xdp_filter.bpf +BPF_TARGETS += vlan_filter.bpf -CLEANFILES = *.bpf +all: $(BPF_TARGETS) + +$(BPF_TARGETS): %.bpf: %.c +# From C-code to LLVM-IR format suffix .ll (clang -S -emit-llvm) + ${CLANG} -Wall $(BPF_CFLAGS) -O2 \ + -I/usr/include/$(build_cpu)-$(build_os)/ \ + -D__KERNEL__ -D__ASM_SYSREG_H \ + -target bpf -S -emit-llvm $< -o ${@:.bpf=.ll} +# From LLVM-IR to BPF-bytecode in ELF-obj file + ${LLC} -march=bpf -filetype=obj ${@:.bpf=.ll} -o $@ + ${RM} ${@:.bpf=.ll} + +CLEANFILES = *.bpf *.ll endif