From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kernel-team@fb.com, yhs@fb.com
Subject: Re: [PATCH bpf-next v3 1/3] libbpf: __attribute__((btf_decl_tag("..."))) for btf dump in C format
Date: Wed, 16 Nov 2022 03:51:56 +0200 [thread overview]
Message-ID: <d1d5c46e31a9016a7e53e2e7877722af6f1f2027.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzYZ-oo38ATgv32=0LhFWYciGtwAUcpSeB3Aam8hJ5Yuzg@mail.gmail.com>
On Mon, 2022-11-14 at 11:56 -0800, Andrii Nakryiko wrote:
> On Fri, Nov 11, 2022 at 1:30 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Fri, 2022-11-11 at 10:58 -0800, Andrii Nakryiko wrote:
> > > On Thu, Nov 10, 2022 at 6:43 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > >
> > >
> > > [...]
> > >
> > > > static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id)
> > > > @@ -1438,9 +1593,12 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
> > > > }
> > > > case BTF_KIND_FUNC_PROTO: {
> > > > const struct btf_param *p = btf_params(t);
> > > > + struct decl_tag_array *decl_tags = NULL;
> > > > __u16 vlen = btf_vlen(t);
> > > > int i;
> > > >
> > > > + hashmap__find(d->decl_tags, id, &decl_tags);
> > > > +
> > > > /*
> > > > * GCC emits extra volatile qualifier for
> > > > * __attribute__((noreturn)) function pointers. Clang
> > >
> > > should there be btf_dump_emit_decl_tags(d, decl_tags, -1) somewhere
> > > here to emit tags of FUNC_PROTO itself?
> >
> > Actually, I have not found a way to attach decl tag to a FUNC_PROTO itself:
>
> I'll need to check with Yonghong, but I think what happens right now
> with decl_tag being attached to FUNC instead of its underlying
> FUNC_PROTO might be a bug (or maybe it's by design, but certainly is
> quite confusing as FUNC itself doesn't have arguments, so
> component_idx != -1 is a bit weird).
>
> But regardless if Clang allows you to express it in C code today or
> not, if we support decl_tags on func proto args, for completeness
> let's support it also on func_proto itself (comp_idx == -1). You can
> build BTF manually for test, just like you do it for func_proto args,
> right?
I can construct the BTF manually, but I need a place in C where
__decl_tag would be printed for such proto and currently there is no
such place.
As Yonghong suggests in a sibling comment there are currently no
use-cases for decl tags on functions, function protos or function
proto parameters. I suggest to drop these places from the current
patch and get back to it when the need arises.
> >
> > typedef void (*fn)(void) __decl_tag("..."); // here tag is attached to typedef
> > struct foo {
> > void (*fn)(void) __decl_tag("..."); // here tag is attached to a foo.fn field
> > }
> > void foo(void (*fn)(void) __decl_tag("...")); // here tag is attached to FUNC foo
> > // parameter but should probably
> > // be attached to
> > // FUNC_PROTO parameter instead.
> >
> > Also, I think that Yonghong had reservations about decl tags attached to
> > FUNC_PROTO parameters.
> > Yonghong, could you please comment?
>
> yep, curious to hear as well
>
>
> >
> > >
> > > > @@ -1481,6 +1639,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
> > > >
> > > > name = btf_name_of(d, p->name_off);
> > > > btf_dump_emit_type_decl(d, p->type, name, lvl);
> > > > + btf_dump_emit_decl_tags(d, decl_tags, i);
> > > > }
> > > >
> > > > btf_dump_printf(d, ")");
> > > > @@ -1896,6 +2055,7 @@ static int btf_dump_var_data(struct btf_dump *d,
> > > > const void *data)
> > > > {
> > > > enum btf_func_linkage linkage = btf_var(v)->linkage;
> > > > + struct decl_tag_array *decl_tags = NULL;
> > > > const struct btf_type *t;
> > > > const char *l;
> > > > __u32 type_id;
> > > > @@ -1920,7 +2080,10 @@ static int btf_dump_var_data(struct btf_dump *d,
> > > > type_id = v->type;
> > > > t = btf__type_by_id(d->btf, type_id);
> > > > btf_dump_emit_type_cast(d, type_id, false);
> > > > - btf_dump_printf(d, " %s = ", btf_name_of(d, v->name_off));
> > > > + btf_dump_printf(d, " %s", btf_name_of(d, v->name_off));
> > > > + hashmap__find(d->decl_tags, id, &decl_tags);
> > > > + btf_dump_emit_decl_tags(d, decl_tags, -1);
> > > > + btf_dump_printf(d, " = ");
> > > > return btf_dump_dump_type_data(d, NULL, t, type_id, data, 0, 0);
> > > > }
> > > >
> > > > @@ -2421,6 +2584,8 @@ int btf_dump__dump_type_data(struct btf_dump *d, __u32 id,
> > > > d->typed_dump->skip_names = OPTS_GET(opts, skip_names, false);
> > > > d->typed_dump->emit_zeroes = OPTS_GET(opts, emit_zeroes, false);
> > > >
> > > > + btf_dump_assign_decl_tags(d);
> > > > +
> > >
> > > I'm actually not sure we want those tags on binary data dump.
> > > Generally data dump is not type definition dump, so this seems
> > > unnecessary, it will just distract from data itself. Let's drop it for
> > > now? If there would be a need we can add it easily later.
> >
> > Well, this is the only place where VARs are processed, removing this code
> > would make the second patch in a series useless.
> > But I like my second patch in a series :) should I just drop it?
> > I can extract it as a separate series and simplify some of the existing
> > data dump tests.
>
> yep, data dump tests can be completely orthogonal, send them
> separately if you are attached to that code ;)
>
> but for decl_tags on dump_type_data() I'd rather be conservative for
> now, unless in practice those decl_tags will turn out to be needed
>
>
> >
> > >
> > > > ret = btf_dump_dump_type_data(d, NULL, t, id, data, 0, 0);
> > > >
> > > > d->typed_dump = NULL;
> > > > --
> > > > 2.34.1
> > > >
> >
next prev parent reply other threads:[~2022-11-16 1:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 14:43 [PATCH bpf-next v3 0/3] libbpf: btf_decl_tag attribute for btf dump in C format Eduard Zingerman
2022-11-10 14:43 ` [PATCH bpf-next v3 1/3] libbpf: __attribute__((btf_decl_tag("..."))) " Eduard Zingerman
2022-11-11 18:58 ` Andrii Nakryiko
2022-11-11 21:30 ` Eduard Zingerman
2022-11-14 19:56 ` Andrii Nakryiko
2022-11-16 1:51 ` Eduard Zingerman [this message]
2022-11-18 0:21 ` Andrii Nakryiko
2022-11-15 20:45 ` Yonghong Song
2022-11-15 20:48 ` Yonghong Song
2022-11-10 14:43 ` [PATCH bpf-next v3 2/3] selftests/bpf: Dump data sections as part of btf_dump_test_case tests Eduard Zingerman
2022-11-11 19:07 ` Andrii Nakryiko
2022-11-10 14:43 ` [PATCH bpf-next v3 3/3] selftests/bpf: Tests for BTF_KIND_DECL_TAG dump in C format Eduard Zingerman
2022-11-11 19:07 ` Andrii Nakryiko
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=d1d5c46e31a9016a7e53e2e7877722af6f1f2027.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox