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 |
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
> 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
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 --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\
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(-)