From e29a9607faae320a92f19b38f0424037ac3bdbfe Mon Sep 17 00:00:00 2001 From: Indu Bhagat Date: Tue, 7 Sep 2021 11:17:55 -0700 Subject: [PATCH] bpf: Add new -mco-re option for BPF CO-RE -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 --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" } */ -- 2.7.4