BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix data_in_arena test with GCC
@ 2026-10-03 15:04 Alexei Starovoitov
  2026-10-03 16:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Alexei Starovoitov @ 2026-10-03 15:04 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/data_in_arena.c: In function 'use_ops':
  progs/data_in_arena.c:65:1: error: indirect call in function, which are not supported by eBPF

Call add1() directly when the test is built with GCC. use_ops() still
loads the pointers to data that are next to the pointer to the function
in .data.rel.ro and dereferences them.

Once the build is fixed data_in_arena/arena_var_no_map fails with GCC:

  test_arena_var_no_map:FAIL:open unexpected pointer: 0x559fb35d3ca0

GCC doesn't support address spaces. __arena is a type tag only there,
so avar is in .data instead of .addr_space.1 and there is nothing wrong
with the object. Use __arena_global. It puts the variable into
.addr_space.1 with both compilers.

Fixes: 27e24617a83b ("selftests/bpf: Add test for global data in arena")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
 tools/testing/selftests/bpf/progs/data_in_arena.c       | 5 +++++
 tools/testing/selftests/bpf/progs/data_in_arena_nomap.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/progs/data_in_arena.c b/tools/testing/selftests/bpf/progs/data_in_arena.c
index ce3838327d6f..18f38103c0fc 100644
--- a/tools/testing/selftests/bpf/progs/data_in_arena.c
+++ b/tools/testing/selftests/bpf/progs/data_in_arena.c
@@ -61,7 +61,12 @@ int use_ops(void *ctx)
 {
 	/* a program has the arena when its code refers to it */
 	counter++;
+#ifdef __clang__
 	return ops.fn(*ops.data) + ops.name[1];
+#else
+	/* gcc doesn't support indirect calls */
+	return add1(*ops.data) + ops.name[1];
+#endif
 }
 
 SEC("syscall")
diff --git a/tools/testing/selftests/bpf/progs/data_in_arena_nomap.c b/tools/testing/selftests/bpf/progs/data_in_arena_nomap.c
index da27a8f10d6f..ccf66321eb36 100644
--- a/tools/testing/selftests/bpf/progs/data_in_arena_nomap.c
+++ b/tools/testing/selftests/bpf/progs/data_in_arena_nomap.c
@@ -9,7 +9,7 @@ char data_in_arena SEC(".arena.data");
 
 int counter = 5;
 /* needs an arena map that is declared. The one that libbpf creates won't do. */
-int __arena avar = 11;
+int __arena_global avar = 11;
 
 SEC("syscall")
 int arena_var(void *ctx)

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

end of thread, other threads:[~2026-10-03 16:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-03 15:04 [PATCH bpf-next] selftests/bpf: Fix data_in_arena test with GCC Alexei Starovoitov
2026-10-03 16:40 ` 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