@@ -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,25 +987,35 @@ 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)
+ /* Emit CTF debug info early always. */
+ if (ctf_debug_info_level > CTFINFO_LEVEL_NONE
+ /* Emit BTF debug info early if the target does not require late
+ emission. */
+ || (btf_debuginfo_p ()
+ && targetm.ctfc_debuginfo_early_finish_p ()))
{
- btf_output (filename);
- btf_finalize ();
+ /* Emit CTF/BTF debug info. */
+ 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 the target needs to update the CTF container
+ (ctfc) in the backend. An example of this, at this time is the BPF CO-RE
+ usecase. */
+ if (btf_debuginfo_p ()
+ && (!in_lto_p && !targetm.ctfc_debuginfo_early_finish_p ()))
+ /* Emit BTF debug info. */
+ ctf_debug_finalize (filename, btf_debuginfo_p ());
}
#include "gt-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.
@@ -31976,6 +31976,11 @@ dwarf2out_finish (const char *filename)
print_die (comp_unit_die (), dump_file);
}
+ /* Generate CTF/BTF debug info. */
+ if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE
+ || btf_debuginfo_p ()) && lang_GNU_C ())
+ ctf_debug_finish (filename);
+
/* Initialize sections and labels used for actual assembler output. */
unsigned generation = init_sections_and_labels (false);
@@ -32788,8 +32793,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. */