| ... | ... | @@ -334,8 +334,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 334 | 334 | try self.writeAllGlobalSymbols(); |
| 335 | 335 | try self.writeAllUndefSymbols(); |
| 336 | 336 | |
| 337 | | // TODO uncomment when we add our own codesigning mechanim |
| 338 | | // try self.writeStringTable(); |
| 337 | try self.writeStringTable(); |
| 339 | 338 | |
| 340 | 339 | switch (self.base.options.output_mode) { |
| 341 | 340 | .Exe => { |
| ... | ... | @@ -385,6 +384,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 385 | 384 | try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off); |
| 386 | 385 | self.libsystem_cmd_dirty = false; |
| 387 | 386 | } |
| 387 | |
| 388 | try self.codeSign(); |
| 388 | 389 | }, |
| 389 | 390 | .Obj => {}, |
| 390 | 391 | .Lib => return error.TODOImplementWritingLibFiles, |
| ... | ... | @@ -397,20 +398,18 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 397 | 398 | const nundefs = @intCast(u32, self.undef_symbols.items.len); |
| 398 | 399 | const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab; |
| 399 | 400 | symtab.nsyms = nlocals + nglobals + nundefs; |
| 400 | | // TODO could we drop this when we add our own codesigning mechanims? |
| 401 | | symtab.stroff = symtab.symoff + symtab.nsyms * @sizeOf(macho.nlist_64); |
| 402 | 401 | } |
| 403 | 402 | |
| 404 | | // TODO remove when we add our own codesigning mechanism |
| 405 | | try self.writeStringTable(); |
| 406 | | try self.codeSign(); |
| 407 | | |
| 408 | | { |
| 409 | | // TODO rework how we preallocate space for the entire __LINKEDIT segment instead of |
| 410 | | // doing dynamic updates like this. |
| 403 | // TODO rework how we preallocate space for the entire __LINKEDIT segment instead of |
| 404 | // doing dynamic updates like this. |
| 405 | if (self.code_signature_cmd_index) |i| { |
| 411 | 406 | const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment; |
| 412 | 407 | const code_sig = &self.load_commands.items[self.code_signature_cmd_index.?].LinkeditData; |
| 413 | 408 | linkedit.filesize = code_sig.dataoff + code_sig.datasize - linkedit.fileoff; |
| 409 | } else { |
| 410 | const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment; |
| 411 | const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab; |
| 412 | linkedit.filesize = symtab.stroff + symtab.strsize - linkedit.fileoff; |
| 414 | 413 | } |
| 415 | 414 | |
| 416 | 415 | if (self.cmd_table_dirty) { |
| ... | ... | @@ -1464,9 +1463,6 @@ pub fn populateMissingMetadata(self: *MachO) !void { |
| 1464 | 1463 | |
| 1465 | 1464 | const segment_size = mem.alignForwardGeneric(u64, file_size, self.page_size); |
| 1466 | 1465 | linkedit.vmsize += segment_size; |
| 1467 | | // TODO this is needed to please codesign_allocate |
| 1468 | | const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfo; |
| 1469 | | dyld_info.export_size = off - dyld_info.export_off; |
| 1470 | 1466 | } |
| 1471 | 1467 | if (symtab.stroff == 0) { |
| 1472 | 1468 | try self.string_table.append(self.base.allocator, 0); |
| ... | ... | @@ -1757,10 +1753,6 @@ fn writeAllUndefSymbols(self: *MachO) !void { |
| 1757 | 1753 | |
| 1758 | 1754 | fn codeSign(self: *MachO) !void { |
| 1759 | 1755 | const code_sig_cmd = &self.load_commands.items[self.code_signature_cmd_index.?].LinkeditData; |
| 1760 | | const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab; |
| 1761 | | const off = mem.alignForwardGeneric(u32, symtab.stroff + symtab.strsize, @sizeOf(u64)); |
| 1762 | | symtab.strsize = off - symtab.stroff; |
| 1763 | | code_sig_cmd.dataoff = off; |
| 1764 | 1756 | // TODO add actual code signing mechanism |
| 1765 | 1757 | try self.base.file.?.pwriteAll(&[_]u8{ 0 }, code_sig_cmd.dataoff + code_sig_cmd.datasize - 1); |
| 1766 | 1758 | } |