dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	dwarves@vger.kernel.org, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andriin@fb.com>, Yonghong Song <yhs@fb.com>,
	Hao Luo <haoluo@google.com>
Subject: Re: [RFC/PATCH 3/3] btf_encoder: Func generation fix
Date: Thu, 12 Nov 2020 22:14:13 +0100	[thread overview]
Message-ID: <20201112211413.GA733055@krava> (raw)
In-Reply-To: <CAEf4BzbhojeSdASwt4y4XEtgAF1caYx=-AuwzWJZv7qKgzkroA@mail.gmail.com>

On Thu, Nov 12, 2020 at 11:54:41AM -0800, Andrii Nakryiko wrote:

SNIP

> > @@ -624,32 +644,46 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
> >                 has_index_type = true;
> >         }
> >
> > -       cu__for_each_function(cu, core_id, fn) {
> > -               /*
> > -                * The functions_cnt != 0 means we parsed all necessary
> > -                * kernel symbols and we are using ftrace location filter
> > -                * for functions. If it's not available keep the current
> > -                * dwarf declaration check.
> > -                */
> > -               if (functions_cnt) {
> > +       /*
> > +        * The functions_cnt != 0 means we parsed all necessary
> > +        * kernel symbols and we are using ftrace location filter
> > +        * for functions. If it's not available keep the current
> > +        * dwarf declaration check.
> > +        */
> > +       if (functions_cnt) {
> > +               cu__for_each_function(cu, core_id, fn) {
> > +                       struct elf_function *p;
> > +                       struct elf_function key = { .name = function__name(fn, cu) };
> > +                       int args_cnt = 0;
> > +
> >                         /*
> > -                        * We check following conditions:
> > -                        *   - argument names are defined
> > -                        *   - there's symbol and address defined for the function
> > -                        *   - function address belongs to ftrace locations
> > -                        *   - function is generated only once
> > +                        * Collect functions that match ftrace filter
> > +                        * and pick the one with proper argument names.
> > +                        * The BTF generation happens at the end in
> > +                        * btf_encoder__encode function.
> >                          */
> > -                       if (!has_arg_names(cu, &fn->proto))
> > +                       p = bsearch(&key, functions, functions_cnt,
> > +                                   sizeof(functions[0]), functions_cmp);
> > +                       if (!p)
> >                                 continue;
> > -                       if (!should_generate_function(btfe, function__name(fn, cu)))
> > +
> > +                       if (!has_arg_names(cu, &fn->proto, &args_cnt))
> 
> So I can't unfortunately reproduce that GCC bug with DWARF info. What
> was exactly the symptom? Maybe you can also share readelf -wi dump for
> your problematic vmlinux?

hum, can't see -wi working for readelf, however I placed my vmlinux
in here:
  http://people.redhat.com/~jolsa/vmlinux.gz

the symptom is that resolve_btfids will fail kernel build:

  BTFIDS  vmlinux
FAILED unresolved symbol vfs_getattr

because BTF data contains multiple FUNC records for same function

and the problem is that declaration tag itself is missing:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060
so pahole won't skip them

the first workaround was to workaround that and go for function
records that have code address attached, but that's buggy as well:
  https://bugzilla.redhat.com/show_bug.cgi?id=1890107

then after some discussions we ended up using ftrace addresses
as filter for what we want to display.. plus we got static functions
as well

however for this way we failed to get proper arguments ;-)

> 
> The reason I'm asking is because I wonder if we should still ignore
> functions if fn->declaration is set. E.g., for the issue we
> investigated yesterday, the function with no arguments has declaration
> set to 1, so just ignoring it would solve the problem. I'm wondering
> if it's enough to do just that instead of doing this whole delayed
> function collection/processing.
> 
> Also, I'd imagine the only expected cases where we can override  the
> function (args_cnt > p->args_cnt) would be if p->args_cnt == 0, no?

I don't know, because originally I'd expect that we would not see
function record with zero args when it actualy has some

> All other cases are either newly discovered "bogusness" of DWARF (and
> would be good to know about this) or it's a name collision for
> functions. Basically, before we go all the way to rework this again,
> let's see if just skipping declarations would be enough?

so there's actualy new developement today in:
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060#c14

gcc might actualy get fixed, so I think we could go back to
using declaration tag and use ftrace as additional filter..
at least this exercise gave us static functions ;-)

however we still have fedora with disabled disabled CONFIG_DEBUG_INFO_BTF
and will need to wait for that fix to enable that back

> 
> >                                 continue;
> > -               } else {
> > +
> > +                       if (!p->fn || args_cnt > p->args_cnt) {
> > +                               p->fn = fn;
> > +                               p->cu = cu;
> > +                               p->args_cnt = args_cnt;
> > +                               p->type_id_off = type_id_off;
> > +                       }
> > +               }
> > +       } else {
> > +               cu__for_each_function(cu, core_id, fn) {
> >                         if (fn->declaration || !fn->external)
> >                                 continue;
> > +                       if (generate_func(btfe, cu, fn, type_id_off))
> > +                               goto out;
> >                 }
> 
> I'm trending towards disliking this completely different fallback
> mechanism. It saved bpf-next accidentally, but otherwise obscured the
> issue and generally makes testing pahole with artificial binary BTFs
> (from test programs) harder. How about we unify approaches, but just
> use mcount symbols opportunistically, as an additional filter, if it's
> available?

ok

> 
> With that, testing that we still handle functions with duplicate names
> properly would be trivial (which I suspect we don't and we'll just
> keep the one with more args now, right?) And it makes static functions
> available for non-vmlinux binaries automatically (might be good or
> bad, but still...).

if we keep just the ftrace filter and rely on declaration tag,
the args checking will go away right?

jirka


  reply	other threads:[~2020-11-12 21:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 15:05 [RFC 0/3] btf_encoder: Fix functions BTF data generation Jiri Olsa
2020-11-12 15:05 ` [RFC/PATCH 1/3] btf_encoder: Generate also .init functions Jiri Olsa
2020-11-12 19:37   ` Andrii Nakryiko
2020-11-12 15:05 ` [RFC/PATCH 2/3] btf_encoder: Put function generation code to generate_func Jiri Olsa
2020-11-12 19:39   ` Andrii Nakryiko
2020-11-12 15:05 ` [RFC/PATCH 3/3] btf_encoder: Func generation fix Jiri Olsa
2020-11-12 19:54   ` Andrii Nakryiko
2020-11-12 21:14     ` Jiri Olsa [this message]
2020-11-13  0:08       ` Andrii Nakryiko
2020-11-13  0:18         ` Alexei Starovoitov
2020-11-13  0:30           ` Andrii Nakryiko
2020-11-13  1:00             ` Yonghong Song
2020-11-13  1:12               ` Andrii Nakryiko
2020-11-13 10:59         ` Jiri Olsa
2020-11-13 11:52           ` Arnaldo Carvalho de Melo

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=20201112211413.GA733055@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=haoluo@google.com \
    --cc=jolsa@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).