authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-17 10:13:23+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-26 11:50:09+01:00
log2972f630a4ff6dc8da556c68a7f5c77de75f2514
treef922c86fbe04bfe54b0d177fa5c4bf0514c10630
parent4e3520a2f750474471308c520af072631dc31a9d

stage2 macho: start reverting some tweaks


1 files changed, 6 insertions(+), 7 deletions(-)

src/link/MachO.zig+6-7
...@@ -326,7 +326,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -326,7 +326,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
326 const tracy = trace(@src());326 const tracy = trace(@src());
327 defer tracy.end();327 defer tracy.end();
328328
329
330 switch (self.base.options.output_mode) {329 switch (self.base.options.output_mode) {
331 .Exe => {330 .Exe => {
332 if (self.entry_addr) |addr| {331 if (self.entry_addr) |addr| {
...@@ -361,7 +360,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -361,7 +360,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
361 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off);360 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off);
362 self.libsystem_cmd_dirty = false;361 self.libsystem_cmd_dirty = false;
363 }362 }
364 363
365 // Write export trie.364 // Write export trie.
366 try self.writeExportTrie();365 try self.writeExportTrie();
367 const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;366 const linkedit = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
...@@ -1166,8 +1165,8 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -1166,8 +1165,8 @@ pub fn populateMissingMetadata(self: *MachO) !void {
1166 text_segment.cmdsize += @sizeOf(macho.section_64);1165 text_segment.cmdsize += @sizeOf(macho.section_64);
1167 text_segment.nsects += 1;1166 text_segment.nsects += 1;
11681167
1169 // const program_code_size_hint = self.base.options.program_code_size_hint;1168 const program_code_size_hint = self.base.options.program_code_size_hint;
1170 const program_code_size_hint = 128;1169 // const program_code_size_hint = 128;
1171 const file_size = mem.alignForwardGeneric(u64, program_code_size_hint, self.page_size);1170 const file_size = mem.alignForwardGeneric(u64, program_code_size_hint, self.page_size);
1172 const off = @intCast(u32, self.findFreeSpace(file_size, self.page_size)); // TODO maybe findFreeSpace should return u32 directly?1171 const off = @intCast(u32, self.findFreeSpace(file_size, self.page_size)); // TODO maybe findFreeSpace should return u32 directly?
1173 const flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS;1172 const flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS;
...@@ -1180,7 +1179,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -1180,7 +1179,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
1180 .addr = text_segment.vmaddr + off,1179 .addr = text_segment.vmaddr + off,
1181 .size = file_size,1180 .size = file_size,
1182 .offset = off,1181 .offset = off,
1183 .@"align" = 2, // 2^12 = 40961182 .@"align" = if (self.base.options.target.cpu.arch == .aarch64) 2 else 1, // 2^2 for aarch64, 2^1 for x86_64
1184 .reloff = 0,1183 .reloff = 0,
1185 .nreloc = 0,1184 .nreloc = 0,
1186 .flags = flags,1185 .flags = flags,
...@@ -1650,7 +1649,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void {...@@ -1650,7 +1649,7 @@ fn writeOffsetTableEntry(self: *MachO, index: usize) !void {
1650fn writeSymbolTable(self: *MachO) !void {1649fn writeSymbolTable(self: *MachO) !void {
1651 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;1650 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
1652 const locals_off = symtab.symoff;1651 const locals_off = symtab.symoff;
1653 1652
1654 var locals = try self.base.allocator.alloc(macho.nlist_64, self.local_symbols.items.len - 1);1653 var locals = try self.base.allocator.alloc(macho.nlist_64, self.local_symbols.items.len - 1);
1655 defer self.base.allocator.free(locals);1654 defer self.base.allocator.free(locals);
16561655
...@@ -1752,7 +1751,7 @@ fn writeStringTable(self: *MachO) !void {...@@ -1752,7 +1751,7 @@ fn writeStringTable(self: *MachO) !void {
1752 // symtab.stroff = @intCast(u32, self.findFreeSpace(needed_size, 1));1751 // symtab.stroff = @intCast(u32, self.findFreeSpace(needed_size, 1));
1753 // }1752 // }
1754 symtab.strsize = mem.alignForwardGeneric(u32, @intCast(u32, needed_size), @sizeOf(u64));1753 symtab.strsize = mem.alignForwardGeneric(u32, @intCast(u32, needed_size), @sizeOf(u64));
1755 try self.base.file.?.pwriteAll(&[_]u8{ 0 }, symtab.stroff + symtab.strsize - 1);1754 try self.base.file.?.pwriteAll(&[_]u8{0}, symtab.stroff + symtab.strsize - 1);
1756 log.debug("writing string table from 0x{x} to 0x{x}\n", .{ symtab.stroff, symtab.stroff + needed_size });1755 log.debug("writing string table from 0x{x} to 0x{x}\n", .{ symtab.stroff, symtab.stroff + needed_size });
1757 try self.base.file.?.pwriteAll(self.string_table.items, symtab.stroff);1756 try self.base.file.?.pwriteAll(self.string_table.items, symtab.stroff);
1758}1757}