--- /dev/null
+From 5aad03685185b5133a28e1ee1d4e98d3fd3642a3 Mon Sep 17 00:00:00 2001
+From: Hengqi Chen <hengqi.chen@gmail.com>
+Date: Tue, 27 Jul 2021 21:25:31 +0800
+Subject: tools/resolve_btfids: Emit warnings and patch zero id for missing symbols
+
+From: Hengqi Chen <hengqi.chen@gmail.com>
+
+commit 5aad03685185b5133a28e1ee1d4e98d3fd3642a3 upstream.
+
+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: Andrii Nakryiko <andrii@kernel.org>
+Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
+Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
+Acked-by: Yonghong Song <yhs@fb.com>
+Link: https://lore.kernel.org/bpf/20210727132532.2473636-2-hengqi.chen@gmail.com
+Cc: "Barry K. Nathan" <barryn@pobox.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/main.c | 13 +++++++------
+ 1 file changed, 7 insertions(+), 6 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/main.c
++++ b/tools/bpf/resolve_btfids/main.c
+@@ -289,7 +289,7 @@ static int compressed_section_fix(Elf *e
+ sh->sh_addralign = expected;
+
+ 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));
+ return -1;
+ }
+@@ -315,6 +315,7 @@ static int elf_collect(struct object *ob
+
+ elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);
+ if (!elf) {
++ close(fd);
+ pr_err("FAILED cannot create ELF descriptor: %s\n",
+ elf_errmsg(-1));
+ return -1;
+@@ -483,7 +484,7 @@ static int symbols_resolve(struct object
+ err = libbpf_get_error(btf);
+ if (err) {
+ pr_err("FAILED: load BTF from %s: %s\n",
+- obj->path, strerror(-err));
++ obj->btf ?: obj->path, strerror(-err));
+ return -1;
+ }
+
+@@ -549,8 +550,7 @@ static int id_patch(struct object *obj,
+ int i;
+
+ if (!id->id) {
+- pr_err("FAILED unresolved symbol %s\n", id->name);
+- return -EINVAL;
++ pr_err("WARN: resolve_btfids: unresolved symbol %s\n", id->name);
+ }
+
+ for (i = 0; i < id->addr_cnt; i++) {
+@@ -728,8 +728,9 @@ int main(int argc, const char **argv)
+
+ err = 0;
+ out:
+- if (obj.efile.elf)
++ if (obj.efile.elf) {
+ elf_end(obj.efile.elf);
+- close(obj.efile.fd);
++ close(obj.efile.fd);
++ }
+ return err;
+ }
--- /dev/null
+From 22e8ebe35a2e30ee19e02c41cacc99c2f896bc4b Mon Sep 17 00:00:00 2001
+From: Brendan Jackman <jackmanb@google.com>
+Date: Thu, 3 Dec 2020 10:22:34 +0000
+Subject: tools/resolve_btfids: Fix some error messages
+
+From: Brendan Jackman <jackmanb@google.com>
+
+commit 22e8ebe35a2e30ee19e02c41cacc99c2f896bc4b upstream.
+
+Add missing newlines and fix polarity of strerror argument.
+
+Signed-off-by: Brendan Jackman <jackmanb@google.com>
+Signed-off-by: Alexei Starovoitov <ast@kernel.org>
+Acked-by: Jiri Olsa <jolsa@redhat.com>
+Link: https://lore.kernel.org/bpf/20201203102234.648540-1-jackmanb@google.com
+Cc: "Barry K. Nathan" <barryn@pobox.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/bpf/resolve_btfids/main.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/tools/bpf/resolve_btfids/main.c
++++ b/tools/bpf/resolve_btfids/main.c
+@@ -459,7 +459,7 @@ static int symbols_collect(struct object
+ return -ENOMEM;
+
+ if (id->addr_cnt >= ADDR_CNT) {
+- pr_err("FAILED symbol %s crossed the number of allowed lists",
++ pr_err("FAILED symbol %s crossed the number of allowed lists\n",
+ id->name);
+ return -1;
+ }
+@@ -482,8 +482,8 @@ static int symbols_resolve(struct object
+ btf = btf__parse(obj->btf ?: obj->path, NULL);
+ err = libbpf_get_error(btf);
+ if (err) {
+- pr_err("FAILED: load BTF from %s: %s",
+- obj->path, strerror(err));
++ pr_err("FAILED: load BTF from %s: %s\n",
++ obj->path, strerror(-err));
+ return -1;
+ }
+