bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Yonghong Song <yhs@fb.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	dwarves@vger.kernel.org, bpf@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andriin@fb.com>, Hao Luo <haoluo@google.com>,
	Sedat Dilek <sedat.dilek@gmail.com>,
	Tom Stellard <tstellar@redhat.com>
Subject: Re: [PATCHv2] btf_encoder: Add extra checks for symbol names
Date: Wed, 13 Jan 2021 19:27:19 +0100	[thread overview]
Message-ID: <20210113182719.GA1358609@krava> (raw)
In-Reply-To: <2c933606-5591-cc20-9832-09a2549e9c58@fb.com>

On Wed, Jan 13, 2021 at 09:20:17AM -0800, Yonghong Song wrote:
> 
> 
> On 1/13/21 2:25 AM, Jiri Olsa wrote:
> > When processing kernel image build by clang we can
> > find some functions without the name, which causes
> > pahole to segfault.
> 
> Just curious. What kinds of functions gcc generates
> names and clang doesn't?

can't say.. I guess we could compare nm output
of both gcc and clang vmlinux for same .config

jirka

> 
> > 
> > Adding extra checks to make sure we always have
> > function's name defined before using it.
> > 
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >    v2 changes:
> >      - reorg the code based on Andrii's suggestion
> > 
> >   btf_encoder.c | 13 +++++++++++--
> >   1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/btf_encoder.c b/btf_encoder.c
> > index 333973054b61..5557c9efd365 100644
> > --- a/btf_encoder.c
> > +++ b/btf_encoder.c
> > @@ -68,10 +68,14 @@ static int collect_function(struct btf_elf *btfe, GElf_Sym *sym)
> >   	struct elf_function *new;
> >   	static GElf_Shdr sh;
> >   	static int last_idx;
> > +	const char *name;
> >   	int idx;
> >   	if (elf_sym__type(sym) != STT_FUNC)
> >   		return 0;
> > +	name = elf_sym__name(sym, btfe->symtab);
> > +	if (!name)
> > +		return 0;
> >   	if (functions_cnt == functions_alloc) {
> >   		functions_alloc = max(1000, functions_alloc * 3 / 2);
> > @@ -94,7 +98,7 @@ static int collect_function(struct btf_elf *btfe, GElf_Sym *sym)
> >   		last_idx = idx;
> >   	}
> > -	functions[functions_cnt].name = elf_sym__name(sym, btfe->symtab);
> > +	functions[functions_cnt].name = name;
> >   	functions[functions_cnt].addr = elf_sym__value(sym);
> >   	functions[functions_cnt].sh_addr = sh.sh_addr;
> >   	functions[functions_cnt].generated = false;
> > @@ -731,8 +735,13 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force,
> >   			continue;
> >   		if (functions_cnt) {
> >   			struct elf_function *func;
> > +			const char *name;
> > +
> > +			name = function__name(fn, cu);
> > +			if (!name)
> > +				continue;
> > -			func = find_function(btfe, function__name(fn, cu));
> > +			func = find_function(btfe, name);
> >   			if (!func || func->generated)
> >   				continue;
> >   			func->generated = true;
> > 
> 


  reply	other threads:[~2021-01-13 18:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 10:25 [PATCHv2] btf_encoder: Add extra checks for symbol names Jiri Olsa
2021-01-13 17:20 ` Yonghong Song
2021-01-13 18:27   ` Jiri Olsa [this message]
2021-01-14  7:45 ` Sedat Dilek

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=20210113182719.GA1358609@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --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=sedat.dilek@gmail.com \
    --cc=tstellar@redhat.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;
as well as URLs for NNTP newsgroup(s).