Skip to contentSkip to conversation

bpftool: Fix generated code in codegen_asserts

PATCH Applied Jiri Olsa 6 participants 7 messages Mar 28, 2022 – Mar 29, 2022

Subsystems (4)
lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/1 bpftool: Fix generated code in codegen_asserts

Arnaldo reported perf compilation fail with:

  $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
  ...
  In file included from util/bpf_counter.c:28:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
    351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
        |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
  cc1: all warnings being treated as errors

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
 	codegen("\
 		\n\
 		__attribute__((unused)) static void			    \n\
-		%1$s__assert(struct %1$s *s)				    \n\
+		%1$s__assert(struct %1$s *s __attribute__((unused)))	    \n\
 		{							    \n\
 		#ifdef __cplusplus					    \n\
 		#define _Static_assert static_assert			    \n\
Signature · 1 line
2.35.1
Tested-by on v1 1/1
#1 lore raw

Em Mon, Mar 28, 2022 at 10:37:03AM +0200, Jiri Olsa escreveu:

Quoted 11 lines

Arnaldo reported perf compilation fail with:

  $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
  ...
  In file included from util/bpf_counter.c:28:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
    351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
        |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
  cc1: all warnings being treated as errors
Quoted 2 lines

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

We need some Makefile dependency to trigger the skels to be regenerated when bpftool is updated.

And before that to notice that the bpftool source code changed and thus the bootstrap bpftool needs to be rebuilt.

So, after a full tools/perf/ build from scratch it works:

Ah, and to wire up a tools/perf/ build when doing a selftests build perhaps so that libbpf developers can check if in-kernel tools linking against it still builds when they change libbpf/bpftool?

Regards,

- Arnaldo

Quoted 23 lines
Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
 tools/bpf/bpftool/gen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
 	codegen("\
 		\n\
 		__attribute__((unused)) static void			    \n\
-		%1$s__assert(struct %1$s *s)				    \n\
+		%1$s__assert(struct %1$s *s __attribute__((unused)))	    \n\
 		{							    \n\
 		#ifdef __cplusplus					    \n\
 		#define _Static_assert static_assert			    \n\
Signature · 1 line
2.35.1
Signature · 1 line
- Arnaldo
#2 lore raw
In reply to Jiri Olsa
Quoted 11 lines · Jiri Olsa

Arnaldo reported perf compilation fail with:

   $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
   ...
   In file included from util/bpf_counter.c:28:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
     351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
         |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
   cc1: all warnings being treated as errors
Quoted 2 lines

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

If there is nothing to generate, should we avoid generating the assert function itself?

Quoted 22 lines
Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
  tools/bpf/bpftool/gen.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
  	codegen("\
  		\n\
  		__attribute__((unused)) static void			    \n\
-		%1$s__assert(struct %1$s *s)				    \n\
+		%1$s__assert(struct %1$s *s __attribute__((unused)))	    \n\
  		{							    \n\
  		#ifdef __cplusplus					    \n\
  		#define _Static_assert static_assert			    \n\
#3 lore raw
Quoted 14 lines · Yonghong Song
Quoted 11 lines · Jiri Olsa

Arnaldo reported perf compilation fail with:

   $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
   ...
   In file included from util/bpf_counter.c:28:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
     351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
         |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
   cc1: all warnings being treated as errors
Quoted 5 lines
Quoted 2 lines

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

If there is nothing to generate, should we avoid generating the assert function itself?

good point, will check

jirka

Quoted 23 lines
Quoted 23 lines
Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
  tools/bpf/bpftool/gen.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
  	codegen("\
  		\n\
  		__attribute__((unused)) static void			    \n\
-		%1$s__assert(struct %1$s *s)				    \n\
+		%1$s__assert(struct %1$s *s __attribute__((unused)))	    \n\
  		{							    \n\
  		#ifdef __cplusplus					    \n\
  		#define _Static_assert static_assert			    \n\
#4 lore raw
Quoted 16 lines · Jiri Olsa
Quoted 14 lines · Yonghong Song
Quoted 11 lines · Jiri Olsa

Arnaldo reported perf compilation fail with:

   $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
   ...
   In file included from util/bpf_counter.c:28:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
   /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
     351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
         |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
   cc1: all warnings being treated as errors
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

If there is nothing to generate, should we avoid generating the assert function itself?

good point, will check

we can use this function for some more assertions in the future, so instead of trying to be smart about generating or not of this function, I think unused attribute is a more robust solution.

Quoted 26 lines

jirka

Quoted 23 lines
Quoted 23 lines
Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
  tools/bpf/bpftool/gen.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
    codegen("\
            \n\
            __attribute__((unused)) static void                         \n\
-           %1$s__assert(struct %1$s *s)                                \n\
+           %1$s__assert(struct %1$s *s __attribute__((unused)))        \n\
            {                                                           \n\
            #ifdef __cplusplus                                          \n\
            #define _Static_assert static_assert                        \n\
#5 lore raw
Quoted 20 lines · Andrii Nakryiko
Quoted 19 lines · Jiri Olsa
Quoted 17 lines · Yonghong Song
Quoted 13 lines · Jiri Olsa

Arnaldo reported perf compilation fail with:

    $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
    ...
    In file included from util/bpf_counter.c:28:
    /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
    /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
      351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
          |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
    cc1: all warnings being treated as errors

If there's nothing to generate in the new assert function, we will get unused 's' warn/error, adding 'unused' attribute to it.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If there is nothing to generate, should we avoid generating the assert function itself?

good point, will check

we can use this function for some more assertions in the future, so instead of trying to be smart about generating or not of this function, I think unused attribute is a more robust solution.

Okay, if there are possibly more assertions down the road, I am fine to keep the function even if it is empty to avoid more and more conditions to decide whether the functions should be generated at all.

Quoted 27 lines
Quoted 27 lines

jirka

Quoted 23 lines
Quoted 23 lines
Cc Delyan Kratunov <[email protected]>
Fixes 08d4dba6ae77 ("bpftool: Bpf skeletons assert type sizes")
---
   tools/bpf/bpftool/gen.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/gen.c +1 -1
index 7ba7ff55d2ea..91af2850b505 100644
@@ -477,7 +477,7 @@ static void codegen_asserts(struct bpf_object *obj, const char *obj_name)
     codegen("\
             \n\
             __attribute__((unused)) static void                         \n\
-           %1$s__assert(struct %1$s *s)                                \n\
+           %1$s__assert(struct %1$s *s __attribute__((unused)))        \n\
             {                                                           \n\
             #ifdef __cplusplus                                          \n\
             #define _Static_assert static_assert                        \n\
#6 lore raw
In reply to Jiri Olsa
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Mon, 28 Mar 2022 10:37:03 +0200 you wrote:

Arnaldo reported perf compilation fail with:

  $ make -k BUILD_BPF_SKEL=1 CORESIGHT=1 PYTHON=python3
  ...
  In file included from util/bpf_counter.c:28:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h: In function ‘bperf_leader_bpf__assert’:
  /tmp/build/perf//util/bpf_skel/bperf_leader.skel.h:351:51: error: unused parameter ‘s’ [-Werror=unused-parameter]
    351 | bperf_leader_bpf__assert(struct bperf_leader_bpf *s)
        |                          ~~~~~~~~~~~~~~~~~~~~~~~~~^
  cc1: all warnings being treated as errors
Quoted 1 line

[...]

Here is the summary with links:
- bpftool: Fix generated code in codegen_asserts

    https://git.kernel.org/bpf/bpf/c/ef8a257b4e49

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html