public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3391] dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase
@ 2021-09-07 18:21 Indu Bhagat
  0 siblings, 0 replies; only message in thread
From: Indu Bhagat @ 2021-09-07 18:21 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:849d5f5929fc1e480aa6d385976810d2b1319755

commit r12-3391-g849d5f5929fc1e480aa6d385976810d2b1319755
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Tue Sep 7 11:18:54 2021 -0700

    dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase
    
    DWARF generation is split between early and late phases when LTO is in effect.
    This poses challenges for CTF/BTF generation especially if late debug info
    generation is desirable, as turns out to be the case for BPF CO-RE.
    
    The approach taken here in this patch is:
    
    1. LTO is disabled for BPF CO-RE
    The reason to disable LTO for BPF CO-RE is that if LTO is in effect, BPF CO-RE
    relocations need to be generated in the LTO link phase _after_ the optimizations
    are done. This means we need to devise way to combine early and late BTF. At
    this time, in absence of linker support for BTF sections, it makes sense to
    steer clear of LTO for BPF CO-RE and bypass the issue.
    
    2. The BPF backend updates the write_symbols with BPF_WITH_CORE_DEBUG to convey
    the case that BTF with CO-RE support needs to be generated.  This information
    is used by the debug info emission routines to defer the emission of BTF/CO-RE
    until dwarf2out_finish.
    
    So, in other words,
    
    dwarf2out_early_finish
      - Always emit CTF here.
      - if (BTF && !BTF_WITH_CORE), emit BTF now.
    
    dwarf2out_finish
      - if (BTF_WITH_CORE) emit BTF now.
    
    gcc/ChangeLog:
    
            * dwarf2ctf.c (ctf_debug_finalize): Make it static.
            (ctf_debug_early_finish): New definition.
            (ctf_debug_finish): Likewise.
            * dwarf2ctf.h (ctf_debug_finalize): Remove declaration.
            (ctf_debug_early_finish): New declaration.
            (ctf_debug_finish): Likewise.
            * dwarf2out.c (dwarf2out_finish): Invoke ctf_debug_finish.
            (dwarf2out_early_finish): Invoke ctf_debug_early_finish.

Diff:
---
 gcc/dwarf2ctf.c | 54 +++++++++++++++++++++++++++++++++++++++++-------------
 gcc/dwarf2ctf.h |  4 +++-
 gcc/dwarf2out.c |  9 +++++++--
 3 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/gcc/dwarf2ctf.c b/gcc/dwarf2ctf.c
index 5e8a7258583..b686bafda44 100644
--- a/gcc/dwarf2ctf.c
+++ b/gcc/dwarf2ctf.c
@@ -917,6 +917,27 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die)
   return type_id;
 }
 
+/* Prepare for output and write out the CTF debug information.  */
+
+static void
+ctf_debug_finalize (const char *filename, bool btf)
+{
+  if (btf)
+    {
+      btf_output (filename);
+      btf_finalize ();
+    }
+
+  else
+    {
+      /* Emit the collected CTF information.  */
+      ctf_output (filename);
+
+      /* Reset the CTF state.  */
+      ctf_finalize ();
+    }
+}
+
 bool
 ctf_do_die (dw_die_ref die)
 {
@@ -966,24 +987,31 @@ ctf_debug_init_postprocess (bool btf)
     btf_init_postprocess ();
 }
 
-/* Prepare for output and write out the CTF debug information.  */
+/* Early finish CTF/BTF debug info.  */
 
 void
-ctf_debug_finalize (const char *filename, bool btf)
+ctf_debug_early_finish (const char * filename)
 {
-  if (btf)
-    {
-      btf_output (filename);
-      btf_finalize ();
-    }
+  /* Emit CTF debug info early always.  */
+  if (ctf_debug_info_level > CTFINFO_LEVEL_NONE
+      /* Emit BTF debug info early if CO-RE relocations are not
+	 required.  */
+      || (btf_debuginfo_p () && !btf_with_core_debuginfo_p ()))
+    ctf_debug_finalize (filename, btf_debuginfo_p ());
+}
 
-  else
-    {
-      /* Emit the collected CTF information.  */
-      ctf_output (filename);
+/* Finish CTF/BTF debug info emission.  */
 
-      /* Reset the CTF state.  */
-      ctf_finalize ();
+void
+ctf_debug_finish (const char * filename)
+{
+  /* Emit BTF debug info here when CO-RE relocations need to be generated.
+     BTF with CO-RE relocations needs to be generated when CO-RE is in effect
+     for the BPF target.  */
+  if (btf_with_core_debuginfo_p ())
+    {
+      gcc_assert (btf_debuginfo_p ());
+      ctf_debug_finalize (filename, btf_debuginfo_p ());
     }
 }
 
diff --git a/gcc/dwarf2ctf.h b/gcc/dwarf2ctf.h
index a3cf5672e25..9edbde0701e 100644
--- a/gcc/dwarf2ctf.h
+++ b/gcc/dwarf2ctf.h
@@ -24,13 +24,15 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_DWARF2CTF_H 1
 
 #include "dwarf2out.h"
+#include "flags.h"
 
 /* Debug Format Interface.  Used in dwarf2out.c.  */
 
 extern void ctf_debug_init (void);
 extern void ctf_debug_init_postprocess (bool);
 extern bool ctf_do_die (dw_die_ref);
-extern void ctf_debug_finalize (const char *, bool);
+extern void ctf_debug_early_finish (const char *);
+extern void ctf_debug_finish (const char *);
 
 /* Wrappers for CTF/BTF to fetch information from GCC DWARF DIE.  Used in
    ctfc.c.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index fbad269b566..72cd1f51380 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -31953,6 +31953,11 @@ dwarf2out_finish (const char *filename)
   unsigned char checksum[16];
   char dl_section_ref[MAX_ARTIFICIAL_LABEL_BYTES];
 
+  /* Generate CTF/BTF debug info.  */
+  if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
+       || btf_debuginfo_p ()) && lang_GNU_C ())
+    ctf_debug_finish (filename);
+
   /* Skip emitting DWARF if not required.  */
   if (!dwarf_debuginfo_p ())
     return;
@@ -32856,8 +32861,8 @@ dwarf2out_early_finish (const char *filename)
 	ctf_debug_do_cu (node->die);
       /* Post process the debug data in the CTF container if necessary.  */
       ctf_debug_init_postprocess (btf_debuginfo_p ());
-      /* Emit CTF/BTF debug info.  */
-      ctf_debug_finalize (filename, btf_debuginfo_p ());
+
+      ctf_debug_early_finish (filename);
     }
 
   /* Do not generate DWARF assembler now when not producing LTO bytecode.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-07 18:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 18:21 [gcc r12-3391] dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase Indu Bhagat

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).