diff mbox series

[bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton

Message ID 20240401170713.2081368-1-andrii@kernel.org (mailing list archive)
State Accepted
Commit 2a24e2485722b0e12e17a2bd473bd15c9e420bdb
Delegated to: BPF
Headers show
Series [bpf-next] bpftool: use __typeof__() instead of typeof() in BPF skeleton | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 2 blamed authors not CCed: yonghong.song@linux.dev thinker.li@gmail.com; 11 maintainers not CCed: john.fastabend@gmail.com sdf@google.com kpsingh@kernel.org qmo@kernel.org martin.lau@linux.dev yonghong.song@linux.dev thinker.li@gmail.com haoluo@google.com jolsa@kernel.org song@kernel.org eddyz87@gmail.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 92 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18 and -O2 optimization
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck

Commit Message

Andrii Nakryiko April 1, 2024, 5:07 p.m. UTC
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(-)

Comments

Kui-Feng Lee April 1, 2024, 5:59 p.m. UTC | #1
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!
Quentin Monnet April 1, 2024, 7:50 p.m. UTC | #2
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>
John Fastabend April 2, 2024, 1:44 a.m. UTC | #3
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>
patchwork-bot+netdevbpf@kernel.org April 2, 2024, 2:30 p.m. UTC | #4
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!
diff mbox series

Patch

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);