Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp757008ybh; Sat, 18 Jul 2020 20:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVG1llUteuwu8+N2P9U4l44hv3E4sAQ4yfjc/ob2Q4xpuFqrkr8AEq38UL0zmhidVHb+BW X-Received: by 2002:a17:906:6a14:: with SMTP id o20mr15665557ejr.128.1595130795211; Sat, 18 Jul 2020 20:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595130795; cv=none; d=google.com; s=arc-20160816; b=p2uABBU7Wkhs9X8RQMZxv+/oYWFlKdCtSVc3RMpfyLu1cZa2yRC5sOOE0dF9hzdYJD ZlnhE/WS0zG8HBcaLvxqcpickmimkWuULDskWqIaiAJ9GK4ezzFJ0m638oDMcx3i8JAj j03LdTRRRxzv3BVf4iGo+ZFL+ptZKClpdd/poFVl/JkRLSiYLseJX3wWz0ch1j1iPgBc 4zebA+dxe0+i4B4SEZDI406byCsy3vNKPrCkJj4NBiV/s2aD8UTQrGyHDz/fxjWze1UP OggXHSmI91q6x1VBMim9gwVaLzKrRcUKcIHatKIXUglP2Lqs/Kn538/UMy38MmjPhsFQ IpeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=HH+LFV8ckb7MRgw6RiflBdfDfAcUZi2F+LZQ/h34g2E=; b=pHpQh3ywizJd/+T2AFXl1MhF+yJm8Z3cj9t/uH2FI4xVsEI36WgmlWEzu1awSKtDpZ frUuzQRa//Ij8ZDLmfD3lsKTbsByLvEkPxnLSPFVgVFYdBSxUGNyjwav+H4xx+QEQwDs Fi1MUEiKO1rqLx9AYojjtX7X84P9lQpfpCHpjiZbd3zI1BjKlytWPlTE1fAQ0NGGtRdB PuoRKOjBNrh/n8qkvzRGNnrqalH0v+ChCfssBJefOnGd1GB4GiAkhKPOC0Lf3v6H0hSl XcEDsghQ5jLbjnFWCvuWOPip++wnAzqtAXiW/2EGngOpBfzLCv0nUO/e4Vv4jrZKbv6I ZBIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G6zbQL2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg2si8756229edb.326.2020.07.18.20.52.51; Sat, 18 Jul 2020 20:53:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G6zbQL2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726512AbgGSDwj (ORCPT + 99 others); Sat, 18 Jul 2020 23:52:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbgGSDwj (ORCPT ); Sat, 18 Jul 2020 23:52:39 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC6C4C0619D2; Sat, 18 Jul 2020 20:52:38 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id di5so5980171qvb.11; Sat, 18 Jul 2020 20:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HH+LFV8ckb7MRgw6RiflBdfDfAcUZi2F+LZQ/h34g2E=; b=G6zbQL2BdKZN9zkB9eB/o8yJ1EIuO+inpr88GMjZB2FDXt5swCzdtRzjJsONVnjI1Z /uaXMPqLb+Sa1/IT3S70pz2QEcc3khjTDHzwZeDNzvR2czU6SuTlLDP1A+gkj4q/Y4dn KQ7JRn9Z2iLYrMLl5mfkpR/KKja9gZDK3PgmttJ6RK5tNxMlB3bwIyO4TUGxHxHctlzO AqVMdbDeeCPJ6NJWNnD7gybR+cj45qigTVKspkuA/scFO/NorDHf7zPI3uUtoDFmUOx5 1arRJxN3lo+IKOlENRwknFt4eip52AQSPK/7IHJfYkdZB/hNUjHRZdZiy0k1P8kd5w05 r5GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HH+LFV8ckb7MRgw6RiflBdfDfAcUZi2F+LZQ/h34g2E=; b=OGJ4xzw7InvqDaZxJzKU0o44ZsnAqYH1tx1kbdMJgUh4JIQKJG+Ur5haOP4Y1qmz8w ZJCVF41CdXSGEmt+E6XXZxaed04SgrIMcsD03IDeMUP7fmNRi4TZGm8tEvFTvSM/VNg5 Cf8qVzDCMPFTQMCHfjq1J0GTUk69k46zIk5Zdsf2U4vbSs4fpWazNcr0WeiWQrHah0I7 KOzVpwpEXKgRxnjco+V0GjTVxeUblaMq90TEt7lZ2VDStr6zgrrr09PkyJEoG0GBfc0+ 2ReaD8yVElRhGIQVTZ2TYF1r44b2mL7gl4cbZcBzmNinPW56je1i72Tq5vSvy2kkr1dX +aXg== X-Gm-Message-State: AOAM531KyMkLDdOgNyAOdXNqhr6b82Pm20N76aNVyjNM1i0yLnQ8tXXo 2mCJsK6OA89aED2DNJGwXiQHHOFiDjzMG46OieY= X-Received: by 2002:a05:6214:946:: with SMTP id dn6mr15722853qvb.224.1595130758033; Sat, 18 Jul 2020 20:52:38 -0700 (PDT) MIME-Version: 1.0 References: <20200717072319.101302-1-irogers@google.com> In-Reply-To: <20200717072319.101302-1-irogers@google.com> From: Andrii Nakryiko Date: Sat, 18 Jul 2020 20:52:27 -0700 Message-ID: Subject: Re: [PATCH] libbpf bpf_helpers: Use __builtin_offsetof for offsetof if available To: Ian Rogers Cc: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Networking , bpf , open list , Stanislav Fomichev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 12:24 AM Ian Rogers wrote: > > The non-builtin route for offsetof has a dependency on size_t from > stdlib.h/stdint.h that is undeclared and may break targets. > The offsetof macro in bpf_helpers may disable the same macro in other > headers that have a #ifdef offsetof guard. Rather than add additional > dependencies improve the offsetof macro declared here to use the > builtin if available. > > Signed-off-by: Ian Rogers > --- > tools/lib/bpf/bpf_helpers.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h > index a510d8ed716f..ed2ac74fc515 100644 > --- a/tools/lib/bpf/bpf_helpers.h > +++ b/tools/lib/bpf/bpf_helpers.h > @@ -40,8 +40,12 @@ > * Helper macro to manipulate data structures > */ > #ifndef offsetof > +#if __has_builtin(__builtin_offsetof) > +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) > +#else > #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) Let's either always use __builtin_offsetof (as Yonghong mentioned, it should always be available on relevant LLVM versions). Or instead of size_t, just cast to (unsigned long), I think it will have absolutely the same effect as size_t casting? > #endif > +#endif > #ifndef container_of > #define container_of(ptr, type, member) \ > ({ \ > -- > 2.28.0.rc0.105.gf9edc3c819-goog >