]> gcc.gnu.org Git - gcc.git/commitdiff
bpf: generate indirect calls for xBPF
authorDavid Faust <david.faust@oracle.com>
Fri, 4 Sep 2020 08:18:56 +0000 (10:18 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Fri, 4 Sep 2020 08:22:42 +0000 (10:22 +0200)
This patch updates the BPF back end to generate indirect calls via
the 'call %reg' instruction when targetting xBPF.

Additionally, the BPF ASM_SPEC is updated to pass along -mxbpf to
gas, where it is now supported.

2020-09-03  David Faust  <david.faust@oracle.com>

gcc/

* config/bpf/bpf.h (ASM_SPEC): Pass -mxbpf to gas, if specified.
* config/bpf/bpf.c (bpf_output_call): Support indirect calls in xBPF.

gcc/testsuite/

* gcc.target/bpf/xbpf-indirect-call-1.c: New test.

(cherry picked from commit c3a0f5373919deff68819de1db88c04261d61a87)

gcc/config/bpf/bpf.c
gcc/config/bpf/bpf.h
gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c [new file with mode: 0644]

index 972a91adcd89d2522e635cfd495ff99130329ad4..13181f21c5b22ae4c8bf03c343eb7ea3302c02d9 100644 (file)
@@ -705,8 +705,13 @@ bpf_output_call (rtx target)
        break;
       }
     default:
-      error ("indirect call in function, which are not supported by eBPF");
-      output_asm_insn ("call 0", NULL);
+      if (TARGET_XBPF)
+       output_asm_insn ("call\t%0", &target);
+      else
+       {
+         error ("indirect call in function, which are not supported by eBPF");
+         output_asm_insn ("call 0", NULL);
+       }
       break;
     }
 
index 940029ba606c16b9affea59d24ca8e168e84f474..359f389a1347f60a2b1068917c4e02a97a2eaa5e 100644 (file)
@@ -22,7 +22,7 @@
 
 /**** Controlling the Compilation Driver.  */
 
-#define ASM_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}"
+#define ASM_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL} %{mxbpf:-mxbpf}"
 #define LINK_SPEC "%{mbig-endian:-EB} %{!mbig-endian:-EL}"
 #define LIB_SPEC ""
 #define STARTFILE_SPEC ""
diff --git a/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c b/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c
new file mode 100644 (file)
index 0000000..dc4b3cf
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-mxbpf" } */
+
+/* GCC should generate an indirect call instruction (call %REG)
+   when targetting xBPF.  */
+
+void
+foo ()
+{
+  ;
+}
+
+void
+bar()
+{
+  void (*funp) () = &foo;
+
+  (*funp) ();
+}
+
+/* { dg-final { scan-assembler "call\t%r" } } */
This page took 0.072458 seconds and 5 git commands to generate.