aquasecurity / libbpfgo

eBPF library for Go. Powered by libbpf.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

many warnings, among others unknown attribute 'preserve_access_index'

MaciekLeks opened this issue · comments

Hello,

at first thank you for your great job, but to the point:
When compiling the code (based on selftest/tc) with:

CC=clang CGO_CFLAGS="-I /usr/include/bpf" CGO_LDFLAGS="-lelf -lz /usr/lib/x86_64-linux-gnu/libbpf.a" go build  -o main

with vmlinux.h generated via:

bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
$cat go.mod
module tc-dns-filter

go 1.19

require github.com/aquasecurity/libbpfgo v0.1.1

require golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 // indirect

I get:

# github.com/aquasecurity/libbpfgo
../go/pkg/mod/github.com/aquasecurity/libbpfgo@v0.1.1/libbpfgo.go:72:10: warning: 'perf_buffer__new_deprecated' is deprecated: libbpf v0.7+: use new variant of perf_buffer__new() instead [-Wdeprecated-declarations]
/usr/include/bpf/libbpf.h:1312:31: note: expanded from macro 'perf_buffer__new'
/usr/include/bpf/libbpf_common.h:59:39: note: expanded from macro '___libbpf_overload'
/usr/include/bpf/libbpf_common.h:56:37: note: expanded from macro '___libbpf_select'
/usr/include/bpf/libbpf_common.h:55:29: note: expanded from macro '___libbpf_cat'
<scratch space>:134:1: note: expanded from here
/usr/include/bpf/libbpf.h:1316:2: note: expanded from macro '___perf_buffer_new3'
/usr/include/bpf/libbpf.h:1308:12: note: 'perf_buffer__new_deprecated' has been explicitly marked deprecated here
/usr/include/bpf/libbpf_common.h:24:4: note: expanded from macro 'LIBBPF_DEPRECATED_SINCE'
/usr/include/bpf/libbpf_common.h:19:47: note: expanded from macro 'LIBBPF_DEPRECATED'
cgo-gcc-prolog:235:11: warning: 'bpf_map__resize' is deprecated: libbpf v0.8+: use bpf_map__set_max_entries() instead [-Wdeprecated-declarations]
/usr/include/bpf/libbpf.h:940:1: note: 'bpf_map__resize' has been explicitly marked deprecated here
/usr/include/bpf/libbpf_common.h:24:4: note: expanded from macro 'LIBBPF_DEPRECATED_SINCE'
/usr/include/bpf/libbpf_common.h:19:47: note: expanded from macro 'LIBBPF_DEPRECATED'
cgo-gcc-prolog:489:35: warning: 'bpf_object__open_buffer' is deprecated: libbpf v0.8+: use bpf_object__open_mem() instead [-Wdeprecated-declarations]
/usr/include/bpf/libbpf.h:183:1: note: 'bpf_object__open_buffer' has been explicitly marked deprecated here
/usr/include/bpf/libbpf_common.h:24:4: note: expanded from macro 'LIBBPF_DEPRECATED_SINCE'
/usr/include/bpf/libbpf_common.h:19:47: note: expanded from macro 'LIBBPF_DEPRECATED'
cgo-gcc-prolog:688:11: warning: 'bpf_program__set_tracepoint' is deprecated: libbpf v0.8+: use bpf_program__set_type() instead [-Wdeprecated-declarations]
/usr/include/bpf/libbpf.h:733:1: note: 'bpf_program__set_tracepoint' has been explicitly marked deprecated here
/usr/include/bpf/libbpf_common.h:24:4: note: expanded from macro 'LIBBPF_DEPRECATED_SINCE'
/usr/include/bpf/libbpf_common.h:19:47: note: expanded from macro 'LIBBPF_DEPRECATED'
# tc-dns-filter
In file included from main.bpf.c:2:
./vmlinux.h:5:46: warning: unknown attribute 'preserve_access_index' ignored [-Wunknown-attributes]
./vmlinux.h:20:1: note: when applied to this declaration
./vmlinux.h:5:46: warning: unknown attribute 'preserve_access_index' ignored [-Wunknown-attributes]
./vmlinux.h:25:1: note: when applied to this declaration
./vmlinux.h:5:46: warning: unknown attribute 'preserve_access_index' ignored [-Wunknown-attributes]
./vmlinux.h:49:1: note: when applied to this declaration
./vmlinux.h:5:46: warning: unknown attribute 'preserve_access_index' ignored [-Wunknown-attributes]
...the same warnings cut off here....

Tooling:

$nmame -a
Linux mlk 5.19.0-29-generic #30-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 4 12:14:09 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$clang -v
Ubuntu clang version 15.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

I'm not saying it's a bug. I just need some collaboration here to get rid of it and to have a better grasp on this.

@MaciekLeks thanks for trying libbpfgo.

I noticed that you're building using a system include in conjunction with a statically compiled lib.

CC=clang CGO_CFLAGS="-I /usr/include/bpf" CGO_LDFLAGS="-lelf -lz /usr/lib/x86_64-linux-gnu/libbpf.a" go build  -o main

The messages seem to be related to using different versions. Try again basing your build on:

$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -c $< -o $@

Being $(OUTPUT) where the current libbpf @ 6597330 is being installed.

Closing as this doesn't look like a bug, but please be my guest to continue the discussion.

Yep this might happen when using "dynamic" targets from the Makefile (as libbpf will be built using your OS libbpf package instead of the static one contained within the repository):

$ make 
all                        libbpfgo-dynamic-test      output/                    test
clean                      libbpfgo-static            selftest                   vagrant-destroy
fmt-check                  libbpfgo-static-test       selftest-clean             vagrant-halt
fmt-fix                    libbpfgo-test-bpf-clean    selftest-dynamic           vagrant-ssh
helpers-test-dynamic-run   libbpfgo-test-bpf-dynamic  selftest-dynamic-run       vagrant-up
helpers-test-run           libbpfgo-test-bpf-static   selftest-run               vmlinuxh
helpers-test-static-run    libbpf-static              selftest-static            
libbpfgo-dynamic           output                     selftest-static-run        

Stick with the static build targets and you should be fine. Let us know if not.

Yep, you guys are right. Thank you for your time. I've removed my libbpf-dev apt package and switched to libbpf submodule in this project.

Let me summarize for me and future users:

  1. Clone libbpfgo project somewhere
  2. Generate vmlinux.h inside libbpfgo dir using, bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
  3. Build static version of libbpf, e..g make libbpfgo-static in libbpfgo dir
  4. Modify your own project Makefile accordingly, e..g OUTPUT should point out output inside libbpggo, LIBBPF_SRC -> libbpf/src inside libbpfgo dir, and LIBBPF_OBJ -> $(abspath $(OUTPUT)/libbpf.a), and the rest of Makefile...hmm look at some selftest example.

Generate vmlinux.h inside libbpfgo dir using, bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h

We're tackling a major change to remove bpftool from libbpfgo's requirements, using a caped vmlinux.h for our selftests. But the libbpfgo consumer will need to generate their own vmlinux.h indeed, caped or not.

Keep an eye on https://github.com/aquasecurity/libbpfgo/pull/288/files.