[PATCH] D76839: [lld-macho] Extend SyntheticSections to cover all segment load commands

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 05:55:39 PDT 2020


int3 created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
int3 edited the summary of this revision.
int3 updated this revision to Diff 252813.
int3 added a comment.
int3 edited the summary of this revision.
int3 added reviewers: ruiu, pcc, MaskRay, alexshap, christylee, smeenai, gkm.
int3 updated this revision to Diff 252815.
int3 marked an inline comment as done.

update


int3 added a comment.

update



================
Comment at: lld/MachO/SyntheticSections.h:23-24
+
+constexpr const char *binding = "__binding";
+constexpr const char *header = "__mach_header";
+constexpr const char *pageZero = "__pagezero";
----------------
The names of hidden sections don't make it to the final executable; they're just for distinguishing the InputSections within lld code and so can be any unique string. But I've picked the same names as the corresponding Atoms in ld64 for easy reference.


Previously, the special segments __PAGEZERO and __LINKEDIT were implemented as special LoadCommands. This diff implements them using special sections instead which have an `isHidden()` attribute. We do not emit section headers for hidden sections, but we use their addresses and file offsets to determine that of their containing segments. In addition to allowing us to share more segment-related code, it's also important for the next step of emitting dylibs:

1. dylibs don't have segments like __PAGEZERO, so we need an easy way of omitting them w/o messing up segment indices
2. Unlike the kernel, which is happy to run an executable with out-of-order segments, dyld requires dylibs to have their segment load commands arranged in increasing address order. This refactor makes it easier to implement sorting of sections and segments.

Depends on D76252 <https://reviews.llvm.org/D76252> for now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76839

Files:
  lld/MachO/Driver.cpp
  lld/MachO/InputSection.h
  lld/MachO/OutputSegment.cpp
  lld/MachO/OutputSegment.h
  lld/MachO/SyntheticSections.cpp
  lld/MachO/SyntheticSections.h
  lld/MachO/Writer.cpp
  lld/MachO/Writer.h
  lld/test/MachO/segments.s
  lld/test/MachO/text-segment.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76839.252815.patch
Type: text/x-patch
Size: 25293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200326/939e7ac1/attachment.bin>


More information about the llvm-commits mailing list