https://gcc.gnu.org/g:4e1f9a0fbe52212663a6de7416d00bbe04d7d7cd

commit r16-4344-g4e1f9a0fbe52212663a6de7416d00bbe04d7d7cd
Author: David Faust <[email protected]>
Date:   Mon Apr 28 12:17:24 2025 -0700

    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.

Diff:
---
 gcc/testsuite/gcc.target/bpf/core-btf-tag-1.c | 23 +++++++++++++++++++++++
 gcc/testsuite/gcc.target/bpf/core-btf-tag-2.c | 23 +++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/gcc/testsuite/gcc.target/bpf/core-btf-tag-1.c 
b/gcc/testsuite/gcc.target/bpf/core-btf-tag-1.c
new file mode 100644
index 000000000000..bd0fb3e40be4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-btf-tag-1.c
@@ -0,0 +1,23 @@
+/* Test that BTF type tags do not interfere with CO-RE relocations.  */
+
+/* { dg-do compile } */
+/* { dg-options "-gbtf -dA -mco-re" } */
+
+struct bpf_cpumask {
+  int i;
+  char c;
+} __attribute__((preserve_access_index));
+
+struct kptr_nested {
+       struct bpf_cpumask * __attribute__((btf_type_tag("kptr"))) mask;
+} __attribute__((preserve_access_index));
+
+void foo (struct kptr_nested *nested)
+{
+  if (nested && nested->mask)
+    nested->mask->i = 5;
+}
+
+/* { dg-final { scan-assembler-times "bpfcr_insn" 3 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type \\(struct" 3 } } */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 3 } } */
diff --git a/gcc/testsuite/gcc.target/bpf/core-btf-tag-2.c 
b/gcc/testsuite/gcc.target/bpf/core-btf-tag-2.c
new file mode 100644
index 000000000000..6654ffe3ae05
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-btf-tag-2.c
@@ -0,0 +1,23 @@
+/* Test that BTF decl tags do not interfere with CO-RE relocations.  */
+
+/* { dg-do compile } */
+/* { dg-options "-gbtf -dA -mco-re" } */
+
+struct bpf_cpumask {
+  int i;
+  char c;
+} __attribute__((preserve_access_index));
+
+struct kptr_nested {
+       struct bpf_cpumask * mask __attribute__((btf_decl_tag ("decltag")));
+} __attribute__((preserve_access_index));
+
+void foo (struct kptr_nested *nested __attribute__((btf_decl_tag ("foo"))))
+{
+  if (nested && nested->mask)
+    nested->mask->i = 5;
+}
+
+/* { dg-final { scan-assembler-times "bpfcr_insn" 3 } } */
+/* { dg-final { scan-assembler-times "bpfcr_type \\(struct" 3 } } */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \\(\"0:0\"\\)" 3 } } */

Reply via email to