This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readobj] [COFF] Cope with debug directory payloads in unmapped areas
ClosedPublic

Authored by mstorsjo on Apr 27 2020, 5:49 AM.

Details

Summary

According to the spec, the payload for debug directories can be in parts of the binary that aren't mapped at runtime - in these cases, AddressOfRawData is just set to zero.

Just skip trying to print the payload in these cases, for now. If we'd really want to print that, we'd need a binary test input file as yaml2obj can't easily be tricked into placing data in padding areas of the file.)

Diff Detail

Event Timeline

mstorsjo created this revision.Apr 27 2020, 5:49 AM
Herald added a project: Restricted Project. · View Herald Transcript

What happens currently without this change? I'm guessing it tries to read something bad?

FWIW, ELF's yaml2obj now has the ability to add data blocks to an ELF, without generating a section header. See the "Fill" section type. Perhaps that's something that could be implemented in COFF's version at some point?

Aside from that, this all looks okay to me, but I'd like another opinion, as I'm not too familiar with COFF.

llvm/test/tools/llvm-readobj/COFF/debug-directory-unmapped.test
2

It might be worth a comment at the start of this test explaining what exactly is being tested, as it's not particularly obvious to me just looking at the test.

mstorsjo marked an inline comment as done.Apr 28 2020, 3:35 AM

What happens currently without this change? I'm guessing it tries to read something bad?

Not really, the getDebugPDBInfo and getRvaAndSizeAsBytes methods do fail cleanly, but the llvm-readobj call errors out at that point without printing info for the rest of the file.

FWIW, ELF's yaml2obj now has the ability to add data blocks to an ELF, without generating a section header. See the "Fill" section type. Perhaps that's something that could be implemented in COFF's version at some point?

That sounds potentially useful - if someone wants to spend more time on this cornercase.

llvm/test/tools/llvm-readobj/COFF/debug-directory-unmapped.test
2

Good point, I can do that.

mstorsjo updated this revision to Diff 260581.Apr 28 2020, 3:38 AM

Added a comment to the test file.

jhenderson accepted this revision.Apr 29 2020, 1:03 AM

LGTM, with the suggestions.

llvm/test/tools/llvm-readobj/COFF/debug-directory-unmapped.test
2–5

Could you use '##' for the comment markers, please. This is a practice I'm encouraging in my reviews, as it helps comments stand out from the lit/FileCheck directives.

Also I'd change the bit in brackets to "Currently llvm-readobj only prints the entry itself and not the payload. Note that there isn't currently any meaningful data in this test input where it claims the debug entry payload is." and probably just get rid of the brackets.

This revision is now accepted and ready to land.Apr 29 2020, 1:03 AM
mstorsjo marked 2 inline comments as done.Apr 29 2020, 1:30 AM
mstorsjo added inline comments.
llvm/test/tools/llvm-readobj/COFF/debug-directory-unmapped.test
2–5

Sure, will fix before pushing. Thanks!

This revision was automatically updated to reflect the committed changes.
mstorsjo marked an inline comment as done.