Re: [PATCH v3 bpf-next] bpftool: Make skeleton C++ compatible with explicit casts

From: Yonghong Song
Date: Mon Jan 05 2026 - 00:31:53 EST




On 1/3/26 6:14 PM, WanLi Niu wrote:
From: WanLi Niu <niuwl1@xxxxxxxxxxxxxxx>

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

Signed-off-by: WanLi Niu <niuwl1@xxxxxxxxxxxxxxx>
Co-developed-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>
Signed-off-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>

LGTM. Could you add a minimum reproducer in the commit message?

Acked-by: Yonghong Song <yonghong.song@xxxxxxxxx>