diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2021-10-20 18:44:02 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-10-21 17:10:10 -0700 |
commit | 30c5bd96476ced0d3e08372be5186ff7f421d10c (patch) | |
tree | 8d83f25aac7e1a1d8c485228553b5e826ad6c331 /tools/testing/selftests/bpf/progs/test_skeleton.c | |
parent | aed659170a3171e425913ae259d46396fb9c10ef (diff) | |
download | linux-30c5bd96476ced0d3e08372be5186ff7f421d10c.tar.gz linux-30c5bd96476ced0d3e08372be5186ff7f421d10c.tar.bz2 linux-30c5bd96476ced0d3e08372be5186ff7f421d10c.zip |
selftests/bpf: Demonstrate use of custom .rodata/.data sections
Enhance existing selftests to demonstrate the use of custom
.data/.rodata sections.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211021014404.2635234-9-andrii@kernel.org
Diffstat (limited to 'tools/testing/selftests/bpf/progs/test_skeleton.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/test_skeleton.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_skeleton.c b/tools/testing/selftests/bpf/progs/test_skeleton.c index 441fa1c552c8..1b1187d2967b 100644 --- a/tools/testing/selftests/bpf/progs/test_skeleton.c +++ b/tools/testing/selftests/bpf/progs/test_skeleton.c @@ -5,6 +5,8 @@ #include <linux/bpf.h> #include <bpf/bpf_helpers.h> +#define __read_mostly SEC(".data.read_mostly") + struct s { int a; long long b; @@ -40,9 +42,20 @@ int kern_ver = 0; struct s out5 = {}; + +const volatile int in_dynarr_sz SEC(".rodata.dyn"); +const volatile int in_dynarr[4] SEC(".rodata.dyn") = { -1, -2, -3, -4 }; + +int out_dynarr[4] SEC(".data.dyn") = { 1, 2, 3, 4 }; + +int read_mostly_var __read_mostly; +int out_mostly_var; + SEC("raw_tp/sys_enter") int handler(const void *ctx) { + int i; + out1 = in1; out2 = in2; out3 = in3; @@ -53,6 +66,11 @@ int handler(const void *ctx) bpf_syscall = CONFIG_BPF_SYSCALL; kern_ver = LINUX_KERNEL_VERSION; + for (i = 0; i < in_dynarr_sz; i++) + out_dynarr[i] = in_dynarr[i]; + + out_mostly_var = read_mostly_var; + return 0; } |