[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQKnvChdGiq80bUK0U6xaWqzUVRdzgShA4a06fBZ5EjVMw@mail.gmail.com>
Date: Tue, 12 Jul 2022 16:57:49 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: James Hilliard <james.hilliard1@...il.com>
Cc: bpf <bpf@...r.kernel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...gle.com>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>, LKML <linux-kernel@...r.kernel.org>,
llvm@...ts.linux.dev
Subject: Re: [PATCH v3] bpf/scripts: Generate GCC compatible helpers
On Tue, Jul 12, 2022 at 4:26 PM James Hilliard
<james.hilliard1@...il.com> wrote:
>
> The current bpf_helper_defs.h helpers are llvm specific and don't work
> correctly with gcc.
>
> GCC appears to required kernel helper funcs to have the following
> attribute set: __attribute__((kernel_helper(NUM)))
>
> Generate gcc compatible headers based on the format in bpf-helpers.h.
>
> This generates GCC/Clang compatible helpers, for example:
> /* Helper macro for GCC/Clang compatibility */
> #define NOARG
> #if __GNUC__ && !__clang__
> #define BPF_HELPER_DEF(num, ret_star, ret_type, name, ...) \
> ret_type ret_star name(__VA_ARGS__) __attribute__((kernel_helper(num)));
> #else
> #define BPF_HELPER_DEF(num, ret_star, ret_type, name, ...) \
> static ret_type ret_star(*name)(__VA_ARGS__) = (void *) num;
> #endif
>
> BPF_HELPER_DEF(1, *, void, bpf_map_lookup_elem, void *map, const void *key)
>
> BPF_HELPER_DEF(2, NOARG, long, bpf_map_update_elem, void *map, const void *key, const void *value, __u64 flags)
>
> See:
> https://github.com/gcc-mirror/gcc/blob/releases/gcc-12.1.0/gcc/config/bpf/bpf-helpers.h#L24-L27
>
> This fixes the following build error:
> error: indirect call in function, which are not supported by eBPF
>
> Signed-off-by: James Hilliard <james.hilliard1@...il.com>
> ---
> Changes v2 -> v3:
> - use a conditional helper macro
> Changes v1 -> v2:
> - more details in commit log
> ---
> scripts/bpf_doc.py | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py
> index a0ec321469bd..45f51ff1318c 100755
> --- a/scripts/bpf_doc.py
> +++ b/scripts/bpf_doc.py
> @@ -717,6 +717,16 @@ class PrinterHelpers(Printer):
> header = '''\
> /* This is auto-generated file. See bpf_doc.py for details. */
>
> +/* Helper macro for GCC/Clang compatibility */
> +#define NOARG
> +#if __GNUC__ && !__clang__
> +#define BPF_HELPER_DEF(num, ret_star, ret_type, name, ...) \\
> +ret_type ret_star name(__VA_ARGS__) __attribute__((kernel_helper(num)));
> +#else
> +#define BPF_HELPER_DEF(num, ret_star, ret_type, name, ...) \\
> +static ret_type ret_star(*name)(__VA_ARGS__) = (void *) num;
> +#endif
Nack for the reasons stated earlier.
Powered by blists - more mailing lists