authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-27 11:30:02+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-27 11:30:02+02:00
log1e65d41a659894eed6beb92ae89ca531f6f9dfd0
tree58fb5ebde51d25e5edca40dbcf39ed5ccfd14a8d
parent705cd64080a5555425de7d13a9fbc6c19af65bde

macho: merge __common with __bss section


1 files changed, 25 insertions(+), 47 deletions(-)

src/link/MachO.zig+25-47
......@@ -127,7 +127,6 @@ tlv_bss_section_index: ?u16 = null,
127127la_symbol_ptr_section_index: ?u16 = null,
128128data_section_index: ?u16 = null,
129129bss_section_index: ?u16 = null,
130common_section_index: ?u16 = null,
131130
132131objc_const_section_index: ?u16 = null,
133132objc_selrefs_section_index: ?u16 = null,
......@@ -1222,31 +1221,17 @@ pub fn getMatchingSection(self: *MachO, sect: macho.section_64) !?MatchingSectio
12221221 };
12231222 },
12241223 macho.S_ZEROFILL => {
1225 if (mem.eql(u8, sectname, "__common")) {
1226 if (self.common_section_index == null) {
1227 self.common_section_index = @intCast(u16, data_seg.sections.items.len);
1228 try data_seg.addSection(self.base.allocator, "__common", .{
1229 .flags = macho.S_ZEROFILL,
1230 });
1231 }
1232
1233 break :blk .{
1234 .seg = self.data_segment_cmd_index.?,
1235 .sect = self.common_section_index.?,
1236 };
1237 } else {
1238 if (self.bss_section_index == null) {
1239 self.bss_section_index = @intCast(u16, data_seg.sections.items.len);
1240 try data_seg.addSection(self.base.allocator, "__bss", .{
1241 .flags = macho.S_ZEROFILL,
1242 });
1243 }
1244
1245 break :blk .{
1246 .seg = self.data_segment_cmd_index.?,
1247 .sect = self.bss_section_index.?,
1248 };
1224 if (self.bss_section_index == null) {
1225 self.bss_section_index = @intCast(u16, data_seg.sections.items.len);
1226 try data_seg.addSection(self.base.allocator, "__bss", .{
1227 .flags = macho.S_ZEROFILL,
1228 });
12491229 }
1230
1231 break :blk .{
1232 .seg = self.data_segment_cmd_index.?,
1233 .sect = self.bss_section_index.?,
1234 };
12501235 },
12511236 macho.S_THREAD_LOCAL_VARIABLES => {
12521237 if (self.tlv_section_index == null) {
......@@ -1598,7 +1583,6 @@ fn sortSections(self: *MachO) !void {
15981583 &self.tlv_data_section_index,
15991584 &self.tlv_bss_section_index,
16001585 &self.bss_section_index,
1601 &self.common_section_index,
16021586 };
16031587 for (indices) |maybe_index| {
16041588 const new_index: u16 = if (maybe_index.*) |index| blk: {
......@@ -2578,16 +2562,16 @@ fn resolveSymbols(self: *MachO) !void {
25782562 while (tentatives.popOrNull()) |entry| {
25792563 const sym = &self.globals.items[entry.key];
25802564 const match: MatchingSection = blk: {
2581 if (self.common_section_index == null) {
2565 if (self.bss_section_index == null) {
25822566 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2583 self.common_section_index = @intCast(u16, data_seg.sections.items.len);
2584 try data_seg.addSection(self.base.allocator, "__common", .{
2567 self.bss_section_index = @intCast(u16, data_seg.sections.items.len);
2568 try data_seg.addSection(self.base.allocator, "__bss", .{
25852569 .flags = macho.S_ZEROFILL,
25862570 });
25872571 }
25882572 break :blk .{
25892573 .seg = self.data_segment_cmd_index.?,
2590 .sect = self.common_section_index.?,
2574 .sect = self.bss_section_index.?,
25912575 };
25922576 };
25932577 _ = try self.section_ordinals.getOrPut(self.base.allocator, match);
......@@ -2890,23 +2874,17 @@ fn addLoadDylibLCs(self: *MachO) !void {
28902874fn flushZld(self: *MachO) !void {
28912875 try self.writeTextBlocks();
28922876
2893 if (self.common_section_index) |index| {
2894 const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2895 const sect = &seg.sections.items[index];
2896 sect.offset = 0;
2897 }
2898
2899 if (self.bss_section_index) |index| {
2900 const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2901 const sect = &seg.sections.items[index];
2902 sect.offset = 0;
2903 }
2904
2905 if (self.tlv_bss_section_index) |index| {
2906 const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2907 const sect = &seg.sections.items[index];
2908 sect.offset = 0;
2909 }
2877 // if (self.bss_section_index) |index| {
2878 // const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2879 // const sect = &seg.sections.items[index];
2880 // sect.offset = 0;
2881 // }
2882
2883 // if (self.tlv_bss_section_index) |index| {
2884 // const seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2885 // const sect = &seg.sections.items[index];
2886 // sect.offset = 0;
2887 // }
29102888
29112889 try self.setEntryPoint();
29122890 try self.writeRebaseInfoTableZld();