linux/tools/testing/selftests/bpf/progs/test_skeleton.c
Andrii Nakryiko caf62492f4 libbpf: Support pre-initializing .bss global variables
Remove invalid assumption in libbpf that .bss map doesn't have to be updated
in kernel. With addition of skeleton and memory-mapped initialization image,
.bss doesn't have to be all zeroes when BPF map is created, because user-code
might have initialized those variables from user-space.

Fixes: eba9c5f498a1 ("libbpf: Refactor global data map initialization")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200612194504.557844-1-andriin@fb.com
2020-06-12 15:27:47 -07:00

58 lines
959 B
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 Facebook */
#include <stdbool.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
struct s {
int a;
long long b;
} __attribute__((packed));
/* .data section */
int in1 = -1;
long long in2 = -1;
/* .bss section */
char in3 = '\0';
long long in4 __attribute__((aligned(64))) = 0;
struct s in5 = {};
/* .rodata section */
const volatile int in6 = 0;
/* .data section */
int out1 = -1;
long long out2 = -1;
/* .bss section */
char out3 = 0;
long long out4 = 0;
int out6 = 0;
extern bool CONFIG_BPF_SYSCALL __kconfig;
extern int LINUX_KERNEL_VERSION __kconfig;
bool bpf_syscall = 0;
int kern_ver = 0;
SEC("raw_tp/sys_enter")
int handler(const void *ctx)
{
static volatile struct s out5;
out1 = in1;
out2 = in2;
out3 = in3;
out4 = in4;
out5 = in5;
out6 = in6;
bpf_syscall = CONFIG_BPF_SYSCALL;
kern_ver = LINUX_KERNEL_VERSION;
return 0;
}
char _license[] SEC("license") = "GPL";