Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1511719ybh; Sun, 19 Jul 2020 23:18:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6USZQtuZZIMJ+GsXBGgkTGN11irGGwO/yCOPH9gMPTV1iaRKEArIzuN8MEXjfe5ubN6OZ X-Received: by 2002:aa7:d44f:: with SMTP id q15mr19283711edr.340.1595225895827; Sun, 19 Jul 2020 23:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595225895; cv=none; d=google.com; s=arc-20160816; b=vFaQC/cg0kojvsJDSi6FDzZ631gxqmI7z7qFME72whyBwIAYRFbu4kCBcrPntce+1A ZnSooUaDQZgr68sC74njC6FOXUL0JU4mQcggxUFyUkba/Jd7IAVzqWtyD2l3+8IUxRUF +vzTbGr5vtKiB+pCyEsKonbACd56rjaZWGyvxmhE1U/CMWz/eV2yJ8Ajw4yXNIr3tDt3 Uo/Zw7rpmcA1zE2hGjNwxRlx47Gb2iGl0tWNifxHiY08J++IWkPwIgAdKCaADSKd26zD C5uHTJUNzaxB+MLEBCmJjkkfRPxulMf21gU1/BDadWuAZzbXRA9FiNf2vqWN8gu38tYT Mjfg== 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=hrTZ3ILM0xAvfuFOaXWaqEFvmBYS4j5nhBs2MogC2d4=; b=QoqTPxjw5cVYnCgiwOAQbiYwhJR6JQhdRQgDTrnxJ6/liMo0pGGVqLsa/YlsspOht6 SJEz1rVgKbKzD/GG0Xvf5+16nnPzVBeZRAeafogq1oV/PWxumG9rqdnObv0pkro4gNuI NAsfKdYAb9FrF6WUk+yYYqSsSeLilLVM8o8GDG8EP+2EAv3K9YYbZgsNTWiWkXr+cTz1 c7727VSm6yzxVlS9sEKRd8rQ9dZXipXK72KvbHoc6WO1F8q1amMuXhjdu3IX3GshXz7Y IBU8qxQiFz62JVV7E27tpn/M05z4CpQVDuHWG4tfxbAygPKaOY2AuoDITeTAULL3e+L7 Ad4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jCza9kOb; 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 j5si9836722ejk.74.2020.07.19.23.17.53; Sun, 19 Jul 2020 23:18: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=@google.com header.s=20161025 header.b=jCza9kOb; 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 S1726775AbgGTGRq (ORCPT + 99 others); Mon, 20 Jul 2020 02:17:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgGTGRp (ORCPT ); Mon, 20 Jul 2020 02:17:45 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5ABC0619D2 for ; Sun, 19 Jul 2020 23:17:45 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id k4so9804466pll.6 for ; Sun, 19 Jul 2020 23:17:45 -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=hrTZ3ILM0xAvfuFOaXWaqEFvmBYS4j5nhBs2MogC2d4=; b=jCza9kObWWd7hRrzAmTOlTIznNK5au/+obW9N2t3FEDENVbFaIuGNwvI+czZfkkjfj yz5Acv84a48iP3jdHNxPq9oYAQ3JsaCd43nn72tDwiAb0KzKjz0D1eRaxZPmSvNI3v5p 14yBIbxUS2mz1cy/VgcYLfGAwLfyPgaeo6KCWa24lFD8fcp2A8oN/a5lernNHq87QTsg uJDXeoEKZy1wotyY285VjM6pvyZt7ZdO0ouJqrQBQpT/blmMz44W6ZUa2RD3iVc6yJ3b 7Xl+rFZB34WWL6EpieqghLEjm+gNI2iCaVcFn7br2mXNH9ssLJR3SbfkLhib6q4xprWM isOg== 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=hrTZ3ILM0xAvfuFOaXWaqEFvmBYS4j5nhBs2MogC2d4=; b=WhBqVFD9NzAe0jNh6bYoXzkOvEDukDDtYnDlhPbiO740ILcbEgnjZAHfEJTx5JZv7u vtflUIR9cdGf3r5CzwAsSih2q3Cn60If1ntgLwBcSMr5EagZjidYVJ2iBSqEbDNSMMG8 c26lH5ICLZ8oyYzVXJGRCWoqv+3MXfm3+vUxjTmpLmqgmsYHoiKb92mk1Lt1cDfmQ9tR 00JQv+WngCykusi50slhQqz16fnU6/jzIf264syZGsI+OgYNrRjrgMjSGnD3wsqtjMkk tHmo9eh74EzkKBjmZPPvzojOIbfHi5/NcZuQMjUztOA6ua0cjeswu7BSPPBx+Mp8Bgze yPbg== X-Gm-Message-State: AOAM531xrxzRle3uOLKgBqA9Lk1dLXSEtiTjmAHvsD7GFj9VRwVxRF80 dhMHLMIoErjbFyqXCF3sMt3sNdAkYVO3 X-Received: by 2002:a17:902:b78b:: with SMTP id e11mr16332011pls.204.1595225864907; Sun, 19 Jul 2020 23:17:44 -0700 (PDT) Date: Sun, 19 Jul 2020 23:17:41 -0700 Message-Id: <20200720061741.1514673-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH v2] libbpf bpf_helpers: Use __builtin_offsetof for offsetof 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 that is available since llvm 3.7 (the first with a BPF backend). Signed-off-by: Ian Rogers --- 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