Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1514602ybh; Sun, 19 Jul 2020 23:24:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRkQSUh0OVB3+FBefjOFdWn5bbJvXcTS/uxr1eQGIZ5U51vNbf67pLEgFoztWyRIxd8XP5 X-Received: by 2002:a17:906:e0c7:: with SMTP id gl7mr18413642ejb.264.1595226276712; Sun, 19 Jul 2020 23:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595226276; cv=none; d=google.com; s=arc-20160816; b=l/HZLXKdCYbWVkJEKuU7XPXVu+wnSi97bSOfW3o2B7+6YPCgQ1bqu+Ky9sE3eF0e9k QLd6pVCsi3qvOCWdqgw++ZXEEWymL/lcWj1S11mhfjxPVWEEmaPFFZNQffVIrfMkP/iW g+fT2z796Fe1iKxa+tVeth9pLVtqbBBMNxKXKyXo2asccRsb8jZkiOI+yRhrc3Zh5F/Q ZcGkU1VyWxjEk5uEf8H6YvCufdiP87Lkv5Vg9scRUJ3zkpBoDeBmfWkcOHA6ZPjMqCTR K15Dn/IgwejYo3mZb88Oa3fzLd2/VWBaDFqPr9Gj0jX3H4EiufK3RSP0VPohfIPn8QT4 AAZg== 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=unEM6mZzBiwmeXXw1zFkZp6UX4pprtiHLNJYCNVdhVo=; b=vqwu8BAzC7mSnR2lKzX7dRWWWvogvsCZQZHJK3jIW4h5oS5nhX1BUubfILRmyqECbm XngzEMVLTpgkcktD5HpdqFA7z2AtprlzVDn/g5lqPA0ww2fcFfCdZpTrBOtqaTsrbjLP Nm+Lb06tAo6mwuTd9Zuz9vYtedJ+ZaBhomKlv3vuoHbvRvgJaoKror/OKr3VcjclhxzO hmb9yD2S9OHKD9lFundqSD3klmQ5uubGK2FveKBGimTaA7lInT2Nhg2873R8gcengIJ+ JL5XecnkuMXZyzXxETArAlEpUvbL+A84QiNunjDytlTvIPSCm/Ghmm0mpzRfEZ54KK2K gpog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JJ6FLlYs; 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 dp9si10740063ejc.352.2020.07.19.23.24.13; Sun, 19 Jul 2020 23:24:36 -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=JJ6FLlYs; 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 S1726801AbgGTGVt (ORCPT + 99 others); Mon, 20 Jul 2020 02:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgGTGVt (ORCPT ); Mon, 20 Jul 2020 02:21:49 -0400 Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1876EC0619D2; Sun, 19 Jul 2020 23:21:49 -0700 (PDT) Received: by mail-qt1-x843.google.com with SMTP id b25so12182573qto.2; Sun, 19 Jul 2020 23:21:49 -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=unEM6mZzBiwmeXXw1zFkZp6UX4pprtiHLNJYCNVdhVo=; b=JJ6FLlYsknqs0cjaFkw+zN+v/a2bj0HXVs9jYEf7a8xNJRyyu1HMg2UJBxOJXZGiZf MSsaukJpXZ2r3u7mLykUCqDKTaXp4YvjIaW8wVUaScuBgrZXT9cT8Uoh6tEbTj742VpB gJ4VyCwNeQ/9MzfKxGzh/ZimeAYvZlK37j7kvljUHBh8kD542Pau3LYWp6lqtQn0rbCY CgwkKXGawPMI0GCpBIF5wLSvHO/IrAHZdV+ZLvPojpbVanr8VA1dEHen6szm+dbbSDRv mufslaPF1GqcUe7TXWIVU0MhRWbHKngdFdgO0/ZqWM/2z8IRhwyUaMvCw/c15I2qooPV FQoA== 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=unEM6mZzBiwmeXXw1zFkZp6UX4pprtiHLNJYCNVdhVo=; b=WqsRHmf2Om/zmRRvWWlWvqHNEIcS3Xr0WMHCIEltMRkHtRrLnTFatwNBHvs7M4uAat GmXqf5/BVZwmn5DWOpfX2mQfqlgr1SKnt2m80BsA2DRwQc1inv3UggBvFry+2iYi1PT1 1K3QM84/L3vHhPimp4VplTT8ckHDfB3fdZWnQFLgJfks8PSgyvy1aBIkbGpPDOIVNpLu smB1hUkwQYoUsn+QxsWgS80oE0AhSKAvnhxb/2Ghtpao/zJm67tn5FbJhyAoLSA9Abze mGm5pk9GwgkT+EliBIzTAIcFooxA1xE0KGQSfcAwT2L76g/fXDtf/1EfdF5TtZGcSSgG AFpw== X-Gm-Message-State: AOAM533OivI5JQuH14bRLl2485PomSXJ2Y7I3k8uEf95Wkkx7Xd6n7Y5 mwSccKtc5YFZYYqI6YHr+bIzJR6oekQhxoAsmB0= X-Received: by 2002:ac8:19c4:: with SMTP id s4mr22463589qtk.117.1595226108291; Sun, 19 Jul 2020 23:21:48 -0700 (PDT) MIME-Version: 1.0 References: <20200720061741.1514673-1-irogers@google.com> In-Reply-To: <20200720061741.1514673-1-irogers@google.com> From: Andrii Nakryiko Date: Sun, 19 Jul 2020 23:21:37 -0700 Message-ID: Subject: Re: [PATCH v2] libbpf bpf_helpers: Use __builtin_offsetof for offsetof 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 Sun, Jul 19, 2020 at 11:18 PM 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 that is available since llvm 3.7 (the first with a BPF backend). > > Signed-off-by: Ian Rogers > --- Acked-by: Andrii Nakryiko > tools/lib/bpf/bpf_helpers.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h > index a510d8ed716f..bc14db706b88 100644 > --- a/tools/lib/bpf/bpf_helpers.h > +++ b/tools/lib/bpf/bpf_helpers.h > @@ -40,7 +40,7 @@ > * Helper macro to manipulate data structures > */ > #ifndef offsetof > -#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) > +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) > #endif > #ifndef container_of > #define container_of(ptr, type, member) \ > -- > 2.28.0.rc0.105.gf9edc3c819-goog >