]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
libbpf: Fix deduplication of typedef with base definitions
authorAntoine Tenart <atenart@kernel.org>
Fri, 17 Apr 2026 08:33:17 +0000 (10:33 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 22 Apr 2026 21:18:41 +0000 (14:18 -0700)
When deduplicating definitions for a module, typedef defined in the base
are not removed. This is because the hash used for base types differs
from the one used in the deduplication logic in btf_dedup_struct_type.

This was introduced by the referenced commit when moving the typedef
deduplication logic handling from btf_dedup_ref_type to
btf_dedup_struct_type, as this also changed the hash logic
(btf_hash_common to btf_hash_typedef).

This also impacts other types referencing those typedef (e.g. const). In
my test, the BTF section size of the openvswitch module went from 31KB
to 45KB.

Fixes: 3781413465df ("libbpf: Fix BTF dedup to support recursive typedef definitions").
Signed-off-by: Antoine Tenart <atenart@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Alan Maguire <alan.maguire@oracle.com>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Link: https://lore.kernel.org/bpf/20260417083319.32716-1-atenart@kernel.org
tools/lib/bpf/btf.c

index 267904939098c89d6592d96ac13c9b82f40bad9a..823bce895178daba74e2f15605b0b4642b19ea7d 100644 (file)
@@ -4592,12 +4592,14 @@ static int btf_dedup_prep(struct btf_dedup *d)
                case BTF_KIND_RESTRICT:
                case BTF_KIND_PTR:
                case BTF_KIND_FWD:
-               case BTF_KIND_TYPEDEF:
                case BTF_KIND_FUNC:
                case BTF_KIND_FLOAT:
                case BTF_KIND_TYPE_TAG:
                        h = btf_hash_common(t);
                        break;
+               case BTF_KIND_TYPEDEF:
+                       h = btf_hash_typedef(t);
+                       break;
                case BTF_KIND_INT:
                case BTF_KIND_DECL_TAG:
                        h = btf_hash_int_decl_tag(t);