libbpf: Make BTF finalization strict
authorAndrii Nakryiko <andriin@fb.com>
Wed, 8 Jul 2020 01:53:13 +0000 (18:53 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 8 Jul 2020 22:44:44 +0000 (00:44 +0200)
With valid ELF and valid BTF, there is no reason (apart from bugs) why BTF
finalization should fail. So make it strict and return error if it fails. This
makes CO-RE relocation more reliable, as they are not going to be just
silently skipped, if BTF finalization failed.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200708015318.3827358-2-andriin@fb.com
tools/lib/bpf/libbpf.c

index 88a483627a2b902232e8cf42af98c839d6801d84..efd857ebd5eed3468235331be2b1e8f56d0d7982 100644 (file)
@@ -2473,19 +2473,11 @@ static int bpf_object__finalize_btf(struct bpf_object *obj)
                return 0;
 
        err = btf__finalize_data(obj, obj->btf);
-       if (!err)
-               return 0;
-
-       pr_warn("Error finalizing %s: %d.\n", BTF_ELF_SEC, err);
-       btf__free(obj->btf);
-       obj->btf = NULL;
-       btf_ext__free(obj->btf_ext);
-       obj->btf_ext = NULL;
-
-       if (libbpf_needs_btf(obj)) {
-               pr_warn("BTF is required, but is missing or corrupted.\n");
-               return -ENOENT;
+       if (err) {
+               pr_warn("Error finalizing %s: %d.\n", BTF_ELF_SEC, err);
+               return err;
        }
+
        return 0;
 }