* [PATCH] bpf: generate indirect calls for xBPF
@ 2020-09-03 16:37 David Faust
2020-09-04 8:24 ` Jose E. Marchesi
0 siblings, 1 reply; 2+ messages in thread
From: David Faust @ 2020-09-03 16:37 UTC (permalink / raw)
To: gcc-patches
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.
---
gcc/config/bpf/bpf.c | 9 ++++++--
gcc/config/bpf/bpf.h | 2 +-
.../gcc.target/bpf/xbpf-indirect-call-1.c | 21 +++++++++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c
diff --git a/gcc/config/bpf/bpf.c b/gcc/config/bpf/bpf.c
index 972a91adcd8..13181f21c5b 100644
--- a/gcc/config/bpf/bpf.c
+++ b/gcc/config/bpf/bpf.c
@@ -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;
}
diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h
index 940029ba606..359f389a134 100644
--- a/gcc/config/bpf/bpf.h
+++ b/gcc/config/bpf/bpf.h
@@ -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
index 00000000000..dc4b3cfb12d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/xbpf-indirect-call-1.c
@@ -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" } } */
--
2.26.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] bpf: generate indirect calls for xBPF
2020-09-03 16:37 [PATCH] bpf: generate indirect calls for xBPF David Faust
@ 2020-09-04 8:24 ` Jose E. Marchesi
0 siblings, 0 replies; 2+ messages in thread
From: Jose E. Marchesi @ 2020-09-04 8:24 UTC (permalink / raw)
To: David Faust via Gcc-patches
Hi David.
> 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.
Thanks for the patch.
I just installed it on your behalf.
Salud!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-04 8:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03 16:37 [PATCH] bpf: generate indirect calls for xBPF David Faust
2020-09-04 8:24 ` Jose E. Marchesi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).