This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Fix a crash scenario in GNUStyle<ELFT>::printHashSymbols().
ClosedPublic

Authored by grimar on Jul 2 2020, 4:34 AM.

Details

Summary

We might crash when the dynamic symbols table is empty and --hash-symbols
is requested. Both .hash and .gnu.hash logic is affected.

The patch fixes this issue.

Diff Detail

Event Timeline

grimar created this revision.Jul 2 2020, 4:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
jhenderson added inline comments.Jul 3 2020, 1:06 AM
llvm/test/tools/llvm-readobj/ELF/hash-symbols.test
517

to produce -> return

(I think it reads cleaner that way. It would be just "produce" anyway).

llvm/tools/llvm-readobj/ELFDumper.cpp
4078

I'm not sure if this does this, but I think we need to distinguish between the dynsym being actually empty (i.e. sh_size == 0 specified by the .dynsym section header) and we just don't know it's empty (i.e. there's no section header at all, but there is a DT_SYMTAB tag). See rGb259ce99 for context. If this code already does that, what in the test ensures we haven't broken this situation? I'm having a bit of a struggle remembering how that change worked, so this might not be relevant at all.

grimar updated this revision to Diff 275346.Jul 3 2020, 3:33 AM
grimar marked 3 inline comments as done.
  • Addressed review comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
4078

dynamic_symbols returns an empty range for both cases when either there is no DynSymRegion at all or when it is found, but empty:

Elf_Sym_Range dynamic_symbols() const {
  if (!DynSymRegion)
    return Elf_Sym_Range();
  return DynSymRegion->getAsArrayRef<Elf_Sym>();
}

To distinguish between these cases we can additionally check the DynSymRegion when reporting a warning. I've did it and added test cases.

jhenderson accepted this revision.Jul 7 2020, 1:26 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jul 7 2020, 1:26 AM
This revision was automatically updated to reflect the committed changes.