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: eba9c5f498 ("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
This commit is contained in:
Andrii Nakryiko
2020-06-12 12:45:04 -07:00
committed by Alexei Starovoitov
parent 22eb78792e
commit caf62492f4
3 changed files with 55 additions and 13 deletions

View File

@@ -10,16 +10,26 @@ struct s {
long long b;
} __attribute__((packed));
int in1 = 0;
long long in2 = 0;
/* .data section */
int in1 = -1;
long long in2 = -1;
/* .bss section */
char in3 = '\0';
long long in4 __attribute__((aligned(64))) = 0;
struct s in5 = {};
long long out2 = 0;
/* .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 out1 = 0;
int out6 = 0;
extern bool CONFIG_BPF_SYSCALL __kconfig;
extern int LINUX_KERNEL_VERSION __kconfig;
@@ -36,6 +46,7 @@ int handler(const void *ctx)
out3 = in3;
out4 = in4;
out5 = in5;
out6 = in6;
bpf_syscall = CONFIG_BPF_SYSCALL;
kern_ver = LINUX_KERNEL_VERSION;