port(Macho): make simple executable running on a real system#1816
port(Macho): make simple executable running on a real system#1816marxin merged 21 commits intowild-linker:mainfrom
Conversation
|
The commands table sounds a bit like the dynamic table in ELF land. At least Regarding 16k alignment for each segment... segment extents are determined by the extents of the sections they contain. Section extents are in turn determined by the extents of the section parts that they contain. So initial placements are decided in |
Looking at the code, you are right, the similarities are pretty high and we should rework the command emission similarly. But, it's something we can postpone a bit, at least to a point where we'll have a working hello world binary. All right, let me play with the layout logic. @davidlattimore thanks for the suggestions |
davidlattimore
left a comment
There was a problem hiding this comment.
Nice! A few random thoughts, but nothing to stop this merging as-is
EDITTED:
The PR implements all the missing parts needed for a very first working example:
Original description:
The PR is currently more of a discussion space for the recent observations I made, which should ideally be addressed as part of it.
I noticed that both
FileHeaderand all load commands are mapped into the__TEXTsegment. That is reflected in the PR, where I ended up with a slightly more complicated section-to-segment mapping:This works reasonably well, but it also made
write_segment_commandsmore complex (segment_type,segment_sections_type). I also noticed that some commands can occur more than once, such asLC_LOAD_DYLIBandLC_RPATH, so the number of commands will not simply be the sum of sections in theLoadCommandssegment. Do you see a simpler approach here?The second limitation is that all segments (
__TEXT,__DATA,__DATA_CONST, and, with some exception handling,__LINKEDIT) must be aligned to page boundaries (16 KiB) both in the file and in virtual memory. That means I would need a mechanism to pad the last section in each segment, most likely something along these lines:Do you see a good place where we could enforce this?
Issue #757