When resolving BTF ids, use the base reference BTF in the module when passed the -r option. Both references to base BTF from split BTF and BTF ids will be reconciled with base vmlinux on module load. Signed-off-by: Alan Maguire <alan.maguire@xxxxxxxxxx> --- tools/bpf/resolve_btfids/main.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c index d9520cb826b3..cdab366bd4d6 100644 --- a/tools/bpf/resolve_btfids/main.c +++ b/tools/bpf/resolve_btfids/main.c @@ -115,6 +115,7 @@ struct object { const char *path; const char *btf; const char *base_btf_path; + int base_ref; struct { int fd; @@ -532,11 +533,21 @@ static int symbols_resolve(struct object *obj) __u32 nr_types; if (obj->base_btf_path) { - base_btf = btf__parse(obj->base_btf_path, NULL); + LIBBPF_OPTS(btf_parse_opts, optp); + const char *path; + + if (obj->base_ref) { + optp.btf_sec = BTF_BASE_REF_ELF_SEC; + path = obj->path; + } else { + optp.btf_sec = BTF_ELF_SEC; + path = obj->base_btf_path; + } + base_btf = btf__parse_opts(path, &optp); err = libbpf_get_error(base_btf); if (err) { pr_err("FAILED: load base BTF from %s: %s\n", - obj->base_btf_path, strerror(-err)); + path, strerror(-err)); return -1; } } @@ -781,6 +792,8 @@ int main(int argc, const char **argv) "BTF data"), OPT_STRING('b', "btf_base", &obj.base_btf_path, "file", "path of file providing base BTF"), + OPT_INCR('r', "base_ref", &obj.base_ref, + "use base reference BTF as base"), OPT_END() }; int err = -1; -- 2.39.3