public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Faust <david.faust@oracle.com>
To: "Jose E. Marchesi" <jose.marchesi@oracle.com>,
	Richard Biener <rguenther@suse.de>
Cc: Indu Bhagat <indu.bhagat@oracle.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH V7 4/7] CTF/BTF debug formats
Date: Fri, 30 Apr 2021 11:53:55 -0700	[thread overview]
Message-ID: <51ebab8c-4474-f3fd-79cf-1a07edec2073@oracle.com> (raw)
In-Reply-To: <875z03kb0p.fsf@oracle.com>


On 4/30/21 9:11 AM, Jose E. Marchesi via Gcc-patches wrote:
> 
>>> For a moment, for the sake of this question, if we establish that CTF/BTF
>>> generation always feeds off DWARF DIEs (so there is no need to access
>>> type/decl tree nodes), what will it take to keep LTO support while keeping
>>> ctf_debug_finalize in dwarf2out_finish ?
>>
>> I don't think it's possible without major surgery.  Now, it looks like
>> you want to emit .ctf at the LTO compile stage and BTF at the LTRANS
>> stage.  Note you do not have access to the CTF data produced at the
>> LTRANS stage.  What DWARF has access to is pointers (symbol name + offset)
>> to the early DWARF generated DIEs for GCCs tree decls from what it
>> adds DW_AT_abstract_origin references and then amending those entities
>> with furthr DWARF attributes.
>>
>> Now, the "major surgery" could for example entail streaming the CTF
>> data you produce from compile through WPA to the LTRANS stage.  Or
>> alternatively simply reading it from the compile time produced objects
>> by means of the DWARF DIE references.  I don't know what kind of (if any)
>> references you need to produce from BTF to the CTF data (I suppose they
>> might share indexes into a same symbol table...).
> 
> I am thinking, given that we have both "early DWARF" and "late DWARF",
> we may want to have three init/fini hooks for debug formats instead of
> two:
> 
> DEBUG_FORMAT_initialize   (called in dwarf2out_early_finish)
> 
> [... traverse early DWARF (DEBUG_FORMAT_do_die) ...]
> 
> DEBUG_FORMAT_early_finish (called in dwarf2out_early_finish)
> DEBUG_FORMAT_finish       (called in dwarf2out_finish)
> 
> Note that CTF and BTF share the ctfc internal data structure (which is
> built from traversing the early DWARF) but these are otherwise distinct
> debug formats: CTF can be completely emitted in ctf_early_finish,
> whereas BTF needs additional information that is only available in
> ctf_finish.)
> 

I like this idea.

As Indu mentioned, the change to writing CTF/BTF in dwarf2out_finish
rather than dwar2out_early_finish is motivated purely by the needs of BPF.

Specifically, it is to support BPF Compile Once - Run Everywhere (BPF
CO-RE). The BPF backend needs BTF information to generate CO-RE
'relocation' records, and it needs to add to the BTF string table. The
relocation records themselves are placed in a .BTF.ext section, but
refer to BTF records by ID.

Note that CO-RE only comes into play when generating BTF information for
a BPF target. Otherwise, the BTF information can also be emitted in
early_finish. That is, BTF is effectively "late DWARF" ONLY for the BPF
target. Of course, this is also the usual use case for BTF.

I do not have much experience with LTO. I am still trying to digest the
LTO section of the manual. But from what what I do understand, and what
is discussed here, I think the following may work:

1. Always emit CTF in early_finish. There is no reason to delay it. This
simplifies both LTO and non-LTO cases.

2. For non-BPF targets, emit BTF in early_finish as well.

3. For non-LTO + BTF + BPF, emit BTF in in (late) finish, to support
generating CO-RE information in the BPF backend.

4. For LTO + BTF + BPF, either emit BTF in early_finish then read it
back later, or stream it through WPA to LTRANS stage. I am not sure
exactly what this streaming means. In either case, end up with enough
information at LTRANS stage to re-emit the BTF, now with CO-RE information.

Does the above make any sense? Is this overly complicated?

Thank you very much Richard for the review, and for raising this LTO
discussion.

David

  reply	other threads:[~2021-04-30 18:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 12:10 Richard Biener
2021-04-29 20:02 ` Indu Bhagat
2021-04-29 22:08   ` Indu Bhagat
2021-04-30  6:17   ` Richard Biener
2021-04-30 16:11     ` Jose E. Marchesi
2021-04-30 18:53       ` David Faust [this message]
2021-05-03  9:01         ` Richard Biener
2021-05-07 17:50     ` Indu Bhagat
  -- strict thread matches above, loose matches on Subject: below --
2021-04-19 16:47 [PATCH V7 0/7] Support for the CTF and BTF " Jose E. Marchesi
2021-04-19 16:47 ` [PATCH V7 4/7] CTF/BTF " Jose E. Marchesi

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=51ebab8c-4474-f3fd-79cf-1a07edec2073@oracle.com \
    --to=david.faust@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=indu.bhagat@oracle.com \
    --cc=jose.marchesi@oracle.com \
    --cc=rguenther@suse.de \
    /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).