bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: ignore STT_SECTION symbols in 'maps' section
@ 2021-09-27 20:58 Toke Høiland-Jørgensen
  2021-09-28  4:30 ` Andrii Nakryiko
  0 siblings, 1 reply; 2+ messages in thread
From: Toke Høiland-Jørgensen @ 2021-09-27 20:58 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: Toke Høiland-Jørgensen, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, bpf, Jiri Benc

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.

Cc: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/lib/bpf/libbpf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index ef5db34bf913..453148fe8b4b 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -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))
@@ -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;
 		}
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: ignore STT_SECTION symbols in 'maps' section
  2021-09-27 20:58 [PATCH bpf-next] libbpf: ignore STT_SECTION symbols in 'maps' section Toke Høiland-Jørgensen
@ 2021-09-28  4:30 ` Andrii Nakryiko
  0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-09-28  4:30 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, bpf, Jiri Benc

On Mon, Sep 27, 2021 at 1:58 PM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> 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.
>
> Cc: Jiri Benc <jbenc@redhat.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---

Applied to bpf-next, thanks.

[...]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-28  4:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 20:58 [PATCH bpf-next] libbpf: ignore STT_SECTION symbols in 'maps' section Toke Høiland-Jørgensen
2021-09-28  4:30 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).