macho: unfortunately, LINKEDIT commands NEED to be in order

Otherwise, Apple's tooling goes mental and reports that the executable
is malformed/fails strict validation. We absolutely have to get it
right to support tools such `codesign` which are required to
successfully launch an app on an iOS device for instance. When Zig
matures enough so that we can ditch any Apple tooling and still be
able to successfully codesign for iOS and other, we can revisit this
area. Until then however, we are stuck in having to rewrite the LINKEDIT
segment at every update run of the self-hosted.

FYI, the strict layout for the MachO binary apparently is (please,
read this with a pinch of salt as this is inferred by me):
* __TEXT segment
* __DATA_CONST segment
* __DATA segment
* __LINKEDIT segment
* dyld info (rebase, bind, weak bind, lazy bind, export)
* symbol table
* dynamic symbol table
* string table
* code signature (if expected)
This commit is contained in:
Jakub Konka 2021-09-04 22:34:16 +02:00
parent 80e1c244b6
commit 7e87f93e06
2 changed files with 344 additions and 571 deletions

File diff suppressed because it is too large Load Diff

View File

@ -844,7 +844,6 @@ pub fn parseRelocs(self: *TextBlock, relocs: []macho.relocation_info, context: R
.sect = context.macho_file.got_section_index.?,
};
_ = try context.macho_file.allocateAtom(atom, match);
context.macho_file.dyld_info_dirty = true;
} else if (parsed_rel.payload == .unsigned) {
switch (parsed_rel.where) {
.undef => {