This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] - Report warnings instead of errors for broken relocations.
ClosedPublic

Authored by grimar on Feb 14 2020, 1:52 AM.

Details

Summary

This is a follow-up for https://reviews.llvm.org/D74545.

It adds test cases for each incorrect case returned in getRelocationTarget.

Diff Detail

Event Timeline

grimar created this revision.Feb 14 2020, 1:52 AM
Herald added a project: Restricted Project. · View Herald Transcript
grimar planned changes to this revision.Feb 14 2020, 1:57 AM

Will check something.

grimar updated this revision to Diff 244607.Feb 14 2020, 3:26 AM
  • Improved how errors looks like.
  • Fixed one more test case.
MaskRay added inline comments.Feb 14 2020, 2:35 PM
llvm/test/Object/invalid.test
420–421

We probably should split invalid.test. For example, segments related errors and sections related errors can be separated.

llvm/test/tools/llvm-readobj/ELF/relocations-errors.test
1 ↗(On Diff #244607)

Maybe relocation-errors.test?

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

Target->first

5772

Target->second

grimar updated this revision to Diff 244868.Feb 16 2020, 4:30 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
llvm/test/Object/invalid.test
420–421

It feels that some of the tests might go to the corresponding tools test folders.
(e.g. docnum 21 below)

jhenderson added inline comments.Feb 17 2020, 7:47 AM
llvm/test/Object/invalid.test
420–421

Better yet would be to replace those tests which are testing library code with gtest unit tests to test the interfaces directly instead (and then additional tests in the tools folder to show the tools correctly handle the respective places properly).

llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
2

Delete "do"

56–59

Seems like this overlaps with reloc-no-sym.test? Could we get rid of one or the other?

70

relocation in a section...

71

is neither SHT_SYMTAB nor SHT_DYNSYM

grimar updated this revision to Diff 245094.Feb 18 2020, 12:58 AM
grimar marked 4 inline comments as done.
  • Addressed review comments.
llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
56–59

This one is a bit different: here we have a SHT_REL section.
(I can't test an addend here, like reloc-no-sym.test do).

And the intention to have it also was to show the order of warnings/normal relocations.
I.e. I wanted to have at least one valid relocation in the middle and
"relocation against a symbol with index 0" works good as it is related to the context and the
current code.

So, I'd keep both. (btw, reloc-no-sym.test seems lacks GNU test and SHT_REL test and might need to be improved).

jhenderson added inline comments.Feb 24 2020, 3:48 AM
llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
48

no a symbol -> no symbol
index of -> index

llvm/tools/llvm-readobj/ELFDumper.cpp
3336–3337

I'm not sure this error message quite makes sense. To me, I read it as dumping the relocation at file offset 0x1234 (i.e. where the relocation is physically stored in the file), whereas the offset is the section-relative offset.

Perhaps this error should print the index of the relocation and its section, i.e. something like "unable to print the relocation with index 4 in .rela.text: ...". I'd also recommend the phrasing I've used there regarding "unable to print" instead of "error dumping".

Same comment goes for LLVM style.

By the way, would it not make sense to print something like "<?>" or "<corrupt>" etc for the invalid values?

grimar updated this revision to Diff 246431.Feb 25 2020, 6:13 AM
grimar marked 2 inline comments as done.
  • Addressed review comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
3336–3337

By the way, would it not make sense to print something like "<?>" or "<corrupt>" etc for the invalid values?

Yes. I had an experiment about refactoring the getRelocationTarget method (used getFullSymbolName for STT_SECTION symbols path as it has very similar code). As a result I had 2 warnings of this patch gone and "<?>" displayed.
I think we might want both: i.e. to show a warning about what is wrong about the object parsed and to dump a relocation, using "<?>" if needed. It seems to be a good possible follow-up change.

Perhaps this error should print the index of the relocation and its section, i.e. something like "unable to print the relocation with index 4 in .rela.text: ...". I'd also recommend the phrasing I've used there regarding "unable to print" instead of "error dumping".

I've applied your suggestion with a change: I've used a section index instead of a section name in the error message:
this is more consistent with our others errors. Looks fine?

jhenderson added inline comments.Feb 27 2020, 1:51 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
3336–3337

Looks fine, if a little verbose. Do you think something like "unable to print relocation 1 in section 2 ..." would be sufficient?

grimar marked an inline comment as done.Feb 27 2020, 1:55 AM
grimar added inline comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
3336–3337

It sounds fine to me. I'll apply.

grimar updated this revision to Diff 246914.Feb 27 2020, 4:52 AM
  • Addressed review comment.
MaskRay accepted this revision.Feb 27 2020, 10:36 AM
This revision is now accepted and ready to land.Feb 27 2020, 10:36 AM
This revision was automatically updated to reflect the committed changes.