Skip to content

Commit

Permalink
bpftool: Use BTF field iterator in btfgen
Browse files Browse the repository at this point in the history
Switch bpftool's code which is using libbpf-internal
btf_type_visit_type_ids() helper to new btf_field_iter functionality.

This makes bpftool code simpler, but also unblocks removing libbpf's
btf_type_visit_type_ids() helper completely.

Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Tested-by: Alan Maguire <[email protected]>
Reviewed-by: Quentin Monnet <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
anakryiko authored and qmonnet committed Jun 27, 2024
1 parent a408b9e commit 9204347
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2379,15 +2379,6 @@ static int btfgen_record_obj(struct btfgen_info *info, const char *obj_path)
return err;
}

static int btfgen_remap_id(__u32 *type_id, void *ctx)
{
unsigned int *ids = ctx;

*type_id = ids[*type_id];

return 0;
}

/* Generate BTF from relocation information previously recorded */
static struct btf *btfgen_get_btf(struct btfgen_info *info)
{
Expand Down Expand Up @@ -2467,10 +2458,15 @@ static struct btf *btfgen_get_btf(struct btfgen_info *info)
/* second pass: fix up type ids */
for (i = 1; i < btf__type_cnt(btf_new); i++) {
struct btf_type *btf_type = (struct btf_type *) btf__type_by_id(btf_new, i);
struct btf_field_iter it;
__u32 *type_id;

err = btf_type_visit_type_ids(btf_type, btfgen_remap_id, ids);
err = btf_field_iter_init(&it, btf_type, BTF_FIELD_ITER_IDS);
if (err)
goto err_out;

while ((type_id = btf_field_iter_next(&it)))
*type_id = ids[*type_id];
}

free(ids);
Expand Down

0 comments on commit 9204347

Please sign in to comment.