| ... | @@ -141,6 +141,9 @@ objc_selrefs_section_index: ?u16 = null, | ... | @@ -141,6 +141,9 @@ objc_selrefs_section_index: ?u16 = null, |
| 141 | objc_classrefs_section_index: ?u16 = null, | 141 | objc_classrefs_section_index: ?u16 = null, |
| 142 | objc_data_section_index: ?u16 = null, | 142 | objc_data_section_index: ?u16 = null, |
| 143 | | 143 | |
| | 144 | rustc_section_index: ?u16 = null, |
| | 145 | rustc_section_size: u64 = 0, |
| | 146 | |
| 144 | bss_file_offset: u32 = 0, | 147 | bss_file_offset: u32 = 0, |
| 145 | tlv_bss_file_offset: u32 = 0, | 148 | tlv_bss_file_offset: u32 = 0, |
| 146 | | 149 | |
| ... | @@ -993,6 +996,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { | ... | @@ -993,6 +996,11 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void { |
| 993 | try self.writeAtoms(); | 996 | try self.writeAtoms(); |
| 994 | } | 997 | } |
| 995 | | 998 | |
| | 999 | if (self.rustc_section_index) |id| { |
| | 1000 | const seg = &self.load_commands.items[self.data_segment_cmd_index.?].segment; |
| | 1001 | const sect = &seg.sections.items[id]; |
| | 1002 | sect.size = self.rustc_section_size; |
| | 1003 | } |
| 996 | if (self.bss_section_index) |idx| { | 1004 | if (self.bss_section_index) |idx| { |
| 997 | const seg = &self.load_commands.items[self.data_segment_cmd_index.?].segment; | 1005 | const seg = &self.load_commands.items[self.data_segment_cmd_index.?].segment; |
| 998 | const sect = &seg.sections.items[idx]; | 1006 | const sect = &seg.sections.items[idx]; |
| ... | @@ -1886,6 +1894,24 @@ pub fn getMatchingSection(self: *MachO, sect: macho.section_64) !?MatchingSectio | ... | @@ -1886,6 +1894,24 @@ pub fn getMatchingSection(self: *MachO, sect: macho.section_64) !?MatchingSectio |
| 1886 | .seg = self.data_segment_cmd_index.?, | 1894 | .seg = self.data_segment_cmd_index.?, |
| 1887 | .sect = self.objc_data_section_index.?, | 1895 | .sect = self.objc_data_section_index.?, |
| 1888 | }; | 1896 | }; |
| | 1897 | } else if (mem.eql(u8, sectname, ".rustc")) { |
| | 1898 | if (self.rustc_section_index == null) { |
| | 1899 | self.rustc_section_index = try self.initSection( |
| | 1900 | self.data_segment_cmd_index.?, |
| | 1901 | ".rustc", |
| | 1902 | sect.size, |
| | 1903 | sect.@"align", |
| | 1904 | .{}, |
| | 1905 | ); |
| | 1906 | // We need to preserve the section size for rustc to properly |
| | 1907 | // decompress the metadata. |
| | 1908 | self.rustc_section_size = sect.size; |
| | 1909 | } |
| | 1910 | |
| | 1911 | break :blk .{ |
| | 1912 | .seg = self.data_segment_cmd_index.?, |
| | 1913 | .sect = self.rustc_section_index.?, |
| | 1914 | }; |
| 1889 | } else { | 1915 | } else { |
| 1890 | if (self.data_section_index == null) { | 1916 | if (self.data_section_index == null) { |
| 1891 | self.data_section_index = try self.initSection( | 1917 | self.data_section_index = try self.initSection( |
| ... | @@ -5212,6 +5238,7 @@ fn sortSections(self: *MachO) !void { | ... | @@ -5212,6 +5238,7 @@ fn sortSections(self: *MachO) !void { |
| 5212 | | 5238 | |
| 5213 | // __DATA segment | 5239 | // __DATA segment |
| 5214 | const indices = &[_]*?u16{ | 5240 | const indices = &[_]*?u16{ |
| | 5241 | &self.rustc_section_index, |
| 5215 | &self.la_symbol_ptr_section_index, | 5242 | &self.la_symbol_ptr_section_index, |
| 5216 | &self.objc_const_section_index, | 5243 | &self.objc_const_section_index, |
| 5217 | &self.objc_selrefs_section_index, | 5244 | &self.objc_selrefs_section_index, |