[PATCH] D100848: [lld-macho] Ensure segments are laid out contiguously

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 05:41:30 PDT 2021


int3 created this revision.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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, so 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100848

Files:
  lld/MachO/OutputSegment.h
  lld/MachO/Writer.cpp
  lld/test/MachO/bitcode-bundle.ll
  lld/test/MachO/bss.s
  lld/test/MachO/linkedit-contiguity.s
  lld/test/MachO/section-headers.s
  lld/test/MachO/segments.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100848.338839.patch
Type: text/x-patch
Size: 10733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210420/8f478538/attachment.bin>


More information about the llvm-commits mailing list