diff mbox series

[V3,2/3] bpf: Add new -mco-re option for BPF CO-RE

Message ID 1630418895-23520-3-git-send-email-indu.bhagat@oracle.com
State New
Headers show
Series Allow means for late BTF generation for BPF CO-RE | expand

Commit Message

Indu Bhagat Aug. 31, 2021, 2:08 p.m. UTC
-mco-re in the BPF backend enables code generation for the CO-RE usecase. LTO is
disabled for CO-RE compilations.

gcc/ChangeLog:

	* config/bpf/bpf.c (bpf_option_override): For BPF backend, disable LTO
	support when compiling for CO-RE.
	* config/bpf/bpf.opt: Add new command line option -mco-re.

gcc/testsuite/ChangeLog:

	* gcc.target/bpf/core-lto-1.c: New test.
---
 gcc/config/bpf/bpf.c                      | 25 +++++++++++++++++++++++++
 gcc/config/bpf/bpf.opt                    |  4 ++++
 gcc/testsuite/gcc.target/bpf/core-lto-1.c |  9 +++++++++
 3 files changed, 38 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/bpf/core-lto-1.c
diff mbox series

Patch

diff --git a/gcc/config/bpf/bpf.c b/gcc/config/bpf/bpf.c
index e635f9e..7228978 100644
--- a/gcc/config/bpf/bpf.c
+++ b/gcc/config/bpf/bpf.c
@@ -54,6 +54,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "predict.h"
 #include "langhooks.h"
+#include "flags.h"
 
 /* Per-function machine data.  */
 struct GTY(()) machine_function
@@ -158,6 +159,30 @@  bpf_option_override (void)
 {
   /* Set the initializer for the per-function status structure.  */
   init_machine_status = bpf_init_machine_status;
+
+  /* BPF CO-RE support requires BTF debug info generation.  */
+  if (TARGET_BPF_CORE && !btf_debuginfo_p ())
+    error ("BPF CO-RE requires BTF debugging information, use %<-gbtf%>");
+
+  /* To support the portability needs of BPF CO-RE approach, BTF debug
+     information includes the BPF CO-RE relocations.  */
+  if (TARGET_BPF_CORE)
+    write_symbols |= BTF_WITH_CORE_DEBUG;
+
+  /* Unlike much of the other BTF debug information, the information necessary
+     for CO-RE relocations is added to the CTF container by the BPF backend.
+     Enabling LTO adds some complications in the generation of the BPF CO-RE
+     relocations because if LTO is in effect, the relocations need to be
+     generated late in the LTO link phase.  This poses a new challenge for the
+     compiler to now provide means to combine the early BTF and late BTF CO-RE
+     debug info, similar to DWARF debug info.  BTF/CO-RE debug info is not
+     amenable to such a split generation and a later merging.
+
+     In any case, in absence of linker support for BTF sections at this time,
+     it is acceptable to simply disallow LTO for BPF CO-RE compilations.  */
+
+  if (flag_lto && TARGET_BPF_CORE)
+    sorry ("BPF CO-RE does not support LTO");
 }
 
 #undef TARGET_OPTION_OVERRIDE
diff --git a/gcc/config/bpf/bpf.opt b/gcc/config/bpf/bpf.opt
index 916b53c..4493067 100644
--- a/gcc/config/bpf/bpf.opt
+++ b/gcc/config/bpf/bpf.opt
@@ -127,3 +127,7 @@  Generate little-endian eBPF.
 mframe-limit=
 Target Joined RejectNegative UInteger IntegerRange(0, 32767) Var(bpf_frame_limit) Init(512)
 Set a hard limit for the size of each stack frame, in bytes.
+
+mco-re
+Target Mask(BPF_CORE)
+Generate all necessary information for BPF Compile Once - Run Everywhere.
diff --git a/gcc/testsuite/gcc.target/bpf/core-lto-1.c b/gcc/testsuite/gcc.target/bpf/core-lto-1.c
new file mode 100644
index 0000000..927de23
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-lto-1.c
@@ -0,0 +1,9 @@ 
+/* Test -mco-re with -flto.
+  
+   -mco-re is used to generate information for BPF CO-RE usecase. To support
+   the generataion of the .BTF and .BTF.ext sections in GCC, -flto is disabled
+   with -mco-re.  */
+
+/* { dg-do compile } */
+/* { dg-message "sorry, unimplemented: BPF CO-RE does not support LTO" "" { target bpf-*-* } 0 } */
+/* { dg-options "-gbtf -mco-re -flto" } */