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, this refactor is also important for the next step of emitting dylibs:
- dylibs don't have segments like __PAGEZERO, so we need an easy way of omitting them w/o messing up segment indices
- 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. The refactor makes it easier to implement sorting of sections and segments.
Depends on D76252: [lld-macho] Add basic support for linking against dylibs.
isHidden implies you *don't* emit the header, right? I'd clarify that in the comment.