[PATCH] D66820: [06/10] [COFF] Add a ResourceSectionRef method for getting resource contents

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 12:08:54 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: thakis, rnk, ruiu.
Herald added subscribers: seiya, rupprecht, mgrang, hiraditya.
Herald added a project: LLVM.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66820

Files:
  llvm/include/llvm/Object/COFF.h
  llvm/lib/Object/COFFObjectFile.cpp
  llvm/test/tools/llvm-cvtres/combined.test
  llvm/test/tools/llvm-cvtres/object.test
  llvm/test/tools/llvm-readobj/coff-resources.test
  llvm/tools/llvm-readobj/COFFDumper.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66820.217468.patch
Type: text/x-patch
Size: 15081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/3fc98667/attachment.bin>


More information about the llvm-commits mailing list