libbpf: never interpret subprogs in .text as entry programs
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 10 Oct 2024 21:17:30 +0000 (14:17 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 11 Oct 2024 18:15:45 +0000 (11:15 -0700)
Libbpf pre-1.0 had a legacy logic of allowing singular non-annotated
(i.e., not having explicit SEC() annotation) function to be treated as
sole entry BPF program (unless there were other explicit entry
programs).

This behavior was dropped during libbpf 1.0 transition period (unless
LIBBPF_STRICT_SEC_NAME flag was unset in libbpf_mode). When 1.0 was
released and all the legacy behavior was removed, the bug slipped
through leaving this legacy behavior around.

Fix this for good, as it actually causes very confusing behavior if BPF
object file only has subprograms, but no entry programs.

Fixes: bd054102a8c7 ("libbpf: enforce strict libbpf 1.0 behaviors")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20241010211731.4121837-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c

index 05ad264ff09bf1d5d7616efc0cf0239522d7ef8c..7c40286c394847487d7b3cb7df0085e6c662305f 100644 (file)
@@ -4417,7 +4417,7 @@ static int bpf_object__collect_externs(struct bpf_object *obj)
 
 static bool prog_is_subprog(const struct bpf_object *obj, const struct bpf_program *prog)
 {
-       return prog->sec_idx == obj->efile.text_shndx && obj->nr_programs > 1;
+       return prog->sec_idx == obj->efile.text_shndx;
 }
 
 struct bpf_program *