public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: WanLi Niu <kiraskyler@163.com>, Quentin Monnet <qmo@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Menglong Dong <menglong8.dong@gmail.com>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	WanLi Niu <niuwl1@chinatelecom.cn>,
	Menglong Dong <dongml2@chinatelecom.cn>
Subject: Re: [PATCH v2 bpf-next] bpftool: Make skeleton C++ compatible with explicit casts
Date: Fri, 2 Jan 2026 11:35:39 -0800	[thread overview]
Message-ID: <988dfd54-9f11-4ff1-803c-393d168a068b@linux.dev> (raw)
In-Reply-To: <20251231102929.3843-1-kiraskyler@163.com>



On 12/31/25 2:29 AM, WanLi Niu wrote:
> From: WanLi Niu <niuwl1@chinatelecom.cn>
>
> Fix C++ compilation errors in generated skeleton by adding explicit
> pointer casts and using integer subtraction for offset calculation.
>
> error: invalid conversion from 'void*' to 'trace_bpf*' [-fpermissive]
>        |         skel = skel_alloc(sizeof(*skel));
>        |                ~~~~~~~~~~^~~~~~~~~~~~~~~
>        |                          |
>        |                          void*
>
> error: invalid use of 'void'
>        |         skel->ctx.sz = (void *)&skel->links - (void *)skel;
>
> Signed-off-by: WanLi Niu <niuwl1@chinatelecom.cn>
> Co-developed-by: Menglong Dong <dongml2@chinatelecom.cn>
> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>

For llvm22, I hacked with core_kern_overflow.lskel.h and has the following
warning/errors:

In file included from prog_tests/core_kern_overflow.cc:4:
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/core_kern_overflow.lskel.h:65:9: error: assigning to
       'struct core_kern_overflow_lskel *' from incompatible type 'void *'
    65 |         skel = skel_alloc(sizeof(*skel));
       |                ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/core_kern_overflow.lskel.h:68:38: error: arithmetic on pointers to void
    68 |         skel->ctx.sz = (void *)&skel->links - (void *)skel;
       |                        ~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~

Your patch fixed the issue.

But for llvm side, I got the following two more errors:

/home/yhs/work/bpf-next/tools/testing/selftests/bpf/core_kern_overflow.lskel.h:73:15: error: assigning to
       'struct core_kern_overflow_lskel__bss *' from incompatible type 'void *'
    73 |                 skel->bss = skel_prep_map_data((void *)data, 4096,
       |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    74 |                                                 sizeof(data) - 1);
       |                                                 ~~~~~~~~~~~~~~~~~
/home/yhs/work/bpf-next/tools/testing/selftests/bpf/core_kern_overflow.lskel.h:223:14: error: assigning to
       'struct core_kern_overflow_lskel__bss *' from incompatible type 'void *'
   223 |         skel->bss = skel_finalize_map_data(&skel->maps.bss.initial_value,
       |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   224 |                                         4096, PROT_READ | PROT_WRITE, skel->maps.bss.map_fd);
       |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So these two issues can be fixed similar to above skel_alloc() case.

Could you fix both of them?

> ---
>   tools/bpf/bpftool/gen.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
> index 993c7d9484a4..71446a776130 100644
> --- a/tools/bpf/bpftool/gen.c
> +++ b/tools/bpf/bpftool/gen.c
> @@ -731,10 +731,10 @@ static int gen_trace(struct bpf_object *obj, const char *obj_name, const char *h
>   		{							    \n\
>   			struct %1$s *skel;				    \n\
>   									    \n\
> -			skel = skel_alloc(sizeof(*skel));		    \n\
> +			skel = (struct %1$s *)skel_alloc(sizeof(*skel));    \n\
>   			if (!skel)					    \n\
>   				goto cleanup;				    \n\
> -			skel->ctx.sz = (void *)&skel->links - (void *)skel; \n\
> +			skel->ctx.sz = (__u64)&skel->links - (__u64)skel;   \n\
>   		",
>   		obj_name, opts.data_sz);
>   	bpf_object__for_each_map(map, obj) {


  reply	other threads:[~2026-01-02 19:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31  9:25 [PATCH bpf-next] bpftool: Make skeleton C++ compatible with explicit casts WanLi Niu
2025-12-31  9:48 ` bot+bpf-ci
2025-12-31 10:29 ` [PATCH v2 " WanLi Niu
2026-01-02 19:35   ` Yonghong Song [this message]
2026-01-04  2:14   ` [PATCH v3 " WanLi Niu
2026-01-05  5:27     ` Yonghong Song
2026-01-05  7:12     ` [PATCH v4 " WanLi Niu
2026-01-05 10:39       ` Quentin Monnet
2026-01-05 11:50       ` Jose E. Marchesi
2026-01-05 12:53         ` WanLi Niu
2026-01-05 16:05           ` Jose E. Marchesi
2026-01-06  2:31       ` [PATCH v5 " WanLi Niu
2026-01-09 19:00         ` patchwork-bot+netdevbpf
2026-01-06  0:46     ` [PATCH v3 " Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=988dfd54-9f11-4ff1-803c-393d168a068b@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dongml2@chinatelecom.cn \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kiraskyler@163.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=menglong8.dong@gmail.com \
    --cc=niuwl1@chinatelecom.cn \
    --cc=qmo@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox