[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f3ab8c9f-3bb9-4427-8b43-c1ed9d488970@kernel.org>
Date: Mon, 5 Jan 2026 10:39:59 +0000
From: Quentin Monnet <qmo@...nel.org>
To: WanLi Niu <kiraskyler@....com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>, Eduard Zingerman
<eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>, Menglong Dong <menglong8.dong@...il.com>,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
WanLi Niu <niuwl1@...natelecom.cn>, Menglong Dong <dongml2@...natelecom.cn>
Subject: Re: [PATCH v4 bpf-next] bpftool: Make skeleton C++ compatible with
explicit casts
On 05/01/2026 07:12, WanLi Niu wrote:
> From: WanLi Niu <niuwl1@...natelecom.cn>
>
> Fix C++ compilation errors in generated skeleton by adding explicit
> pointer casts and using integer subtraction for offset calculation.
>
> Use struct outer::inner syntax under __cplusplus to access nested skeleton map
> structs, ensuring C++ compilation compatibility while preserving C support
>
> error: invalid conversion from 'void*' to '<obj_name>*' [-fpermissive]
> | skel = skel_alloc(sizeof(*skel));
> | ~~~~~~~~~~^~~~~~~~~~~~~~~
> | |
> | void*
>
> error: arithmetic on pointers to void
> | skel->ctx.sz = (void *)&skel->links - (void *)skel;
> | ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~
>
> error: assigning to 'struct <obj_name>__<ident> *' from incompatible type 'void *'
> | skel-><ident> = skel_prep_map_data((void *)data, 4096,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | sizeof(data) - 1);
> | ~~~~~~~~~~~~~~~~~
>
> error: assigning to 'struct <obj_name>__<ident> *' from incompatible type 'void *'
> | skel-><ident> = skel_finalize_map_data(&skel->maps.<ident>.initial_value,
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> | 4096, PROT_READ | PROT_WRITE, skel->maps.<ident>.map_fd);
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Minimum reproducer:
>
> $ cat test.bpf.c
> int val; // placed in .bss section
>
> #include "vmlinux.h"
> #include <bpf/bpf_helpers.h>
>
> SEC("raw_tracepoint/sched_wakeup_new") int handle(void *ctx) { return 0; }
>
> $ cat test.cpp
> #include <cerrno>
>
> extern "C" {
> #include "test.bpf.skel.h"
> }
>
> $ bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
> $ clang -g -O2 -target bpf -c test.bpf.c -o test.bpf.o
> $ bpftool gen skeleton test.bpf.o -L > test.bpf.skel.h
> $ g++ -c test.cpp -I.
I tried it and could confirm that the warnings are gone.
> Signed-off-by: WanLi Niu <niuwl1@...natelecom.cn>
> Co-developed-by: Menglong Dong <dongml2@...natelecom.cn>
> Signed-off-by: Menglong Dong <dongml2@...natelecom.cn>
Acked-by: Quentin Monnet <qmo@...nel.org>
Thank you!
Powered by blists - more mailing lists