On Fri, Mar 28, 2025 at 12:16 PM Mykyta Yatsenko <mykyta.yatsenko5@xxxxxxxxx> wrote: > > On 28/03/2025 17:14, Andrii Nakryiko wrote: > > On Wed, Mar 26, 2025 at 11:07 AM Mykyta Yatsenko > > <mykyta.yatsenko5@xxxxxxxxx> wrote: > >> From: Mykyta Yatsenko <yatsenko@xxxxxxxx> > >> > >> Introducing new libbpf API getters for BTF.ext func and line info, > >> namely: > >> bpf_program__func_info > >> bpf_program__func_info_cnt > >> bpf_program__func_info_rec_size > >> bpf_program__line_info > >> bpf_program__line_info_cnt > >> bpf_program__line_info_rec_size > >> > >> This change enables scenarios, when user needs to load bpf_program > >> directly using `bpf_prog_load`, instead of higher-level > >> `bpf_object__load`. Line and func info are required for checking BTF > >> info in verifier; verification may fail without these fields if, for > >> example, program calls `bpf_obj_new`. > >> > > Really, bpf_obj_new() needs func_info/line_info? Can you point where > > in the verifier we check this, curious why we do that. > Indirectly, yes: > in verifier.c function check_btf_info_early sets > `env->prog->aux->btf = btf;` > only if line_info_cnt or func_info_cnt are non zero. > and then there is a check that errors out: > `verbose(env, "bpf_obj_new/bpf_percpu_obj_new requires prog BTF\n");` > perhaps this can be improved as well, by setting aux->btf even if no > func info and line info lol, doesn't seem intentional (just in the early days prog BTF was only referenced and used with func_info/line_info, which isn't true anymore), we can probably swap the order and load and remember prog BTF regardless of func_info/line_info. Feel free to send a patch. > > > >> Signed-off-by: Mykyta Yatsenko <yatsenko@xxxxxxxx> > >> --- > >> tools/lib/bpf/libbpf.c | 30 ++++++++++++++++++++++++++++++ > >> tools/lib/bpf/libbpf.h | 8 ++++++++ > >> tools/lib/bpf/libbpf.map | 6 ++++++ > >> 3 files changed, 44 insertions(+) > >> [...] > >> diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map > >> index d8b71f22f197..a5d83189c084 100644 > >> --- a/tools/lib/bpf/libbpf.map > >> +++ b/tools/lib/bpf/libbpf.map > >> @@ -437,6 +437,12 @@ LIBBPF_1.6.0 { > >> bpf_linker__add_fd; > >> bpf_linker__new_fd; > >> bpf_object__prepare; > >> + bpf_program__func_info; > >> + bpf_program__func_info_cnt; > >> + bpf_program__func_info_rec_size; > >> + bpf_program__line_info; > >> + bpf_program__line_info_cnt; > >> + bpf_program__line_info_rec_size; nit: hm... please check tabs vs spaces, formatting looks off > >> btf__add_decl_attr; > >> btf__add_type_attr; > >> } LIBBPF_1.5.0; > >> -- > >> 2.48.1 > >> >