public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: David Faust <david.faust@oracle.com>, gcc-patches@gcc.gnu.org
Cc: jose.marchesi@oracle.com, cupertino.miranda@oracle.com
Subject: Re: [PATCH v3 1/6] ctf, btf: restructure CTF/BTF emission
Date: Wed, 5 Jun 2024 00:27:24 -0700	[thread overview]
Message-ID: <528c74ef-9cdb-4843-9dbb-56c115675a3c@oracle.com> (raw)
In-Reply-To: <20240530213222.440435-2-david.faust@oracle.com>

On 5/30/24 14:32, David Faust wrote:
> This commit makes some structural changes to the CTF/BTF debug info
> emission.  In particular:
> 
>   a) CTF is new always fully generated and emitted before any
>      BTF-related procedures are run.  This means that BTF-related
>      functions can change, even irreversibly, the shared in-memory
>      representation used by the two formats without issue.
> 
>   b) BTF generation has fewer entry points, and is cleanly divided
>      into early_finish and finish.
> 
>   c) BTF is now always emitted at finish (called from dwarf2out_finish),
>      for all targets in non-LTO builds, rather than being emitted at
>      early_finish for targets other than BPF CO-RE.  In LTO builds,
>      BTF is emitted at early_finish as before.
> 
>      Note that this change alone does not alter the contents of BTF at
>      all, regardless of whether it would have previously been emitted at
>      early_finish or finish, because the calculation of the BTF to be
>      emitted is not moved by this patch, only the write-out.
> 
> The changes are transparent to both CTF and BTF emission.
> 

OK.

This will work to keep supporting -flto with BTF (for non-BPF targets) 
and of course -flto with CTF.

One question/nit below.

