Re: [PATCH] libbpf: fix BTF dedup to support recursive typedef definitions
From: Eduard Zingerman
Date: Mon Nov 10 2025 - 14:07:08 EST
On Fri, 2025-11-07 at 21:49 +0100, polo wrote:
> Hello Eduard,
>
> On Fri, 7 Nov 2025 at 20:45, Eduard Zingerman <eddyz87@xxxxxxxxx> wrote:
> >
> > On Fri, 2025-11-07 at 16:34 +0100, paulhoussel2@xxxxxxxxx wrote:
> > > From: Paul Houssel <paul.houssel@xxxxxxxxxx>
> > >
> > > Handle recursive typedefs in BTF deduplication
> > >
> > > 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_ref_type() 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.
> > >
> > > Co-developed-by: Martin Horth <martin.horth@xxxxxxxxxxxxxxxxxxx>
> > > Signed-off-by: Martin Horth <martin.horth@xxxxxxxxxxxxxxxxxxx>
> > > Co-developed-by: Ouail Derghal <ouail.derghal@xxxxxxxxxxxxxxxxx>
> > > Signed-off-by: Ouail Derghal <ouail.derghal@xxxxxxxxxxxxxxxxx>
> > > Co-developed-by: Guilhem Jazeron <guilhem.jazeron@xxxxxxxx>
> > > Signed-off-by: Guilhem Jazeron <guilhem.jazeron@xxxxxxxx>
> > > Co-developed-by: Ludovic Paillat <ludovic.paillat@xxxxxxxx>
> > > Signed-off-by: Ludovic Paillat <ludovic.paillat@xxxxxxxx>
> > > Co-developed-by: Robin Theveniaut <robin.theveniaut@xxxxxxx>
> > > Signed-off-by: Robin Theveniaut <robin.theveniaut@xxxxxxx>
> > > Suggested-by: Tristan d'Audibert <tristan.daudibert@xxxxxxxxx>
> > > Signed-off-by: Paul Houssel <paul.houssel@xxxxxxxxxx>
> > >
> > > ---
> > > The issue was originally observed when attempting to encode BTF for
> > > Kubernetes binaries (kubectl, kubeadm):
> > >
> > > $ git clone --depth 1 https://github.com/kubernetes/kubernetes
> > > $ cd ./kubernetes
> > > $ make kubeadm DBG=1
> > > $ pahole --btf_encode_detached=kubeadm.btf _output/bin/kubeadm
> > > btf_encoder__encode: btf__dedup failed!
> > > Failed to encode BTF
> >
> > Hi Paul,
> >
> > Could you please provide some details on why would you like to use BTF
> > for golang programs?
>
> We would like to use BTF for Golang programs in order to trace
> compiled Go user-space applications using eBPF uprobe programs.
> Tetragon [1] implements the use of the BTF file to resolve paths to
> attributes in hook parameters, and therefore if we can obtain the BTF
> for Go programs, we will be able to start reading any attributes.
> Recently, this feature has been extended to support uprobes [2].
>
> [1] https://tetragon.io/docs/concepts/tracing-policy/hooks/#attribute-resolution
> [2] https://github.com/cilium/tetragon/pull/4286#pullrequestreview-3427725698
>
> > Also, is this the only scenario when golang
> > generated DWARF has loops not possible in C code?
>
> This is the only scenario we’ve identified where Golang DWARF contains
> loops, which are not possible in C. We’re not aware of any other
> Go-specific characteristics that could cause additional DWARF loops.
> We tested BTF generation on a set of Go projects that are quite large
> and representative of the diversity of Go programs, and we only
> observed loops for this specific typedef usage.
>
> Paul Houssel
Hi Paul,
Thank you for explaining, this sounds like a reasonable use-case.
I'll comment on the patch itself in the separate email.
Thanks,
Eduard