selftests/bpf: add CO-RE relocs modifiers/typedef tests
Add tests validating correct handling of various combinations of typedefs and const/volatile/restrict modifiers. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:

committed by
Alexei Starovoitov

parent
d9db355030
commit
9654e2ae90
3
tools/testing/selftests/bpf/progs/btf__core_reloc_mods.c
Normal file
3
tools/testing/selftests/bpf/progs/btf__core_reloc_mods.c
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "core_reloc_types.h"
|
||||
|
||||
void f(struct core_reloc_mods x) {}
|
@@ -0,0 +1,3 @@
|
||||
#include "core_reloc_types.h"
|
||||
|
||||
void f(struct core_reloc_mods___mod_swap x) {}
|
@@ -0,0 +1,3 @@
|
||||
#include "core_reloc_types.h"
|
||||
|
||||
void f(struct core_reloc_mods___typedefs x) {}
|
@@ -454,3 +454,75 @@ struct core_reloc_primitives___err_non_ptr {
|
||||
int d; /* int instead of ptr */
|
||||
int (*f)(const char *);
|
||||
};
|
||||
|
||||
/*
|
||||
* MODS
|
||||
*/
|
||||
struct core_reloc_mods_output {
|
||||
int a, b, c, d, e, f, g, h;
|
||||
};
|
||||
|
||||
typedef const int int_t;
|
||||
typedef const char *char_ptr_t;
|
||||
typedef const int arr_t[7];
|
||||
|
||||
struct core_reloc_mods_substruct {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} core_reloc_mods_substruct_t;
|
||||
|
||||
struct core_reloc_mods {
|
||||
int a;
|
||||
int_t b;
|
||||
char *c;
|
||||
char_ptr_t d;
|
||||
int e[3];
|
||||
arr_t f;
|
||||
struct core_reloc_mods_substruct g;
|
||||
core_reloc_mods_substruct_t h;
|
||||
};
|
||||
|
||||
/* a/b, c/d, e/f, and g/h pairs are swapped */
|
||||
struct core_reloc_mods___mod_swap {
|
||||
int b;
|
||||
int_t a;
|
||||
char *d;
|
||||
char_ptr_t c;
|
||||
int f[3];
|
||||
arr_t e;
|
||||
struct {
|
||||
int y;
|
||||
int x;
|
||||
} h;
|
||||
core_reloc_mods_substruct_t g;
|
||||
};
|
||||
|
||||
typedef int int1_t;
|
||||
typedef int1_t int2_t;
|
||||
typedef int2_t int3_t;
|
||||
|
||||
typedef int arr1_t[5];
|
||||
typedef arr1_t arr2_t;
|
||||
typedef arr2_t arr3_t;
|
||||
typedef arr3_t arr4_t;
|
||||
|
||||
typedef const char * const volatile restrict fancy_char_ptr_t;
|
||||
|
||||
typedef core_reloc_mods_substruct_t core_reloc_mods_substruct_tt;
|
||||
|
||||
/* we need more typedefs */
|
||||
struct core_reloc_mods___typedefs {
|
||||
core_reloc_mods_substruct_tt g;
|
||||
core_reloc_mods_substruct_tt h;
|
||||
arr4_t f;
|
||||
arr4_t e;
|
||||
fancy_char_ptr_t d;
|
||||
fancy_char_ptr_t c;
|
||||
int3_t b;
|
||||
int3_t a;
|
||||
};
|
||||
|
62
tools/testing/selftests/bpf/progs/test_core_reloc_mods.c
Normal file
62
tools/testing/selftests/bpf/progs/test_core_reloc_mods.c
Normal file
@@ -0,0 +1,62 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
// Copyright (c) 2019 Facebook
|
||||
|
||||
#include <linux/bpf.h>
|
||||
#include <stdint.h>
|
||||
#include "bpf_helpers.h"
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
static volatile struct data {
|
||||
char in[256];
|
||||
char out[256];
|
||||
} data;
|
||||
|
||||
struct core_reloc_mods_output {
|
||||
int a, b, c, d, e, f, g, h;
|
||||
};
|
||||
|
||||
typedef const int int_t;
|
||||
typedef const char *char_ptr_t;
|
||||
typedef const int arr_t[7];
|
||||
|
||||
struct core_reloc_mods_substruct {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} core_reloc_mods_substruct_t;
|
||||
|
||||
struct core_reloc_mods {
|
||||
int a;
|
||||
int_t b;
|
||||
char *c;
|
||||
char_ptr_t d;
|
||||
int e[3];
|
||||
arr_t f;
|
||||
struct core_reloc_mods_substruct g;
|
||||
core_reloc_mods_substruct_t h;
|
||||
};
|
||||
|
||||
SEC("raw_tracepoint/sys_enter")
|
||||
int test_core_mods(void *ctx)
|
||||
{
|
||||
struct core_reloc_mods *in = (void *)&data.in;
|
||||
struct core_reloc_mods_output *out = (void *)&data.out;
|
||||
|
||||
if (BPF_CORE_READ(&out->a, &in->a) ||
|
||||
BPF_CORE_READ(&out->b, &in->b) ||
|
||||
BPF_CORE_READ(&out->c, &in->c) ||
|
||||
BPF_CORE_READ(&out->d, &in->d) ||
|
||||
BPF_CORE_READ(&out->e, &in->e[2]) ||
|
||||
BPF_CORE_READ(&out->f, &in->f[1]) ||
|
||||
BPF_CORE_READ(&out->g, &in->g.x) ||
|
||||
BPF_CORE_READ(&out->h, &in->h.y))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user