On Tue, Nov 9, 2021 at 9:20 PM Yonghong Song <yhs@xxxxxx> wrote: > > Add libbpf support for BTF_KIND_TYPE_TAG. > > Signed-off-by: Yonghong Song <yhs@xxxxxx> > --- Few nits below. Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > tools/lib/bpf/btf.c | 23 +++++++++++++++++++++++ > tools/lib/bpf/btf.h | 9 ++++++++- > tools/lib/bpf/btf_dump.c | 9 +++++++++ > tools/lib/bpf/libbpf.c | 31 ++++++++++++++++++++++++++++++- > tools/lib/bpf/libbpf.map | 1 + > tools/lib/bpf/libbpf_internal.h | 2 ++ > 6 files changed, 73 insertions(+), 2 deletions(-) > > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c > index 7e4c5586bd87..4d9883bef330 100644 > --- a/tools/lib/bpf/btf.c > +++ b/tools/lib/bpf/btf.c > @@ -299,6 +299,7 @@ static int btf_type_size(const struct btf_type *t) > case BTF_KIND_TYPEDEF: > case BTF_KIND_FUNC: > case BTF_KIND_FLOAT: > + case BTF_KIND_TYPE_TAG: > return base_size; > case BTF_KIND_INT: > return base_size + sizeof(__u32); > @@ -349,6 +350,7 @@ static int btf_bswap_type_rest(struct btf_type *t) > case BTF_KIND_TYPEDEF: > case BTF_KIND_FUNC: > case BTF_KIND_FLOAT: > + case BTF_KIND_TYPE_TAG: > return 0; > case BTF_KIND_INT: > *(__u32 *)(t + 1) = bswap_32(*(__u32 *)(t + 1)); > @@ -649,6 +651,7 @@ int btf__align_of(const struct btf *btf, __u32 id) > case BTF_KIND_VOLATILE: > case BTF_KIND_CONST: > case BTF_KIND_RESTRICT: > + case BTF_KIND_TYPE_TAG: > return btf__align_of(btf, t->type); > case BTF_KIND_ARRAY: > return btf__align_of(btf, btf_array(t)->type); > @@ -2235,6 +2238,22 @@ int btf__add_restrict(struct btf *btf, int ref_type_id) > return btf_add_ref_kind(btf, BTF_KIND_RESTRICT, NULL, ref_type_id); > } > > +/* > + * Append new BTF_KIND_TYPE_TAGtype with: missing space > + * - *value*, non-empty/non-NULL name; s/name/tag value/ ? It's not just a name, some tags can have "parameters", right? > + * - *ref_type_id* - referenced type ID, it might not exist yet; > + * Returns: > + * - >0, type ID of newly added BTF type; > + * - <0, on error. > + */ > +int btf__add_type_tag(struct btf *btf, const char *value, int ref_type_id) > +{ > + if (!value|| !value[0]) > + return libbpf_err(-EINVAL); > + > + return btf_add_ref_kind(btf, BTF_KIND_TYPE_TAG, value, ref_type_id); > +} > + [...]