OSDN Git Service

libbpf: Fix a couple of missed btf_type_tag handling in btf.c
authorYonghong Song <yhs@fb.com>
Mon, 15 Nov 2021 16:39:37 +0000 (08:39 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 16 Nov 2021 12:10:52 +0000 (13:10 +0100)
commit69a055d546156adc6f7727ec981f721d5ba9231a
tree6d4ed8a7d0a52203879928159b0ef683be18c405
parente47d0bf800e8d7f4de501987b2788c7f2ce22cd1
libbpf: Fix a couple of missed btf_type_tag handling in btf.c

Commit 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG") added the
BTF_KIND_TYPE_TAG support. But to test vmlinux build with ...

  #define __user __attribute__((btf_type_tag("user")))

... I needed to sync libbpf repo and manually copy libbpf sources to
pahole. To simplify process, I used BTF_KIND_RESTRICT to simulate the
BTF_KIND_TYPE_TAG with vmlinux build as "restrict" modifier is barely
used in kernel.

But this approach missed one case in dedup with structures where
BTF_KIND_RESTRICT is handled and BTF_KIND_TYPE_TAG is not handled in
btf_dedup_is_equiv(), and this will result in a pahole dedup failure.
This patch fixed this issue and a selftest is added in the subsequent
patch to test this scenario.

The other missed handling is in btf__resolve_size(). Currently the compiler
always emit like PTR->TYPE_TAG->... so in practice we don't hit the missing
BTF_KIND_TYPE_TAG handling issue with compiler generated code. But lets
add case BTF_KIND_TYPE_TAG in the switch statement to be future proof.

Fixes: 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211115163937.3922235-1-yhs@fb.com
tools/lib/bpf/btf.c