All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	dwarves@vger.kernel.org, bpf@vger.kernel.org, kernel-team@fb.com,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	yhs@fb.com, jose.marchesi@oracle.com, david.faust@oracle.com,
	alan.maguire@oracle.com
Subject: Re: [PATCH dwarves v2 1/5] fprintf: Correct names for types with btf_type_tag attribute
Date: Thu, 30 Mar 2023 08:29:04 -0300	[thread overview]
Message-ID: <ZCVygOn0+zKFEqW2@kernel.org> (raw)
In-Reply-To: <f9664121426c5665ff0fc8cb61c466689beadd36.camel@gmail.com>

Em Wed, Mar 29, 2023 at 07:02:45PM +0300, Eduard Zingerman escreveu:
> On Wed, 2023-03-29 at 12:43 -0300, Arnaldo Carvalho de Melo wrote:
> [...]
> > > > diff --git a/dwarves_fprintf.c b/dwarves_fprintf.c
> > > > index 1e6147a82056c188..1ecc24321bf8f975 100644
> > > > --- a/dwarves_fprintf.c
> > > > +++ b/dwarves_fprintf.c
> > > > @@ -788,8 +788,15 @@ next_type:
> > > >  			if (n)
> > > >  				return printed + n;
> > > >  			if (ptype->tag == DW_TAG_LLVM_annotation) {
> > > > -				type = ptype;
> > > > -				goto next_type;
> > > > +				// FIXME: Just skip this for now, we need to print this annotation
> > > > +				// to match the original source code.
> > > > +
> > > > +				if (ptype->type == 0) {
> > > > +					printed += fprintf(fp, "%-*s %s", tconf.type_spacing, "void *", name);
> > > > +					break;
> > > > +				}
> > > > +
> > > > +				ptype = cu__type(cu, ptype->type);
> > > >  			}
> > > >  			if (ptype->tag == DW_TAG_subroutine_type) {
> > > >  				printed += ftype__fprintf(tag__ftype(ptype),
> > > 
> > > This explains why '*' was missing, but unfortunately it breaks apart
> > > when there are multiple type tags, e.g.:
> > > 
> > > 
> > >     $ cat tag-test.c
> > >     #define __t __attribute__((btf_type_tag("t1")))
> > >     
> > >     struct foo {
> > >       int  (__t __t *a)(void);
> > >     } g;
> > >     $ clang -g -c tag-test.c -o tag-test.o && pahole -J tag-test.o && pahole --sort -F dwarf tag-test.o
> > >     struct foo {
> > >     	int ()(void)   *           a;                    /*     0     8 */
> > >     
> > >     	/* size: 8, cachelines: 1, members: 1 */
> > >     	/* last cacheline: 8 bytes */
> > >     };
> > >     $ clang -g -c tag-test.c -o tag-test.o && pahole -J tag-test.o && pahole --sort -F btf tag-test.o
> > >     struct foo {
> > >     	int ()(void)   *           a;                    /*     0     8 */
> > >     
> > >     	/* size: 8, cachelines: 1, members: 1 */
> > >     	/* last cacheline: 8 bytes */
> > >     };
> > >     
> > > What I don't understand is why pointer's type is LLVM_annotation.
> > 
> > Well, that is how it is encoded in BTF and then you supported it in:
> > 
> > Author: Eduard Zingerman <eddyz87@gmail.com>
> > Date:   Wed Mar 15 01:04:14 2023 +0200
> > 
> >     btf_loader: A hack for BTF import of btf_type_tag attributes`
> 
> To be honest, I was under impression that I add a workaround and the
> preferred way is to do what dwarf loader does with
> btf_type_tag_ptr_type::annots.
>  
> > I find it natural, and think that annots thing is a variation on how to
> > store modifiers for types, see, this DW_TAG_LLVM_annotation is in the
> > same class as 'restrict', 'const', 'volatile', "atomic", etc
> > 
> > I understand that for encoding _DWARF_ people preferred to make it as a
> > child DIE to avoid breaking existing DWARF consumers, but in
> > pahole's dwarf_loader.c we can just make it work like BTF and insert the
> > btf_type_tag in the chain, just like 'const', etc, no?
> > 
> > pahole wants to print those annotation just like it prints 'const',
> > 'volatile', etc.
> 
> Actually, if reflecting physical structure of the DWARF is not a goal,

Well reflecting the physical structure of DWARF _pre_
DW_TAG_llvm_annotation was the goal, but now, since this was done
differently of DW_TAG_const_type, DW_TAG_pointer_type, etc, as one link
in the chain, to avoid breaking existing DWARF consumers, we ended up
with this annot thing, but the internal representation in pahole can
continue being as a chain, as BTF does, right?

> forgoing "annots" fields altogether and treating type tags as derived
> types should make support for btf:type_tag (the v2 version) simpler.

I think it should simplify as we're used to these chains.
 
> Then, getting back to the current issue, I need to add
> skip_llvm_annotations function with a loop inside, right?

You can, to remove them completely and its like they don't exist for
dwarf_fprintf.c, but what I think should be done is to actually print
them, to reconstruct the original source code.

You can start removing them and we can work later on properly printing
it, so that we can get 1.25 out of the door as there are multiple
requests for it to be released to solve other problems with using 1.24.

- Arnaldo
 
> > > Probably, the cleanest solution would be to make DWARF and BTF loaders
> > > work in a similar way and attach LLVM_annotation as `annots` field of
> > > the `struct btf_type_tag_ptr_type`. Thus, avoiding 'LLVM_annotation's
> > > in the middle of type chains. I'll work on this.

  reply	other threads:[~2023-03-30 11:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14 23:04 [PATCH dwarves v2 0/5] Support for new btf_type_tag encoding Eduard Zingerman
2023-03-14 23:04 ` [PATCH dwarves v2 1/5] fprintf: Correct names for types with btf_type_tag attribute Eduard Zingerman
2023-03-27 11:46   ` Arnaldo Carvalho de Melo
2023-03-27 12:10     ` Eduard Zingerman
2023-03-27 12:55       ` Arnaldo Carvalho de Melo
2023-03-28 12:40       ` Arnaldo Carvalho de Melo
2023-03-28 13:40         ` Eduard Zingerman
2023-03-28 13:59   ` Arnaldo Carvalho de Melo
2023-03-28 14:08     ` Eduard Zingerman
2023-03-28 15:26       ` Arnaldo Carvalho de Melo
2023-03-28 15:30         ` Eduard Zingerman
2023-03-28 21:17           ` Arnaldo Carvalho de Melo
2023-03-29 15:36             ` Eduard Zingerman
2023-03-29 15:43               ` Arnaldo Carvalho de Melo
2023-03-29 16:02                 ` Eduard Zingerman
2023-03-30 11:29                   ` Arnaldo Carvalho de Melo [this message]
2023-03-30 12:34                     ` Eduard Zingerman
2023-03-14 23:04 ` [PATCH dwarves v2 2/5] btf_loader: A hack for BTF import of btf_type_tag attributes Eduard Zingerman
2023-03-14 23:04 ` [PATCH dwarves v2 3/5] dwarf_loader: Consolidate llvm_annotation and btf_type_tag_type Eduard Zingerman
2023-03-14 23:04 ` [PATCH dwarves v2 4/5] dwarf_loader: Track unspecified types in a separate list Eduard Zingerman
2023-03-14 23:04 ` [PATCH dwarves v2 5/5] dwarf_loader: Support for btf:type_tag Eduard Zingerman

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=ZCVygOn0+zKFEqW2@kernel.org \
    --to=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=david.faust@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=jose.marchesi@oracle.com \
    --cc=kernel-team@fb.com \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.