Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1780290ybh; Fri, 17 Jul 2020 00:26:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2jhy+M7IHWNHa6XKTPnN68Xug3co+1MPNGJV5Dhpcg2DEiPI6++rq5qThyVlTx/U/xi/9 X-Received: by 2002:a17:906:b217:: with SMTP id p23mr7634861ejz.98.1594970763214; Fri, 17 Jul 2020 00:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594970763; cv=none; d=google.com; s=arc-20160816; b=udrYFStZjV4WHy64unVBeLNLSiII7oPlRpSlk09qd+pLEfRpC8E7Qxt0c2z0wjq5sL 3uj6vbu5y048OfcPCALc8UCmU6Te8xftxl7c77XP3vzSx3zIfXRfPaxctKT6UMEj83xH 6ps4kxuEDN/XQOIArpEywdLZqAT6iIcYDrVj2UAWLRM0+vmwkWdLyKy/OqTw4k0DVste S3ot33YXoUH9rCXad1c3pMZejTdX+ADWz591fXh78Cmn0jWfEGCM1fSLcenv62OH1H4v B0tWWw7L4Q88b4tQtwNEcrq1LrXrbZWwZXNcZG0TKCuE32hYJW3//gtKy5dXkD8pSNia SDjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=5JEHKtkNKwD/IFM6abRMVdLiY/nHNFDRNsJu7Y4oxIQ=; b=P7llX356YXlvJAfcTyFPFOMjoo+P2CoZPrNT+w6IiZgu5lG/K/dQ+sDnD6XwXDLZft oxiq59VFASRYd2SgJdw4B9U8hUdhaXJOwwFu7dFyrWAe42V1j3yC+pgg6uFVznBK4M9d m4ktG3bVOvSrNiYrcKL8M82pRtkSuSQFBbC8vxnep/Xae4UUSVpJ2oVh1rPl/qg9yQ8U HQspXHVDgUSJoEiXYtrd3NrLHC6SpqtsCeU/HXh/68c4YD5vXVIlhPfD5NIDArTirWrW +twVcWmn6hJUuVQ+kaDmjvkfVi0RLtYGcHgi/gJ2Q0qiuu9EXzoRJvF4OKmEorQ7bry6 1xUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EVLuhEDf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d25si4499050eja.521.2020.07.17.00.25.40; Fri, 17 Jul 2020 00:26:03 -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=@google.com header.s=20161025 header.b=EVLuhEDf; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728080AbgGQHX0 (ORCPT + 99 others); Fri, 17 Jul 2020 03:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbgGQHXZ (ORCPT ); Fri, 17 Jul 2020 03:23:25 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B57C08C5C0 for ; Fri, 17 Jul 2020 00:23:24 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id s5so5468591qkj.1 for ; Fri, 17 Jul 2020 00:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=5JEHKtkNKwD/IFM6abRMVdLiY/nHNFDRNsJu7Y4oxIQ=; b=EVLuhEDfl6DZfCFR93tOM8LMOcPSAmqarvN0/aeKDzhjJYsPnD9A76hKAwYn5U+vLl X7nj7aHYzY4TzVwkilEoKwV6Ns3VmLifEJtEfuWg4vHnd7VPvumlPkpdZuLPeWo7GOqU lQPQp4w1EtYwsS98PsELQYO2qF7wd2VRo8EVI9Z0Al/Xcu5hYNIAKOuoz2TmrKsO3Bom Za8jUnqGG5TpaxAA+3Dx3imqKnHPD92aJfjs0uLieGleb+sD5faOWhZhW8Nr8aNfKal+ cN8+7hatUtaeN8yo4AdOrjYVoUwqzEh2h6vBq9KCZZCNZkNNrQUtF/Ze7TFtOY1nATBk 4B2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=5JEHKtkNKwD/IFM6abRMVdLiY/nHNFDRNsJu7Y4oxIQ=; b=OV1go9obXBNuCX+xEUOGhe6ZGbugWFHigArNP5z/zF4j/fFl5FkRk0AY6jLoigJ5WY qzsqXY90QOMRHHa+xI6lIMnvYtTmVLorYFCbHm/ZpJs0866zf+Rt94S/bJi2kvccnHrW K+cDtkF22eMN0W1oAppQ+XcwbNR609gqcRzBiL/mPNAHf3XNZJHLoSwpENjJOuc4SLYi 1oE1fDk7emzgjT83knwAd8/Rj+nK46ZUjJMZ6kvDmM2UHrwYZtAlJLEEoSmhJvgrg+Zm vligr+55A/xoFCtpQ0VAOHyXa4uDcHWXSkh5G6EVjDX7yZnq6+KuWXFtzu4hEGEUqk46 rhFQ== X-Gm-Message-State: AOAM532HNaIweqlhUzt24IlSnKhE+meP6R0B8PamatIVMZAVdCIJGahG 7wgYqDcDIMTmyDqyEHRkQMMToh1946eE X-Received: by 2002:a0c:e747:: with SMTP id g7mr7589622qvn.77.1594970603845; Fri, 17 Jul 2020 00:23:23 -0700 (PDT) Date: Fri, 17 Jul 2020 00:23:19 -0700 Message-Id: <20200717072319.101302-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH] libbpf bpf_helpers: Use __builtin_offsetof for offsetof if available From: Ian Rogers To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stanislav Fomichev , Ian Rogers 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 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) #endif +#endif #ifndef container_of #define container_of(ptr, type, member) \ ({ \ -- 2.28.0.rc0.105.gf9edc3c819-goog