Skip to content

libbpf: fix BTF dedup to support recursive typedef

Paul Houssel bpf linux-kselftest lkml 4 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 2 repliesApplied 2/2
  2. v32 patches 0 repliesSuperseded
  3. v22 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v11 patch4 repliesSuperseded

Changes in v3 from the cover letter

1. Patch 1: Adjusted the comment of btf_dedup_ref_type() to refer to typedef as well.
2. Patch 2: Update of the "dedup: recursive typedef" test to include a duplicated version of the types to make sure deduplication still happens in this case.

Patches in v4 All 2 applied

#Subject and filesSizeRepliesApplied
1/2libbpf: fix BTF dedup to support recursive typedef definitionstools/lib/bpf/btf.c+55 -161 replyApplied
2/2selftests/bpf: add BTF dedup tests for recursive typedef definitionstools/testing/selftests/bpf/prog_tests/btf.c+65 -01 replyApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/2A-b
2/2A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/2] libbpf: fix BTF dedup to support recursive typedef

Pahole fails to encode BTF for some Go projects (e.g. Kubernetes and Podman) due to recursive type definitions that create reference loops not representable in C. These recursive typedefs trigger a failure in the BTF deduplication algorithm.

This patch extends btf_dedup_struct_types() to properly handle potential recursion for BTF_KIND_TYPEDEF, similar to how recursion is already handled for BTF_KIND_STRUCT. This allows pahole to successfully generate BTF for Go binaries using recursive types without impacting existing C-based workflows.

Changes in v4: fix typo found by Claude-based CI

Changes in v3:
1. Patch 1: Adjusted the comment of btf_dedup_ref_type() to refer to typedef as well.
2. Patch 2: Update of the "dedup: recursive typedef" test to include a duplicated version of the types to make sure deduplication still happens in this case.

Changes in v2:
1. Patch 1: Refactored code to prevent copying existing logic. Instead of adding a new function we modify the existing btf_dedup_struct_type() function to handle the BTF_KIND_TYPEDEF case. Calls to btf_hash_struct() and btf_shallow_equal_struct() are replaced with calls to functions that select btf_hash_struct() / btf_hash_typedef() based on the type.
2. Patch 2: Added tests

v3: https://lore.kernel.org/lkml/[email protected]/

v2: https://lore.kernel.org/lkml/[email protected]/

v1: https://lore.kernel.org/lkml/[email protected]/

Paul Houssel (2):
libbpf: fix BTF dedup to support recursive typedef definitions selftests/bpf: add BTF dedup tests for recursive typedef definitions

 tools/lib/bpf/btf.c                          | 71 +++++++++++++++-----
 tools/testing/selftests/bpf/prog_tests/btf.c | 65 ++++++++++++++++++
 2 files changed, 120 insertions(+), 16 deletions(-)
Signature · 1 line
2.51.0