This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj/readelf] - Refine the implementation of printMipsOptions().
ClosedPublic

Authored by grimar on Jul 29 2020, 8:35 AM.

Details

Summary

printMipsOptions() and the test related has the following issues currently:

  1. It does not check the value of Elf_Mips_Options<ELFT>::size field.
  2. For ODK_REGINFO options it is possible to read past the end of buffer, because there is no check against the sizeof(Elf_Mips_RegInfo<ELFT>).
  3. The error about the broken size is just printed to the standard output.
  4. The binary input is used for the test.
  5. There is no testing for multiple options in the .MIPS.options section, though the code supports it.
  6. Only llvm-readobj is tested, but not llvm-readelf.
  7. "Unsupported MIPS options tag" message does not reveal the tag ID.

This patch fixes all of these points.

Diff Detail

Event Timeline

grimar created this revision.Jul 29 2020, 8:35 AM
grimar requested review of this revision.Jul 29 2020, 8:35 AM
This revision is now accepted and ready to land.Jul 29 2020, 9:19 AM
jhenderson added inline comments.Jul 31 2020, 12:22 AM
llvm/test/tools/llvm-readobj/ELF/mips-options-sec.test
48

for a one -> for one

80

Here and below, why are you running the llvm-readobj command twice? Did you mean for it to be llvm-readelf?

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

a wrong size -> an invalid size

3359

the descriptior -> a descriptor

Don't we need something about the descriptor's offset in here somewhere? If I'm not mistaken, the sizes here mgiht be a bit misleading (e.g. the section size might be the remaining section size rather than the total section size, despite saying the section size is 0x1234)

3370

If there can be more than one entry in the section, this message is misleading too, since it's saying the whole section has a single kind. Should it be "a .MIPS.options entry of kind"?

3371

a wrong size -> an invalid size

grimar updated this revision to Diff 282606.Aug 3 2020, 6:19 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/mips-options-sec.test
80

Right. Fixed.

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

I've added offset and fixed the calculation of the size.

3370

Fixed.