Re: [RFC bpf 2/2] btf: adapt relo_core for kernel compilation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 16, 2021 at 9:12 PM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Thu, Sep 16, 2021 at 6:22 PM Matteo Croce <mcroce@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > How can we share the helpers source too instead of duplicating it?
>
> Ideally. Yes.
> Andrii pointed out that libbpf's btf.h is installed,
> so it's part of libbpf api.
> Therefore it's safer to rename kernel helpers with equivalent meaning
> instead of risking libbpf renames.
>
> >
> > Indeed, I found a small difference between the userspace and kernel code.
> >
> > In tools/lib/bpf/btf.h we have btf_is_mod() which returns true for
> > { BTF_KIND_VOLATILE, BTF_KIND_CONST, BTF_KIND_RESTRICT },
> > while in kernel/bpf/btf.c we have btf_type_is_modifier() which returns
> > true also for BTF_KIND_TYPEDEF.
> >
> > Which is the right one?
>
> btf_is_mod() is part of libbpf btf.h, so we cannot change it.
> btf_type_is_modifier() is kernel internal helper.
> It doesn't need to change and doesn't need to match.

libbpf's btf_is_mod() is not including typedef because there are cases
where typedef shouldn't be skipped. I see one such case in btf_dump.c.
So typedef is certainly not just a modifier from libbpf's point of
view. Kernel doesn't care, though, which is why this difference
exists.

> The equivalent helpers are
> skip_mods_and_typedefs() in the libbpf
> and
> btf_type_skip_modifiers() in the kernel.
> In this case it's probably better to search-and-replace in libbpf.

27 uses in kernel vs 42 in libbpf, so, technically, libbpf should win.
I don't mind mass-renaming of internal helpers, I'd just prefer the
name of the function to reflect the actual logic (where as I pointed
out above, libbpf knows and cares about the distinction between
modifiers (const, volatile, restrict) and typedef). Should we rename
both to btf_type_skip_mods_and_typedefs() or
btf_type_skip_mods_typedefs()?

BTW, kernel might need to start caring about typedefs separately from
modifiers in the context of btf_tag work by Yonghong. Typedefs might
have btf_tags associated with them, I think.

> In most other cases kernel search-and-replace will be necessary.
> For example:
> btf_type_vlen->btf_vlen
> btf_type_member->btf_members



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux