libbpf: Support initialized global variables

Initialized global variables are no different in ELF from static variables,
and don't require any extra support from libbpf. But they are matching
semantics of global data (backed by BPF maps) more closely, preventing
LLVM/Clang from aggressively inlining constant values and not requiring
volatile incantations to prevent those. This patch enables global variables.
It still disables uninitialized variables, which will be put into special COM
(common) ELF section, because BPF doesn't allow uninitialized data to be
accessed.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191121070743.1309473-5-andriin@fb.com
This commit is contained in:
Andrii Nakryiko 2019-11-20 23:07:43 -08:00 committed by Alexei Starovoitov
parent 8983b731ce
commit 393cdfbee8
14 changed files with 28 additions and 33 deletions

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_arrays_output {
int a2;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_bitfields {
/* unsigned bitfields */

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_bitfields {
/* unsigned bitfields */

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_existence_output {
int a_exists;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_flavors {
int a;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_ints {
uint8_t u8_field;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_kernel_output {
int valid[10];

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_misc_output {
int a, b, c;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_mods_output {
int a, b, c, d, e, f, g, h;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_nesting_substruct {
int a;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
enum core_reloc_primitives_enum {
A = 0,

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_ptr_as_arr {
int a;

View file

@ -8,10 +8,10 @@
char _license[] SEC("license") = "GPL";
static volatile struct data {
struct {
char in[256];
char out[256];
} data;
} data = {};
struct core_reloc_size_output {
int int_sz;