All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix build of callx tests with GCC
@ 2026-09-24 18:21 Alexei Starovoitov
  2026-09-24 19:50 ` Ihor Solodrai
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2026-09-24 18:21 UTC (permalink / raw)
  To: bpf; +Cc: daniel, andrii, eddyz87, memxor

From: Alexei Starovoitov <ast@kernel.org>

GCC doesn't support indirect calls in BPF:

  progs/verifier_callx.c: In function 'apply_op':
  progs/verifier_callx.c:977:1: error: indirect call in function, which are not supported by eBPF
  progs/verifier_callx_rodata.c: In function 'use_shape':
  progs/verifier_callx_rodata.c:746:1: error: indirect call in function, which are not supported by eBPF

Build verifier_callx, verifier_callx_rodata and callx_rodata progs
with clang only. Skip callx_rodata_lskel test when progs are built
with GCC.

Fixes: e9b22d50796d ("selftests/bpf: Add tests for callx")
Fixes: b018e998e645 ("selftests/bpf: Add tests for callx through pointers in read-only data")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 .../bpf/prog_tests/callx_rodata_lskel.c       |  6 ++++
 .../selftests/bpf/progs/callx_rodata.c        | 28 +++++++++++++++++--
 .../selftests/bpf/progs/verifier_callx.c      |  3 +-
 .../bpf/progs/verifier_callx_rodata.c         |  3 +-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
index 96f6179f0492..6a43b880d730 100644
--- a/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
+++ b/tools/testing/selftests/bpf/prog_tests/callx_rodata_lskel.c
@@ -35,6 +35,12 @@ void test_callx_rodata_lskel(void)
 	if (!ASSERT_OK_PTR(skel, "open"))
 		return;
 
+	/* gcc doesn't support indirect calls */
+	if (skel->rodata->skip) {
+		test__skip();
+		goto out;
+	}
+
 	skel->rodata->bias = 7;
 
 	if (!ASSERT_OK(callx_rodata_lskel__load(skel), "load"))
diff --git a/tools/testing/selftests/bpf/progs/callx_rodata.c b/tools/testing/selftests/bpf/progs/callx_rodata.c
index 07ae2d1b6b8e..e3f8335f80f8 100644
--- a/tools/testing/selftests/bpf/progs/callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/callx_rodata.c
@@ -1,16 +1,21 @@
 // SPDX-License-Identifier: GPL-2.0
 /* callx through pointers to functions in .rodata, loaded by light skeleton */
 
+#include <stdbool.h>
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 
-typedef int (*op_fn)(int);
-
 /* set by user space before the programs are loaded, it's in .rodata too */
 const volatile int bias = 1;
 
 int op_idx;
 
+#ifdef __clang__
+
+const volatile bool skip = false;
+
+typedef int (*op_fn)(int);
+
 static __noinline int add_bias(int x)
 {
 	return x + bias;
@@ -41,6 +46,25 @@ int both_ops(void *ctx)
 	return ops[1](ops[0](4));
 }
 
+#else
+
+/* gcc doesn't support indirect calls */
+const volatile bool skip = true;
+
+SEC("socket")
+int select_op(void *ctx)
+{
+	return 0;
+}
+
+SEC("socket")
+int both_ops(void *ctx)
+{
+	return 0;
+}
+
+#endif
+
 /* no callx here */
 SEC("socket")
 int read_bias(void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx.c b/tools/testing/selftests/bpf/progs/verifier_callx.c
index ea3d3f97da31..bc31d0221f6a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx.c
@@ -6,7 +6,8 @@
 #include "bpf_misc.h"
 #include "../../../include/linux/filter.h"
 
-#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
+/* gcc doesn't support indirect calls */
+#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && defined(__clang__)
 
 #define CALLX_INSN(DST, SRC, OFF, IMM) \
 	BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, DST, SRC, OFF, IMM)
diff --git a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
index 65d34769c8bf..db3169a1ddf6 100644
--- a/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
+++ b/tools/testing/selftests/bpf/progs/verifier_callx_rodata.c
@@ -6,7 +6,8 @@
 #include "bpf_misc.h"
 #include "../../../include/linux/filter.h"
 
-#if defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)
+/* gcc doesn't support indirect calls */
+#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && defined(__clang__)
 
 /*
  * Read-only data with pointers to functions, where the compiler puts tables
-- 
2.55.0


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

end of thread, other threads:[~2026-09-25  6:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24 18:21 [PATCH bpf-next] selftests/bpf: Fix build of callx tests with GCC Alexei Starovoitov
2026-09-24 19:50 ` Ihor Solodrai
2026-09-24 20:00 ` patchwork-bot+netdevbpf
2026-09-25  6:50 ` Vineet Gupta
2026-09-25  6:50   ` Vineet Gupta

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.