On Tue, Jan 12, 2021 at 10:43 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > When processing kernel image build by clang we can > find some functions without the name, which causes > pahole to segfault. > > Adding extra checks to make sure we always have > function's name defined before using it. > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > --- > btf_encoder.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/btf_encoder.c b/btf_encoder.c > index 333973054b61..17f7a14f2ef0 100644 > --- a/btf_encoder.c > +++ b/btf_encoder.c > @@ -72,6 +72,8 @@ static int collect_function(struct btf_elf *btfe, GElf_Sym *sym) > > if (elf_sym__type(sym) != STT_FUNC) > return 0; > + if (!elf_sym__name(sym, btfe->symtab)) > + return 0; elf_sym__name() is called below again, so might be better to just use local variable to store result? > > if (functions_cnt == functions_alloc) { > functions_alloc = max(1000, functions_alloc * 3 / 2); > @@ -730,9 +732,11 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, > if (!has_arg_names(cu, &fn->proto)) > continue; > if (functions_cnt) { > - struct elf_function *func; > + const char *name = function__name(fn, cu); > + struct elf_function *func = NULL; > > - func = find_function(btfe, function__name(fn, cu)); > + if (name) > + func = find_function(btfe, name); isn't this a more convoluted way of writing: name = function__name(fn, cu); if (!name) continue; func = find_function(btfe, name); if (!func || func->generated) continue ? > if (!func || func->generated) > continue; > func->generated = true; > -- > 2.26.2 >