selftests/bpf: Fix data_in_arena test with GCC

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: 27e24617a8 ("selftests/bpf: Add test for global data in arena")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20261003150456.168903-1-alexei.starovoitov@gmail.com
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
Alexei Starovoitov 2026-10-03 15:04:56 +00:00 committed by Kumar Kartikeya Dwivedi
parent d82cbceca4
commit 1ad83c31ab
No known key found for this signature in database
GPG Key ID: 472D377B63542F83
2 changed files with 6 additions and 1 deletions

View File

@ -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")

View File

@ -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)