authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-04-21 06:48:12+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-04-24 08:13:53+02:00
log4f7765de7c0203ceed3a5acbe0d4c07b678557b5
treea72c576fa43b3dfbff84e1fdf294811995d71849
parenta279f18bce488460f87f41545411fc964dcaa4b0

zld: common section should be writable


1 files changed, 8 insertions(+), 8 deletions(-)

src/link/MachO/Zld.zig+8-8
......@@ -64,7 +64,6 @@ got_section_index: ?u16 = null,
6464mod_init_func_section_index: ?u16 = null,
6565mod_term_func_section_index: ?u16 = null,
6666data_const_section_index: ?u16 = null,
67common_section_index: ?u16 = null,
6867
6968// __DATA segment sections
7069tlv_section_index: ?u16 = null,
......@@ -73,6 +72,7 @@ tlv_bss_section_index: ?u16 = null,
7372la_symbol_ptr_section_index: ?u16 = null,
7473data_section_index: ?u16 = null,
7574bss_section_index: ?u16 = null,
75common_section_index: ?u16 = null,
7676
7777symtab: std.StringArrayHashMapUnmanaged(Symbol) = .{},
7878strtab: std.ArrayListUnmanaged(u8) = .{},
......@@ -487,10 +487,10 @@ fn updateMetadata(self: *Zld) !void {
487487 if (mem.eql(u8, sectname, "__common")) {
488488 if (self.common_section_index != null) continue;
489489
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, .{
492492 .sectname = makeStaticString("__common"),
493 .segname = makeStaticString("__DATA_CONST"),
493 .segname = makeStaticString("__DATA"),
494494 .addr = 0,
495495 .size = 0,
496496 .offset = 0,
......@@ -656,7 +656,7 @@ fn getMatchingSection(self: *Zld, section: macho.section_64) ?MatchingSection {
656656 macho.S_ZEROFILL => {
657657 if (mem.eql(u8, sectname, "__common")) {
658658 break :blk .{
659 .seg = self.data_const_segment_cmd_index.?,
659 .seg = self.data_segment_cmd_index.?,
660660 .sect = self.common_section_index.?,
661661 };
662662 }
......@@ -764,7 +764,6 @@ fn sortSections(self: *Zld) !void {
764764 &self.mod_init_func_section_index,
765765 &self.mod_term_func_section_index,
766766 &self.data_const_section_index,
767 &self.common_section_index,
768767 };
769768 for (indices) |maybe_index| {
770769 const new_index: u16 = if (maybe_index.*) |index| blk: {
......@@ -787,11 +786,12 @@ fn sortSections(self: *Zld) !void {
787786 // __DATA segment
788787 const indices = &[_]*?u16{
789788 &self.la_symbol_ptr_section_index,
790 &self.tlv_section_index,
791789 &self.data_section_index,
790 &self.tlv_section_index,
792791 &self.tlv_data_section_index,
793792 &self.tlv_bss_section_index,
794793 &self.bss_section_index,
794 &self.common_section_index,
795795 };
796796 for (indices) |maybe_index| {
797797 const new_index: u16 = if (maybe_index.*) |index| blk: {
......@@ -2153,7 +2153,7 @@ fn populateMetadata(self: *Zld) !void {
21532153
21542154fn flush(self: *Zld) !void {
21552155 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;
21572157 const sect = &seg.sections.items[index];
21582158 sect.offset = 0;
21592159 }