| ... | @@ -1152,33 +1152,6 @@ pub const Zld = struct { | ... | @@ -1152,33 +1152,6 @@ pub const Zld = struct { |
| 1152 | segment.vmsize = mem.alignForward(u64, segment.vmsize, page_size); | 1152 | segment.vmsize = mem.alignForward(u64, segment.vmsize, page_size); |
| 1153 | } | 1153 | } |
| 1154 | | 1154 | |
| 1155 | fn writeSegmentHeaders(self: *Zld, writer: anytype) !void { | | |
| 1156 | for (self.segments.items, 0..) |seg, i| { | | |
| 1157 | const indexes = self.getSectionIndexes(@as(u8, @intCast(i))); | | |
| 1158 | var out_seg = seg; | | |
| 1159 | out_seg.cmdsize = @sizeOf(macho.segment_command_64); | | |
| 1160 | out_seg.nsects = 0; | | |
| 1161 | | | |
| 1162 | // Update section headers count; any section with size of 0 is excluded | | |
| 1163 | // since it doesn't have any data in the final binary file. | | |
| 1164 | for (self.sections.items(.header)[indexes.start..indexes.end]) |header| { | | |
| 1165 | if (header.size == 0) continue; | | |
| 1166 | out_seg.cmdsize += @sizeOf(macho.section_64); | | |
| 1167 | out_seg.nsects += 1; | | |
| 1168 | } | | |
| 1169 | | | |
| 1170 | if (out_seg.nsects == 0 and | | |
| 1171 | (mem.eql(u8, out_seg.segName(), "__DATA_CONST") or | | |
| 1172 | mem.eql(u8, out_seg.segName(), "__DATA"))) continue; | | |
| 1173 | | | |
| 1174 | try writer.writeStruct(out_seg); | | |
| 1175 | for (self.sections.items(.header)[indexes.start..indexes.end]) |header| { | | |
| 1176 | if (header.size == 0) continue; | | |
| 1177 | try writer.writeStruct(header); | | |
| 1178 | } | | |
| 1179 | } | | |
| 1180 | } | | |
| 1181 | | | |
| 1182 | fn writeLinkeditSegmentData(self: *Zld) !void { | 1155 | fn writeLinkeditSegmentData(self: *Zld) !void { |
| 1183 | try self.writeDyldInfoData(); | 1156 | try self.writeDyldInfoData(); |
| 1184 | try self.writeFunctionStarts(); | 1157 | try self.writeFunctionStarts(); |
| ... | @@ -3035,7 +3008,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr | ... | @@ -3035,7 +3008,7 @@ pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progr |
| 3035 | var lc_buffer = std.ArrayList(u8).init(arena); | 3008 | var lc_buffer = std.ArrayList(u8).init(arena); |
| 3036 | const lc_writer = lc_buffer.writer(); | 3009 | const lc_writer = lc_buffer.writer(); |
| 3037 | | 3010 | |
| 3038 | try zld.writeSegmentHeaders(lc_writer); | 3011 | try MachO.writeSegmentHeaders(&zld, lc_writer); |
| 3039 | try lc_writer.writeStruct(zld.dyld_info_cmd); | 3012 | try lc_writer.writeStruct(zld.dyld_info_cmd); |
| 3040 | try lc_writer.writeStruct(zld.function_starts_cmd); | 3013 | try lc_writer.writeStruct(zld.function_starts_cmd); |
| 3041 | try lc_writer.writeStruct(zld.data_in_code_cmd); | 3014 | try lc_writer.writeStruct(zld.data_in_code_cmd); |