Re: [PATCH bpf-next v2 3/4] resolve_btfids: introduce enum btf_id_kind
From: Andrii Nakryiko
Date: Wed Dec 03 2025 - 19:43:12 EST
On Tue, Dec 2, 2025 at 11:08 AM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote:
>
> On 12/1/25 9:27 AM, Andrii Nakryiko wrote:
> > On Thu, Nov 27, 2025 at 10:53 AM Ihor Solodrai <ihor.solodrai@xxxxxxxxx> wrote:
> >>
> >> Instead of using multiple flags, make struct btf_id tagged with an
> >> enum value indicating its kind in the context of resolve_btfids.
> >>
> >> Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxxxxxx>
> >> ---
> >> tools/bpf/resolve_btfids/main.c | 62 ++++++++++++++++++++++-----------
> >> 1 file changed, 42 insertions(+), 20 deletions(-)
> >
> > [...]
> >
> >>
> >> -static struct btf_id *add_set(struct object *obj, char *name, bool is_set8)
> >> +static struct btf_id *add_set(struct object *obj, char *name, enum btf_id_kind kind)
> >> {
> >> /*
> >> * __BTF_ID__set__name
> >> * name = ^
> >> * id = ^
> >> */
> >> - char *id = name + (is_set8 ? sizeof(BTF_SET8 "__") : sizeof(BTF_SET "__")) - 1;
> >> + int prefixlen = kind == BTF_ID_KIND_SET8 ? sizeof(BTF_SET8 "__") : sizeof(BTF_SET "__");
> >> + char *id = name + prefixlen - 1;
> >> int len = strlen(name);
> >> + struct btf_id *btf_id;
> >>
> >> if (id >= name + len) {
> >> pr_err("FAILED to parse set name: %s\n", name);
> >> return NULL;
> >> }
> >>
> >> - return btf_id__add(&obj->sets, id, true);
> >> + btf_id = btf_id__add(&obj->sets, id, true);
> >> + if (btf_id)
> >> + btf_id->kind = kind;
> >> +
> >> + return btf_id;
> >> }
> >>
> >> static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
> >> {
> >> + struct btf_id *btf_id;
> >> char *id;
> >>
> >> id = get_id(name + size);
> >> @@ -288,7 +301,11 @@ static struct btf_id *add_symbol(struct rb_root *root, char *name, size_t size)
> >> return NULL;
> >> }
> >>
> >> - return btf_id__add(root, id, false);
> >> + btf_id = btf_id__add(root, id, false);
> >> + if (btf_id)
> >> + btf_id->kind = BTF_ID_KIND_SYM;
> >
> > seeing this pattern repeated, wouldn't it make sense to just pass this
> > kind to btf_id__add() and set it there?
>
> I like the idea, because we could get rid the "unique" flag then.
>
> But the btf_id__add() does not necessarily create a new struct, and so
> if we pass the kind in, what do we do with existing objects?
> Overwrite the kind? If not, do we check for a mismatch?
>
no idea, don't know code well enough, but your newly added code seems
to overwrite the kind always, no?
> >
> >> +
> >> + return btf_id;
> >> }
> >>
> >
> > [...]
> >
> >> @@ -643,7 +656,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
> >> int i;
> >>
> >> /* For set, set8, id->id may be 0 */
> >> - if (!id->id && !id->is_set && !id->is_set8) {
> >> + if (!id->id && id->kind == BTF_ID_KIND_SYM) {
> >
> > nit: comment says the exception is specifically for SET and SET8, so I
> > think checking for those two instead of for SYM (implying that only
> > other possible options are set and set8) would be a bit more
> > future-proof?
>
> ok
>
> >
> >> pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
> >> warnings++;
> >> }
> >
> > [...]
>