-mcore 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 -mcore.
gcc/testsuite/ChangeLog:
* gcc.dg/debug/btf/btf-mcore-1.c: New test.
---
gcc/config/bpf/bpf.c | 15 +++++++++++++++
gcc/config/bpf/bpf.opt | 4 ++++
gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c | 14 ++++++++++++++
3 files changed, 33 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c
diff --git a/gcc/config/bpf/bpf.c b/gcc/config/bpf/bpf.c
index e635f9e..028013e 100644
--- a/gcc/config/bpf/bpf.c
+++ b/gcc/config/bpf/bpf.c
@@ -158,6 +158,21 @@ bpf_option_override (void)
{
/* Set the initializer for the per-function status structure. */
init_machine_status = bpf_init_machine_status;
+
+ /* To support the portability needs of BPF CO-RE approach, BTF debug
+ information includes the BPF CO-RE relocations. The information
+ necessary for these relocations is added to the CTF container by the
+ BPF backend. Enabling LTO poses challenges in the generation of the BPF
+ CO-RE relocations because if LTO is in effect, they need to be
+ generated late in the LTO link phase. This in turn means the compiler
+ needs to provide means to combine the early and late BTF debug info,
+ similar to DWARF debug info.
+
+ 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)
+ error ("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..e8926f5 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.
+
+mcore
+Target Mask(BPF_CORE)
+Generate all necessary information for BPF Compile Once - Run Everywhere.
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c
b/gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c
new file mode 100644
index 0000000..58f20d0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c
@@ -0,0 +1,14 @@
+/* Testcase for BPF CO-RE.
+
+ -mcore 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 -mcore. */
+
+/* { dg-do compile { target bpf-*-* } } */
+/* { dg-error "BPF CO-RE does not support LTO" "" { target btf-*-* } 0 } */
+
+/* { dg-require-effective-target lto } */
+
+/* { dg-options "-gbtf -mcore -flto" } */
+
+void func(void) { }
--
1.8.3.1