On Thu, Sep 23, 2021 at 7:39 PM Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote: > > When a BPF object is compiled without BTF info (without -g), > trying to link such objects using bpftool causes a SIGSEGV due to > btf__get_nr_types accessing obj->btf which is NULL. Fix this by > checking for the NULL pointer, and return error. > > Reproducer: > $ cat a.bpf.c > extern int foo(void); > int bar(void) { return foo(); } > $ cat b.bpf.c > int foo(void) { return 0; } > $ clang -O2 -target bpf -c a.bpf.c > $ clang -O2 -target bpf -c b.bpf.c > $ bpftool gen obj out a.bpf.o b.bpf.o > Segmentation fault (core dumped) > > After fix: > $ bpftool gen obj out a.bpf.o b.bpf.o > libbpf: failed to find BTF info for object 'a.bpf.o' > Error: failed to link 'a.bpf.o': Unknown error -22 (-22) > > Fixes: a46349227cd8 (libbpf: Add linker extern resolution support for functions and global variables) > Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> > --- > tools/lib/bpf/linker.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > Applied to bpf, thanks. [...]