-
Notifications
You must be signed in to change notification settings - Fork 449
Add embed directive to embed the compiled CORE bpf object into go binary #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f35983f
a367961
d02dd43
0e18163
dc68355
6441253
5f7115c
7353f80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,8 @@ OUT_DIR ?= dist | |
GO_SRC := $(shell find . -type f -name '*.go') | ||
OUT_BIN := $(OUT_DIR)/tracee-ebpf | ||
BPF_SRC := tracee/tracee.bpf.c | ||
|
||
ifndef CORE | ||
OUT_BPF := $(OUT_DIR)/tracee.bpf.$(subst .,_,$(KERN_RELEASE)).$(subst .,_,$(VERSION)).o | ||
else | ||
OUT_BPF := $(OUT_DIR)/tracee.bpf.core.$(subst .,_,$(VERSION)).o | ||
endif | ||
OUT_BPF_CORE := $(OUT_DIR)/tracee.bpf.core.o | ||
BPF_HEADERS := 3rdparty/include | ||
BPF_BUNDLE := $(OUT_DIR)/tracee.bpf.tar.gz | ||
LIBBPF_SRC := 3rdparty/libbpf/src | ||
|
@@ -47,9 +43,9 @@ build: $(OUT_BIN) | |
|
||
go_env := GOOS=linux GOARCH=$(ARCH:x86_64=amd64) CC=$(CMD_CLANG) CGO_CFLAGS="-I $(abspath $(LIBBPF_HEADERS))" CGO_LDFLAGS="$(abspath $(LIBBPF_OBJ))" | ||
ifndef DOCKER | ||
$(OUT_BIN): $(LIBBPF_HEADERS) $(LIBBPF_OBJ) $(filter-out *_test.go,$(GO_SRC)) $(BPF_BUNDLE) | $(OUT_DIR) | ||
$(OUT_BIN): $(LIBBPF_HEADERS) $(LIBBPF_OBJ) $(OUT_BPF_CORE) $(filter-out *_test.go,$(GO_SRC)) $(BPF_BUNDLE) | $(OUT_DIR) | ||
$(go_env) go build -v -o $(OUT_BIN) \ | ||
-ldflags "-X main.version=$(VERSION) -X main.bpf_core=$(CORE)" | ||
-ldflags "-X main.version=$(VERSION)" | ||
else | ||
$(OUT_BIN): $(DOCKER_BUILDER) | $(OUT_DIR) | ||
$(call docker_builder_make,$@ VERSION=$(VERSION)) | ||
|
@@ -74,11 +70,10 @@ $(BPF_BUNDLE): $(BPF_SRC) $(LIBBPF_HEADERS)/bpf $(BPF_HEADERS) | |
cp $$(find $^ -type f) $(bpf_bundle_dir) | ||
|
||
.PHONY: bpf | ||
bpf: $(OUT_BPF) | ||
bpf: $(OUT_BPF) $(OUT_BPF_CORE) | ||
|
||
linux_arch := $(ARCH:x86_64=x86) | ||
ifndef DOCKER | ||
ifndef CORE | ||
$(OUT_DIR)/tracee.bpf.%.o: $(BPF_SRC) $(LIBBPF_HEADERS) | $(OUT_DIR) $(bpf_compile_tools) | ||
@v=$$($(CMD_CLANG) --version); test $$(echo $${v#*version} | head -n1 | cut -d '.' -f1) -ge '9' || (echo 'required minimum clang version: 9' ; false) | ||
$(CMD_CLANG) -S \ | ||
|
@@ -117,9 +112,8 @@ $(OUT_DIR)/tracee.bpf.%.o: $(BPF_SRC) $(LIBBPF_HEADERS) | $(OUT_DIR) $(bpf_compi | |
$(CMD_LLC) -march=bpf -filetype=obj -o $@ $(@:.o=.ll) | ||
-$(CMD_LLVM_STRIP) -g $@ | ||
rm $(@:.o=.ll) | ||
else | ||
#docker no, CO:RE yes | ||
$(OUT_DIR)/tracee.bpf.core.%.o: $(BPF_SRC) $(LIBBPF_HEADERS) $(CMD_CLANG) | ||
|
||
$(OUT_BPF_CORE): $(BPF_SRC) $(LIBBPF_HEADERS) $(CMD_CLANG) | ||
$(CMD_CLANG) \ | ||
-I $(LIBBPF_HEADERS)/bpf \ | ||
-I $(BPF_HEADERS) \ | ||
|
@@ -132,11 +126,13 @@ $(OUT_DIR)/tracee.bpf.core.%.o: $(BPF_SRC) $(LIBBPF_HEADERS) $(CMD_CLANG) | |
-DLINUX_VERSION_CODE=$(LINUX_VERSION_CODE) \ | ||
-target bpf \ | ||
-O2 -c -g -o $@ $< | ||
endif | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DOCKER mode seem to be inconsistently supported for the obj files now. We need to be able to build both obj targets with docker and without. currently I think it's not possible? (haven't tried, just by reading the code) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it resolved? I don't see any change in the code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh, I forgot to git push... Sorry about that. |
||
#docker yes | ||
$(OUT_BPF): $(DOCKER_BUILDER) | $(OUT_DIR) | ||
$(call docker_builder_make,$@) | ||
|
||
$(OUT_BPF_CORE): $(DOCKER_BUILDER) | $(OUT_DIR) | ||
$(call docker_builder_make,$@) | ||
endif | ||
|
||
.PHONY: test | ||
|
@@ -164,12 +160,12 @@ define docker_builder_make | |
-v $(abspath $(DOCKER_BUILDER_KERN_SRC_MNT)):$(DOCKER_BUILDER_KERN_SRC_MNT) \ | ||
-v $(abspath .):/tracee/tracee-ebpf \ | ||
-w /tracee/tracee-ebpf \ | ||
--entrypoint make $(DOCKER_BUILDER) KERN_BLD_PATH=$(DOCKER_BUILDER_KERN_BLD) CORE="$(CORE)" KERN_SRC_PATH=$(DOCKER_BUILDER_KERN_SRC) $(1) | ||
--entrypoint make $(DOCKER_BUILDER) KERN_BLD_PATH=$(DOCKER_BUILDER_KERN_BLD) KERN_SRC_PATH=$(DOCKER_BUILDER_KERN_SRC) $(1) | ||
endef | ||
|
||
.PHONY: mostlyclean | ||
mostlyclean: | ||
-rm -rf $(OUT_BIN) $(bpf_bundle_dir) $(OUT_BPF) $(BPF_BUNDLE) | ||
-rm -rf $(OUT_BIN) $(bpf_bundle_dir) $(OUT_BPF) $(OUT_BPF_CORE) $(BPF_BUNDLE) | ||
|
||
.PHONY: clean | ||
clean: | ||
|
Uh oh!
There was an error while loading. Please reload this page.