Skip to content

Commit

Permalink
add support for split BTF to gen min_core_btf
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Kahle <bryce.kahle@datadoghq.com>
  • Loading branch information
brycekahle committed Jan 13, 2024
1 parent b0e69ac commit 8e59ae3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1695,14 +1695,14 @@ btfgen_new_info(const char *targ_btf_path)
if (!info)
return NULL;

info->src_btf = btf__parse(targ_btf_path, NULL);
info->src_btf = btf__parse_split(targ_btf_path, base_btf);
if (!info->src_btf) {
err = -errno;
p_err("failed parsing '%s' BTF file: %s", targ_btf_path, strerror(errno));
goto err_out;
}

info->marked_btf = btf__parse(targ_btf_path, NULL);
info->marked_btf = btf__parse_split(targ_btf_path, base_btf);
if (!info->marked_btf) {
err = -errno;
p_err("failed parsing '%s' BTF file: %s", targ_btf_path, strerror(errno));
Expand Down Expand Up @@ -2139,12 +2139,18 @@ static int btfgen_remap_id(__u32 *type_id, void *ctx)
/* Generate BTF from relocation information previously recorded */
static struct btf *btfgen_get_btf(struct btfgen_info *info)
{
const struct btf *base;
struct btf *btf_new = NULL;
unsigned int *ids = NULL;
unsigned int i, n = btf__type_cnt(info->marked_btf);
int err = 0;
int start_id = 1;

btf_new = btf__new_empty();
base = btf__base_btf(info->src_btf);
if (base)
start_id = btf__type_cnt(base);

btf_new = btf__new_empty_split((struct btf *)base);
if (!btf_new) {
err = -errno;
goto err_out;
Expand All @@ -2157,7 +2163,7 @@ static struct btf *btfgen_get_btf(struct btfgen_info *info)
}

/* first pass: add all marked types to btf_new and add their new ids to the ids map */
for (i = 1; i < n; i++) {
for (i = start_id; i < n; i++) {
const struct btf_type *cloned_type, *type;
const char *name;
int new_id;
Expand Down Expand Up @@ -2213,7 +2219,7 @@ 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++) {
for (i = start_id; i < btf__type_cnt(btf_new); i++) {
struct btf_type *btf_type = (struct btf_type *) btf__type_by_id(btf_new, i);

err = btf_type_visit_type_ids(btf_type, btfgen_remap_id, ids);
Expand Down

0 comments on commit 8e59ae3

Please sign in to comment.