* [PATCH bpf-next v2] selftests/bpf: fix a clang compilation error for send_signal.c
@ 2022-03-11 0:37 Yonghong Song
2022-03-11 21:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2022-03-11 0:37 UTC (permalink / raw)
To: bpf; +Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team
Building selftests/bpf with latest clang compiler (clang15 built
from source), I hit the following compilation error:
/.../prog_tests/send_signal.c:43:16: error: variable 'j' set but not used [-Werror,-Wunused-but-set-variable]
volatile int j = 0;
^
1 error generated.
The problem also exists with clang13 and clang14. clang12 is okay.
In send_signal.c, we have the following code
volatile int j = 0;
...
for (int i = 0; i < 100000000 && !sigusr1_received; i++)
j /= i + 1;
to burn cpu cycles so bpf_send_signal() helper can be tested
in nmi mode.
Slightly changing 'j /= i + 1' to 'j /= i + j + 1' or 'j++' can
fix the problem. Further investigation indicated this should be
a clang bug ([1]). The upstream fix will be proposed later. But it is
a good idea to workaround the issue to unblock people who build
kernel/selftests with clang.
[1] https://discourse.llvm.org/t/strange-clang-unused-but-set-variable-error-with-volatile-variables/60841
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/testing/selftests/bpf/prog_tests/send_signal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/send_signal.c b/tools/testing/selftests/bpf/prog_tests/send_signal.c
index def50f1c5c31..d71226e34c34 100644
--- a/tools/testing/selftests/bpf/prog_tests/send_signal.c
+++ b/tools/testing/selftests/bpf/prog_tests/send_signal.c
@@ -65,7 +65,7 @@ static void test_send_signal_common(struct perf_event_attr *attr,
/* wait a little for signal handler */
for (int i = 0; i < 100000000 && !sigusr1_received; i++)
- j /= i + 1;
+ j /= i + j + 1;
buf[0] = sigusr1_received ? '2' : '0';
ASSERT_EQ(sigusr1_received, 1, "sigusr1_received");
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: fix a clang compilation error for send_signal.c
2022-03-11 0:37 [PATCH bpf-next v2] selftests/bpf: fix a clang compilation error for send_signal.c Yonghong Song
@ 2022-03-11 21:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-11 21:20 UTC (permalink / raw)
To: Yonghong Song; +Cc: bpf, ast, andrii, daniel, kernel-team
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Thu, 10 Mar 2022 16:37:21 -0800 you wrote:
> Building selftests/bpf with latest clang compiler (clang15 built
> from source), I hit the following compilation error:
> /.../prog_tests/send_signal.c:43:16: error: variable 'j' set but not used [-Werror,-Wunused-but-set-variable]
> volatile int j = 0;
> ^
> 1 error generated.
> The problem also exists with clang13 and clang14. clang12 is okay.
>
> [...]
Here is the summary with links:
- [bpf-next,v2] selftests/bpf: fix a clang compilation error for send_signal.c
https://git.kernel.org/bpf/bpf-next/c/d3b351f65bf4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-11 22:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-11 0:37 [PATCH bpf-next v2] selftests/bpf: fix a clang compilation error for send_signal.c Yonghong Song
2022-03-11 21:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox