From nobody Sat Feb 7 20:57:58 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 F2C8933B6C4 for ; Thu, 13 Nov 2025 11:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032513; cv=none; b=hGzOmKz+87NUvpn42WFRAmGRfsbuMhBoMke6mLD0cc8gK8svkQyn09/tlbB6OrPiiketYUGP7OkIHUSf454Yk3hLMt9FRb2Uk/W/WxZ0vWNbazstb/ydzySNlBNP1Hkv4GXUb14LCJp9yWTlP0vF6Vx0A5RL94B3knFoFM1iDoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032513; c=relaxed/simple; bh=1XD6PWKm58Gt7LW0tKjW7rvVrHAdnRX2aZm40CNVExI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ONBc9fOJYFdRw7ejetOlsdQ/7o8VsqHDmRW0m/traNwpswZthGtnltx8IA26XEnecFbavdy83DqYRr8J6++0dYqoCuCJfBW0hIAy5WCxiKnVArEcdwZRP+GLcY/65S4h9XfXKKNscO32s6LVcvLxcoFYb0OluLw3lT5HuVYMGvk= 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=hVZtwFuM; arc=none smtp.client-ip=209.85.128.46 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="hVZtwFuM" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4775e891b5eso3679505e9.2 for ; Thu, 13 Nov 2025 03:15:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763032508; x=1763637308; 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=Z6Y6kzG2O6uwjBrHzCB632WRHU3Yg3b3hYi/wFvLK7M=; b=hVZtwFuMsxI/hY3Yhmm1dZz8CACg6Z1IqLL2AnPNEB7DXis1GYdP6CA1I39JXYI1My Soh7v5aetKxX1sPAFs3TbUFY0OcIEBfqhTbTDCO48VUcCXV003xjSh5uTjphO3APgcmP ClbBjZc8RXCSZG2QQ+rmzqJcD74zYj9L3iPauDaNIFXUxEpnuFwRsXJPeCsqgTqvRscW q1EA7JgCUQ8YK849r8afVXVpDpCOA6tuMFcXjDc2pQ86tqairWypGfDNgzI5APIYFyRp 1armnuGGgzyrbsdbe3k9N03Cj/FAjUOvUchPVvzodyw80CbcrolcrVTzv9pwFmJPoj/3 9tzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763032508; x=1763637308; 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=Z6Y6kzG2O6uwjBrHzCB632WRHU3Yg3b3hYi/wFvLK7M=; b=lVPmvNO7l7d5um2m6cvnU013TK9HWM6S2b0GWSFBHhL3g3hHWIPefAbbcHuZYZvm6r 4yulVbltqSczUTKLX0l5lcJeVuVXKV9RDuyzAT3bE40gEAh59v5pPIZ3615cqBLdChbe Sk87EFXnDSgZOZufpTaEFlTNT3FqatQ4/AWwyhvN0eUqZGt31LKQ4Ppa/V0vJrwL9Jjz mX0vsU68Uhmozra3I8In9MBbfbIhhtD2rC7k72aqZq1363LR4LbS8vWk+O5ydW4wa01e ZYxEbtT9BsoAW2RXkMotguG9RlayHLwfmc87gx7zuE4iGFexWXFWF0J8Wt3nxtWefnWD /OHQ== X-Forwarded-Encrypted: i=1; AJvYcCUvA6KMWdvrPcvifi+BLE9D2qBr54dCy73KfzFyXVMoHykm/vZuSyErHuZFjvaKJAfjDA9PTNJKo0BjVO0=@vger.kernel.org X-Gm-Message-State: AOJu0YxgHMhdRNgDSTZcDrhDiCSM/UuPYeJXqHpoRM8uEJDEw7cxnZ+0 vTsTvXcZPWicvOpBEPorW64craMCqfQPUSMgebJQdqfUD9MnQ0bXAHfy X-Gm-Gg: ASbGncsBR38wWaR2Q4UUuSJV2wufXC/NO2Su4Q1hjv5oa4fdF6FDNp4NpcZktgmp6CK 7/V+Fdoges9zHK3bEsQwWUZVrIg8KTnqBrFL1Du6PfoKz0X5nrJ26X2dRC1GdWFs/W0Kyy4eors sHe0ivV51RjnKaZ3eT84PCJRkUwUrf1++99X6DnD6TuIbZgO3+XBQhpHcNgLxLBQKk4D5SNIz/s FTWhFWQ+gW20Xd2MGwl3cxtw71x0CcCmatWICeTZaZJvhOVRMW6Ey+JRXdJmxmbMITlGzFyCQFg OeYdHRRqRDql+cQVqqfQHPNEvcM+AqTUwbaFnv5pwU7dyOPJVXjoMN0bmHuJG2kdlJ107A5r/gf s0cTcO/4A6IWNH9QmeUJ3N+Ng/rBgamJSOUaLKeYiaxErqNlV3Mqv0S4RtuBEOREOZfTXix7l+W dufpRwSKueokfX X-Google-Smtp-Source: AGHT+IErKo2J91Ztft92gvrE6uO+NgsD0IyPPSDULKbUxxZU0C2orUCJe2QMzHZRp0g72BUUgExazA== X-Received: by 2002:a05:600c:3b17:b0:475:de12:d3b2 with SMTP id 5b1f17b1804b1-477870cdce6mr55124405e9.36.1763032507984; Thu, 13 Nov 2025 03:15:07 -0800 (PST) Received: from paul-Precision-5770 ([80.12.41.69]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4778bcfa2e9sm17739825e9.12.2025.11.13.03.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 03:15:07 -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 v3 1/2] libbpf: fix BTF dedup to support recursive typedef definitions Date: Thu, 13 Nov 2025 12:14:05 +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 --- 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 | 73 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 9f141395c074..5c4035eb9493 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,18 +4979,18 @@ 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 - * resolution can be done either immediately for primitive or struct/union= types - * (because they were deduped in previous two phases) or recursively for + * resolution can be done either immediately for primitive, struct/union, = and typedef + * types (because they were deduped in previous two phases) or recursively= for * reference types. Recursion will always terminate at either primitive or - * struct/union type, at which point we can "unwind" chain of reference ty= pes - * one by one. 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 inevit= ably - * reach struct/union at some point. + * struct/union and typedef types, at which point we can "unwind" chain of= reference + * types one by one. There is no danger of encountering cycles in C, as th= e only way to + * form a type cycle is through struct or union types. Go can form such cy= cles through + * typedef. Thus, any chain of reference types, even those taking part in = a type cycle, + * will inevitably reach a struct/union or typedef type at some point. * * 2. Once all referenced type IDs are resolved into canonical ones, BTF t= ype * becomes "stable", in the sense that no further deduplication will cause @@ -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 Sat Feb 7 20:57:58 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 E60DF2D7813 for ; Thu, 13 Nov 2025 11:15:16 +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=1763032519; cv=none; b=jbWeqGSDyiOcxNhv6AKMPsqCLSRkl5vd6z1ntWs6F4QMRXRfOv0NmTJgui+lHvV996Ot2ppBKVERCM1dGqirGfkzb6MzcbXuAjgRYcPvOrM8RQxbIy/oxBeVoT6AK6SCdyMiFXEXByYBAQvBI+GZfaUMjKCy+ngTYqGVZssvtpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763032519; c=relaxed/simple; bh=ZDIjKrxNRsNKjDHyHEBYoPmLkLVi1miMphnKseqdm2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vEJkG3AsCtgYj3NAQZfBTfCWA5osMX4DUDyk8tYbzKpmIf0APgYwofYS9E2/asvSB7xZ/kd7KzTmPOvE9VB8+RvDrW87/UcBLmJoWHnP17e4qLKx+ykgUoLxzAj4wgt4nqQUeqc9y3KQo+UR9o0B4RRv4t5sSqNiqLSfaxiHAV8= 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=ekL7KdFa; 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="ekL7KdFa" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4777707a7c2so14594005e9.1 for ; Thu, 13 Nov 2025 03:15:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763032515; x=1763637315; 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=MO9XnnVHj/rspITKiAGHVAzlJx09tqhwIOhjHMpSEAU=; b=ekL7KdFacIWNCU+Z7idSzNL5LXSB0isrLFrrCBfQoBIp9HIr6hcNxzf4TM29pfhvei IAB4tfNEYTqtYmURIMYZ2HmYFiGVzhaIp6owckjsGs/RRPkdGDYXwdOgC29BDDBqql7X Csft1dSvkN3q7siWtYZ7ZrSco2mtoS0knTnMLlvBCu5HUu849q9PzLWKGRdLtJUB00n/ PKD/NGskl3JaPeBqVH5ROVBFEgy/xIB/4wrvP8YaguHq2Ag2qmggEYFEo1q3ETsxQxdU ViyPNDHlqJRUz7PasJ0uPaiR3o8tWeN2FkTCJ98GQEsAyyM3FXmceop/ZFXk6Q2ei/dm TWVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763032515; x=1763637315; 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=MO9XnnVHj/rspITKiAGHVAzlJx09tqhwIOhjHMpSEAU=; b=mbtvmLPfcobXD/zzehmAEBzYfn5mY3cUFZwvzuspGT6AOCTCztXYTBCPJy7SXkvVaz 1BSVL/ZpHuAyPHaEwcR+xFodVZQWXjpnZL9vmfPIuMXR62uZhOc7lPNYfqNO+ZffS7sj vlSuWW/FChAW1SFK5Q73H2KcV4vTIcYVovgxdCGheFzEVOuIkQm5KseHPTMcXrDbw3rg /BAoHYuJEZKuFTHtDhtYsmC6gvh68QLy84buB//29BLjpY3nnZoZvfy7PTiT0yHMy9Ay ld2nQS0RCUVLmc7zh8z7hj5uPQAUadjVCKYZpnkjRYKou0SqIeejwUsv4jqwH46QpVpo jeew== X-Forwarded-Encrypted: i=1; AJvYcCXDU+D2yw1emBeGH4jt3WZLJK3xPJI3Uv25qARy8H+RF4OGpBachVBzG+fsEDYD4pzhoCMCE2VEqwVnK14=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0cyTkv9ekwRhbKPxPAsdwx+TAnq+0sXD9ZXnPTiPMZi7l7lv9 g1v67z0YnIO1r6PXImKj/WdkT+AqUIP/Q3GCClM6mCsRn/6Pfnsg3hkb X-Gm-Gg: ASbGnculJi7/utQXebBlaqC9ODasFIxkz4RTn0u0uL05EzNtklq90t++Sbnhrluxue6 KJkxzJTjXtVry06t3cyLbXnBht1s+b06TwRzi17530bpeQC41dMqt4gp9eWT0RYjT8TBpL4HbMl vLJR/1KJGRBwNhHBgvobKahuYKsaXkpGSmfWBaUQJ5oicIwMDUq7R34uTsTrTn+QJIWW91+8II9 oaeOIQ64xxufRlkPHSQVoLVr8eRskhf50mqKGzv2s/LUPNuYc7ib5WtgUHzUjH1Au5NuixY3nFV ddMLVKIwTYY0PYC7NxMbY4zc05ancO/TQ6yCMDIpEdZNQbNXq1gJjeoKAVYmtL162Ep9QV4vJus fL16w4vZJXQdW/z5v8zdMejcsaIhJ3G7Ha0ZAdX4G+V58zTdndm82AaG4ZDt/4IBBVhMJGnGSo3 jwvO5tIvWMfgBJ X-Google-Smtp-Source: AGHT+IEXbGLWZEjRrYrXvD5qQyxHy/qVaSW5hVRb4W7YjSQHnlUr1eV81RIDEqWn4jjaLy1xF5bxNA== X-Received: by 2002:a05:600c:285:b0:477:3fcf:368c with SMTP id 5b1f17b1804b1-4778bcdb884mr18553865e9.9.1763032515217; Thu, 13 Nov 2025 03:15:15 -0800 (PST) Received: from paul-Precision-5770 ([80.12.41.69]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4778bcfa2e9sm17739825e9.12.2025.11.13.03.15.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Nov 2025 03:15:14 -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 v3 2/2] selftests/bpf: add BTF dedup tests for recursive typedef definitions Date: Thu, 13 Nov 2025 12:14:06 +0100 Message-ID: <6aa4391604ee79ee7c9805906a7340ce60ff8a0c.1763024337.git.paul.houssel@orange.com> 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 | 65 ++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/s= elftests/bpf/prog_tests/btf.c index 8a9ba4292109..054ecb6b1e9f 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -7495,6 +7495,71 @@ 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 + * [3] typedef Foo -> func() Foo + * [4] func_proto() -> Foo + */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */ + BTF_FUNC_PROTO_ENC(1, 0), /* [2] */ + BTF_TYPEDEF_ENC(NAME_NTH(1), 4), /* [3] */ + BTF_FUNC_PROTO_ENC(3, 0), /* [4] */ + 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