diff mbox series

bpftool: fix -Wcast-qual warning

Message ID 20230906111717.2876511-1-dzagorui@cisco.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpftool: fix -Wcast-qual warning | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-8 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 fail Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 fail Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-15 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-0 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-7 success Logs for veristat

Commit Message

Denys Zagorui Sept. 6, 2023, 11:17 a.m. UTC
This cast was made by purpose for older libbpf where the
bpf_object_skeleton field is void * instead of const void *
to eliminte a warning (as i understand
-Wincompatible-pointer-types-discards-qualifiers) but this
cast introduces another warnging (-Wcast-qual) for libbpf
where data field is const void *

It makes sense for bpftool to be in sync with libbpf from
kernel sources

Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
---
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Quentin Monnet Sept. 6, 2023, 4:51 p.m. UTC | #1
On 06/09/2023 12:17, Denys Zagorui wrote:
> This cast was made by purpose for older libbpf where the
> bpf_object_skeleton field is void * instead of const void *
> to eliminte a warning (as i understand

s/eliminte/eliminate/

> -Wincompatible-pointer-types-discards-qualifiers) but this
> cast introduces another warnging (-Wcast-qual) for libbpf

s/warnging/warning/

> where data field is const void *
> 
> It makes sense for bpftool to be in sync with libbpf from
> kernel sources
> 
> Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
> ---
>  tools/bpf/bpftool/gen.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index 2883660d6b67..04c47745b3ea 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -1209,7 +1209,7 @@ static int do_skeleton(int argc, char **argv)
>  	codegen("\
>  		\n\
>  									    \n\
> -			s->data = (void *)%2$s__elf_bytes(&s->data_sz);	    \n\
> +			s->data = %2$s__elf_bytes(&s->data_sz);		    \n\
>  									    \n\
>  			obj->skeleton = s;				    \n\
>  			return 0;					    \n\

If I follow correctly, the cast was added in bpftool in a6cc6b34b93e
("bpftool: Provide a helper method for accessing skeleton's embedded ELF
data"), which mentions indeed:

    The assignment to s->data is cast to void * to ensure no warning is
    issued if compiled with a previous version of libbpf where the
    bpf_object_skeleton field is void * instead of const void *

but in libbpf, s->data's type had already been changed since commit
08a6f22ef6f8 ("libbpf: Change bpf_object_skeleton data field to const
pointer"), part of libbpf 0.6, is this correct?

If this is the case then the commit makes sense to me, I think it's OK
to have a warning with libbpf < 1.0 if it helps suppressing one when
loading skeletons with the current version of the lib.

Thanks,
Quentin
Denys Zagorui Sept. 7, 2023, 8:56 a.m. UTC | #2
> If I follow correctly, the cast was added in bpftool in a6cc6b34b93e
> ("bpftool: Provide a helper method for accessing skeleton's embedded ELF
> data"), which mentions indeed:
> 
>    The assignment to s->data is cast to void * to ensure no warning is
>    issued if compiled with a previous version of libbpf where the
>    bpf_object_skeleton field is void * instead of const void *
> 
> but in libbpf, s->data's type had already been changed since commit
> 08a6f22ef6f8 ("libbpf: Change bpf_object_skeleton data field to const
> pointer"), part of libbpf 0.6, is this correct?
yes, this is correct
Quentin Monnet Sept. 7, 2023, 8:59 a.m. UTC | #3
On 07/09/2023 09:56, Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at
Cisco) wrote:
>> If I follow correctly, the cast was added in bpftool in a6cc6b34b93e
>> ("bpftool: Provide a helper method for accessing skeleton's embedded ELF
>> data"), which mentions indeed:
>>
>>    The assignment to s->data is cast to void * to ensure no warning is
>>    issued if compiled with a previous version of libbpf where the
>>    bpf_object_skeleton field is void * instead of const void *
>>
>> but in libbpf, s->data's type had already been changed since commit
>> 08a6f22ef6f8 ("libbpf: Change bpf_object_skeleton data field to const
>> pointer"), part of libbpf 0.6, is this correct?
> yes, this is correct
> 


OK, thanks

Acked-by: Quentin Monnet <quentin@isovalent.com>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 2883660d6b67..04c47745b3ea 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -1209,7 +1209,7 @@  static int do_skeleton(int argc, char **argv)
 	codegen("\
 		\n\
 									    \n\
-			s->data = (void *)%2$s__elf_bytes(&s->data_sz);	    \n\
+			s->data = %2$s__elf_bytes(&s->data_sz);		    \n\
 									    \n\
 			obj->skeleton = s;				    \n\
 			return 0;					    \n\