From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7850) id 788D53857435; Tue, 7 Sep 2021 18:21:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 788D53857435 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Indu Bhagat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3390] bpf: Add new -mco-re option for BPF CO-RE X-Act-Checkin: gcc X-Git-Author: Indu Bhagat X-Git-Refname: refs/heads/master X-Git-Oldrev: 053db9a49b00d422cd735bee4c0939b7ff07c40e X-Git-Newrev: e29a9607faae320a92f19b38f0424037ac3bdbfe Message-Id: <20210907182110.788D53857435@sourceware.org> Date: Tue, 7 Sep 2021 18:21:10 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2021 18:21:10 -0000 https://gcc.gnu.org/g:e29a9607faae320a92f19b38f0424037ac3bdbfe commit r12-3390-ge29a9607faae320a92f19b38f0424037ac3bdbfe Author: Indu Bhagat Date: Tue Sep 7 11:17:55 2021 -0700 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. Diff: --- 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(+) diff --git a/gcc/config/bpf/bpf.c b/gcc/config/bpf/bpf.c index e635f9edb40..7228978a3a9 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 916b53c15ea..4493067b987 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 00000000000..927de23671b --- /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" } */