Re: [PATCH bpf-next v3 1/6] libbpf: Separate interfaces shared with in-tree tools
From: Andrii Nakryiko
Date: Tue Nov 24 2026 - 17:53:21 EST
On Tue, Nov 24, 2026 at 2:50 PM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote:
>
> On 2026-11-24 3:48 p.m., Ihor Solodrai wrote:
> > resolve_btfids and bpftool link libbpf statically and use some of its
> > internal helpers from libbpf_internal.h. That header also defines
> > logging macros and poisons kernel integer typedefs, so resolve_btfids
> > wraps the SHA-256 helper in a separate source file.
> >
> > Move the declarations these tools use to libbpf_tools.h and include it
> > instead of libbpf_internal.h. The header is for in-tree tools and stays
> > uninstalled. No shared-library symbols change.
> >
> > No functional change.
>
> I posted v3 with the refactoring as described in my comment [1].
>
> However now I'm thinking it might be an overkill. With the re-design
> vs v1, resolve_btfids now only needs btf_kfunc_proto_match(), if it
> includes relo_core.h, so the new libbpf_tools.h is not as appealing.
>
> Speaking of "API levels", libbpf_internal.h has already been
> functioning as the "in-tree users only", and there is another special
> user among those: the selftests (see paste below). So if v3 is landed
> as posted, we now have two "levels" of in-tree users.
>
> It's... fine, but not exciting. Adding libbpf_tools.h doesn't help
> that much, and dropping it doesn't hurt. It's all bikeshedding, not
> directly relevant to the series, ultimately caused by name collisions
> between resolve_btfids and libbpf (u32 poisoning and pr_* macros).
>
> Quentin, Andrii, Eduard, please let me know if anyone has a strong
> preference here, I'm happy to respin. Thanks!
>
heh, we raced to the minute. I don't like libbpf_tools.h approach, if
GCC poison is a problem I'd rather guard that.
don't respin just yet, let Eduard do a pass at least
> [1]
> https://lore.kernel.org/bpf/faecfef3-ac9f-41be-8bc3-83a66572066a@xxxxxxxxx/
>
> $ grep -rl --include="*.[ch]" 'include.*libbpf_internal.h'
> tools/testing/selftests/bpf
> tools/testing/selftests/bpf/prog_tests/bpf_obj_pinning.c
> tools/testing/selftests/bpf/prog_tests/btf_field_iter.c
> tools/testing/selftests/bpf/prog_tests/btf_sanitize.c
> tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> tools/testing/selftests/bpf/prog_tests/cpu_mask.c
> tools/testing/selftests/bpf/prog_tests/fill_link_info.c
> tools/testing/selftests/bpf/prog_tests/get_smp_processor_id.c
> tools/testing/selftests/bpf/prog_tests/global_data_init.c
> tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c
> tools/testing/selftests/bpf/prog_tests/module_fentry_shadow.c
> tools/testing/selftests/bpf/prog_tests/perf_branches.c
> tools/testing/selftests/bpf/prog_tests/perf_buffer.c
> tools/testing/selftests/bpf/prog_tests/raw_tp_test_run.c
> tools/testing/selftests/bpf/prog_tests/recursive_attach.c
> tools/testing/selftests/bpf/prog_tests/sha256.c
> tools/testing/selftests/bpf/prog_tests/test_global_funcs.c
> tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
> tools/testing/selftests/bpf/prog_tests/signed_loader.c
> tools/testing/selftests/bpf/prog_tests/tracing_multi.c
> tools/testing/selftests/bpf/urandom_read.c
> tools/testing/selftests/bpf/urandom_read_lib1.c
> tools/testing/selftests/bpf/trace_helpers.c
>
>
> >
> > Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
> > ---
> > tools/bpf/bpftool/Makefile | 6 +-
> > tools/bpf/bpftool/common.c | 2 +-
> > tools/bpf/bpftool/gen.c | 3 +-
> > tools/bpf/bpftool/prog.c | 2 +-
> > tools/bpf/bpftool/xlated_dumper.c | 2 +-
> > tools/bpf/resolve_btfids/btf_colors.c | 15 +--
> > tools/bpf/resolve_btfids/btf_colors.h | 4 -
> > tools/bpf/resolve_btfids/main.c | 5 +-
> > tools/lib/bpf/libbpf_internal.h | 162 +----------------------
> > tools/lib/bpf/libbpf_tools.h | 184 ++++++++++++++++++++++++++
> > 10 files changed, 199 insertions(+), 186 deletions(-)
> > create mode 100644 tools/lib/bpf/libbpf_tools.h
> >
> > [...]