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,...@@ -64,7 +64,6 @@ got_section_index: ?u16 = null,
64mod_init_func_section_index: ?u16 = null,64mod_init_func_section_index: ?u16 = null,
65mod_term_func_section_index: ?u16 = null,65mod_term_func_section_index: ?u16 = null,
66data_const_section_index: ?u16 = null,66data_const_section_index: ?u16 = null,
67common_section_index: ?u16 = null,
6867
69// __DATA segment sections68// __DATA segment sections
70tlv_section_index: ?u16 = null,69tlv_section_index: ?u16 = null,
...@@ -73,6 +72,7 @@ tlv_bss_section_index: ?u16 = null,...@@ -73,6 +72,7 @@ tlv_bss_section_index: ?u16 = null,
73la_symbol_ptr_section_index: ?u16 = null,72la_symbol_ptr_section_index: ?u16 = null,
74data_section_index: ?u16 = null,73data_section_index: ?u16 = null,
75bss_section_index: ?u16 = null,74bss_section_index: ?u16 = null,
75common_section_index: ?u16 = null,
7676
77symtab: std.StringArrayHashMapUnmanaged(Symbol) = .{},77symtab: std.StringArrayHashMapUnmanaged(Symbol) = .{},
78strtab: std.ArrayListUnmanaged(u8) = .{},78strtab: 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;
489489
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 segment786 // __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 {
21532153
2154fn flush(self: *Zld) !void {2154fn 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 }