Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add support of gcc BPF backend
  • Loading branch information
brianwitte committed Jun 6, 2024
commit aa80c2f27dd9212468a43146b014a16088b9d253
31 changes: 28 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ SRCARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
-e s/aarch64.*/arm64/ )

CLANG ?= clang
GCC_BPF ?=
LLC ?= llc
LLVM_STRIP ?= llvm-strip
BPFTOOL ?= bpftool
BPF_INCLUDE := /usr/include
BPF_CFLAGS := -g -fno-stack-protector -Wall
NL_INCLUDE := /usr/include/libnl3
INCLUDES := -I../include -I$(BPF_INCLUDE) -I$(NL_INCLUDE) -I../include/uapi

INSTALL ?= install

DESTDIR ?= /
Expand Down Expand Up @@ -104,11 +104,15 @@ NOBTF_BPF_SKELS = $(patsubst %.skel.h,%.skel.nobtf.h,$(BPF_SKELS))

.PHONY: clean

ifeq ($(GCC_BPF),)
all: analyze $(OPATH) $(OPATH)bpftune $(TUNER_LIBS)
else
all: $(OPATH) $(OPATH)bpftune $(TUNER_LIBS)
endif

$(OPATH):
mkdir $(OPATH)

analyze: $(BPF_SKELS) $(LEGACY_BPF_SKELS) $(NOBTF_BPF_SKELS)
$(CLANG) --analyze $(INCLUDES) libbpftune.c bpftune.c $(TUNER_SRCS)
clean:
Expand Down Expand Up @@ -163,6 +167,8 @@ $(OPATH)bpftune.o: $(OPATH)libbpftune.so
%.skel.h: %.bpf.o
$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@

# check if GCC_BPF flag is set, otherwise use CLANG
ifeq ($(GCC_BPF),)
$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@)
Expand All @@ -176,6 +182,26 @@ $(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../include/bpftun
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)
else
GCC_BPF_FLAGS := -g -O2 \
$(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) \
-gbtf -mcpu=v3 -Wno-error=attributes \
-Wno-error=address-of-packed-member \
-Wno-compare-distinct-pointer-types \
$(INCLUDES)

$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -c $(patsubst %.o,%.c,$(@)) \
-o $(@)

$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -DBPFTUNE_LEGACY -c $(patsubst %.legacy.o,%.c,$(@)) \
-o $(@)

$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -DBPFTUNE_NOBTF -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)
endif

$(BPF_SKELS): $(BPF_OBJS)
$(BPFTOOL) gen skeleton $(subst .skel.h,.bpf.o,$@) > $@
Expand All @@ -185,4 +211,3 @@ $(LEGACY_BPF_SKELS): $(LEGACY_BPF_OBJS)

$(NOBTF_BPF_SKELS): $(NOBTF_BPF_OBJS)
$(BPFTOOL) gen skeleton $(subst .skel.nobtf.h,.bpf.nobtf.o,$@) > $(subst .skel.h,.skel.nobtf.h,$@)

33 changes: 29 additions & 4 deletions test/strategy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ CLANG ?= clang
LLC ?= llc
LLVM_STRIP ?= llvm-strip
BPFTOOL ?= bpftool
BPF_INCLUDE := ../../include
GCC_BPF ?=
BPF_INCLUDE := /usr/include
BPF_CFLAGS := -g -fno-stack-protector -Wall
NL_INCLUDE := /usr/include/libnl3
INCLUDES := -I$(BPF_INCLUDE) -I$(NL_INCLUDE) -I/usr/include/uapi
INCLUDES := -I../../include -I$(BPF_INCLUDE) -I$(NL_INCLUDE) -I/usr/include/uapi

INSTALL ?= install

Expand Down Expand Up @@ -74,7 +75,7 @@ NOBTF_BPF_SKELS = $(patsubst %.skel.h,%.skel.nobtf.h,$(BPF_SKELS))
.PHONY: clean

all: $(TUNER_LIBS)

clean:
$(Q)$(RM) *.o *.d *.so*
$(Q)$(RM) *.skel*.h
Expand All @@ -86,6 +87,9 @@ $(TUNER_LIBS): $(BPF_SKELS) $(TUNER_OBJS)

$(TUNER_OBJS): $(BPF_SKELS) $(LEGACY_BPF_SKELS) $(NOBTF_BPF_SKELS)


# check if GCC_BPF flag is set, otherwise use CLANG
ifeq ($(GCC_BPF),)
$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@)
Expand All @@ -100,6 +104,28 @@ $(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../../include/bpf
$(INCLUDES) -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)

else
GCC_BPF_FLAGS := -g -O2 \
$(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) \
-gbtf -mcpu=v3 -Wno-error=attributes \
-Wno-error=address-of-packed-member \
-Wno-compare-distinct-pointer-types \
$(INCLUDES)

$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -c $(patsubst %.o,%.c,$(@)) \
-o $(@)

$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -DBPFTUNE_LEGACY -c $(patsubst %.legacy.o,%.c,$(@)) \
-o $(@)

$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(GCC_BPF) $(GCC_BPF_FLAGS) -DBPFTUNE_NOBTF -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)

endif

$(BPF_SKELS): $(BPF_OBJS)
$(BPFTOOL) gen skeleton $(subst .skel.h,.bpf.o,$@) > $@

Expand All @@ -108,4 +134,3 @@ $(LEGACY_BPF_SKELS): $(LEGACY_BPF_OBJS)

$(NOBTF_BPF_SKELS): $(NOBTF_BPF_OBJS)
$(BPFTOOL) gen skeleton $(subst .skel.nobtf.h,.bpf.nobtf.o,$@) > $(subst .skel.h,.skel.nobtf.h,$@)