port(MachO): section/segment mapping and first final output#1795
Merged
marxin merged 21 commits intowild-linker:mainfrom Apr 4, 2026
Merged
port(MachO): section/segment mapping and first final output#1795marxin merged 21 commits intowild-linker:mainfrom
marxin merged 21 commits intowild-linker:mainfrom
Conversation
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
marxin
commented
Apr 3, 2026
davidlattimore
approved these changes
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The second Mach-O port PR implements the concept of sections, segments and I'm able to reach the point a final output file is produced. So far, the designed
Platformtrait has guided me pretty well.First, let's start a bit with the Mach-O layout explanation and how I map it to the Wild's essential concepts (

PartIdthat is 1:1 mapping toOutputSectionId; and theProgramSegmentDef):The mapping is following:
Mach Headerispart_id::FILE_HEADER__TEXT_SEGMENTsegment_command_64 is mapped topart_id::TEXT_SEGMENT__DATA_SEGMENTsegment_command_64 is mapped topart_id::DATA_SEGMENT__textsection data is mapped topart_id::TEXT__datasection data is mapped topart_id::DATAand the following program segments are created (with the clarification how are they used):
SegmentType::Header- contains only thepart_id::FILE_HEADERSegmentType::LoadCommand- contains all load commands (__TEXT_SEGMENT,__DATA_SEGMENT,__PAGEZERO_SEGMENT) - we need the information about the number of load commands (and their total size)SegmentType::Text- contains__textsection content (and will include all other sections defined in __TEXT segment in input files) - based on that we can fill-up the__TEXT_SEGMENTsegment_command_64 (number of sections, names, their offset in memory and file)The suggested approach works fine, except I feel the section iteration of a segment is a bit cumbersome and it heavily depends on the
ProgramSegmentDef. I'm going to mark methods in the code that might be improved.After a small tweak to the ELF part, I was able to introduce an extra Mach-O specific
part_ids and so we can basically live with a sparse output section maps. Plus, a lifetime of a method was adjusted based on Mach-O needs.Right now, I am pretty strict when it comes to the supported segments and sections, but I believe we can get pretty far as the number of used sections is limited. At least to a point, where a simple hello world program will run. Once having that, we can fill the missing gaps.
There are still many cut corners, but it's pretty neat the PR reaches a point where a final output file scaffolding is laid out:
Issue #757