| ... | ... | @@ -64,7 +64,6 @@ got_section_index: ?u16 = null, |
| 64 | 64 | mod_init_func_section_index: ?u16 = null, |
| 65 | 65 | mod_term_func_section_index: ?u16 = null, |
| 66 | 66 | data_const_section_index: ?u16 = null, |
| 67 | | common_section_index: ?u16 = null, |
| 68 | 67 | |
| 69 | 68 | // __DATA segment sections |
| 70 | 69 | tlv_section_index: ?u16 = null, |
| ... | ... | @@ -73,6 +72,7 @@ tlv_bss_section_index: ?u16 = null, |
| 73 | 72 | la_symbol_ptr_section_index: ?u16 = null, |
| 74 | 73 | data_section_index: ?u16 = null, |
| 75 | 74 | bss_section_index: ?u16 = null, |
| 75 | common_section_index: ?u16 = null, |
| 76 | 76 | |
| 77 | 77 | symtab: std.StringArrayHashMapUnmanaged(Symbol) = .{}, |
| 78 | 78 | strtab: std.ArrayListUnmanaged(u8) = .{}, |
| ... | ... | @@ -487,10 +487,10 @@ fn updateMetadata(self: *Zld) !void { |
| 487 | 487 | if (mem.eql(u8, sectname, "__common")) { |
| 488 | 488 | if (self.common_section_index != null) continue; |
| 489 | 489 | |
| 490 | | self.common_section_index = @intCast(u16, data_const_seg.sections.items.len); |
| 491 | | try data_const_seg.addSection(self.allocator, .{ |
| 490 | self.common_section_index = @intCast(u16, data_seg.sections.items.len); |
| 491 | try data_seg.addSection(self.allocator, .{ |
| 492 | 492 | .sectname = makeStaticString("__common"), |
| 493 | | .segname = makeStaticString("__DATA_CONST"), |
| 493 | .segname = makeStaticString("__DATA"), |
| 494 | 494 | .addr = 0, |
| 495 | 495 | .size = 0, |
| 496 | 496 | .offset = 0, |
| ... | ... | @@ -656,7 +656,7 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection { |
| 656 | 656 | macho.S_ZEROFILL => { |
| 657 | 657 | if (mem.eql(u8, sectname, "__common")) { |
| 658 | 658 | break :blk .{ |
| 659 | | .seg = self.data_const_segment_cmd_index.?, |
| 659 | .seg = self.data_segment_cmd_index.?, |
| 660 | 660 | .sect = self.common_section_index.?, |
| 661 | 661 | }; |
| 662 | 662 | } |
| ... | ... | @@ -764,7 +764,6 @@ fn sortSections(self: *Zld) !void { |
| 764 | 764 | &self.mod_init_func_section_index, |
| 765 | 765 | &self.mod_term_func_section_index, |
| 766 | 766 | &self.data_const_section_index, |
| 767 | | &self.common_section_index, |
| 768 | 767 | }; |
| 769 | 768 | for (indices) |maybe_index| { |
| 770 | 769 | const new_index: u16 = if (maybe_index.*) |index| blk: { |
| ... | ... | @@ -787,11 +786,12 @@ fn sortSections(self: *Zld) !void { |
| 787 | 786 | // __DATA segment |
| 788 | 787 | const indices = &[_]*?u16{ |
| 789 | 788 | &self.la_symbol_ptr_section_index, |
| 790 | | &self.tlv_section_index, |
| 791 | 789 | &self.data_section_index, |
| 790 | &self.tlv_section_index, |
| 792 | 791 | &self.tlv_data_section_index, |
| 793 | 792 | &self.tlv_bss_section_index, |
| 794 | 793 | &self.bss_section_index, |
| 794 | &self.common_section_index, |
| 795 | 795 | }; |
| 796 | 796 | for (indices) |maybe_index| { |
| 797 | 797 | const new_index: u16 = if (maybe_index.*) |index| blk: { |
| ... | ... | @@ -2153,7 +2153,7 @@ fn populateMetadata(self: *Zld) !void { |
| 2153 | 2153 | |
| 2154 | 2154 | fn flush(self: *Zld) !void { |
| 2155 | 2155 | if (self.common_section_index) |index| { |
| 2156 | | const seg = &self.load_commands.items[self.data_const_segment_cmd_index.?].Segment; |
| 2156 | const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; |
| 2157 | 2157 | const sect = &seg.sections.items[index]; |
| 2158 | 2158 | sect.offset = 0; |
| 2159 | 2159 | } |