Re: [PATCH] bpftool: fix -Wcast-qual warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
> ---
>  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




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux