Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2634660iof; Wed, 8 Jun 2022 08:55:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVMNXWErh85MxlliPKjVdn1CCFVZpCw1Gax498YDYkeKpn9U7ZzsrUsTuACsR9vzyH5tb3 X-Received: by 2002:a17:90b:388d:b0:1e6:a0a4:c80f with SMTP id mu13-20020a17090b388d00b001e6a0a4c80fmr33696584pjb.39.1654703729699; Wed, 08 Jun 2022 08:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654703729; cv=none; d=google.com; s=arc-20160816; b=G4SMg0jGfaKb06wXxWaEN3RV4qLis8ZlsSJaIxLSOE2rF88DeOmr+YpbedPw8WAtrm oRYwbI8EOAhimkmoyvrFv0rHC+LjWonn3C9F8c3bRr8jXJLrIt4FKqGj5rOiXUHmWxEF fERl51584FwcEx67OTfh4w8L2lgY0NcXQ3efZG+lhrChMlJTIAZXyCu1BDfKAqQWPLbS ri0obd37YBcXn+BEQOS/ZcbCYLRy8eh37Kn3GRIHBubfDVvvN/E3Wo5aGQXGhpJn7etp 9P2AvmW+yLuY4kzrEEkk6pb8qzQsgZLiOTOwmQ1eEekAG+HrhBi17AxSb6fzN/5AvuH3 AkKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=qlofdKK2rIvQQ4BR3qq38NjjUgxo+B1vfHdfevMzwXk=; b=egLnsLW4SgwqbwtQcvLlGO0UcFSs/5ZIWKw0O56FJUj13y0DIqzuTXGTjwRTX569oQ Qfi5Hlgv+jgVmgX9t9S8r0PSrnfjNuD5ESDMljRk5DKHyThhV/cJzmGWdJqz/3DspHZ2 oPf7smJoZGnttFS2gmJx7fVoaVyrcz9szuja2rloRTYFYJZ0UbeTHOobUiebIX47zX08 Ue/bIREHJlvbdFhGf6GW9P7RKZfFnZp6pKcSjMKyfiALHnTKY6pQhZ592yXYYju2l1O3 igMgkfkJlPjAKYXwP3OxjdlqdFQ926xCqHua1q0M70X+Eu+l3TnSzAu5iwczxQ8V4ANB cWMA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i185-20020a6387c2000000b003fe15ee463dsi5192709pge.436.2022.06.08.08.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 08:55:29 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 85E441D0E0; Wed, 8 Jun 2022 08:27:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244238AbiFHP0e (ORCPT + 99 others); Wed, 8 Jun 2022 11:26:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244543AbiFHP0K (ORCPT ); Wed, 8 Jun 2022 11:26:10 -0400 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82FAB13F439; Wed, 8 Jun 2022 08:22:39 -0700 (PDT) Received: from sslproxy05.your-server.de ([78.46.172.2]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1nyxW0-00004u-8F; Wed, 08 Jun 2022 17:22:36 +0200 Received: from [85.1.206.226] (helo=linux.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyxVz-000O7y-Rn; Wed, 08 Jun 2022 17:22:35 +0200 Subject: Re: [PATCH v2 1/1] libbpf: replace typeof with __typeof__ To: James Hilliard Cc: bpf , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "open list:BPF (Safe dynamic programs and tools)" , open list References: <20220608064004.1493239-1-james.hilliard1@gmail.com> From: Daniel Borkmann Message-ID: <3230febd-d346-8348-76e7-b9548f01cb87@iogearbox.net> Date: Wed, 8 Jun 2022 17:22:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.6/26566/Wed Jun 8 10:05:45 2022) X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 6/8/22 3:04 PM, James Hilliard wrote: > On Wed, Jun 8, 2022 at 6:50 AM Daniel Borkmann wrote: >> On 6/8/22 8:40 AM, James Hilliard wrote: >>> It seems the gcc preprocessor breaks when typeof is used with >>> macros. >>> >>> Fixes errors like: >>> error: expected identifier or '(' before '#pragma' >>> 106 | SEC("cgroup/bind6") >>> | ^~~ >>> >>> error: expected '=', ',', ';', 'asm' or '__attribute__' before '#pragma' >>> 114 | char _license[] SEC("license") = "GPL"; >>> | ^~~ >>> >>> Signed-off-by: James Hilliard >>> --- >>> Changes v1 -> v2: >>> - replace typeof with __typeof__ instead of changing pragma macros >>> --- >>> tools/lib/bpf/bpf_core_read.h | 16 ++++++++-------- >>> tools/lib/bpf/bpf_helpers.h | 4 ++-- >>> tools/lib/bpf/bpf_tracing.h | 24 ++++++++++++------------ >>> tools/lib/bpf/btf.h | 4 ++-- >>> tools/lib/bpf/libbpf_internal.h | 6 +++--- >>> tools/lib/bpf/usdt.bpf.h | 6 +++--- >>> tools/lib/bpf/xsk.h | 12 ++++++------ >>> 7 files changed, 36 insertions(+), 36 deletions(-) >>> >>> diff --git a/tools/lib/bpf/bpf_core_read.h b/tools/lib/bpf/bpf_core_read.h >>> index fd48b1ff59ca..d3a88721c9e7 100644 >>> --- a/tools/lib/bpf/bpf_core_read.h >>> +++ b/tools/lib/bpf/bpf_core_read.h >>> @@ -111,7 +111,7 @@ enum bpf_enum_value_kind { >>> }) >>> >>> #define ___bpf_field_ref1(field) (field) >>> -#define ___bpf_field_ref2(type, field) (((typeof(type) *)0)->field) >>> +#define ___bpf_field_ref2(type, field) (((__typeof__(type) *)0)->field) >>> #define ___bpf_field_ref(args...) \ >>> ___bpf_apply(___bpf_field_ref, ___bpf_narg(args))(args) >>> >> >> Can't we just add the below? >> >> #ifndef typeof >> # define typeof __typeof__ >> #endif > > From what I can tell it's not actually missing, but rather is > preprocessed differently > as the errors seem to be macro related. Are you saying that the above suggestion wouldn't work? Do you have some more details? I'm mainly wondering if there's a way where we could prevent letting typeof() usage slip through in future given from kernel side people are used to it. > I did also find this change which seems related: > https://github.com/torvalds/linux/commit/8faf7fc597d59b142af41ddd4a2d59485f75f88a > >> >> Thanks, >> Daniel