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. */
/* -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=). */
--- /dev/null
+/* -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;
+}
--- /dev/null
+/* 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" } */