* [PATCH bpf] tools/bpftool: make skeleton code C++17-friendly by dropping typeof()
@ 2020-08-12 2:59 Andrii Nakryiko
2020-08-12 15:34 ` Song Liu
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-08-12 2:59 UTC (permalink / raw)
To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko
Seems like C++17 standard mode doesn't recognize typeof() anymore. This can
be tested by compiling test_cpp test with -std=c++17 or -std=c++1z options.
The use of typeof in skeleton generated code is unnecessary, all types are
well-known at the time of code generation, so remove all typeof()'s to make
skeleton code more future-proof when interacting with C++ compilers.
Fixes: 985ead416df3 ("bpftool: Add skeleton codegen command")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/bpf/bpftool/gen.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index 8a4c2b3b0cd6..db80e836816e 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -397,7 +397,7 @@ static int do_skeleton(int argc, char **argv)
{ \n\
struct %1$s *obj; \n\
\n\
- obj = (typeof(obj))calloc(1, sizeof(*obj)); \n\
+ obj = (struct %1$s *)calloc(1, sizeof(*obj)); \n\
if (!obj) \n\
return NULL; \n\
if (%1$s__create_skeleton(obj)) \n\
@@ -461,7 +461,7 @@ static int do_skeleton(int argc, char **argv)
{ \n\
struct bpf_object_skeleton *s; \n\
\n\
- s = (typeof(s))calloc(1, sizeof(*s)); \n\
+ s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));\n\
if (!s) \n\
return -1; \n\
obj->skeleton = s; \n\
@@ -479,7 +479,7 @@ static int do_skeleton(int argc, char **argv)
/* maps */ \n\
s->map_cnt = %zu; \n\
s->map_skel_sz = sizeof(*s->maps); \n\
- s->maps = (typeof(s->maps))calloc(s->map_cnt, s->map_skel_sz);\n\
+ s->maps = (struct bpf_map_skeleton *)calloc(s->map_cnt, s->map_skel_sz);\n\
if (!s->maps) \n\
goto err; \n\
",
@@ -515,7 +515,7 @@ static int do_skeleton(int argc, char **argv)
/* programs */ \n\
s->prog_cnt = %zu; \n\
s->prog_skel_sz = sizeof(*s->progs); \n\
- s->progs = (typeof(s->progs))calloc(s->prog_cnt, s->prog_skel_sz);\n\
+ s->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);\n\
if (!s->progs) \n\
goto err; \n\
",
--
2.24.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] tools/bpftool: make skeleton code C++17-friendly by dropping typeof()
2020-08-12 2:59 [PATCH bpf] tools/bpftool: make skeleton code C++17-friendly by dropping typeof() Andrii Nakryiko
@ 2020-08-12 15:34 ` Song Liu
2020-08-13 1:10 ` Alexei Starovoitov
0 siblings, 1 reply; 3+ messages in thread
From: Song Liu @ 2020-08-12 15:34 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, netdev, Alexei Starovoitov, daniel, andrii.nakryiko, Kernel Team
> On Aug 11, 2020, at 7:59 PM, Andrii Nakryiko <andriin@fb.com> wrote:
>
> Seems like C++17 standard mode doesn't recognize typeof() anymore. This can
> be tested by compiling test_cpp test with -std=c++17 or -std=c++1z options.
> The use of typeof in skeleton generated code is unnecessary, all types are
> well-known at the time of code generation, so remove all typeof()'s to make
> skeleton code more future-proof when interacting with C++ compilers.
>
> Fixes: 985ead416df3 ("bpftool: Add skeleton codegen command")
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: <stable@vger.kernel.org> # v5.7+
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] tools/bpftool: make skeleton code C++17-friendly by dropping typeof()
2020-08-12 15:34 ` Song Liu
@ 2020-08-13 1:10 ` Alexei Starovoitov
0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-08-13 1:10 UTC (permalink / raw)
To: Song Liu
Cc: Andrii Nakryiko, bpf, netdev, Alexei Starovoitov, daniel,
andrii.nakryiko, Kernel Team
On Wed, Aug 12, 2020 at 8:35 AM Song Liu <songliubraving@fb.com> wrote:
>
>
>
> > On Aug 11, 2020, at 7:59 PM, Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > Seems like C++17 standard mode doesn't recognize typeof() anymore. This can
> > be tested by compiling test_cpp test with -std=c++17 or -std=c++1z options.
> > The use of typeof in skeleton generated code is unnecessary, all types are
> > well-known at the time of code generation, so remove all typeof()'s to make
> > skeleton code more future-proof when interacting with C++ compilers.
> >
> > Fixes: 985ead416df3 ("bpftool: Add skeleton codegen command")
> > Signed-off-by: Andrii Nakryiko <andriin@fb.com>
>
> Acked-by: Song Liu <songliubraving@fb.com>
Applied. Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-13 1:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 2:59 [PATCH bpf] tools/bpftool: make skeleton code C++17-friendly by dropping typeof() Andrii Nakryiko
2020-08-12 15:34 ` Song Liu
2020-08-13 1:10 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).