This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/obj] - Improve diagnostics when printing NT_FILE notes.
ClosedPublic

Authored by grimar on Dec 4 2020, 12:00 AM.

Details

Summary

This changes the printNotesHelper to report warnings on its side when
there are errors when dumping notes.

With that we can provide more content when reporting warnings about broken notes.

Diff Detail

Event Timeline

grimar created this revision.Dec 4 2020, 12:00 AM
grimar requested review of this revision.Dec 4 2020, 12:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 12:00 AM

Thanks!

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

This is checking more than just the file mappings number, it also includes the page size (note the check above is for 2 bytes).
How about: "the note of size 0x1 is too short, expected at least 0x2"?

5348

I'd probably just say "unable to read file mappings".

If you prefer this, there's a typo: tripples -> triples.

5349

Maybe this could also say how many bytes it expected it to be? It should be (2 + 3 * FileCount) * Bytes IIRC.

And maybe say what FileCount is? That may give indication to a developer debugging a bad note whether the note is really too short or if the number of files is bogus.

5362

"file name for the file mapping" feels a little redundant -- maybe just "file name for the mapping"?

5575

Index should probably be incremented at the end, otherwise it reports the first note as index 1, not index 0.

grimar updated this revision to Diff 309833.Dec 7 2020, 1:28 AM
grimar marked 5 inline comments as done.
  • Addressed review comments.
llvm/tools/llvm-readobj/ELFDumper.cpp
5337

Done. Note: it is not 2 bytes, but 2 addresses. I.e 8 or 16 bytes.

5340

Side note: I think this doesn't work when N = 0 ("# of file mappings", see function comment) case.
Seems we should move this check below and exit a bit eariler when there are no mappings.

5349

Maybe this could also say how many bytes it expected it to be? It should be (2 + 3 * FileCount) * Bytes IIRC.

I think that (2 + 3 * FileCount) * Bytes is not the right value, because there should be at least N=FileCount NUL bytes in
filenames area it seems. I.e. here we have a check for (2 + 3 * FileCount) bytes, but only because we check
file names data in the code below and not right here.
So, I am not sure that we should mention an expected data size here?

5575

This is intentional. We enumerate program headers (few lines above) starting from 1 too.
And we do the same when printing warnings for relocations (in DumpStyle<ELFT>::forEachRelocationDo).

jhenderson added inline comments.Dec 7 2020, 1:51 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
5575

Seems to me like this is inconsistent with our indexes elsewhere (where we index from 0). We should probably fix both cases here.

grimar updated this revision to Diff 309842.Dec 7 2020, 2:20 AM
grimar marked an inline comment as done.
  • Index notes from 0, not from 1.
grimar added inline comments.Dec 7 2020, 2:22 AM
llvm/tools/llvm-readobj/ELFDumper.cpp
5359

Do we want to index file mappings from 0 too?

This revision is now accepted and ready to land.Dec 8 2020, 12:40 AM