* [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
@ 2024-04-01 17:07 Andrii Nakryiko
2024-04-01 17:59 ` Kui-Feng Lee
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2024-04-01 17:07 UTC (permalink / raw)
To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team
When generated BPF skeleton header is included in C++ code base, some
compiler setups will emit warning about using language extensions due to
typeof() usage, resulting in something like:
error: extension used [-Werror,-Wlanguage-extension-token]
obj->struct_ops.empty_tcp_ca = (typeof(obj->struct_ops.empty_tcp_ca))
^
It looks like __typeof__() is a preferred way to do typeof() with better
C++ compatibility behavior, so switch to that. With __typeof__() we get
no such warning.
Fixes: c2a0257c1edf ("bpftool: Cast pointers for shadow types explicitly.")
Fixes: 00389c58ffe9 ("bpftool: Add support for subskeletons")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/gen.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 786268f1a483..b3979ddc0189 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -386,7 +386,7 @@ static int codegen_subskel_datasecs(struct bpf_object *obj, const char *obj_name
*/
needs_typeof = btf_is_array(var) || btf_is_ptr_to_func_proto(btf, var);
if (needs_typeof)
- printf("typeof(");
+ printf("__typeof__(");
err = btf_dump__emit_type_decl(d, var_type_id, &opts);
if (err)
@@ -1131,7 +1131,7 @@ static void gen_st_ops_shadow_init(struct btf *btf, struct bpf_object *obj)
continue;
codegen("\
\n\
- obj->struct_ops.%1$s = (typeof(obj->struct_ops.%1$s))\n\
+ obj->struct_ops.%1$s = (__typeof__(obj->struct_ops.%1$s))\n\
bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
\n\
", ident);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
2024-04-01 17:07 [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton Andrii Nakryiko
@ 2024-04-01 17:59 ` Kui-Feng Lee
2024-04-01 19:50 ` Quentin Monnet
2024-04-02 1:44 ` John Fastabend
2024-04-02 14:30 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Kui-Feng Lee @ 2024-04-01 17:59 UTC (permalink / raw)
To: Andrii Nakryiko, bpf, ast, daniel, martin.lau; +Cc: kernel-team
On 4/1/24 10:07, Andrii Nakryiko wrote:
> When generated BPF skeleton header is included in C++ code base, some
> compiler setups will emit warning about using language extensions due to
> typeof() usage, resulting in something like:
>
> error: extension used [-Werror,-Wlanguage-extension-token]
> obj->struct_ops.empty_tcp_ca = (typeof(obj->struct_ops.empty_tcp_ca))
> ^
>
> It looks like __typeof__() is a preferred way to do typeof() with better
> C++ compatibility behavior, so switch to that. With __typeof__() we get
> no such warning.
>
> Fixes: c2a0257c1edf ("bpftool: Cast pointers for shadow types explicitly.")
> Fixes: 00389c58ffe9 ("bpftool: Add support for subskeletons")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
> tools/bpf/bpftool/gen.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index 786268f1a483..b3979ddc0189 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -386,7 +386,7 @@ static int codegen_subskel_datasecs(struct bpf_object *obj, const char *obj_name
> */
> needs_typeof = btf_is_array(var) || btf_is_ptr_to_func_proto(btf, var);
> if (needs_typeof)
> - printf("typeof(");
> + printf("__typeof__(");
>
> err = btf_dump__emit_type_decl(d, var_type_id, &opts);
> if (err)
> @@ -1131,7 +1131,7 @@ static void gen_st_ops_shadow_init(struct btf *btf, struct bpf_object *obj)
> continue;
> codegen("\
> \n\
> - obj->struct_ops.%1$s = (typeof(obj->struct_ops.%1$s))\n\
> + obj->struct_ops.%1$s = (__typeof__(obj->struct_ops.%1$s))\n\
> bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
> \n\
> ", ident);
LGTM!
Acked-by: Kui-Feng Lee <thinker.li@gmail.com>
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
2024-04-01 17:59 ` Kui-Feng Lee
@ 2024-04-01 19:50 ` Quentin Monnet
0 siblings, 0 replies; 5+ messages in thread
From: Quentin Monnet @ 2024-04-01 19:50 UTC (permalink / raw)
To: Kui-Feng Lee, Andrii Nakryiko, bpf, ast, daniel, martin.lau; +Cc: kernel-team
On 01/04/2024 18:59, Kui-Feng Lee wrote:
>
>
> On 4/1/24 10:07, Andrii Nakryiko wrote:
>> When generated BPF skeleton header is included in C++ code base, some
>> compiler setups will emit warning about using language extensions due to
>> typeof() usage, resulting in something like:
>>
>> error: extension used [-Werror,-Wlanguage-extension-token]
>> obj->struct_ops.empty_tcp_ca = (typeof(obj->struct_ops.empty_tcp_ca))
>> ^
>>
>> It looks like __typeof__() is a preferred way to do typeof() with better
>> C++ compatibility behavior, so switch to that. With __typeof__() we get
>> no such warning.
>>
>> Fixes: c2a0257c1edf ("bpftool: Cast pointers for shadow types
>> explicitly.")
>> Fixes: 00389c58ffe9 ("bpftool: Add support for subskeletons")
>> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
>> ---
>> tools/bpf/bpftool/gen.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
>> index 786268f1a483..b3979ddc0189 100644
>> --- a/tools/bpf/bpftool/gen.c
>> +++ b/tools/bpf/bpftool/gen.c
>> @@ -386,7 +386,7 @@ static int codegen_subskel_datasecs(struct
>> bpf_object *obj, const char *obj_name
>> */
>> needs_typeof = btf_is_array(var) ||
>> btf_is_ptr_to_func_proto(btf, var);
>> if (needs_typeof)
>> - printf("typeof(");
>> + printf("__typeof__(");
>> err = btf_dump__emit_type_decl(d, var_type_id, &opts);
>> if (err)
>> @@ -1131,7 +1131,7 @@ static void gen_st_ops_shadow_init(struct btf
>> *btf, struct bpf_object *obj)
>> continue;
>> codegen("\
>> \n\
>> - obj->struct_ops.%1$s = (typeof(obj->struct_ops.%1$s))\n\
>> + obj->struct_ops.%1$s = (__typeof__(obj->struct_ops.
>> %1$s))\n\
>> bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
>> \n\
>> ", ident);
>
>
> LGTM!
>
> Acked-by: Kui-Feng Lee <thinker.li@gmail.com>
>
> Thanks!
>
Acked-by: Quentin Monnet <qmo@kernel.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
2024-04-01 17:07 [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton Andrii Nakryiko
2024-04-01 17:59 ` Kui-Feng Lee
@ 2024-04-02 1:44 ` John Fastabend
2024-04-02 14:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: John Fastabend @ 2024-04-02 1:44 UTC (permalink / raw)
To: Andrii Nakryiko, bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team
Andrii Nakryiko wrote:
> When generated BPF skeleton header is included in C++ code base, some
> compiler setups will emit warning about using language extensions due to
> typeof() usage, resulting in something like:
>
> error: extension used [-Werror,-Wlanguage-extension-token]
> obj->struct_ops.empty_tcp_ca = (typeof(obj->struct_ops.empty_tcp_ca))
> ^
>
> It looks like __typeof__() is a preferred way to do typeof() with better
> C++ compatibility behavior, so switch to that. With __typeof__() we get
> no such warning.
>
> Fixes: c2a0257c1edf ("bpftool: Cast pointers for shadow types explicitly.")
> Fixes: 00389c58ffe9 ("bpftool: Add support for subskeletons")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---
> tools/bpf/bpftool/gen.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index 786268f1a483..b3979ddc0189 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -386,7 +386,7 @@ static int codegen_subskel_datasecs(struct bpf_object *obj, const char *obj_name
> */
> needs_typeof = btf_is_array(var) || btf_is_ptr_to_func_proto(btf, var);
> if (needs_typeof)
> - printf("typeof(");
> + printf("__typeof__(");
>
> err = btf_dump__emit_type_decl(d, var_type_id, &opts);
> if (err)
> @@ -1131,7 +1131,7 @@ static void gen_st_ops_shadow_init(struct btf *btf, struct bpf_object *obj)
> continue;
> codegen("\
> \n\
> - obj->struct_ops.%1$s = (typeof(obj->struct_ops.%1$s))\n\
> + obj->struct_ops.%1$s = (__typeof__(obj->struct_ops.%1$s))\n\
> bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
> \n\
> ", ident);
> --
> 2.43.0
>
>
sure.
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
2024-04-01 17:07 [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton Andrii Nakryiko
2024-04-01 17:59 ` Kui-Feng Lee
2024-04-02 1:44 ` John Fastabend
@ 2024-04-02 14:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-02 14:30 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Mon, 1 Apr 2024 10:07:13 -0700 you wrote:
> When generated BPF skeleton header is included in C++ code base, some
> compiler setups will emit warning about using language extensions due to
> typeof() usage, resulting in something like:
>
> error: extension used [-Werror,-Wlanguage-extension-token]
> obj->struct_ops.empty_tcp_ca = (typeof(obj->struct_ops.empty_tcp_ca))
> ^
>
> [...]
Here is the summary with links:
- [bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton
https://git.kernel.org/bpf/bpf-next/c/2a24e2485722
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-02 14:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01 17:07 [PATCH bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton Andrii Nakryiko
2024-04-01 17:59 ` Kui-Feng Lee
2024-04-01 19:50 ` Quentin Monnet
2024-04-02 1:44 ` John Fastabend
2024-04-02 14:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox