Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: add subprog to BPF object file with no entry programs

Add a subprogram to BPF object file that otherwise has no entry BPF
programs to validate that libbpf can still load this correctly.

Until this was fixed, user could expect this very confusing error message:

libbpf: prog 'dangling_subprog': missing BPF prog type, check ELF section name '.text'
libbpf: prog 'dangling_subprog': failed to load: -22
libbpf: failed to load object 'struct_ops_detach'
libbpf: failed to load BPF skeleton 'struct_ops_detach': -22

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20241010211731.4121837-2-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
82370ed5 db089c91

+12
+12
tools/testing/selftests/bpf/progs/struct_ops_detach.c
··· 6 6 7 7 char _license[] SEC("license") = "GPL"; 8 8 9 + /* 10 + * This subprogram validates that libbpf handles the situation in which BPF 11 + * object has subprograms in .text section, but has no entry BPF programs. 12 + * At some point that was causing issues due to legacy logic of treating such 13 + * subprogram as entry program (with unknown program type, which would fail). 14 + */ 15 + int dangling_subprog(void) 16 + { 17 + /* do nothing, just be here */ 18 + return 0; 19 + } 20 + 9 21 SEC(".struct_ops.link") 10 22 struct bpf_testmod_ops testmod_do_detach;