Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2431830ioo; Mon, 23 May 2022 19:23:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw15XpBTy9Xjaxrt19N68G2tPUefClXoLjTZ8q7L5/R/hUPxf/CAG8a2yig5ZKo45ej6oJK X-Received: by 2002:a17:907:7396:b0:6fe:9a92:6c2b with SMTP id er22-20020a170907739600b006fe9a926c2bmr20683710ejc.113.1653359031583; Mon, 23 May 2022 19:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653359031; cv=none; d=google.com; s=arc-20160816; b=vLAHOzDQ295m+n+gLEDp4LRuth8JAF2hquAabuxtfkZ9OWBI//U614SYusAGBcVpog cIqLHkN5PU6tmFVEc13zvBHCTICBENg6cLp1gttwV/y6Srd28Zd9b3HQa7PquUUj43SJ G+k147jldY34lwNxPmOET9CxikfvKas2UbAh40MlecjQMfRuYKj0R/A5M/VdtWKJeiGo l9pe41BcVmTkub0bDC6Y5cJnOYr37irfb5OKqp/j2Qz9nMBclqdohPtf6glEGP+uBsuE WAdv4AjcPFF9+hKeFArKcow0WR0tU5/KvDhsbEzNaX0g83KkPlmE0LOfNtdB0N+bxsAC 7y1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XSlHjnTpNeJkBXf9g/KNtqsnSqM2X0+xdvEyIgTr6JQ=; b=BgwBQ3v9roSsp8JqoUAfyjuw9VIzgZpkR4hR+DXHuzOi5/b6Vo55nG7rHwPDdQlZMv T3reY52wjfBM/8HdLbRWqzhsXJSQaYJJlN/GM26p8bLZIfyc+P/GBIuodtX23ncTPwhl opx/a62U7eDOC2HooUbEy80aQZ9z/xkEz6xo9P5LtMixvVyWbfEk1DUN10BKcddywDPF M3/8SQ5Ch09ptXCSWL2g6/ENEJEkeNraxiKe/Ho2mSS8FNJ6lOq5ZJCydFH2mgQ1pSSE pEUQFGTDzG62yZeCK7IQRIxCWlJmSe8z2pz/Y9tfT700dOcCT7N18OmDaWLenrQue6Vs tjeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EWwnTLM1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg18-20020a170907a41200b006f407a163cesi17964641ejc.522.2022.05.23.19.23.25; Mon, 23 May 2022 19:23:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EWwnTLM1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbiEWWHY (ORCPT + 99 others); Mon, 23 May 2022 18:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiEWWHW (ORCPT ); Mon, 23 May 2022 18:07:22 -0400 Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB77B38BF2; Mon, 23 May 2022 15:07:20 -0700 (PDT) Received: by mail-vs1-xe32.google.com with SMTP id b7so16483939vsq.1; Mon, 23 May 2022 15:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XSlHjnTpNeJkBXf9g/KNtqsnSqM2X0+xdvEyIgTr6JQ=; b=EWwnTLM16H2GID9+UMX+0nE+pP3lqI2zGGAdpDUwji1ya5dw7SMD1eY9VBTTyzZ97p pnByUqrOiDK2UWSurC7DobSo4CmD+ZAvHtc04GRJIsGw0fSO+eLor7K60PCvjH5JEVyS e/eH4dT5yygEZpGlkm6i0xZPBRNG+Bw7w0NVBq8AcoYzA9Xhu2CCIxlyaXrckX+jhUE2 zy0bMaodYI5pg8r4ys5ei2CpT7VSiYqgQjcmbmH/Tje8evG8fCsaD2DZ1WPXq+5aGyjR 8BpBP/zt3jvcyEp80mLe/oV8xS1aBQ8q6qqiPSdBWfwlFIc7IpG714GItGipaHKVGzvo 4cEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XSlHjnTpNeJkBXf9g/KNtqsnSqM2X0+xdvEyIgTr6JQ=; b=YFFE/PyYILo4LQ9lw4dENDg8wPPNEAe+rXSPb6ldXkj9EutMboYNoDxm1oCaV+tYLU UdYa0oqe8djUlXv0B/8Pq9FG4EV32y5Jx5c5jM8DFNvff6YqoAmP2HdpnjhzXFlgBUbY 5kvq6xPoJ20EY/igavjubXYHZRF0ucDwkj9IpOk08sOQmAradClDUA1h5yOysDX/kldB /28hjqMJhn8Nt1PF20iAQ68wtIFL6SImQg5h3r9C9O8uVBI+ganf1gI1MJTBpYdpvGFB Dj7ETNfbc+LUJmXnLdhDoL0xVDnJGhQJLLM4UKNYVMZvDiZ5um+PO+LgPhfQgQ6TOZCt if0w== X-Gm-Message-State: AOAM533flFvpBr8awJ0XlfVmmdtY9uN0WfE8JihmYsUgOlbKX81MVjTq 3K40+9EOJSa9RrpUpWWv94ADRnYyKBGtOa8qk5k= X-Received: by 2002:a05:6102:370a:b0:333:c0e7:77e8 with SMTP id s10-20020a056102370a00b00333c0e777e8mr9914433vst.54.1653343639818; Mon, 23 May 2022 15:07:19 -0700 (PDT) MIME-Version: 1.0 References: <20220523102955.43844-1-douglas.raillard@arm.com> <4268b7c5-458e-32cc-36c4-79058be0480e@iogearbox.net> In-Reply-To: <4268b7c5-458e-32cc-36c4-79058be0480e@iogearbox.net> From: Andrii Nakryiko Date: Mon, 23 May 2022 15:07:08 -0700 Message-ID: Subject: Re: [PATCH v2] libbpf: Fix determine_ptr_size() guessing To: Daniel Borkmann Cc: Douglas RAILLARD , bpf , beata.michalska@arm.com, Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Nathan Chancellor , Nick Desaulniers , Tom Rix , Networking , open list , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2022 at 2:00 PM Daniel Borkmann wrote: > > On 5/23/22 12:29 PM, Douglas RAILLARD wrote: > > 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. > > Could you elaborate for the commit msg what both emit differently? > > > Lookup all the names for such a type so that libbpf can hope to find the > > information it wants. > > > > Signed-off-by: Douglas Raillard > > --- > > 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; > > > > - if (strcmp(name, "long int") == 0 || > > - strcmp(name, "long unsigned int") == 0) { > > + if ( > > + strcmp(name, "long") == 0 || > > + strcmp(name, "long int") == 0 || > > + strcmp(name, "int long") == 0 || > > + strcmp(name, "unsigned long") == 0 || > > + strcmp(name, "long unsigned") == 0 || > > + strcmp(name, "unsigned long int") == 0 || > > + strcmp(name, "unsigned int long") == 0 || > > + strcmp(name, "long unsigned int") == 0 || > > + strcmp(name, "long int unsigned") == 0 || > > + strcmp(name, "int unsigned long") == 0 || > > + strcmp(name, "int long unsigned") == 0 > > + ) { > > I was wondering whether strstr(3) or regexec(3) would be better, but then it's regexec() seems like an overkill, but strstr() won't work because we'll mistakingly find "long long". Splitting by space and sorting also feels like going a bit too far. So I guess let's stick to this exhaustive comparison approach. But Douglas, can you please a table instead of writing out all those strcmp(): const char *long_aliases[] = { "long", "long int", ... } for (i = 0; i < ARRAY_SIZE(long_aliases); i++) { ... } ? > probably not worth it and having the different combinations spelled out is > probably still better. Pls make sure though to stick to kernel coding convention > (similar alignment around strcmp() as the lines you remove). > > > if (t->size != 4 && t->size != 8) > > continue; > > return t->size; > > > > Thanks, > Daniel