aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Faust <david.faust@oracle.com>2021-08-03 10:28:53 -0700
committerDavid Faust <david.faust@oracle.com>2021-09-07 13:48:58 -0700
commitf4cdfd4856f6e90376dbe277912cefda51922488 (patch)
tree3f19056aac3e5d68cf537885b423a0a06e0567e4 /gcc
parent8bdabb37549f12ce727800a1c8aa182c0b1dd42a (diff)
downloadgcc-f4cdfd4856f6e90376dbe277912cefda51922488.zip
gcc-f4cdfd4856f6e90376dbe277912cefda51922488.tar.gz
gcc-f4cdfd4856f6e90376dbe277912cefda51922488.tar.bz2
bpf testsuite: Add BPF CO-RE tests
This commit adds several tests for the new BPF CO-RE functionality to the BPF target testsuite. gcc/testsuite/ChangeLog: * gcc.target/bpf/core-attr-1.c: New test. * gcc.target/bpf/core-attr-2.c: Likewise. * gcc.target/bpf/core-attr-3.c: Likewise. * gcc.target/bpf/core-attr-4.c: Likewise * gcc.target/bpf/core-builtin-1.c: Likewise * gcc.target/bpf/core-builtin-2.c: Likewise. * gcc.target/bpf/core-builtin-3.c: Likewise. * gcc.target/bpf/core-section-1.c: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-attr-1.c23
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-attr-2.c21
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-attr-3.c41
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-attr-4.c35
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-builtin-1.c64
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-builtin-2.c26
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-builtin-3.c26
-rw-r--r--gcc/testsuite/gcc.target/bpf/core-section-1.c38
8 files changed, 274 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-1.c b/gcc/testsuite/gcc.target/bpf/core-attr-1.c
new file mode 100644
index 0000000..1af9dc5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-1.c
@@ -0,0 +1,23 @@
+/* Basic test for struct __attribute__((preserve_access_index))
+ for BPF CO-RE support. */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct S {
+ int a;
+ int b;
+ int c;
+} __attribute__((preserve_access_index));
+
+void
+func (struct S * s)
+{
+ /* 0:2 */
+ int *x = &(s->c);
+
+ *x = 4;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-2.c b/gcc/testsuite/gcc.target/bpf/core-attr-2.c
new file mode 100644
index 0000000..25c819a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-2.c
@@ -0,0 +1,21 @@
+/* Basic test for union __attribute__((preserve_access_index))
+ for BPF CO-RE support. */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+union U {
+ int a;
+ char c;
+} __attribute__((preserve_access_index));
+
+void
+func (union U *u)
+{
+ /* 0:1 */
+ char *c = &(u->c);
+ *c = 'c';
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-3.c b/gcc/testsuite/gcc.target/bpf/core-attr-3.c
new file mode 100644
index 0000000..b46549f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-3.c
@@ -0,0 +1,41 @@
+/* Test for __attribute__((preserve_access_index)) for BPF CO-RE support
+ for nested structure.
+
+ Note that even though struct O lacks the attribute, when accessed as a
+ member of another attributed type, CO-RE relocations should still be
+ generated. */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct O {
+ int e;
+ int f;
+};
+
+struct S {
+ int a;
+ struct {
+ int b;
+ int c;
+ } inner;
+ struct O other;
+} __attribute__((preserve_access_index));
+
+void
+func (struct S *foo)
+{
+ /* 0:1:1 */
+ int *x = &(foo->inner.c);
+
+ /* 0:2:0 */
+ int *y = &(foo->other.e);
+
+ *x = 4;
+ *y = 5;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:1:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+
+/* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-attr-4.c b/gcc/testsuite/gcc.target/bpf/core-attr-4.c
new file mode 100644
index 0000000..9c0f966
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-attr-4.c
@@ -0,0 +1,35 @@
+/* Test for BPF CO-RE __attribute__((preserve_access_index)) with accesses on
+ LHS and both LHS and RHS of assignment. */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct T {
+ int a;
+ int b;
+ struct U {
+ int c;
+ struct V {
+ int d;
+ int e[4];
+ int f;
+ } v;
+ } u;
+} __attribute__((preserve_access_index));
+
+
+void
+func (struct T *t)
+{
+ /* 0:2:1:1:3 */
+ t->u.v.e[3] = 0xa1;
+
+ /* 0:2:0, 0:0, 0:1 */
+ t->u.c = t->a + t->b;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:2:1:1:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:0.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 4 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-1.c b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
new file mode 100644
index 0000000..e994dc6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-1.c
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct S {
+ int a;
+ int b;
+ char c;
+};
+
+union U {
+ unsigned int u;
+ int i;
+ unsigned char uc[4];
+ signed char ic[4];
+};
+
+struct S my_s;
+union U my_u;
+
+unsigned long ula[8];
+
+#define _(x) (__builtin_preserve_access_index (x))
+
+void
+func (void)
+{
+ /* 1 */
+ int b = _(my_s.b);
+
+ /* 2 */
+ char c = _(my_s.c);
+
+ /* 2:3 */
+ unsigned char uc = _(my_u.uc[3]);
+
+ /* 6 */
+ unsigned long ul = _(ula[6]);
+}
+
+char
+s_ptr (struct S *ps)
+{
+ /* 0:2 */
+ char x = _(ps->c);
+ return x;
+}
+
+unsigned char
+u_ptr (union U *pu)
+{
+ /* 0:2:3 */
+ unsigned char x = _(pu->uc[3]);
+ return x;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"1.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"2:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"6.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+
+/* { dg-final { scan-assembler-times "bpfcr_type" 6 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x6c\[\t \]+\[^\n\]*core_relo_len" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-2.c b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
new file mode 100644
index 0000000..c9ec899
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-2.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct S {
+ int a;
+ union {
+ int _unused;
+ int b;
+ char c;
+ } u[4];
+};
+
+struct S foo;
+
+#define _(x) (__builtin_preserve_access_index (x))
+
+void func (void)
+{
+ char *x = __builtin_preserve_access_index (&foo.u[3].c);
+
+ *x = 's';
+}
+
+/* { dg-final { scan-assembler-times "\[\t \]0x4000002\[\t \]+\[^\n\]*btt_info" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"1:3:2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-builtin-3.c b/gcc/testsuite/gcc.target/bpf/core-builtin-3.c
new file mode 100644
index 0000000..190ec26
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-builtin-3.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -dA -gbtf -mco-re" } */
+
+struct T {
+ int a;
+ int b;
+ struct U {
+ int c;
+ struct V {
+ int d;
+ int e[4];
+ int f;
+ } v;
+ } u;
+};
+
+void func (struct T * foo)
+{
+ /* Access string: "0:2:1:1:3" */
+ int *x = __builtin_preserve_access_index (&(foo->u.v.e[3]));
+
+ *x = 17;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:2:1:1:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 1 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c b/gcc/testsuite/gcc.target/bpf/core-section-1.c
new file mode 100644
index 0000000..031acd5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -gbtf -dA -mco-re" } */
+
+struct T {
+ int a;
+ int b;
+ struct U {
+ int c;
+ struct V {
+ int d;
+ int e[4];
+ int f;
+ } v;
+ } u;
+};
+
+__attribute__((section("foo_sec"), used))
+int foo_func (struct T *t)
+{
+ t->u.c = 5;
+ return __builtin_preserve_access_index (t->u.v.e[3]);
+}
+
+__attribute__((section("bar_sec"), used))
+int bar_func (struct T *t)
+{
+ int *x = __builtin_preserve_access_index (&(t->u.v.f));
+ int old = *x;
+ *x = 4;
+ return old;
+}
+
+/* { dg-final { scan-assembler-times "ascii \"0:2:1:1:3.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"0:2:1:2.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
+/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */