This is an archive of the discontinued LLVM Phabricator instance.

[llvm][llvm-objcopy] When outputting to binary don't output segments that cover no sections
ClosedPublic

Authored by jakehehrlich on Aug 1 2017, 3:54 PM.

Details

Summary

Sometimes LLD will produce a PT_LOAD segment that only covers the headers (and covers no sections). GNU objcopy does not output the segment contents for these sections. In particular this is an issue in building magenta because the final link step for the kernel would produce just such a PT_LOAD segment. This change is to support this case and to match what GNU objcopy does in this case.

Diff Detail

Repository
rL LLVM

Event Timeline

jakehehrlich created this revision.Aug 1 2017, 3:54 PM
jhenderson edited edge metadata.Aug 2 2017, 1:42 AM

Looks fine to me, but could we have a test, please?

tools/llvm-objcopy/Object.cpp
358 ↗(On Diff #109243)

Not sure if there's a typical way of doing this, but I have a preference for an explicit comparison against nullptr (i.e. Segment->firstSection() != nullptr). I'm happy either way though.

377 ↗(On Diff #109243)

Ditto.

jakehehrlich edited the summary of this revision. (Show Details)

The binary being uploaded can be downloaded here: https://drive.google.com/file/d/0B3gtIAmiMwZXNlZzckpOcEJfYzA/view?usp=sharing

It was compiled by clang (which I think just uses llvm-mc) and linked using ld.lld. It has a sectionless segment that covers a PT_PHDR segment. I plan on using this binary for multiple tests involving this strange case.

The test ensures that exactly the .text and .data sections worth of data is copied. If the extra PT_LOAD segment was copied it would cause the size to increase by at least a page.

This revision is now accepted and ready to land.Aug 3 2017, 1:23 AM
This revision was automatically updated to reflect the committed changes.