From nobody Mon Feb 9 07:19:33 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A58327B4FB for ; Wed, 12 Nov 2025 14:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762956760; cv=none; b=RbKcC5FW1YYE57FTYetK1ou7QvCU0bLhziI5Mx5Q5HspLn7W4KhxW0XiPZ+ebWoWBxc28JVld1/4sNwuVzMOW0IZYq0IDxfAqFhfQydQFfLc9QoTrrhJEIcLJaRPG4Ym70QrvIxpH5eMpX/1bh4HVNZEEOcP3uioSf3WZetPyEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762956760; c=relaxed/simple; bh=SGkn2MfpFy3VCfieLbHx4DUS0yTNXZsrYgUgHGZnHfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eJfOoPXZSARkMolUsfLI0pK5EX7FvlhVa8rafpqTgBdrXR1pHGJMW/k0T5vNsjBp469OKrTPtTyQNjxWVEwcVdLP3eYIjxokRsZ07CCrqXBsddbpg5jt7vlaXQj9YcPFBUZnKRsK7YbnreqlzQDoitmLy6RdUY8KcHr/qwGguCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GtML36v6; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GtML36v6" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-47774d3536dso6510115e9.0 for ; Wed, 12 Nov 2025 06:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762956757; x=1763561557; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bm8jjKEufBDMJusIwnH1y3gkH233WkUBO977RuHJoy8=; b=GtML36v6fw+dyHKygKzabvA74ezx1lwHaRQ+anmdesflFFdlEnXeygiK8Qf8jFZYaE ulZ5QCXpcZfhi4+XkvySjzaS/NCxcbuSsrNTnhouQKVi2csqbtFbshxKIY0cG/ojHVxd 3SV07IycREGCq3jPgLtAgBB5/ZnaYoWg7PufTGTzbS0SoirkB1WvykvYy0tZvENSL3vq XtOpyZRFAmxQ3sU3TkE+Sq+/c/eYk2QaG6ZueJ7YM2WT7U34oeaotbap1qZw7kOM2O6t izYo2GqUWaKK3WNXNQi2hg4FhqT2XHFx2jopF6bFQNtISL40uWQY+PHMm3TN+gL2zRZK DYlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762956757; x=1763561557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bm8jjKEufBDMJusIwnH1y3gkH233WkUBO977RuHJoy8=; b=V24Ofx5L2M2HE6II4gfWNa7UimqjO/XS6XpD0gkaPBGZ6SOvENZ6kqtiAzhmc4v3yp 4jUbXrP2lpB1Nzm4gysOVm+4+xmEemBB/ytFy39rhelwjWcMwVrhrH1sxs90Ihc+RDM7 3dWyEIrga4JmImmw6LypsCYtP+T9kEPFF9SSdZqkBUxrUD4U5y/FQ2jWYYk0XiLg4Ep7 V73Po3TVpvyHAO5ha1JRu3oOwK+W/uRUHspXizHrPzXzAkabaJkDH4/OSMWbs3DdYhv8 TAj/b+WuMBSrWKxIiTJl6qjZX4b0hE5PlvIycm3OnHCR3Bgp6PcT+Lnr4kUdhx8oIXQJ FOaA== X-Forwarded-Encrypted: i=1; AJvYcCWbnBAmgF64M1oLrHDmTnfGmrBq/EMdk0/o7liwy/YMlGL6I9JneX393TUZFJ3q2+outUt++/ZepQQ74wI=@vger.kernel.org X-Gm-Message-State: AOJu0YyrmDez6N/InfsI1uZQSz9ye/sV49nv1k2hHNkAIzjY/0pNHjdU nBoKsbgugB1PCUVHedPfWeEkfzDN6QbdzAlRwz8bb8sFu7QVlhpm8qk8 X-Gm-Gg: ASbGncvgPMDe3/zQfcew+ooEZnQCN0eBg3Ii0f2BKJ+isRYs/1wKsLg5o09tAyD5yU1 l5XNwGGzgytv6A2l9zEdi2siCPuXBckEXWz2V1lzmb5t4W3tPdPP2KX3ds8mBUvUMyWkuR0O7sV SO2FRdalrJwzG67HcUDZoGRinjaCY8R0JqD0AqujvVlW7Ttn9QNiYfnAy4VFVIiei9OJ6Eoi0yW xWSqcYBL09zhuxA9aI/tII8hOsl6TQBJcZ+EScnXSC1iZm2cagLw+z4NKqRqNALzg7HeMB42qxr 8wECJgElQQF702/u5Uzzyw/Yp2wcKrvLJ2e5bl101AyIqn2RV4ija8PmEBlcvdsFM1h241qeGdo Wx9H2pVo7zu2+tKaBcuuY5zewceb58YtgtQTpAIrd19BgLVKV2LMnsUmJQ/b8VJ4Ye+SVdKtrsw rrYrCRXougw3DF X-Google-Smtp-Source: AGHT+IGbS39zZrPEcpZxv9DmwS0T4es4ixXV73jziRjH2BspkatVpgGyDoy9lEVSFhR+zmF+vqB6Jw== X-Received: by 2002:a05:600c:1f91:b0:477:25c0:798c with SMTP id 5b1f17b1804b1-4778735a127mr27992615e9.20.1762956756359; Wed, 12 Nov 2025 06:12:36 -0800 (PST) Received: from paul-Precision-5770 ([80.12.41.68]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b2b08a91esm28303603f8f.2.2025.11.12.06.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 06:12:35 -0800 (PST) From: Paul Houssel X-Google-Original-From: Paul Houssel To: Paul Houssel , Eduard Zingerman , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Martin Horth , Ouail Derghal , Guilhem Jazeron , Ludovic Paillat , Robin Theveniaut , Tristan d'Audibert , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Paul Houssel Subject: [PATCH v2 1/2] libbpf: fix BTF dedup to support recursive typedef definitions Date: Wed, 12 Nov 2025 15:11:33 +0100 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 Signed-off-by: Martin Horth Co-developed-by: Ouail Derghal Signed-off-by: Ouail Derghal Co-developed-by: Guilhem Jazeron Signed-off-by: Guilhem Jazeron Co-developed-by: Ludovic Paillat Signed-off-by: Ludovic Paillat Co-developed-by: Robin Theveniaut Signed-off-by: Robin Theveniaut Suggested-by: Tristan d'Audibert Signed-off-by: Paul Houssel Acked-by: Eduard Zingerman --- 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=3D1 $ pahole --btf_encode_detached=3Dkubeadm.btf _output/bin/kubeadm btf_encoder__encode: btf__dedup failed! Failed to encode BTF The root cause lies in recursive type definitions that cannot exist in C but are valid in Go. program.go: "package main type Foo func() Foo func main() { bar() } func bar() Foo { return nil }" Building and encoding this program with pahole triggers the same deduplication failure: $ go build -gcflags "all=3D-N -l" ./program.go $ pahole --btf_encode_detached=3Dprogram.btf program btf_encoder__encode: btf__dedup failed! Failed to encode BTF As noted in the comment of btf_dedup_ref_type(), the deduplication logic previously assumed recursion only occurs through structs or unions: "[...] there is no danger of encountering cycles because in C type system the only way to form type cycle is through struct/union, so any chain of reference types, even those taking part in a type cycle, will inevitably reach struct/union at some point." However, Go allows such recursion through typedef-like constructs (function types, aliases), requiring a special case for BTF_KIND_TYPEDEF. This patch introduces that special handling, ensuring pahole can handle Go-generated BTFs while maintaining compatibility with existing C workflows. --- tools/lib/bpf/btf.c | 59 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 9f141395c074..5e7c2cae7b27 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -3901,6 +3901,20 @@ static int btf_dedup_strings(struct btf_dedup *d) return err; } =20 +/* + * Calculate type signature hash of TYPEDEF, ignoring referenced type IDs, + * as referenced type IDs equivalence is established separately during type + * graph equivalence check algorithm. + */ +static long btf_hash_typedef(struct btf_type *t) +{ + long h; + + h =3D hash_combine(0, t->name_off); + h =3D hash_combine(h, t->info); + return h; +} + static long btf_hash_common(struct btf_type *t) { long h; @@ -3918,6 +3932,13 @@ static bool btf_equal_common(struct btf_type *t1, st= ruct btf_type *t2) t1->size =3D=3D t2->size; } =20 +/* Check structural compatibility of two TYPEDEF. */ +static bool btf_equal_typedef(struct btf_type *t1, struct btf_type *t2) +{ + return t1->name_off =3D=3D t2->name_off && + t1->info =3D=3D t2->info; +} + /* Calculate type signature hash of INT or TAG. */ static long btf_hash_int_decl_tag(struct btf_type *t) { @@ -4844,14 +4865,31 @@ static void btf_dedup_merge_hypot_map(struct btf_de= dup *d) } } =20 +static inline long btf_hash_by_kind(struct btf_type *t, __u16 kind) +{ + if (kind =3D=3D BTF_KIND_TYPEDEF) + return btf_hash_typedef(t); + else + return btf_hash_struct(t); +} + +static inline bool btf_equal_by_kind(struct btf_type *t1, struct btf_type = *t2, __u16 kind) +{ + if (kind =3D=3D BTF_KIND_TYPEDEF) + return btf_equal_typedef(t1, t2); + else + return btf_shallow_equal_struct(t1, t2); +} + /* - * Deduplicate struct/union types. + * Deduplicate struct/union and typedef types. * * For each struct/union type its type signature hash is calculated, taking * into account type's name, size, number, order and names of fields, but * ignoring type ID's referenced from fields, because they might not be de= duped - * completely until after reference types deduplication phase. This type h= ash - * is used to iterate over all potential canonical types, sharing same has= h. + * completely until after reference types deduplication phase. For each ty= pedef + * type, the hash is computed based on the type=E2=80=99s name and size. T= his type hash + * is used to iterate over all potential canonical types, sharingsame hash. * For each canonical candidate we check whether type graphs that they form * (through referenced types in fields and so on) are equivalent using alg= orithm * implemented in `btf_dedup_is_equiv`. If such equivalence is found and @@ -4882,18 +4920,20 @@ static int btf_dedup_struct_type(struct btf_dedup *= d, __u32 type_id) t =3D btf_type_by_id(d->btf, type_id); kind =3D btf_kind(t); =20 - if (kind !=3D BTF_KIND_STRUCT && kind !=3D BTF_KIND_UNION) + if (kind !=3D BTF_KIND_STRUCT && + kind !=3D BTF_KIND_UNION && + kind !=3D BTF_KIND_TYPEDEF) return 0; =20 - h =3D btf_hash_struct(t); + h =3D btf_hash_by_kind(t, kind); for_each_dedup_cand(d, hash_entry, h) { __u32 cand_id =3D hash_entry->value; int eq; =20 /* * Even though btf_dedup_is_equiv() checks for - * btf_shallow_equal_struct() internally when checking two - * structs (unions) for equivalence, we need to guard here + * btf_equal_by_kind() internally when checking two + * structs (unions) or typedefs for equivalence, we need to guard here * from picking matching FWD type as a dedup candidate. * This can happen due to hash collision. In such case just * relying on btf_dedup_is_equiv() would lead to potentially @@ -4901,7 +4941,7 @@ static int btf_dedup_struct_type(struct btf_dedup *d,= __u32 type_id) * FWD and compatible STRUCT/UNION are considered equivalent. */ cand_type =3D btf_type_by_id(d->btf, cand_id); - if (!btf_shallow_equal_struct(t, cand_type)) + if (!btf_equal_by_kind(t, cand_type, kind)) continue; =20 btf_dedup_clear_hypot_map(d); @@ -4939,7 +4979,7 @@ static int btf_dedup_struct_types(struct btf_dedup *d) /* * Deduplicate reference type. * - * Once all primitive and struct/union types got deduplicated, we can easi= ly + * Once all primitive, struct/union and typedef types got deduplicated, we= can easily * deduplicate all other (reference) BTF types. This is done in two steps: * * 1. Resolve all referenced type IDs into their canonical type IDs. This @@ -4982,7 +5022,6 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __= u32 type_id) case BTF_KIND_VOLATILE: case BTF_KIND_RESTRICT: case BTF_KIND_PTR: - case BTF_KIND_TYPEDEF: case BTF_KIND_FUNC: case BTF_KIND_TYPE_TAG: ref_type_id =3D btf_dedup_ref_type(d, t->type); --=20 2.51.0 From nobody Mon Feb 9 07:19:33 2026 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B83D1F4176 for ; Wed, 12 Nov 2025 14:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762956780; cv=none; b=OFIB9NBh4ADQKx0BGgY5tIEkzy3aiZpNFCBq/iv/1Wk5xxqP/fSaKWYPaC9jLgIVtfdJJpHnofJoSqVKmBrWM3eq0QO3sAuDvZ02A/T/djkU5gxlmdL5iTSM+lFPsFhzvf6DLQSjRiKyyS639At/eOEfctnEQNIG+VsxCkxWxRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762956780; c=relaxed/simple; bh=pVP2OILUU+1rzWIBbsAl/6YtKwi9rPRCel6NowAfs78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HuPG5hYh5W3lBAPyD9ZjClv7m7RRybukunWkFl/I5YPmrGcck2aDef2z+C85W/1QFn2KKHQGa2STL80ZteyUxqs6BxqJaaprG2A+kGQwpY9NXqGSuqGEdmG/8Ws9m4jrTnv13Dpov4vxqRHx/GVHuFjlrkFiko7sizF/uHtfXCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T5w+yE4d; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T5w+yE4d" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-42b2a0c18caso724157f8f.1 for ; Wed, 12 Nov 2025 06:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762956777; x=1763561577; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l/iGYxZtLORX3ELbLt9jFe4ep67d1sKTixtTlZRLqY0=; b=T5w+yE4dv6WzPr49oYvFbx6sySmsxGSB3B0Qbk4nQ2iXQcTVwvIyzXUoisE+/TLziq TJVaIpGg2MbmfBQe30SmDez0fy42VSR8vs0HewNTfCLOh5eigM301YfCkS2UeG204nu2 06weNRsHhJ7lOHlcdEWPg/rF7BbGfX7y8t3UxipFzhB4UsvlYcQwLfP8ZRpyNaJ1GLVZ I7NgmN0W9ZyzMfChyFfVqFdgvcdHYNj0KBhKw1xXfFAOMDeOqGmBQQW/6PQChHxtgVEp wC51XPZ7P9xdRJ321g9P8g/VhRB6EcfCs+OuWSO+HZU8newRbhtALUAxQuCVR+DAYWK6 T4Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762956777; x=1763561577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=l/iGYxZtLORX3ELbLt9jFe4ep67d1sKTixtTlZRLqY0=; b=VcwXTP/1GxtUbyh2uKcXIXrzf+xgAcREHmLbDLyrfshfzQ47XcIUfTETQR3CJ+Vg10 NAvD+ym9RLqy0B50G19v2xzEdtTXP49qNLDQZTJoczO7b3PuxEQZbiWxk9lKA9g5XUPZ OdW/pjsZPq2GoUyr/ObOzXE5ReEfklr57LAAbR0EQcCj6ZzTY4ww5fh9E00zpe9RXE9L jMpMn77dPL4fqQcVrpZ6af+noX2QzQTwCiX19L2V6NxMQnG+CJ3cVYGxaw5Koc8at1nU E3OdZ7NXc0sgcP3CWAEEyGWqjlRj1/IAcPTQmYSL/d9EGoqbT9XgkddeW9sCGbRuxZzT 6tsA== X-Forwarded-Encrypted: i=1; AJvYcCXZDRMvAH7YMyw36vHFeb4WwP+tpZz2obMIs4qvkrdGwYes66b0hr3EgZ+pIG9OyOVatceHKMIaj3GFW7Q=@vger.kernel.org X-Gm-Message-State: AOJu0YwqnBshIZJAQQSYmx2NMdc8M88uWyh+pXj7wFT/gwyRAqbHqaie JnLkefRjYCiT42I/Yo23+99ihxbUAXTisLO/NZ186URjaRXxM3/ZGSLy X-Gm-Gg: ASbGncvjhbcfLG4RGCzSF82PslPIItFIZm8nxgkHxvrkCF3uV2rZsnq5VNsMBnaXULb DLBlOgDPmi57as1YwqarfUhAX0YaPaCyfY+2LBpkPRYUZPj3nXIbBGi4STrVWYNmQVlYS5PGV6l 1ZBAvrOBRSZT1H89eURi+7m+dHU+GRYndpiAj7ZWqYAfrHkynFkm5YJ1VSoJyMxqFF/8If3Vt/z jmISUZVWeM6wWXUqrEQlU6uUheRFgacJQsp0oyc96elMP/BtMOgXb6lbx9W0Pw8r4IcKOKPz1Bt 2zpeFK8tm2wQetythToa+CG/Wr23skKZ7bm6QuP21a/JISMA6A1coWDd4B4WckI654veQkJ+sFS HR1FRKS4oZwgtxDqAY5EegVVLIk8EIJjcz4ky7gkOUbPZoRPk7O06BhuiWonBB7JfN9mBfNYobZ uDd8lm5eFlf/Sp X-Google-Smtp-Source: AGHT+IGYNoOTXnre/4ceRR7yKQ/OoOBBVZ7Ao+Bo2jO9uF7B6Yz0Tq6gekxjquRjIP2nqgGKT+RdVQ== X-Received: by 2002:a05:6000:4210:b0:429:d66b:508f with SMTP id ffacd0b85a97d-42b4bdb03a9mr2990959f8f.30.1762956777196; Wed, 12 Nov 2025 06:12:57 -0800 (PST) Received: from paul-Precision-5770 ([80.12.41.68]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b2b08a91esm28303603f8f.2.2025.11.12.06.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Nov 2025 06:12:56 -0800 (PST) From: Paul Houssel X-Google-Original-From: Paul Houssel To: Paul Houssel , Eduard Zingerman , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Martin Horth , Ouail Derghal , Guilhem Jazeron , Ludovic Paillat , Robin Theveniaut , Tristan d'Audibert , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Paul Houssel Subject: [PATCH v2 2/2] selftests/bpf: add BTF dedup tests for recursive typedef definitions Date: Wed, 12 Nov 2025 15:11:34 +0100 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add several ./test_progs tests: 1. btf/dedup:recursive typedef ensures that deduplication no longer fails on recursive typedefs. 2. btf/dedup:typedef ensures that typedefs are deduplicated correctly just as they were before this patch. Signed-off-by: Paul Houssel --- tools/testing/selftests/bpf/prog_tests/btf.c | 61 ++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/s= elftests/bpf/prog_tests/btf.c index 8a9ba4292109..a19db159475a 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -7495,6 +7495,67 @@ static struct btf_dedup_test dedup_tests[] =3D { BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"), }, }, +{ + .descr =3D "dedup: recursive typedef", + /* + * This test simulates a recursive typedef, which in GO is defined as suc= h: + * + * type Foo func() Foo + * + * In BTF terms, this is represented as a TYPEDEF referencing + * a FUNC_PROTO that returns the same TYPEDEF. + */ + .input =3D { + .raw_types =3D { + /* + * [1] typedef Foo -> func() Foo + * [2] func_proto() -> Foo + */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */ + BTF_FUNC_PROTO_ENC(1, 0), /* [2] */ + BTF_END_RAW, + }, + BTF_STR_SEC("\0Foo"), + }, + .expect =3D { + .raw_types =3D { + BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */ + BTF_FUNC_PROTO_ENC(1, 0), /* [2] */ + BTF_END_RAW, + }, + BTF_STR_SEC("\0Foo"), + }, +}, +{ + .descr =3D "dedup: typedef", + /* + * // CU 1: + * typedef int foo; + * + * // CU 2: + * typedef int foo; + */ + .input =3D { + .raw_types =3D { + /* CU 1 */ + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */ + /* CU 2 */ + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [3] */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 3), /* [4] */ + BTF_END_RAW, + }, + BTF_STR_SEC("\0foo"), + }, + .expect =3D { + .raw_types =3D { + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */ + BTF_END_RAW, + }, + BTF_STR_SEC("\0foo"), + }, +}, { .descr =3D "dedup: typedef tags", .input =3D { --=20 2.51.0