Skip to content

Commit 4e1f9a0

Browse files
committed
bpf: add tests for CO-RE and BTF tag interaction
Add a couple of tests to ensure that BTF type/decl tags do not interfere with generation of BPF CO-RE relocations. gcc/testsuite/ * gcc.target/bpf/core-btf-tag-1.c: New test. * gcc.target/bpf/core-btf-tag-2.c: New test.
1 parent 8b5d751 commit 4e1f9a0

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Test that BTF type tags do not interfere with CO-RE relocations. */
2+
3+
/* { dg-do compile } */
4+
/* { dg-options "-gbtf -dA -mco-re" } */
5+
6+
struct bpf_cpumask {
7+
int i;
8+
char c;
9+
} __attribute__((preserve_access_index));
10+
11+
struct kptr_nested {
12+
struct bpf_cpumask * __attribute__((btf_type_tag("kptr"))) mask;
13+
} __attribute__((preserve_access_index));
14+
15+
void foo (struct kptr_nested *nested)
16+
{
17+
if (nested && nested->mask)
18+
nested->mask->i = 5;
19+
}
20+
21+
/* { dg-final { scan-assembler-times "bpfcr_insn" 3 } } */
22+
/* { dg-final { scan-assembler-times "bpfcr_type \\(struct" 3 } } */
23+
/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 3 } } */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Test that BTF decl tags do not interfere with CO-RE relocations. */
2+
3+
/* { dg-do compile } */
4+
/* { dg-options "-gbtf -dA -mco-re" } */
5+
6+
struct bpf_cpumask {
7+
int i;
8+
char c;
9+
} __attribute__((preserve_access_index));
10+
11+
struct kptr_nested {
12+
struct bpf_cpumask * mask __attribute__((btf_decl_tag ("decltag")));
13+
} __attribute__((preserve_access_index));
14+
15+
void foo (struct kptr_nested *nested __attribute__((btf_decl_tag ("foo"))))
16+
{
17+
if (nested && nested->mask)
18+
nested->mask->i = 5;
19+
}
20+
21+
/* { dg-final { scan-assembler-times "bpfcr_insn" 3 } } */
22+
/* { dg-final { scan-assembler-times "bpfcr_type \\(struct" 3 } } */
23+
/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 3 } } */

0 commit comments

Comments
 (0)