Skip to content

Commit

Permalink
libbpf: Ignore STT_SECTION symbols in 'maps' section
Browse files Browse the repository at this point in the history
When parsing legacy map definitions, libbpf would error out when
encountering an STT_SECTION symbol. This becomes a problem because some
versions of binutils will produce SECTION symbols for every section when
processing an ELF file, so BPF files run through 'strip' will end up with
such symbols, making libbpf refuse to load them.

There's not really any reason why erroring out is strictly necessary, so
change libbpf to just ignore SECTION symbols when parsing the ELF.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210927205810.715656-1-toke@redhat.com
  • Loading branch information
Toke Høiland-Jørgensen authored and Andrii Nakryiko committed Sep 28, 2021
1 parent 4c9f093 commit c3e8c44
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/lib/bpf/libbpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
continue;
if (sym.st_shndx != obj->efile.maps_shndx)
continue;
if (GELF_ST_TYPE(sym.st_info) == STT_SECTION)
continue;

map = bpf_object__add_map(obj);
if (IS_ERR(map))
Expand All @@ -1881,8 +1883,7 @@ static int bpf_object__init_user_maps(struct bpf_object *obj, bool strict)
return -LIBBPF_ERRNO__FORMAT;
}

if (GELF_ST_TYPE(sym.st_info) == STT_SECTION
|| GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
if (GELF_ST_BIND(sym.st_info) == STB_LOCAL) {
pr_warn("map '%s' (legacy): static maps are not supported\n", map_name);
return -ENOTSUP;
}
Expand Down

0 comments on commit c3e8c44

Please sign in to comment.