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)
commit47ea7417b0744324424405fc1207e266053237a9
treea22d754b60690412ceb85acdbc40613c44bce1db
parentf86d1fbbe7858884d6754534a0afbb74fc30bc26
libbpf: Skip empty sections in bpf_object__init_global_data_maps

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