Commit 5aad0368 authored by Hengqi Chen's avatar Hengqi Chen Committed by Andrii Nakryiko

tools/resolve_btfids: Emit warnings and patch zero id for missing symbols

Kernel functions referenced by .BTF_ids may be changed from global to static
and get inlined or get renamed/removed, and thus disappears from BTF.
This causes kernel build failure when resolve_btfids do id patch for symbols
in .BTF_ids in vmlinux. Update resolve_btfids to emit warning messages and
patch zero id for missing symbols instead of aborting kernel build process.
Suggested-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarHengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarYonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210727132532.2473636-2-hengqi.chen@gmail.com
parent 33b57e0c
...@@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh) ...@@ -291,7 +291,7 @@ static int compressed_section_fix(Elf *elf, Elf_Scn *scn, GElf_Shdr *sh)
sh->sh_addralign = expected; sh->sh_addralign = expected;
if (gelf_update_shdr(scn, sh) == 0) { if (gelf_update_shdr(scn, sh) == 0) {
printf("FAILED cannot update section header: %s\n", pr_err("FAILED cannot update section header: %s\n",
elf_errmsg(-1)); elf_errmsg(-1));
return -1; return -1;
} }
...@@ -317,6 +317,7 @@ static int elf_collect(struct object *obj) ...@@ -317,6 +317,7 @@ static int elf_collect(struct object *obj)
elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL); elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
if (!elf) { if (!elf) {
close(fd);
pr_err("FAILED cannot create ELF descriptor: %s\n", pr_err("FAILED cannot create ELF descriptor: %s\n",
elf_errmsg(-1)); elf_errmsg(-1));
return -1; return -1;
...@@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj) ...@@ -484,7 +485,7 @@ static int symbols_resolve(struct object *obj)
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->path, strerror(-err)); obj->btf ?: obj->path, strerror(-err));
return -1; return -1;
} }
...@@ -555,8 +556,7 @@ static int id_patch(struct object *obj, struct btf_id *id) ...@@ -555,8 +556,7 @@ static int id_patch(struct object *obj, struct btf_id *id)
int i; int i;
if (!id->id) { if (!id->id) {
pr_err("FAILED unresolved symbol %s\n", id->name); pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
return -EINVAL;
} }
for (i = 0; i < id->addr_cnt; i++) { for (i = 0; i < id->addr_cnt; i++) {
...@@ -734,8 +734,9 @@ int main(int argc, const char **argv) ...@@ -734,8 +734,9 @@ int main(int argc, const char **argv)
err = 0; err = 0;
out: out:
if (obj.efile.elf) if (obj.efile.elf) {
elf_end(obj.efile.elf); elf_end(obj.efile.elf);
close(obj.efile.fd); close(obj.efile.fd);
}
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment