From: Yonghong Song <yhs@fb.com>
To: Ian Rogers <irogers@google.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Andrii Nakryiko <andriin@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>, <netdev@vger.kernel.org>,
<bpf@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>
Subject: Re: [PATCH] libbpf bpf_helpers: Use __builtin_offsetof for offsetof if available
Date: Fri, 17 Jul 2020 23:00:29 -0700 [thread overview]
Message-ID: <a0a26308-a1d7-a57c-727c-000652a5d246@fb.com> (raw)
In-Reply-To: <20200717072319.101302-1-irogers@google.com>
On 7/17/20 12:23 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 <irogers@google.com>
Thanks. I didn't pay attention to __builtin_offsetof() and clearly
it is preferred. Ack the change with a nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> 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)
The __builtin_offsetof is actually available at least since llvm 3.7,
so it is safe to use it always.
> +#else
> #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
> #endif
> +#endif
> #ifndef container_of
> #define container_of(ptr, type, member) \
> ({ \
>
next prev parent reply other threads:[~2020-07-18 6:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-17 7:23 Ian Rogers
2020-07-18 6:00 ` Yonghong Song [this message]
2020-07-19 3:52 ` Andrii Nakryiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a0a26308-a1d7-a57c-727c-000652a5d246@fb.com \
--to=yhs@fb.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=irogers@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®