On Tue, Jan 21, 2025 at 6:53 PM Ihor Solodrai <ihor.solodrai@xxxxx> wrote: > > Add the following functions to libbpf API: > * btf__add_type_attr() > * btf__add_decl_attr() > > These functions allow to add to BTF the type tags and decl tags with > info->kflag set to 1. The kflag indicates that the tag directly > encodes an __attribute__ and not a normal tag. > > See Documentation/bpf/btf.rst changes for details on the semantics. > > Suggested-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxx> > --- > Documentation/bpf/btf.rst | 27 +++++++++-- > tools/include/uapi/linux/btf.h | 3 +- kernel documentation and uapi changes should be in a separate patch from libbpf-side changes > tools/lib/bpf/btf.c | 87 +++++++++++++++++++++++++--------- > tools/lib/bpf/btf.h | 3 ++ > tools/lib/bpf/libbpf.map | 2 + > 5 files changed, 93 insertions(+), 29 deletions(-) > Please double-check whitespacing, tabs vs space might have been messed up in this patch. pw-bot: cr > diff --git a/Documentation/bpf/btf.rst b/Documentation/bpf/btf.rst > index 2478cef758f8..615ded7b2442 100644 > --- a/Documentation/bpf/btf.rst > +++ b/Documentation/bpf/btf.rst > @@ -102,8 +102,9 @@ Each type contains the following common data:: > * bits 24-28: kind (e.g. int, ptr, array...etc) > * bits 29-30: unused > * bit 31: kind_flag, currently used by > - * struct, union, fwd, enum and enum64. > - */ > + * struct, union, enum, fwd, enum64, > + * DECL_TAG and TYPE_TAG keep it lower case > + */ > __u32 info; > /* "size" is used by INT, ENUM, STRUCT, UNION and ENUM64. > * "size" tells the size of the type it is describing. [...] > -/* > - * Append new BTF_KIND_DECL_TAG type with: > - * - *value* - non-empty/non-NULL string; > - * - *ref_type_id* - referenced type ID, it might not exist yet; > - * - *component_idx* - -1 for tagging reference type, otherwise struct/union > - * member or function argument index; > - * Returns: > - * - >0, type ID of newly added BTF type; > - * - <0, on error. > - */ > -int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id, > - int component_idx) > + > +static int __btf__add_decl_tag(struct btf *btf, const char *value, > + int ref_type_id, int component_idx, int kflag) nit: please call it "btf_add_decl_tag" (to distinguish it from public API, but also not use double-underscored name unnecessarily) > { > struct btf_type *t; > int sz, value_off; [..]