yanivagman/BPFroid

Missing zstd symbols while building BPFroid

18712886438 opened this issue · 10 comments

I managed to build BPFroid for Google Pixel 3a xl with android-msm-bonito-4.9-android11 as https://github.com/yanivagman/BPFroid#building-bpfroid-for-arm64
but I got some errors

 /tracee # KERN_HEADERS=/headers make
fatal: No names found, cannot describe anything.
mkdir -p dist
cd 3rdparty/libbpf/src && make install_headers install_uapi_headers DESTDIR=/tracee/dist/libbpf
make[1]: Entering directory '/tracee/3rdparty/libbpf/src'
  INSTALL  bpf.h libbpf.h btf.h xsk.h libbpf_util.h bpf_helpers.h bpf_helper_defs.h bpf_tracing.h bpf_endian.h bpf_core_read.h libbpf_common.h
  INSTALL  bpf.h bpf_common.h btf.h
make[1]: Leaving directory '/tracee/3rdparty/libbpf/src'
cd 3rdparty/libbpf/src && make OBJDIR=/tracee/dist/libbpf BUILD_STATIC_ONLY=1 
make[1]: Entering directory '/tracee/3rdparty/libbpf/src'
  MKDIR    staticobjs
  CC       bpf.o
  CC       btf.o
  CC       libbpf.o
  CC       libbpf_errno.o
  CC       netlink.o
  CC       nlattr.o
  CC       str_error.o
  CC       libbpf_probes.o
  CC       bpf_prog_linfo.o
  CC       xsk.o
  CC       btf_dump.o
  CC       hashmap.o
  CC       ringbuf.o
  AR       libbpf.a
make[1]: Leaving directory '/tracee/3rdparty/libbpf/src'
mkdir -p dist/tracee.bpf
cp $(find tracee/tracee.bpf.c dist/libbpf/usr/include/bpf 3rdparty/include -type f) dist/tracee.bpf
tar -czf dist/tracee.bpf.tar.gz dist/tracee.bpf
fatal: No names found, cannot describe anything.
GOOS=linux GOARCH=arm64 CC=clang CGO_CFLAGS="-I /tracee/dist/libbpf/usr/include" CGO_LDFLAGS="/tracee/dist/libbpf/libbpf.a" go build -v -o dist/tracee \
-ldflags "-extldflags=-static -X main.bpfBundleInjected=$(base64 -w 0 dist/tracee.bpf.tar.gz) -X main.version="
github.com/aquasecurity/tracee
# github.com/aquasecurity/tracee
/usr/local/go/pkg/tool/linux_arm64/link: running clang failed: exit status 1
/usr/bin/ld: /usr/lib/libelf.a(elf_compress.o): in function `__libelf_compress':
elf_compress.c:(.text+0x104): undefined reference to `ZSTD_createCCtx'
/usr/bin/ld: elf_compress.c:(.text+0x160): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: elf_compress.c:(.text+0x190): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: elf_compress.c:(.text+0x218): undefined reference to `ZSTD_compressStream2'
/usr/bin/ld: elf_compress.c:(.text+0x220): undefined reference to `ZSTD_isError'
/usr/bin/ld: elf_compress.c:(.text+0x288): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: elf_compress.c:(.text+0x294): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: elf_compress.c:(.text+0x2fc): undefined reference to `ZSTD_freeCCtx'
/usr/bin/ld: /usr/lib/libelf.a(elf_compress.o): in function `__libelf_decompress':
elf_compress.c:(.text+0x6f8): undefined reference to `ZSTD_decompress'
/usr/bin/ld: elf_compress.c:(.text+0x6fc): undefined reference to `ZSTD_isError'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [Makefile:53: dist/tracee] Error 1

I tried to add -lzstd to libbpfgo's LDFLAGS but not found.

Looks like a duplicate of #13
As I wrote there - not sure why it happens or how to fix it

Looks like a duplicate of #13 As I wrote there - not sure why it happens or how to fix it

ok, thx anyway

Build with the bullseye of golang image instead of alpine. I get pass that error this way even if the image is bigger ~300 mb

Build with the bullseye of golang image instead of alpine. I get pass that error this way even if the image is bigger ~300 mb

thx, my friend. Actually, I added zstd-static package to DockerFile and add -L/usr/lib/ -lzstd to #CGO LDFLAGS. It works.

Build with the bullseye of golang image instead of alpine. I get pass that error this way even if the image is bigger ~300 mb

thx, my friend. Actually, I added zstd-static package to DockerFile and add -L/usr/lib/ -lzstd to #CGO LDFLAGS. It works.

Weird, I tried manually install the package but it said it was already installed and those flags didn't worked. Anyway I'll be able to test it in monday, and I suppose this will be the best thongs to do instead of moving to bullseye @yanivagman

Build with the bullseye of golang image instead of alpine. I get pass that error this way even if the image is bigger ~300 mb

thx, my friend. Actually, I added zstd-static package to DockerFile and add -L/usr/lib/ -lzstd to #CGO LDFLAGS. It works.

Weird, I tried manually install the package but it said it was already installed and those flags didn't worked. Anyway I'll be able to test it in monday, and I suppose this will be the best thongs to do instead of moving to bullseye @yanivagman

do not forget to add -L/usr/lib/ -lzstd to #CGO LDFLAGS here

#cgo LDFLAGS: -lelf -lz

Build with the bullseye of golang image instead of alpine. I get pass that error this way even if the image is bigger ~300 mb

thx, my friend. Actually, I added zstd-static package to DockerFile and add -L/usr/lib/ -lzstd to #CGO LDFLAGS. It works.

Weird, I tried manually install the package but it said it was already installed and those flags didn't worked. Anyway I'll be able to test it in monday, and I suppose this will be the best thongs to do instead of moving to bullseye @yanivagman

do not forget to add -L/usr/lib/ -lzstd to #CGO LDFLAGS here

#cgo LDFLAGS: -lelf -lz

Ahh I added it to the Makefile

But the question is, would this affect in any negative way builds outside of docker?

But the question is, would this affect in any negative way builds outside of docker?

Maybe. and that's why I didnot make a pr

It looks like some dependency changed in one of these packages: https://github.com/yanivagman/BPFroid/blob/main/builder/Dockerfile#L3
so now lzstd is also required.
If that's the case - then it is safe to add libzstd since it now became a requirement.