| ... | ... | @@ -860,46 +860,32 @@ pub fn flush(self: *MachO, comp: *Compilation) !void { |
| 860 | 860 | |
| 861 | 861 | pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 862 | 862 | _ = comp; |
| 863 | |
| 863 | 864 | const tracy = trace(@src()); |
| 864 | 865 | defer tracy.end(); |
| 865 | 866 | |
| 866 | | const output_mode = self.base.options.output_mode; |
| 867 | try self.setEntryPoint(); |
| 868 | try self.writeRebaseInfoTable(); |
| 869 | try self.writeBindInfoTable(); |
| 870 | try self.writeLazyBindInfoTable(); |
| 871 | try self.writeExportInfo(); |
| 872 | try self.writeAllGlobalAndUndefSymbols(); |
| 873 | try self.writeIndirectSymbolTable(); |
| 874 | try self.writeStringTable(); |
| 875 | try self.updateLinkeditSegmentSizes(); |
| 867 | 876 | |
| 868 | | switch (output_mode) { |
| 869 | | .Exe => { |
| 870 | | if (self.entry_addr) |addr| { |
| 871 | | // Update LC_MAIN with entry offset. |
| 872 | | const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment; |
| 873 | | const main_cmd = &self.load_commands.items[self.main_cmd_index.?].Main; |
| 874 | | main_cmd.entryoff = addr - text_segment.inner.vmaddr; |
| 875 | | main_cmd.stacksize = self.base.options.stack_size_override orelse 0; |
| 876 | | self.load_commands_dirty = true; |
| 877 | | } |
| 878 | | try self.writeRebaseInfoTable(); |
| 879 | | try self.writeBindInfoTable(); |
| 880 | | try self.writeLazyBindInfoTable(); |
| 881 | | try self.writeExportInfo(); |
| 882 | | try self.writeAllGlobalAndUndefSymbols(); |
| 883 | | try self.writeIndirectSymbolTable(); |
| 884 | | try self.writeStringTable(); |
| 885 | | try self.updateLinkeditSegmentSizes(); |
| 886 | | |
| 887 | | if (self.d_sym) |*ds| { |
| 888 | | // Flush debug symbols bundle. |
| 889 | | try ds.flushModule(self.base.allocator, self.base.options); |
| 890 | | } |
| 877 | if (self.d_sym) |*ds| { |
| 878 | // Flush debug symbols bundle. |
| 879 | try ds.flushModule(self.base.allocator, self.base.options); |
| 880 | } |
| 891 | 881 | |
| 892 | | if (self.requires_adhoc_codesig) { |
| 893 | | // Preallocate space for the code signature. |
| 894 | | // We need to do this at this stage so that we have the load commands with proper values |
| 895 | | // written out to the file. |
| 896 | | // The most important here is to have the correct vm and filesize of the __LINKEDIT segment |
| 897 | | // where the code signature goes into. |
| 898 | | try self.writeCodeSignaturePadding(); |
| 899 | | } |
| 900 | | }, |
| 901 | | .Obj => {}, |
| 902 | | .Lib => return error.TODOImplementWritingLibFiles, |
| 882 | if (self.requires_adhoc_codesig) { |
| 883 | // Preallocate space for the code signature. |
| 884 | // We need to do this at this stage so that we have the load commands with proper values |
| 885 | // written out to the file. |
| 886 | // The most important here is to have the correct vm and filesize of the __LINKEDIT segment |
| 887 | // where the code signature goes into. |
| 888 | try self.writeCodeSignaturePadding(); |
| 903 | 889 | } |
| 904 | 890 | |
| 905 | 891 | try self.writeLoadCommands(); |
| ... | ... | @@ -2704,6 +2690,7 @@ fn setEntryPoint(self: *MachO) !void { |
| 2704 | 2690 | const ec = &self.load_commands.items[self.main_cmd_index.?].Main; |
| 2705 | 2691 | ec.entryoff = @intCast(u32, sym.n_value - seg.inner.vmaddr); |
| 2706 | 2692 | ec.stacksize = self.base.options.stack_size_override orelse 0; |
| 2693 | self.load_commands_dirty = true; |
| 2707 | 2694 | } |
| 2708 | 2695 | |
| 2709 | 2696 | fn writeRebaseInfoTableZld(self: *MachO) !void { |