public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] bpf: set PREFERRED_DEBUGGING_TYPE to BTF_DEBUG
@ 2024-04-25 17:23 David Faust
  2024-04-25 18:45 ` Jose E. Marchesi
  0 siblings, 1 reply; 2+ messages in thread
From: David Faust @ 2024-04-25 17:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: jose.marchesi

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

Tested on x86_64-linux-gnu host for bpf-unknown-none target.

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.
---
 gcc/config/bpf/bpf.h                           |  5 +++++
 .../gcc.target/bpf/bpf-debug-options-1.c       | 17 +++++++++++++++++
 .../gcc.target/bpf/bpf-debug-options-2.c       | 18 ++++++++++++++++++
 .../gcc.target/bpf/bpf-debug-options-3.c       | 14 ++++++++++++++
 gcc/testsuite/gcc.target/bpf/core-options-4.c  |  4 ++++
 5 files changed, 58 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
 create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
 create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
 create mode 100644 gcc/testsuite/gcc.target/bpf/core-options-4.c

diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h
index c67e17526bf..e163fbf688d 100644
--- a/gcc/config/bpf/bpf.h
+++ b/gcc/config/bpf/bpf.h
@@ -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
diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
new file mode 100644
index 00000000000..409466c4ead
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
new file mode 100644
index 00000000000..03bde12315b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
new file mode 100644
index 00000000000..d41790e0928
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
@@ -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" } */
+}
diff --git a/gcc/testsuite/gcc.target/bpf/core-options-4.c b/gcc/testsuite/gcc.target/bpf/core-options-4.c
new file mode 100644
index 00000000000..fde4195da42
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/core-options-4.c
@@ -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" } */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: set PREFERRED_DEBUGGING_TYPE to BTF_DEBUG
  2024-04-25 17:23 [PATCH] bpf: set PREFERRED_DEBUGGING_TYPE to BTF_DEBUG David Faust
@ 2024-04-25 18:45 ` Jose E. Marchesi
  0 siblings, 0 replies; 2+ messages in thread
From: Jose E. Marchesi @ 2024-04-25 18:45 UTC (permalink / raw)
  To: David Faust; +Cc: gcc-patches


Hi David.
OK.  Thanks for the patch.

> BTF is the standard debug info used with BPF programs, so it makes sense
> to default to BTF rather than DWARF.
>
> Tested on x86_64-linux-gnu host for bpf-unknown-none target.
>
> 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.
> ---
>  gcc/config/bpf/bpf.h                           |  5 +++++
>  .../gcc.target/bpf/bpf-debug-options-1.c       | 17 +++++++++++++++++
>  .../gcc.target/bpf/bpf-debug-options-2.c       | 18 ++++++++++++++++++
>  .../gcc.target/bpf/bpf-debug-options-3.c       | 14 ++++++++++++++
>  gcc/testsuite/gcc.target/bpf/core-options-4.c  |  4 ++++
>  5 files changed, 58 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
>  create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
>  create mode 100644 gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
>  create mode 100644 gcc/testsuite/gcc.target/bpf/core-options-4.c
>
> diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h
> index c67e17526bf..e163fbf688d 100644
> --- a/gcc/config/bpf/bpf.h
> +++ b/gcc/config/bpf/bpf.h
> @@ -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
> diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
> new file mode 100644
> index 00000000000..409466c4ead
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-1.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
> new file mode 100644
> index 00000000000..03bde12315b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-2.c
> @@ -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" } } */
> diff --git a/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
> new file mode 100644
> index 00000000000..d41790e0928
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/bpf-debug-options-3.c
> @@ -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" } */
> +}
> diff --git a/gcc/testsuite/gcc.target/bpf/core-options-4.c b/gcc/testsuite/gcc.target/bpf/core-options-4.c
> new file mode 100644
> index 00000000000..fde4195da42
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/bpf/core-options-4.c
> @@ -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" } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-25 18:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 17:23 [PATCH] bpf: set PREFERRED_DEBUGGING_TYPE to BTF_DEBUG David Faust
2024-04-25 18:45 ` Jose E. Marchesi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).