Re: [PATCH] objtool: support symtab_shndx during dump

From: Miroslav Benes
Date: Fri Sep 04 2020 - 03:54:32 EST


On Thu, 3 Sep 2020, Josh Poimboeuf wrote:

> On Wed, Aug 12, 2020 at 10:57:11AM -0700, Kristen Carlson Accardi wrote:
>
> > if (GELF_ST_TYPE(sym.st_info) == STT_SECTION) {
> > - scn = elf_getscn(elf, sym.st_shndx);
> > + if ((sym.st_shndx > SHN_UNDEF &&
> > + sym.st_shndx < SHN_LORESERVE) ||
> > + (xsymtab && sym.st_shndx == SHN_XINDEX)) {
> > + if (sym.st_shndx != SHN_XINDEX)
> > + shndx = sym.st_shndx;
>
> The sym.st_shndx checks are redundant, if 'sym.st_shndx == SHN_XINDEX'
> then 'sym.st_shndx != SHN_XINDEX' can't be true.

It is probably a copy-paste from read_symbols() in elf.c, where the logic
is different.

> Actually I think this can be even further simplified to something like
>
> if (!shndx)
> shndx = sym.st_shndx;

This relies on the fact that gelf_getsymshndx() always initializes shndx,
no? I think it would be better to initialize it in orc_dump() too. Safer
and easier to read. It applies to Kristen's patch as well. I missed that.

Miroslav