opts: allow -gctf, -gbtf, -gdwarf simultaneously

Message ID 20240710155526.3993-1-david.faust@oracle.com
State New
Headers
Series opts: allow -gctf, -gbtf, -gdwarf simultaneously |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

David Faust July 10, 2024, 3:55 p.m. UTC
  [This is a resend of a patch previously sent as:
   PATCH v4 6/6 opts: allow any combination of DWARF,CTF,BTF
   https://gcc.gnu.org/pipermail/gcc-patches/2024-June/654253.html]

Previously it was not supported to generate both CTF and BTF debug info
in the same compiler run, as both formats made incompatible changes to
the same internal data structures.

With the structural changes to CTF and BTF generation made in:

  d3f586ec50d3 ctf, btf: restructure CTF/BTF emission

in particular, with the guarantee that CTF will always be fully emitted
before any BTF translation occurs, there is no longer anything
preventing generation of both CTF and BTF at the same time.

This patch changes option parsing to lift the restriction on specifying
both -gbtf and -gctf at the same time, allowing for any combination of
-gdwarf, -gctf, and -gbtf to be active in the same compiler invocation.

Bootstrapped and tested on x86_64-linux-gnu.
Also tested on x86_64-linux-gnu for bpf-unknown-none.

gcc/
	* opts.cc (set_debug_level): Allow any combination of -gdwarf,
	-gctf and -gbtf to be enabled at the same time.

gcc/testsuite/
	* gcc.dg/debug/btf/btf-3.c: New test.
	* gcc.dg/debug/btf/btf-4.c: Likewise.
	* gcc.dg/debug/btf/btf-5.c: Likewise.
---
 gcc/opts.cc                            | 20 +++++---------------
 gcc/testsuite/gcc.dg/debug/btf/btf-3.c |  8 ++++++++
 gcc/testsuite/gcc.dg/debug/btf/btf-4.c |  8 ++++++++
 gcc/testsuite/gcc.dg/debug/btf/btf-5.c |  9 +++++++++
 4 files changed, 30 insertions(+), 15 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-3.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-4.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-5.c
  

Patch

diff --git a/gcc/opts.cc b/gcc/opts.cc
index d7e0126e11f8..735d0dd8accf 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -3508,21 +3508,11 @@  set_debug_level (uint32_t dinfo, int extended, const char *arg,
     }
   else
     {
-      /* Make and retain the choice if both CTF and DWARF debug info are to
-	 be generated.  */
-      if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG))
-	  && ((opts->x_write_symbols == (DWARF2_DEBUG|CTF_DEBUG))
-	      || (opts->x_write_symbols == DWARF2_DEBUG)
-	      || (opts->x_write_symbols == CTF_DEBUG)))
-	{
-	  opts->x_write_symbols |= dinfo;
-	  opts_set->x_write_symbols |= dinfo;
-	}
-      /* However, CTF and BTF are not allowed together at this time.  */
-      else if (((dinfo == DWARF2_DEBUG) || (dinfo == BTF_DEBUG))
-	       && ((opts->x_write_symbols == (DWARF2_DEBUG|BTF_DEBUG))
-		   || (opts->x_write_symbols == DWARF2_DEBUG)
-		   || (opts->x_write_symbols == BTF_DEBUG)))
+      /* Any combination of DWARF, CTF and BTF is allowed.  */
+      if (((dinfo == DWARF2_DEBUG) || (dinfo == CTF_DEBUG)
+	   || (dinfo == BTF_DEBUG))
+	  && ((opts->x_write_symbols | (DWARF2_DEBUG | CTF_DEBUG | BTF_DEBUG))
+	       == (DWARF2_DEBUG | CTF_DEBUG | BTF_DEBUG)))
 	{
 	  opts->x_write_symbols |= dinfo;
 	  opts_set->x_write_symbols |= dinfo;
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-3.c b/gcc/testsuite/gcc.dg/debug/btf/btf-3.c
new file mode 100644
index 000000000000..93c8164a2a54
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-3.c
@@ -0,0 +1,8 @@ 
+/* Verify that BTF debug info can co-exist with DWARF.  */
+/* { dg-do compile } */
+/* { dg-options "-gdwarf -gbtf -dA" } */
+/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */
+/* { dg-final { scan-assembler "DWARF version number" } } */
+
+void func (void)
+{ }
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-4.c
new file mode 100644
index 000000000000..b087917188bb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-4.c
@@ -0,0 +1,8 @@ 
+/* Verify that BTF debug info can co-exist with CTF.  */
+/* { dg-do compile } */
+/* { dg-options "-gctf -gbtf -dA" } */
+/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */
+/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */
+
+void func (void)
+{ }
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-5.c b/gcc/testsuite/gcc.dg/debug/btf/btf-5.c
new file mode 100644
index 000000000000..45267b5fc422
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/btf/btf-5.c
@@ -0,0 +1,9 @@ 
+/* Verify that BTF, CTF and DWARF can all co-exist happily.  */
+/* { dg-do compile } */
+/* { dg-options "-gctf -gbtf -gdwarf -dA" } */
+/* { dg-final { scan-assembler "0xeb9f.*btf_magic" } } */
+/* { dg-final { scan-assembler "0xdff2.*CTF preamble magic number" } } */
+/* { dg-final { scan-assembler "DWARF version number" } } */
+
+void func (void)
+{ }