bpf: set PREFERRED_DEBUGGING_TYPE to BTF_DEBUG

BTF is the standard debug info used with BPF programs, so it makes sense
to default to BTF rather than DWARF.

gcc/
	* config/bpf/bpf.h (PREFERRED_DEBUGGING_TYPE): Set to BTF_DEBUG.

gcc/testsuite/
	* gcc.target/bpf/bpf-debug-options-1.c: New test.
	* gcc.target/bpf/bpf-debug-options-2.c: Likewise.
	* gcc.target/bpf/bpf-debug-options-3.c: Likewise.
	* gcc.target/bpf/core-options-4.c: Likewise.
This commit is contained in:
David Faust 2024-04-24 15:01:02 -07:00
parent f541757ba4
commit 1604f7cebc
5 changed files with 58 additions and 0 deletions

View file

@ -245,6 +245,11 @@ enum reg_class
/**** Debugging Info ****/
/* Use BTF debug info by default. */
#undef PREFERRED_DEBUGGING_TYPE
#define PREFERRED_DEBUGGING_TYPE BTF_DEBUG
/* In eBPF it is not possible to unwind frames. Disable CFA. */
#define DWARF2_FRAME_INFO 0

View file

@ -0,0 +1,17 @@
/* Default to BTF debug info. */
/* { dg-do compile } */
/* { dg-options "-g -dA" }*/
struct A {
int x;
int y;
};
int
foo (struct A *a)
{
return a->x;
}
/* { dg-final { scan-assembler-not "DWARF version" } } */
/* { dg-final { scan-assembler "btf_version" } } */

View file

@ -0,0 +1,18 @@
/* -g defaults to BTF, which in turn implies -mco-re. */
/* { dg-do compile } */
/* { dg-options "-g -dA" }*/
struct A {
int x;
int y;
};
int
foo (struct A *a)
{
return __builtin_preserve_access_index (a->x);
}
/* { dg-final { scan-assembler-not "DWARF version" } } */
/* { dg-final { scan-assembler "btf_version" } } */
/* { dg-final { scan-assembler "btfext_version" } } */

View file

@ -0,0 +1,14 @@
/* Using -g does not incorrectly force CO-RE enabled. */
/* { dg-do compile } */
/* { dg-options "-g -dA -mno-co-re" }*/
struct A {
int x;
int y;
};
int
foo (struct A *a)
{
return __builtin_preserve_access_index (a->x); /* { dg-error "BPF CO-RE is required" } */
}

View file

@ -0,0 +1,4 @@
/* -g implies BTF, -gtoggle turns it off. CO-RE should not work. */
/* { dg-do compile } */
/* { dg-options "-g -mco-re -gtoggle" } */
/* { dg-excess-errors "BPF CO-RE requires BTF debugging information" } */