From: Kui-Feng Lee <sinquersw@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Kui-Feng Lee <thinker.li@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, martin.lau@linux.dev,
song@kernel.org, kernel-team@meta.com, andrii@kernel.org,
kuifeng@meta.com, yhs@meta.com
Subject: Re: [PATCH bpf-next] bpftool: cast pointers for shadow types explicitly.
Date: Tue, 12 Mar 2024 17:07:58 -0700 [thread overview]
Message-ID: <c1781093-69fe-4760-9df5-8ae71a3ecd05@gmail.com> (raw)
In-Reply-To: <CAEf4BzZafCA3gQVgmL1-OnpcWPXNJZ8iXgdaH82gAvu5TEOVEw@mail.gmail.com>
On 3/12/24 15:47, Andrii Nakryiko wrote:
> On Mon, Mar 11, 2024 at 6:38 PM Kui-Feng Lee <thinker.li@gmail.com> wrote:
>>
>> According to a report, skeletons fail to assign shadow pointers when being
>> compiled with C++ programs. Unlike C doing implicit casting for void
>> pointers, C++ requires an explicit casting.
>>
>> To support C++, we do explicit casting for each shadow pointer.
>>
>> Cc: yhs@meta.com
>> Signed-off-by: Kui-Feng Lee <thinker.li@gmail.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 4fa4ade1ce74..dedafea0c127 100644
>> --- a/tools/bpf/bpftool/gen.c
>> +++ b/tools/bpf/bpftool/gen.c
>> @@ -1131,7 +1131,7 @@ static void gen_st_ops_shadow_init(struct btf *btf, struct bpf_object *obj)
>> continue;
>> codegen("\
>> \n\
>> - obj->struct_ops.%1$s = bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
>> + obj->struct_ops.%1$s = (typeof(obj->struct_ops.%1$s))bpf_map__initial_value(obj->maps.%1$s, NULL);\n\
>
> Given we have a named struct type for this and we use explicit type
> names in other parts of generated skeleton code, let's maybe use
> "struct %s__%s__%s" explicitly here (passing in obj_name, ident,
> type_name)?
I have considered about this solution. But, C++ works differently. It
has nested namespaces. That means it should be referred as
"XXX_skeleton::OOO_st_ops_map" in C++. Then, we need #if #else #endif
directives to provide two separated casting.
>
> No strong preferences, but feels like a consistent approach here would be nice.
>
>> \n\
>> ", ident);
>> }
>> --
>> 2.34.1
>>
next prev parent reply other threads:[~2024-03-13 0:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 1:37 [PATCH bpf-next] bpftool: cast pointers for shadow types explicitly Kui-Feng Lee
2024-03-12 5:22 ` Yonghong Song
2024-03-12 9:53 ` Quentin Monnet
2024-03-12 22:47 ` Andrii Nakryiko
2024-03-13 0:07 ` Kui-Feng Lee [this message]
2024-03-13 0:27 ` Andrii Nakryiko
2024-03-13 0:37 ` Kui-Feng Lee
2024-03-13 15:51 ` Andrii Nakryiko
2024-03-14 20:36 ` Andrii Nakryiko
2024-03-14 20:40 ` patchwork-bot+netdevbpf
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=c1781093-69fe-4760-9df5-8ae71a3ecd05@gmail.com \
--to=sinquersw@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=thinker.li@gmail.com \
--cc=yhs@meta.com \
/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