From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221071; b=WaAdyigaTtsWzhGfJCIDIuBytPoBVHsB8d/hldbwfGDNV5YYGpO78DXrZv5h1y5KLSI9 5WtFgfBa4sJtCwl5zMzhRWlqaJTsw3kNRBICOZbK/qElJHjxN+JxlsxiC7uATG17TcULM FZGifbO6cZH1ZtaZ1P7rQUQsUsYchGL40EqPR5KMeIDNxL8S9eN7mv9MQQCb9v73eXcNe fRAKuA7465G++IJWw/TcOthbNEBSNjSv34irMp4k9S58rvnzPrIaEFVAiM4Icbt9MhyLo dOQymaRqj6JEB5RfTgQmt9X1y8DLthuZ10F7CAFZP5r7ZGV+o9oUR76m5zFF8Tk71Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221071; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=RHlkOLunfdambwUgQjBECxIxxgCcomIhPh24LKitDXs=; b=SrrPKGDDbXyCV3pwf334s+N0agQkVZaOR5mF6QbuIUT4iOhuDXZSikNR5HZj89DLjA2F auitriQMGOpltq0A2Xx2eQZi6pTMzbp1jFrnICgA/2EiqZxxjcbmryOw55ZgAPWL+/mA4 8qshMO8tX1nUxCf4qy1M+4sroEU36ou/aVRU7ImpZDMm6W2N8UlGq2xW6uX9Fpleh2YTl lLvj/lUdmfU++KC/oJ6MGGNqKxgrwiGNY8JLRGC5aP7FUH/a0H1k0vOiAtU9O7X3LI/8d wgz3obul0pX1Dj312ldHnqlEd45rlPAbB+Gf1d/+dKpeIKqyaXTKI1Y4OeBlG89tcNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="VGk/CCd+"; arc=none smtp.remote-ip=74.125.82.46 Received: from mail-dl1-f46.google.com (mail-dl1-f46.google.com [74.125.82.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA0D7606A32C for ; Wed, 2 Dec 2026 14:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA0D7606A32C 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.a=rsa-sha256 header.s=20260707 header.b=VGk/CCd+ Received: by mail-dl1-f46.google.com with SMTP id a92af1059eb24-1a3c08d6928so20195900c88.0 for ; Wed, 02 Dec 2026 06:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796221070; x=1796825870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=RHlkOLunfdambwUgQjBECxIxxgCcomIhPh24LKitDXs=; b=VGk/CCd+LtKhQVN0/pLwLxurniO5we6IBD3H78oG+Sh66KkJxDOu6HgFzA47g15LpP VpMxV6ayqGlBtLjMAHl7n76BV/0A80ozW3cfL/yd8/zvTeN0NIBIc9xdi683VA3j0INq Ov21dw0XJ3Z+L8bxKeu8zWKihdOtlU52FIwgpE7DgPxJAzKz9wo3JDNhxInDo7/9qwaD nnXGK0GdHCq4YAqyGkqiojxTqb5WUYu20J0lYbn179LcYLZFlSGtCM0kDXYgcM2ZANmc uRl+4Wq8lqXkTd3jtCTAECr5GeqB9wg2JmqpHRHY8TZaDPquJslJQfJt43zRWY4/Vt6d EVWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796221070; x=1796825870; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RHlkOLunfdambwUgQjBECxIxxgCcomIhPh24LKitDXs=; b=nfuFUfeGhoKb1jUKztklvbjqbn25r4CYVVNpTCRkz2FoJgt5nTJtKmvJNZ35DnmkjT PF3upcQC8RcpvtHJoW0k4uHcBQuUB02q3QB30rEv0NLEb8XXzlUR1gWfiC90ggcMN6aS f+ockwLGi4hqDyURyBStnbCDSk+n/McHO560M2DlDKHrZjZikvuD6oe88tgMsQfzHkcw cXQmw26NDJOu5EePhXuCniSHRfZtHIPJoUZnjg3qBAJV96J0sZjTsTX/H3H4Wp5800mD GbroJjJ1KpPYxJipI7bCtEFZFoNTPquiKZyphJFeShUMKvW1GbXNvPN/Olw5ljl184Ao /z8Q== X-Gm-Message-State: APuU4Z9k3c1uy7XpupTJ8boIHu7NDellbqwH0dmwq33FuYisr61e4H8Z Zl2geRiMW75fhv41MZBV/vMM08YrX/kRvXHaPyJ9qTGjiFMIQKPSylIK X-Gm-Gg: AZFdTZfznEaxCw8oVcC5W9fFMYdY7llsm3ZMwiRImwdI6dtEl3I/Yt0oTfxTqfMSSYW 6L5GuYGbBIQG7H6okxd+NdD1W2qLJExuWsbMC/qYsMF1qQvBW82cyPO+xtAmUBYSvirzbG7hqXY gjKwiBRUn21AeRsGxVoxJ3y4ra7riEu+niOgh0I0K9OMrpoKx9fX1HZJmsSuVJf73y8DzSMN2yw Ar9JK1gaR8o6PwReNqk1v62CkkpHBQ1obBpexR8ESx4E5QTLtE4ovSTq0DC6EALN9lr0jY+N1g3 iZYDNi2PtI6TyRp7wznUe+dztrB9LKceDmoiT+VEWtQhtiLzIpmjJDSN6Bkl+CNTkP1qVrrq1Gu no74jam/njLy85fpcwW/ZSj1QzYcMt8ImUpvbnAAgXRTlaVloRfvdLJmJmdkjBDJTTnQf9XPute FapZQAv0ygiZM17NmiPfFxx5LDe0yYwgxQD60570woWPsGANa+8vMn1luAp8glSEC2S3YMbXHLo iYwnAv/ewZWFxpkacR6VjVnSVqZDNWnofBUPvgKekloVWLSHTgFxOtDQ0uBx0UQ78WNnw2DbQ/l fUGAFZtFP4NcwgKqlhq7UrDEc6WuyF2d8/g7r1i7etMH1VXjV8GZnQ== X-Received: by 2002:a05:7022:7f0c:b0:1b5:c7ab:b57 with SMTP id a92af1059eb24-1b5c7ab0c95mr1635878c88.17.1796221069675; Wed, 02 Dec 2026 06:17:49 -0800 (PST) Received: from dreamer-R7000P.localdomain ([240c:c983:1:6e93:5c53:f60e:627c:f2ca]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556829d31sm153286920c88.9.2026.12.02.06.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 06:17:49 -0800 (PST) From: Haowen Deng To: bpf@vger.kernel.org Cc: linux-kselftest@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Shuah Khan , =?UTF-8?q?Daniel=20M=C3=BCller?= Subject: [PATCH bpf] libbpf: Ignore integer type names in CO-RE type matching Date: Wed, 2 Dec 2026 22:16:08 +0800 Message-ID: <20261202141620.366-1-denghaowen59@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit GCC and Clang can encode the same integer type under different BTF names. For example, a function parameter declared as unsigned short can appear as "short unsigned int" in GCC BTF and "unsigned short" in Clang BTF. The name comparison in __bpf_core_types_match() rejects these parameters before reaching the integer comparison. Skip the integer name comparison and use the existing size and signedness checks. Add a BPF selftest that checks differently named integer parameters and verifies that a change in size or signedness still prevents a match. The new test failed with the original libbpf and passed with the fix when linked to each version in a standalone runner. On an x86-64 QEMU guest running the patched bpf tree, test_progs -t core_reloc,core_reloc_btfgen reported 3 tests and 159 subtests passed, 16 skipped, and no failures. Codex assisted with investigating the reported mismatch, implementing the fix, and writing and running the regression test. Fixes: ec6209c8d42f ("bpf, libbpf: Add type match support") Closes: https://github.com/libbpf/libbpf/issues/995 Signed-off-by: Haowen Deng --- tools/lib/bpf/relo_core.c | 14 ++++-- .../selftests/bpf/prog_tests/core_reloc.c | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c index 2672623a4..9d81688bb 100644 --- a/tools/lib/bpf/relo_core.c +++ b/tools/lib/bpf/relo_core.c @@ -1582,16 +1582,20 @@ int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const st if (!local_t || !targ_t) return -EINVAL; - /* While the name check happens after typedefs are skipped, root-level + local_k = btf_kind(local_t); + targ_k = btf_kind(targ_t); + + /* Integer type names can differ by compiler. Match them by size and + * signedness below. + * + * While the name check happens after typedefs are skipped, root-level * typedefs would still be name-matched as that's the contract with * callers. */ - if (!bpf_core_names_match(local_btf, local_t->name_off, targ_btf, targ_t->name_off)) + if (local_k != BTF_KIND_INT && + !bpf_core_names_match(local_btf, local_t->name_off, targ_btf, targ_t->name_off)) return 0; - local_k = btf_kind(local_t); - targ_k = btf_kind(targ_t); - switch (local_k) { case BTF_KIND_UNKN: return local_k == targ_k; diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/testing/selftests/bpf/prog_tests/core_reloc.c index 80432c465..a6690a359 100644 --- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c @@ -7,6 +7,7 @@ #include #include #include +#include "bpf/relo_core.h" #include "bpftool_helpers.h" static int duration = 0; @@ -1147,8 +1148,54 @@ static void run_core_reloc_tests(bool use_btfgen) } } +static void test_integer_type_names(void) +{ + static const struct { + const char *label; + int size; + int encoding; + int expected; + } cases[] = { + { "same_size_and_signedness", 2, 0, 1 }, + { "different_size", 4, 0, 0 }, + { "different_signedness", 2, BTF_INT_SIGNED, 0 }, + }; + int i, local_int, local_proto, targ_int, targ_proto; + struct btf *btf; + + btf = btf__new_empty(); + if (!ASSERT_OK_PTR(btf, "btf_new")) + return; + + local_int = btf__add_int(btf, "unsigned short", 2, 0); + if (!ASSERT_GT(local_int, 0, "local_int")) + goto out; + local_proto = btf__add_func_proto(btf, 0); + if (!ASSERT_GT(local_proto, 0, "local_proto") || + !ASSERT_OK(btf__add_func_param(btf, "mode", local_int), "local_param")) + goto out; + + for (i = 0; i < ARRAY_SIZE(cases); i++) { + targ_int = btf__add_int(btf, "short unsigned int", cases[i].size, + cases[i].encoding); + if (!ASSERT_GT(targ_int, 0, "targ_int")) + goto out; + targ_proto = btf__add_func_proto(btf, 0); + if (!ASSERT_GT(targ_proto, 0, "targ_proto") || + !ASSERT_OK(btf__add_func_param(btf, "mode", targ_int), "targ_param")) + goto out; + + ASSERT_EQ(bpf_core_types_match(btf, local_proto, btf, targ_proto), + cases[i].expected, cases[i].label); + } +out: + btf__free(btf); +} + void test_core_reloc(void) { + if (test__start_subtest("integer_type_names")) + test_integer_type_names(); run_core_reloc_tests(false); } base-commit: 12e84ae1e0bd1f221eb804ecfa2a1e2105270015 -- 2.43.0