Open grantseltzer opened 3 years ago
This was somehow handled by:
https://github.com/aquasecurity/libbpfgo/pull/28
But now we have to address the following:
https://github.com/aquasecurity/libbpfgo/pull/28#issuecomment-877265305
So I would say this issue has become the issue described above.
The Makefile
file in tracee uses pkgconfig
for the libbpf static compilation:
libbpfgo could do the same and use:
// #cgo pkg-config: libelf zlib
to have this issue addressed.
Just faced the exact same bug when trying to run a test here in Tracee with:
tracee/cmd/tracee-ebpf/internal/printer
go test -v
I've struggled the same or almost the same "thing". So, this code does not work:
CGO_CFLAGS_STATIC = "-I$(abspath $(LIBBPF_DIR))"
CGO_LDFLAGS_STATIC = "-lelf -lz $(LIBBPF_STATIC_LIB)"
CGO_EXTLDFLAGS_STATIC = '-w -extldflags "-static"'
.PHONY: k8s-build-cmd
k8s-build-cmd: $(CMD_K8S_GO_SOURCE) $(TARGET_BPF)
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
$(GO) build -x \
-tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \
-o $(TARGET_K8S) ./cmd/kubernetes/$(MAIN).go
but this works well:
CGO_CFLAGS_STATIC = "-I$(abspath $(LIBBPF_DIR))"
CGO_LDFLAGS_STATIC = "-lelf -lz $(LIBBPF_STATIC_LIB)"
GO_EXTLDFLAGS_STATIC = '-w -extldflags "-static $(LIBBPF_STATIC_LIB) -lelf -lz"'
#^ librabbry order is important for GO_EXTLDFLAGS_STATIC
k8s-build-cmd: $(CMD_K8S_GO_SOURCE) $(TARGET_BPF)
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
$(GO) build -x \
-tags netgo -ldflags $(GO_EXTLDFLAGS_STATIC) \
-o $(TARGET_K8S) ./cmd/kubernetes/$(MAIN).go
So, the only difference is moving LDFLAGS on the go build level and changing order of the libs.
When building a project that uses libbpfgo, the go compiler must be given a linker flag pointing to libbpf. If libbpf is installed in a standard location
-lbpf
can be passed. They can also point to a specific location. Sincego get
attempts to build the package without any ldflags, this will cause the errors pasted below.Users could do something like:
CGO_LDFLAGS="-lbpf" go get github.com/aquasecurity/tracee
. Alternatively we can add a line for CGO_LDFLAGS in the CGO code.This shouldn't cause any related issues if not using
go get
.For example: