lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a0a26308-a1d7-a57c-727c-000652a5d246@fb.com>
Date:   Fri, 17 Jul 2020 23:00:29 -0700
From:   Yonghong Song <yhs@...com>
To:     Ian Rogers <irogers@...gle.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>,
        Andrii Nakryiko <andriin@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...omium.org>, <netdev@...r.kernel.org>,
        <bpf@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     Stanislav Fomichev <sdf@...gle.com>
Subject: Re: [PATCH] libbpf bpf_helpers: Use __builtin_offsetof for offsetof
 if available



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@...gle.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@...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)				\
>   	({							\
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