This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj/libObject] - Allow dumping objects that has a broken SHT_SYMTAB_SHNDX section.
ClosedPublic

Authored by grimar on Oct 14 2020, 2:37 AM.

Details

Summary

Currently it is impossible to create an instance of ELFObjectFile when the
SHT_SYMTAB_SHNDX can't be read. We error out when fail to parse the
SHT_SYMTAB_SHNDX section in the factory method.

This change delays reading of the SHT_SYMTAB_SHNDX section entries,
with it llvm-readobj is now able to work with such inputs.

Diff Detail

Event Timeline

grimar created this revision.Oct 14 2020, 2:37 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar requested review of this revision.Oct 14 2020, 2:37 AM

Currently it is impossible to create an instance of ELFObjectFile when the SHT_SYMTAB_SHNDX can't be read.

.. it errors ... when failed to parse SHT_SYMTAB_SHNDX

It happens because ELFObjectFile tries to read its entries too early, in the constructor.

ELFObjectFile::create is not a constructor. It is a factory function.

llvm/include/llvm/Object/ELFObjectFile.h
699

Is it because yaml2obj cannot emit a malformed SHT_SYMTAB_SHNDX?

llvm/unittests/Object/ELFObjectFileTest.cpp
303

Seems misaligned

grimar updated this revision to Diff 299289.Oct 20 2020, 12:54 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
llvm/include/llvm/Object/ELFObjectFile.h
699

No, it is because I think that testing of this place is a bit unrelated to what this patch does.
The idea of the patch is to allow to create an instance of ELFObjectFile when the
SHT_SYMTAB_SHNDX can't be read. I had to update this place because of API change,
but hopefully it doesn't mean I need to add a test for each place that can now report an error right now
(given that there are few others "Test this error" TODOs in this file).

Note, that this method (getSymbolSection) is very specific: it is only invoked by llvm-readobj by following 3 tests:

LLVM :: tools/llvm-readobj/ELF/AArch64/dwarf-cfi.s
LLVM :: tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
LLVM :: tools/llvm-readobj/ELF/stack-sizes.test

First two are using it because lib/DebugInfo/DWARF (DWARFObjInMemory) calls it.
Stack sizes implementation also uses ELFObjectFile<ELFT>::getSymbolSection(DataRefImpl Symb) API,
though it should probably use ELFFile<ELFT> instead (see D87362).

grimar edited the summary of this revision. (Show Details)Oct 20 2020, 12:55 AM
jhenderson added inline comments.Oct 22 2020, 1:33 AM
llvm/include/llvm/Object/ELFObjectFile.h
697

Debugging code needs removing?

llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
1–2 ↗(On Diff #299289)

Looks like you don't need to do this as part of this change, since this file is otherwise unaffected?

llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test
258
265

Presumably not part of this patch, since I can't see the error message being reported anywhere in the changes, but this should be "the associated symbol table".

llvm/unittests/Object/ELFObjectFileTest.cpp
314

The test name here doesn't correspond with the behaviour being tested.

grimar planned changes to this revision.Oct 22 2020, 1:35 AM
grimar marked an inline comment as done.
grimar added inline comments.
llvm/include/llvm/Object/ELFObjectFile.h
697

Oops.

llvm/test/tools/llvm-readobj/ELF/ARM/dwarf-cfi.s
1–2 ↗(On Diff #299289)

Right. I think I forgot to revert changes I did for debugging..

grimar updated this revision to Diff 300186.Oct 23 2020, 12:56 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/symbol-shndx.test
265

Yeah. It comes from ELFFile<ELFT>::getSHNDXTable. I'll fix.

jhenderson accepted this revision.Oct 23 2020, 1:36 AM

Looks good, (I'm ambivalent on the testing discussion, and will let you and @MaskRay come to a conclusion).

This revision is now accepted and ready to land.Oct 23 2020, 1:36 AM

@MaskRay, are you OK with the current version?

Ping @MaskRay?
If there will be no objections, I am going to commit this in my tomorrow.