Skip to content
Snippets Groups Projects
Commit f175622d authored by David Faust's avatar David Faust
Browse files

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.
parent 14d48516
No related branches found
No related tags found
No related merge requests found
...@@ -192,7 +192,8 @@ bpf_option_override (void) ...@@ -192,7 +192,8 @@ bpf_option_override (void)
init_machine_status = bpf_init_machine_status; init_machine_status = bpf_init_machine_status;
/* BPF CO-RE support requires BTF debug info generation. */ /* 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%>"); error ("BPF CO-RE requires BTF debugging information, use %<-gbtf%>");
/* BPF applications always generate .BTF.ext. */ /* BPF applications always generate .BTF.ext. */
...@@ -215,7 +216,9 @@ bpf_option_override (void) ...@@ -215,7 +216,9 @@ bpf_option_override (void)
/* -gbtf implies -mcore when using the BPF backend, unless -mno-co-re /* -gbtf implies -mcore when using the BPF backend, unless -mno-co-re
is specified. */ 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; target_flags |= MASK_BPF_CORE;
/* Determine available features from ISA setting (-mcpu=). */ /* Determine available features from ISA setting (-mcpu=). */
......
/* -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;
}
/* { 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;
}
/* 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" } */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment