Skip to contentSkip to conversation

libbpf: properly ignore STT_SECTION symbols in legacy map definitions

PATCH Applied Toke Høiland-Jørgensen 2 participants 2 messages Sep 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: properly ignore STT_SECTION symbols in legacy map definitions

The previous patch to ignore STT_SECTION symbols only added the ignore condition in one of them. This fails if there's more than one map definition in the 'maps' section, because the subsequent modulus check will fail, resulting in error messages like:

libbpf: elf: unable to determine legacy map definition size in ./xdpdump_xdp.o

Fix this by also ignoring STT_SECTION in the first loop.

Fixes c3e8c44a9063 ("libbpf: Ignore STT_SECTION symbols in 'maps' section")

---
Terribly sorry for not catching this in the previous patch. I was testing with an object file with only one map definition, which worked fine :(

 tools/lib/bpf/libbpf.c | 2 ++
 1 file changed, 2 insertions(+)
tools/lib/bpf/libbpf.c +2 -0
index 453148fe8b4b..c20b2167e354 100644
@@ -1845,6 +1845,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;
 		nr_maps++;
 	}
 	/* Assume equally sized map definitions */
Signature · 1 line
2.33.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (refs/heads/master):

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

Quoted 8 lines · On Wed, 29 Sep 2021 23:38:37 +0200 you wrote:

The previous patch to ignore STT_SECTION symbols only added the ignore condition in one of them. This fails if there's more than one map definition in the 'maps' section, because the subsequent modulus check will fail, resulting in error messages like:

libbpf: elf: unable to determine legacy map definition size in ./xdpdump_xdp.o

[...]

Here is the summary with links:
- [bpf-next] libbpf: properly ignore STT_SECTION symbols in legacy map definitions

    https://git.kernel.org/bpf/bpf-next/c/161ecd537948

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html