From: Alexei Starovoitov 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 --- 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)