diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index 98fb755bb8b705aea48b532acf0ec1f9582ee390..e6ea211a2c6033f99982e990cc7ce3e937a76ab5 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 0000000000000000000000000000000000000000..7d8c677f239bc40778428285b087ddcd9491dd1a --- /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 0000000000000000000000000000000000000000..8f466258e29ea7f0fe8ec727157c23eb8b4cacb4 --- /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 0000000000000000000000000000000000000000..ca32a7c401245efd17addec606d55ab76b24c0e6 --- /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" } */