iovisor / gobpf

Go bindings for creating BPF programs.
Apache License 2.0
2.14k stars 313 forks source link

Failed to load elf. #267

Open k82cn opened 3 years ago

k82cn commented 3 years ago

I'm trying to use this lib to load a hello world of ebpf, but I got the following errors:

panic: invalid relocation: insn code=0x85, symbol name=bpf_trace_printk
symbol section: Name=, Type=SHT_NULL, Flags=0x0

goroutine 1 [running]:
main.main()
        /home/ubuntu/go/src/github.com/k82cn/ebpf-learn/hello/main.go:15 +0x285

The source code is: https://github.com/k82cn/ebpf-learn/tree/main/hello

If any suggestion/comments, please let me know :)

chenhengqi commented 3 years ago

Hi, you may miss out this compile warning:

hello.c:9:5: warning: implicit declaration of function 'bpf_trace_printk' is invalid in C99 [-Wimplicit-function-declaration]
    bpf_trace_printk(msg, sizeof(msg));
    ^
1 warning generated.

You can obtain a copy of bpf_helpers.h from here, include this file and your hello sample works.