> gcc/
> 	* btfout.cc (btf_init_postprocess): Rename to...
> 	(btf_early_finish): ...this.
> 	(btf_output): Rename to...
> 	(btf_finish): ...this.
> 	* ctfc.h: Analogous changes.
> 	* dwarf2ctf.cc (ctf_debug_early_finish): Conditionally call
> 	btf_early_finish, or ctf_finalize as appropriate.  Emit BTF
> 	here for LTO builds.
> 	(ctf_debug_finish): Always call btf_finish here if generating
> 	BTF info in non-LTO builds.
> 	(ctf_debug_finalize, ctf_debug_init_postprocess): Delete.
> 	* dwarf2out.cc (dwarf2out_early_finish): Remove call to
> 	ctf_debug_init_postprocess.
> ---
>   gcc/btfout.cc    | 28 +++++++++++++++++++++
>   gcc/ctfc.h       |  4 +--
>   gcc/dwarf2ctf.cc | 65 +++++++++++++++---------------------------------
>   gcc/dwarf2out.cc |  2 --
>   4 files changed, 50 insertions(+), 49 deletions(-)
> 
> diff --git a/gcc/btfout.cc b/gcc/btfout.cc
> index 07f066a47068..1b6a9ed811f0 100644
> --- a/gcc/btfout.cc
> +++ b/gcc/btfout.cc
> @@ -1491,6 +1491,34 @@ btf_finalize (void)
>     tu_ctfc = NULL;
>   }
>   
> +/* Initial entry point of BTF generation, called at early_finish () after
> +   CTF information has possibly been output.  Translate all CTF information
> +   to BTF, and do any processing that must be done early, such as creating
> +   BTF_KIND_FUNC records.  */
> +
> +void
> +btf_early_finish (void)
> +{
> +  btf_init_postprocess ();
> +}
> +
> +/* Late entry point for BTF generation, called from dwarf2out_finish ().
> +   Complete and emit BTF information.  */
> +
> +void
> +btf_finish (const char * filename)
> +{
> +  btf_output (filename);
> +
> +  /* If compiling for BPF with CO-RE info, we cannot deallocate until after
> +     CO-RE information is created, which happens very late in BPF backend.

I am wondering if it is more precise to say that "until after contents 
for the .BTF.ext section are finalized" ? We have already called the 
btf_output () above, which means _some_ CO-RE information is already 
created (like the accessor strings for CO-RE relocs that go in the .BTF 
section).

> +     Therefore, the deallocation (i.e. btf_finalize ()) is delayed until
> +     TARGET_ASM_FILE_END for BPF CO-RE.  */
> +  if (!btf_with_core_debuginfo_p ())
> +    btf_finalize ();
> +}
> +
> +
>   /* Traversal function for all BTF_KIND_FUNC type records.  */
>   
>   bool
> diff --git a/gcc/ctfc.h b/gcc/ctfc.h
> index fa188bf2f5a4..e7bd93901cfa 100644
> --- a/gcc/ctfc.h
> +++ b/gcc/ctfc.h
> @@ -384,8 +384,8 @@ extern void ctf_init (void);
>   extern void ctf_output (const char * filename);
>   extern void ctf_finalize (void);
>   
> -extern void btf_output (const char * filename);
> -extern void btf_init_postprocess (void);
> +extern void btf_early_finish (void);
> +extern void btf_finish (const char * filename);
>   extern void btf_finalize (void);
>   
>   extern ctf_container_ref ctf_get_tu_ctfc (void);
> diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc
> index dc59569fe560..8f9e2fada9e3 100644
> --- a/gcc/dwarf2ctf.cc
> +++ b/gcc/dwarf2ctf.cc
> @@ -933,30 +933,6 @@ 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 when compiling BPF applciations gets deallocated by the
> -	 BPF target in bpf_file_end.  */
> -      if (btf_debuginfo_p () && !btf_with_core_debuginfo_p ())
> -	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)
>   {
> @@ -996,27 +972,27 @@ ctf_debug_init (void)
>     add_name_attribute (ctf_unknown_die, "unknown");
>   }
>   
> -/* Preprocess the CTF debug information after initialization.  */
> -
> -void
> -ctf_debug_init_postprocess (bool btf)
> -{
> -  /* Only BTF requires postprocessing right after init.  */
> -  if (btf)
> -    btf_init_postprocess ();
> -}
> -
>   /* Early finish CTF/BTF debug info.  */
>   
>   void
>   ctf_debug_early_finish (const char * filename)
>   {
> -  /* 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 ());
> +  /* Emit the collected CTF information.  */
> +  if (ctf_debug_info_level > CTFINFO_LEVEL_NONE)
> +    ctf_output (filename);
> +
> +  /* If emitting BTF, start translation to BTF.  */
> +  if (btf_debuginfo_p ())
> +    {
> +      btf_early_finish ();
> +
> +      /* For LTO builds, also emit BTF now.  */
> +      if (flag_lto && !in_lto_p)
> +	btf_finish (filename);
> +    }
> +  else
> +    /* Otherwise, done with the CTF container.  */
> +    ctf_finalize ();
>   }
>   
>   /* Finish CTF/BTF debug info emission.  */
> @@ -1024,11 +1000,10 @@ ctf_debug_early_finish (const char * filename)
>   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_debuginfo_p () && btf_with_core_debuginfo_p ())
> -    ctf_debug_finalize (filename, btf_debuginfo_p ());
> +  /* Emit BTF late, unless this is an LTO build in which case it was
> +     already done early.  */
> +  if (btf_debuginfo_p () && !flag_lto)
> +    btf_finish (filename);
>   }
>   
>   #include "gt-dwarf2ctf.h"
> diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
> index 5b064ffd78ad..e406df8673ce 100644
> --- a/gcc/dwarf2out.cc
> +++ b/gcc/dwarf2out.cc
> @@ -33202,8 +33202,6 @@ dwarf2out_early_finish (const char *filename)
>         ctf_debug_do_cu (comp_unit_die ());
>         for (limbo_die_node *node = limbo_die_list; node; node = node->next)
>   	ctf_debug_do_cu (node->die);
> -      /* Post process the debug data in the CTF container if necessary.  */
> -      ctf_debug_init_postprocess (btf_debuginfo_p ());
>   
>         ctf_debug_early_finish (filename);
>       }


  reply	other threads:[~2024-06-05  7:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30 21:32 [PATCH v3 0/6] btf: refactor and add pruning option David Faust
2024-05-30 21:32 ` [PATCH v3 1/6] ctf, btf: restructure CTF/BTF emission David Faust
2024-06-05  7:27   ` Indu Bhagat [this message]
2024-05-30 21:32 ` [PATCH v3 2/6] ctf: use pointers instead of IDs internally David Faust
2024-06-05  7:31   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 3/6] btf: refactor and simplify implementation David Faust
2024-06-05  7:41   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 4/6] btf: add -fprune-btf option David Faust
2024-05-31  7:07   ` Richard Biener
2024-05-31 15:57     ` David Faust
2024-05-31 16:24       ` Richard Biener
2024-06-05  7:56   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 5/6] bpf,btf: enable BTF pruning by default for BPF David Faust
2024-06-05 20:49   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 6/6] opts: allow any combination of DWARF, CTF, BTF David Faust
2024-06-05 22:16   ` Indu Bhagat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=528c74ef-9cdb-4843-9dbb-56c115675a3c@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=cupertino.miranda@oracle.com \
    --cc=david.faust@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jose.marchesi@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).