]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
libbpf: Skip empty sections in bpf_object__init_global_data_maps
authorJames Hilliard <james.hilliard1@gmail.com>
Sun, 31 Jul 2022 23:26:49 +0000 (17:26 -0600)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 4 Aug 2022 21:39:07 +0000 (14:39 -0700)
The GNU assembler generates an empty .bss section. This is a well
established behavior in GAS that happens in all supported targets.

The LLVM assembler doesn't generate an empty .bss section.

bpftool chokes on the empty .bss section.

Additionally in bpf_object__elf_collect the sec_desc->data is not
initialized when a section is not recognized. In this case, this
happens with .comment.

So we must check that sec_desc->data is initialized before checking
if the size is 0.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20220731232649.4668-1-james.hilliard1@gmail.com
tools/lib/bpf/libbpf.c

index 50d41815f431a7498ac92f17b3fa41332d3e9c85..77e3797cf75abd342f4cfc15e23917ae88a02a08 100644 (file)
@@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
        for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
                sec_desc = &obj->efile.secs[sec_idx];
 
+               /* Skip recognized sections with size 0. */
+               if (sec_desc->data && sec_desc->data->d_size == 0)
+                       continue;
+
                switch (sec_desc->sec_type) {
                case SEC_DATA:
                        sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));