Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/bpf: Adapt inline asm operand constraint for GCC support

GCC errors when compiling tailcall_bpf2bpf_hierarchy2.c and
tailcall_bpf2bpf_hierarchy3.c with the following error:

progs/tailcall_bpf2bpf_hierarchy2.c: In function 'tailcall_bpf2bpf_hierarchy_2':
progs/tailcall_bpf2bpf_hierarchy2.c:66:9: error: input operand constraint contains '+'
66 | asm volatile (""::"r+"(ret));
| ^~~

Changed implementation to make use of __sink macro that abstracts the
desired behaviour.

The proposed change seems valid for both GCC and CLANG.

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240819151129.1366484-4-cupertino.miranda@oracle.com

authored by

Cupertino Miranda and committed by
Andrii Nakryiko
d9075ac6 2aa93695

+4 -4
+2 -2
tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy2.c
··· 58 58 SEC("tc") 59 59 int tailcall_bpf2bpf_hierarchy_2(struct __sk_buff *skb) 60 60 { 61 - volatile int ret = 0; 61 + int ret = 0; 62 62 63 63 subprog_tail0(skb); 64 64 subprog_tail1(skb); 65 65 66 - asm volatile (""::"r+"(ret)); 66 + __sink(ret); 67 67 return (count1 << 16) | count0; 68 68 } 69 69
+2 -2
tools/testing/selftests/bpf/progs/tailcall_bpf2bpf_hierarchy3.c
··· 51 51 SEC("tc") 52 52 int tailcall_bpf2bpf_hierarchy_3(struct __sk_buff *skb) 53 53 { 54 - volatile int ret = 0; 54 + int ret = 0; 55 55 56 56 bpf_tail_call_static(skb, &jmp_table0, 0); 57 57 58 - asm volatile (""::"r+"(ret)); 58 + __sink(ret); 59 59 return ret; 60 60 } 61 61