From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7824) id 7580F3858C5F; Thu, 25 Apr 2024 18:19:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7580F3858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714069163; bh=t7KYvgo+gXdlb6ct9SgHnVn0o+NdLN5HkZR6NH1gWAk=; h=From:To:Subject:Date:From; b=ce/yO7qlcDS3c9tZQC+FsawuldLZK2WrA4ZROOx0/wlzqTcTnq1Zmimd4+1O5YpGX f43H/r4HCWw5lIoDrXEzjUAXNQW5rLNZ5SkiYqwKZ3kIxt/sHHQN8dKpyoL3khv4KX jehPI7APSSrkAfZrIxuJtwJVXHgmSE1beWEHDVeA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Faust To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10131] bpf: avoid issues with CO-RE and -gtoggle X-Act-Checkin: gcc X-Git-Author: David Faust X-Git-Refname: refs/heads/master X-Git-Oldrev: 14d48516e588ad2b35e2007b3970bdcb1b3f145c X-Git-Newrev: f175622d25e4146bb7450430831ec48615e6e4cb Message-Id: <20240425181923.7580F3858C5F@sourceware.org> Date: Thu, 25 Apr 2024 18:19:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f175622d25e4146bb7450430831ec48615e6e4cb commit r14-10131-gf175622d25e4146bb7450430831ec48615e6e4cb Author: David Faust Date: Thu Apr 25 09:31:14 2024 -0700 bpf: avoid issues with CO-RE and -gtoggle Compiling a BPF program with CO-RE relocations (and BTF) while also passing -gtoggle led to an inconsistent state where CO-RE support was enabled but BTF would not be generated, and this was not caught by the existing option parsing. This led to an ICE when generating the CO-RE relocation info, since BTF is required for CO-RE. Update bpf_option_override to avoid this case, and add a few tests for the interactions of these options. gcc/ * config/bpf/bpf.cc (bpf_option_override): Improve handling of CO-RE options to avoid issues with -gtoggle. gcc/testsuite/ * gcc.target/bpf/core-options-1.c: New test. * gcc.target/bpf/core-options-2.c: Likewise. * gcc.target/bpf/core-options-3.c: Likewise. Diff: --- gcc/config/bpf/bpf.cc | 7 +++++-- gcc/testsuite/gcc.target/bpf/core-options-1.c | 15 +++++++++++++++ gcc/testsuite/gcc.target/bpf/core-options-2.c | 14 ++++++++++++++ gcc/testsuite/gcc.target/bpf/core-options-3.c | 5 +++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 98fb755bb8b..e6ea211a2c6 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -192,7 +192,8 @@ bpf_option_override (void) init_machine_status = bpf_init_machine_status; /* BPF CO-RE support requires BTF debug info generation. */ - if (TARGET_BPF_CORE && !btf_debuginfo_p ()) + if (TARGET_BPF_CORE + && (!btf_debuginfo_p () || (debug_info_level < DINFO_LEVEL_NORMAL))) error ("BPF CO-RE requires BTF debugging information, use %<-gbtf%>"); /* BPF applications always generate .BTF.ext. */ @@ -215,7 +216,9 @@ bpf_option_override (void) /* -gbtf implies -mcore when using the BPF backend, unless -mno-co-re is specified. */ - if (btf_debuginfo_p () && !(target_flags_explicit & MASK_BPF_CORE)) + if (btf_debuginfo_p () + && (debug_info_level >= DINFO_LEVEL_NORMAL) + && !(target_flags_explicit & MASK_BPF_CORE)) target_flags |= MASK_BPF_CORE; /* Determine available features from ISA setting (-mcpu=). */ diff --git a/gcc/testsuite/gcc.target/bpf/core-options-1.c b/gcc/testsuite/gcc.target/bpf/core-options-1.c new file mode 100644 index 00000000000..7d8c677f239 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/core-options-1.c @@ -0,0 +1,15 @@ +/* -gbtf for the BPF target should enable CO-RE support automatically. */ +/* { dg-do compile } */ +/* { dg-options "-gbtf" } */ + +struct A { + int x; + int y; + char c; +}; + +int +foo (struct A *a) { + int y = __builtin_preserve_access_index (a->y); + return y; +} diff --git a/gcc/testsuite/gcc.target/bpf/core-options-2.c b/gcc/testsuite/gcc.target/bpf/core-options-2.c new file mode 100644 index 00000000000..8f466258e29 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/core-options-2.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-gbtf -gtoggle" } */ + +struct A { + int x; + int y; + char c; +}; + +int +foo (struct A *a) { + int y = __builtin_preserve_access_index (a->y); /* { dg-error "BPF CO-RE is required" } */ + return y; +} diff --git a/gcc/testsuite/gcc.target/bpf/core-options-3.c b/gcc/testsuite/gcc.target/bpf/core-options-3.c new file mode 100644 index 00000000000..ca32a7c4012 --- /dev/null +++ b/gcc/testsuite/gcc.target/bpf/core-options-3.c @@ -0,0 +1,5 @@ +/* This combination of options tries to enable CO-RE without BTF, and should + produce an error. */ +/* { dg-do compile } */ +/* { dg-options "-gbtf -gtoggle -mco-re" } */ +/* { dg-excess-errors "BPF CO-RE requires BTF debugging information" } */