This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Ensure segments are laid out contiguously
ClosedPublic

Authored by int3 on Apr 20 2021, 5:41 AM.

Details

Summary

codesign/libstuff checks that the __LLVM segment is directly
before __LINKEDIT by checking that `fileOff + fileSize == next segment
fileOff`. Previously, there would be gaps between the segments due to
the fact that their fileOffs are page-aligned but their fileSizes
aren't. In order to satisfy codesign, we page-align fileOff *before*
calculating fileSize. (I don't think codesign checks for the relative
ordering of other segments, so in theory we could do this just for
__LLVM, but ld64 seems to do it for all segments.)

Note that we *don't* round up the fileSize of the __LINKEDIT segment.
Since it's the last segment, it doesn't need to worry about contiguity;
in addition, codesign checks that the last (hidden) section in
__LINKEDIT covers the last byte of the segment, so if we rounded up
__LINKEDIT's size we would have to do the same for its last section,
which is a bother.

While at it, I also addressed a FIXME in the linkedit-contiguity.s test
to cover more __LINKEDIT sections.

Diff Detail

Event Timeline

int3 created this revision.Apr 20 2021, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 5:41 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
int3 requested review of this revision.Apr 20 2021, 5:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2021, 5:41 AM
int3 edited the summary of this revision. (Show Details)Apr 20 2021, 7:45 AM
thakis accepted this revision.Apr 20 2021, 8:36 AM
This revision is now accepted and ready to land.Apr 20 2021, 8:36 AM
This revision was automatically updated to reflect the committed changes.