This is an archive of the discontinued LLVM Phabricator instance.

[06/10] [COFF] Add a ResourceSectionRef method for getting resource contents
ClosedPublic

Authored by mstorsjo on Aug 27 2019, 12:08 PM.

Details

Summary

This allows llvm-readobj to print the contents of each resource when printing resources from an object file or executable, like it already does for plain .res files.

This requires providing the whole COFFObjectFile to ResourceSectionRef.

This supports both object files and executables. For executables, the DataRVA field is used as is to look up the right section.

For object files, ideally we would need to complete linking of them and fix up all relocations to know what the DataRVA field would end up being. In practice, the only thing that makes sense for an RVA field is an ADDR32NB relocation. Thus, find a relocation pointing at this field, verify that it has the expected type, locate the symbol it points at, look up the section the symbol points at, and read from the right offset in that section.

This works both for GNU windres object files (which use one single .rsrc section, with all relocations against the base of the .rsrc section, with the original value of the DataRVA field being the offset of the data from the beginning of the .rsrc section) and cvtres object files (with two separate .rsrc$01 and .rsrc$02 sections, and one symbol per data entry, with the original pre-relocated DataRVA field being set to zero).

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 27 2019, 12:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2019, 12:08 PM
thakis accepted this revision.Aug 29 2019, 1:37 PM

lgtm, nice.

llvm/test/tools/llvm-cvtres/combined.test
37

These Data ( sections here print data, but since the next line says CHECK instead of CHECK-NEXT we just don't print hit here, right?

This revision is now accepted and ready to land.Aug 29 2019, 1:37 PM
mstorsjo marked an inline comment as done.Aug 29 2019, 1:39 PM
mstorsjo added inline comments.
llvm/test/tools/llvm-cvtres/combined.test
37

Yes, I didn't want to bloat the test with all the bulk raw data here. I kept one entry at the top of coff-resources.test where I have a check for the full printout.

This revision was automatically updated to reflect the committed changes.