This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] [COFF] Always set PointerToRawData when writing a COFF file
ClosedPublic

Authored by mstorsjo on Nov 28 2022, 2:50 AM.

Details

Summary

If we don't want to set PointerToRawData, for an empty section,
we do must set it to zero explicitly. Some object file generators
do set it to zero for empty sections, while others set a nonzero
value pointing at the end of the previous section.

If the value was nonzero on input, we need to update it - either
setting it to zero, or to a valid offset in the output file (not
out of bounds)

This fixes https://github.com/mstorsjo/llvm-mingw/issues/313.

Testing this is tricky, because we can't use yaml2obj, since that
doesn't produce object files with nonzero PointerToRawData for
empty sections. We can use llvm-mc to assemble a small file
(assuming that LLVM's MC layer keeps this behaviour), or bundle
a small binary object file. I opted for using llvm-mc for now here
(with a test that it actually does keep this property), but I don't
mind changing it to a canned object file to make the test less brittle.

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 28 2022, 2:50 AM
mstorsjo requested review of this revision.Nov 28 2022, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 2:50 AM
jhenderson accepted this revision.Nov 28 2022, 2:54 AM

This looks fine, but you could always look to see how hard it would be to parameterise the PointerToRawData field in yaml2obj. (I'm not particularly familiar with the COFF side of yaml2obj, so don't know whether it's a simple task or not).

This revision is now accepted and ready to land.Nov 28 2022, 2:54 AM

This looks fine, but you could always look to see how hard it would be to parameterise the PointerToRawData field in yaml2obj. (I'm not particularly familiar with the COFF side of yaml2obj, so don't know whether it's a simple task or not).

I guess that could be useful, for letting the yaml format encapsulate more details of the COFF object files. Although, I'm not sure in how many other cases that would be useful... In any case - I think I'll refrain from taking on that right now, but wouldn't mind if someone else does.

This revision was landed with ongoing or failed builds.Nov 28 2022, 12:40 PM
This revision was automatically updated to reflect the committed changes.