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