tools: Allow specifying base BTF file in resolve_btfids
This commit allows specifying the base BTF for resolving btf id lists/sets during link time in the resolve_btfids tool. The base BTF is set to NULL if no path is passed. This allows resolving BTF ids for module kernel objects. Also, drop the --no-fail option, as it is only used in case .BTF_ids section is not present, instead make no-fail the default mode. The long option name is same as that of pahole. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20211002011757.311265-5-memxor@gmail.com
This commit is contained in:
Родитель
14f267d95f
Коммит
f614f2c755
|
@ -89,6 +89,7 @@ struct btf_id {
|
||||||
struct object {
|
struct object {
|
||||||
const char *path;
|
const char *path;
|
||||||
const char *btf;
|
const char *btf;
|
||||||
|
const char *base_btf_path;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -477,16 +478,27 @@ static int symbols_resolve(struct object *obj)
|
||||||
int nr_structs = obj->nr_structs;
|
int nr_structs = obj->nr_structs;
|
||||||
int nr_unions = obj->nr_unions;
|
int nr_unions = obj->nr_unions;
|
||||||
int nr_funcs = obj->nr_funcs;
|
int nr_funcs = obj->nr_funcs;
|
||||||
|
struct btf *base_btf = NULL;
|
||||||
int err, type_id;
|
int err, type_id;
|
||||||
struct btf *btf;
|
struct btf *btf;
|
||||||
__u32 nr_types;
|
__u32 nr_types;
|
||||||
|
|
||||||
btf = btf__parse(obj->btf ?: obj->path, NULL);
|
if (obj->base_btf_path) {
|
||||||
|
base_btf = btf__parse(obj->base_btf_path, NULL);
|
||||||
|
err = libbpf_get_error(base_btf);
|
||||||
|
if (err) {
|
||||||
|
pr_err("FAILED: load base BTF from %s: %s\n",
|
||||||
|
obj->base_btf_path, strerror(-err));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
btf = btf__parse_split(obj->btf ?: obj->path, base_btf);
|
||||||
err = libbpf_get_error(btf);
|
err = libbpf_get_error(btf);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_err("FAILED: load BTF from %s: %s\n",
|
pr_err("FAILED: load BTF from %s: %s\n",
|
||||||
obj->btf ?: obj->path, strerror(-err));
|
obj->btf ?: obj->path, strerror(-err));
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = -1;
|
err = -1;
|
||||||
|
@ -545,6 +557,7 @@ static int symbols_resolve(struct object *obj)
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
out:
|
out:
|
||||||
|
btf__free(base_btf);
|
||||||
btf__free(btf);
|
btf__free(btf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -678,7 +691,6 @@ static const char * const resolve_btfids_usage[] = {
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
bool no_fail = false;
|
|
||||||
struct object obj = {
|
struct object obj = {
|
||||||
.efile = {
|
.efile = {
|
||||||
.idlist_shndx = -1,
|
.idlist_shndx = -1,
|
||||||
|
@ -695,8 +707,8 @@ int main(int argc, const char **argv)
|
||||||
"be more verbose (show errors, etc)"),
|
"be more verbose (show errors, etc)"),
|
||||||
OPT_STRING(0, "btf", &obj.btf, "BTF data",
|
OPT_STRING(0, "btf", &obj.btf, "BTF data",
|
||||||
"BTF data"),
|
"BTF data"),
|
||||||
OPT_BOOLEAN(0, "no-fail", &no_fail,
|
OPT_STRING('b', "btf_base", &obj.base_btf_path, "file",
|
||||||
"do not fail if " BTF_IDS_SECTION " section is not found"),
|
"path of file providing base BTF"),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
int err = -1;
|
int err = -1;
|
||||||
|
@ -717,10 +729,8 @@ int main(int argc, const char **argv)
|
||||||
*/
|
*/
|
||||||
if (obj.efile.idlist_shndx == -1 ||
|
if (obj.efile.idlist_shndx == -1 ||
|
||||||
obj.efile.symbols_shndx == -1) {
|
obj.efile.symbols_shndx == -1) {
|
||||||
if (no_fail)
|
pr_debug("Cannot find .BTF_ids or symbols sections, nothing to do\n");
|
||||||
return 0;
|
return 0;
|
||||||
pr_err("FAILED to find needed sections\n");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symbols_collect(&obj))
|
if (symbols_collect(&obj))
|
||||||
|
|
|
@ -454,7 +454,7 @@ $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
|
||||||
| $(TRUNNER_BINARY)-extras
|
| $(TRUNNER_BINARY)-extras
|
||||||
$$(call msg,BINARY,,$$@)
|
$$(call msg,BINARY,,$$@)
|
||||||
$(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
|
$(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
|
||||||
$(Q)$(RESOLVE_BTFIDS) --no-fail --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
|
$(Q)$(RESOLVE_BTFIDS) --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче