Skip to content

Commit

Permalink
gcc ebpf: alternative to clang, llvm, llc
Browse files Browse the repository at this point in the history
note: gcc does not support:
 -Wno-unknown-warning-option’
 -Wno-gnu-variable-sized-type-not-at-end’
 -Wno-compare-distinct-pointer-types’

usage:
  CLANG=gcc make
   or
  LLC=gcc make

Should you need to compile using llc:
  LLC=llc-18 make -j $(nproc)

WARNING: currently, the tests fail on my ARM64 CPU with gcc.
  • Loading branch information
vjardin committed Aug 1, 2024
1 parent 70739a9 commit 3a5ec74
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ BIN = ../../bin
# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
LLC ?= llc
CLANG ?= clang

# gcc does not support Assembly IR, so there is no such LLC wich gcc
ifeq ($(CLANG), gcc)
LLC = gcc
endif
ifeq ($(LLC), gcc)
CLANG = gcc
endif

CFLAGS := -g -O2 -Wall -Werror

# Include for BPF are pointing to libbpf
Expand All @@ -47,6 +56,19 @@ clean:
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
# But, there is no easy way to fix it, so just exclude it since it is
# useless for BPF samples.
ifeq ($(LLC), gcc)
$(TARGETS): %.bpf: %.c
@echo " GCC-bpf" $@
@$(CLANG) $(CFLAGS) -S $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
-D__KERNEL__ -D__ASM_SYSREG_H \
-D__BPF_TRACING__ \
-Wall \
-Wno-unused-value -Wno-pointer-sign \
-D__TARGET_ARCH_$(ARCH) \
-Wno-tautological-compare \
-Wno-address-of-packed-member \
-O2 -emit-llvm -g -c $< -o $(BIN)/$@
else
$(TARGETS): %.bpf: %.c
@echo " CLANG-bpf" $@
@$(CLANG) $(CFLAGS) -S $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
Expand All @@ -62,3 +84,4 @@ $(TARGETS): %.bpf: %.c
-Wno-address-of-packed-member \
-O2 -emit-llvm -g -c $< -o ${@:.bpf=.ll}
@$(LLC) -march=bpf -filetype=obj -o $(BIN)/$@ ${@:.bpf=.ll}
endif

0 comments on commit 3a5ec74

Please sign in to comment.