From nobody Tue May 7 11:20:40 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F32BBC433F5 for ; Mon, 23 May 2022 10:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234120AbiEWKbh (ORCPT ); Mon, 23 May 2022 06:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234204AbiEWKbW (ORCPT ); Mon, 23 May 2022 06:31:22 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3BB9D2C1; Mon, 23 May 2022 03:31:21 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ECA6511FB; Mon, 23 May 2022 03:31:20 -0700 (PDT) Received: from e126130.arm.com (unknown [10.57.81.119]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 51E7B3F73D; Mon, 23 May 2022 03:31:17 -0700 (PDT) From: Douglas RAILLARD To: bpf@vger.kernel.org Cc: beata.michalska@arm.com, Douglas Raillard , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Nathan Chancellor , Nick Desaulniers , Tom Rix , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2] libbpf: Fix determine_ptr_size() guessing Date: Mon, 23 May 2022 11:29:55 +0100 Message-Id: <20220523102955.43844-1-douglas.raillard@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Douglas Raillard One strategy employed by libbpf to guess the pointer size is by finding the size of "unsigned long" type. This is achieved by looking for a type of with the expected name and checking its size. Unfortunately, the C syntax is friendlier to humans than to computers as there is some variety in how such a type can be named. Specifically, gcc and clang do not use the same name in debug info. Lookup all the names for such a type so that libbpf can hope to find the information it wants. Signed-off-by: Douglas Raillard Acked-by: Yonghong Song --- tools/lib/bpf/btf.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) CHANGELOG v2: * Added missing case for "long" diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 1383e26c5d1f..ab92b3bc2724 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -489,8 +489,19 @@ static int determine_ptr_size(const struct btf *btf) if (!name) continue; =20 - if (strcmp(name, "long int") =3D=3D 0 || - strcmp(name, "long unsigned int") =3D=3D 0) { + if ( + strcmp(name, "long") =3D=3D 0 || + strcmp(name, "long int") =3D=3D 0 || + strcmp(name, "int long") =3D=3D 0 || + strcmp(name, "unsigned long") =3D=3D 0 || + strcmp(name, "long unsigned") =3D=3D 0 || + strcmp(name, "unsigned long int") =3D=3D 0 || + strcmp(name, "unsigned int long") =3D=3D 0 || + strcmp(name, "long unsigned int") =3D=3D 0 || + strcmp(name, "long int unsigned") =3D=3D 0 || + strcmp(name, "int unsigned long") =3D=3D 0 || + strcmp(name, "int long unsigned") =3D=3D 0 + ) { if (t->size !=3D 4 && t->size !=3D 8) continue; return t->size; --=20 2.25.1