From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796221071; b=rK3wZgI51IjyQf31yahspDu51iaFtxnqh9K81mKXd51PS2YhWIc3OeMbznn+1+WQiC4e hSNx1dopjkZPqsyxMsIKD+eqqYYWVe8mnQOW/M4Zg/8ejt8Xicxbehs+JzrPacGgShFYu JuDteGxeFmmFAxhLwKAEszsR688y6wXEWfX1xA/FkkmXjkarjrghx510J4QEsKduZdDX8 l2juML4C4jXSxQo8nej4QcQLDhvdHQPmOOc9KbJKFekqxd72xAjxIM+Sh4vP+72x04phq ugmQ6nWjXKnmMwKuH5RCe9T1cFQl6o7Bl1AZosACWCTv2hv4he3HsWfhUn5BzyZ/GXw== 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=zAvtogCPMVK3hWHDjOKN04DStSDTlz1QNJdzeWaZPlTyDOnPjNEiX+fLxm9mE51V1ddJ 0NJ4QOaGNNXKE5lteK7VnBuxqBspQkJuL+0V0+sVc3zYlOM3tH+UFthb++pSeKXkYhumn cvyORUjZRgV8ZRxbE3volP5OjEt3DomfKiwLKl04YKCCqi0oCo1y2ceRnSqaiKi6AAKMc vPFzp0wpGrj3Iaj1N+4OZgM5J9p2JvDGGgrtHyl7AmpAVDtnZaa2BelOmo4BSFSpPeuVf SCvRmc18Nw0Y/OgQMhXnBvjR659WiWeSmwdR/jTOOAw8JLV9FQzPMSzW2+mySAjFgIQ== 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.48 Received: from mail-dl1-f48.google.com (mail-dl1-f48.google.com [74.125.82.48]) (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 B859A606A31A for ; Wed, 2 Dec 2026 14:17:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B859A606A31A 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-f48.google.com with SMTP id a92af1059eb24-1b5b910c838so3518255c88.1 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=J86SbURmsl3IRYrrpil7l7Wen59SyvJJE9GSjcqm8AjXjhcWGhEmN4Glf/OKYYlc6j uwb6qQJwm8Opww06NcnR9d/dygC2djPTMSVzuKftUVlr+w6YoUN6a5Grck4/akv4UQnF j33d4m0AH0IFSmwrLWvzhYHGyJs1bindeXCIGCksun/z5l3BKLy8u8EX7Q1dVrpeCGYh 5JS6gHWyCU6Ahyh8OFj5f/uwu/XVPzz5yZmM6Myo5DwhybQIkl0xR/rSYeqUWqbHhftw 62wZTfJ3ImrvmSICsU9kYnPnhs89Q+kvnU1xEGGCuPmpuSb5MFQItswMDLE0r16IJqNn hWFw== X-Gm-Message-State: APuU4Z/bbo0chXtSi6/24I50de6fmjagw9d+9uthNx+mHM12qQaSlosW 03hdtYsv7gjA+S5jkf3QbYORF1LNsIJfQnSESpfd1yfLKw63WSt3lFJ8StWJ0HLcdMiNDQ== X-Gm-Gg: AZFdTZdi1/tquL9wlx65X+/RTv20COXyxs121ngt1AMqJR1XEy1284iikvluBfQLVda tDMp7/o+O/n65WClz+zH8+pZjMhwI5kL3e1sx9OeORa0OyRwoiFScKaIPr/GyP8KdcfqLkx/VOI sAGNDpIJcXg3sa7DGRXKaOh45UOlmqgClsb6B7qb0ZQjWQjIyQrcLQgC8w25pPC/rDeLjTZOkTr LRkd01UbUbJ1C4GsYoQ/PF7L0e59ZKbWj06Fl1m41TKWUR5JYItlLcVnxt5aeZrkm04EYB7O+7v DSrLD3XY26RtbwYB+mznzCiyDc3z8POSpfdW5bgEx0zgks/grFMBCkDjMMyhxHCUGaU7VDhHwLa EVKikcltQPO9se6LioUnb0NUqIbCOjBx/1dfpxeE5hmT9M4JclOVhObTriEnlyPkexBe22ya8FR iPxedoh7/DDkOcgFg2cUFxZDsIwBAI4IaUlmcRR10fRMw9fZzACaSo88b4OlwqpEEJ2952WydEw 6W99WLaF8BF6wHEcCDCbz/QFekf/8C+Ih0YQiCRU1n9bSbOf5OokN1C1KcPZNbxOXHlSJ0AsMfG igbHLmQx7yUtJXhnQgP+Vz2+bG5QJoixvhVDFW/L4A7lxu2KEFb8yg== 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: bpf@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