BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v1] selftests/bpf: Skip callx switch table test for clang-22 with cpu=v4
@ 2026-09-30  2:08 Ihor Solodrai
  2026-09-30  9:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Ihor Solodrai @ 2026-09-30  2:08 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Kumar Kartikeya Dwivedi
  Cc: bpf, Yonghong Song

clang-22 miscompiles call_by_switch() when targeting -mcpu=v4: it turns
the switch into an array of pointers to functions and then erroneously
removes the array in BPFAsmPrinter::doFinalization(), breaking the build
with:

  error: Undefined temporary symbol .Lswitch.table.call_by_switch

Fixed by llvm commit 9fc458a1d95b ("[BPF] Fix erroneous removal of
non-jump-table globals"), first released in clang-23; older clangs are
fine. test_progs-cpuv4 is built by default whenever clang supports v4,
so selftests/bpf fails to build with any clang-22 release. Guard just
this test with the compiler/cpu check and leave a __skip placeholder
for the broken combination, so the gap is reported as SKIP instead of
silently missing.

Fixes: b018e998e645 ("selftests/bpf: Add tests for callx through pointers in read-only data")
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 .../bpf/progs/verifier_callx_rodata.c         | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
index db3169a1ddf6..3e7a1c2c2a9a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
@@ -803,6 +803,14 @@ int callx_c_ops_selected(void *ctx)
 	return use_shape(ops, 3);
 }
 
+/*
+ * clang-22 with -mcpu=v4 drops the lookup table it builds for this switch
+ * ("Undefined temporary symbol .Lswitch.table.call_by_switch").
+ * Fixed in clang-23 by llvm commit 9fc458a1d95b.
+ *
+ * https://github.com/llvm/llvm-project/commit/9fc458a1d95b
+ */
+#if __clang_major__ != 22 || __BPF_CPU_VERSION__ < 4
 /* the compiler might turn the switch into a table that has no symbol */
 static __noinline int call_by_switch(unsigned int idx, int x)
 {
@@ -847,6 +855,18 @@ int callx_c_switch_table(void *ctx)
 	return call_by_switch(op_idx - 8, 3);
 }
 
+#else
+
+SEC("socket")
+__skip("clang-22 bug with -mcpu=v4, switch table test cannot be built")
+__success
+int callx_c_switch_table(void *ctx)
+{
+	return 0;
+}
+
+#endif
+
 /*
  * Misaligned pointers to functions are ignored, the rest of the data is
  * accessible as before. The program doesn't have callx, so libbpf doesn't

base-commit: cc6010e6e5cbe1f743d3011991041f227d976a5e
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next v1] selftests/bpf: Skip callx switch table test for clang-22 with cpu=v4
  2026-09-30  2:08 [PATCH bpf-next v1] selftests/bpf: Skip callx switch table test for clang-22 with cpu=v4 Ihor Solodrai
@ 2026-09-30  9:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-30  9:10 UTC (permalink / raw)
  To: Ihor Solodrai; +Cc: ast, andrii, daniel, eddyz87, memxor, bpf, yonghong.song

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue, 29 Sep 2026 19:08:51 -0700 you wrote:
> clang-22 miscompiles call_by_switch() when targeting -mcpu=v4: it turns
> the switch into an array of pointers to functions and then erroneously
> removes the array in BPFAsmPrinter::doFinalization(), breaking the build
> with:
> 
>   error: Undefined temporary symbol .Lswitch.table.call_by_switch
> 
> [...]

Here is the summary with links:
  - [bpf-next,v1] selftests/bpf: Skip callx switch table test for clang-22 with cpu=v4
    https://git.kernel.org/bpf/bpf-next/c/99c3e74f8d96

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:[~2026-09-30  9:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30  2:08 [PATCH bpf-next v1] selftests/bpf: Skip callx switch table test for clang-22 with cpu=v4 Ihor Solodrai
2026-09-30  9:10 ` 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