authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-01-08 22:40:09+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-01-13 23:54:56+01:00
log21c7217e09b48bf3bf9656fb1e8e69b85422b02e
tree8e6b417311640513a6154a9063cd79705a865d83
parent44a052a65f5c59b02383178f36fcc231df28b49f

macho: memorize start of stubs in helper


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

src/link/MachO.zig+6-6
...@@ -115,7 +115,7 @@ global_symbol_free_list: std.ArrayListUnmanaged(u32) = .{},...@@ -115,7 +115,7 @@ global_symbol_free_list: std.ArrayListUnmanaged(u32) = .{},
115offset_table_free_list: std.ArrayListUnmanaged(u32) = .{},115offset_table_free_list: std.ArrayListUnmanaged(u32) = .{},
116116
117dyld_stub_binder_index: ?u16 = null,117dyld_stub_binder_index: ?u16 = null,
118next_stub_helper_off: ?u64 = null,118stub_helper_stubs_start_off: ?u64 = null,
119119
120/// Table of symbol names aka the string table.120/// Table of symbol names aka the string table.
121string_table: std.ArrayListUnmanaged(u8) = .{},121string_table: std.ArrayListUnmanaged(u8) = .{},
...@@ -1274,7 +1274,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1274,7 +1274,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1274 mem.writeIntSliceLittle(u32, placeholder, aarch64.Instruction.bl(@intCast(i28, displacement)).toU32());1274 mem.writeIntSliceLittle(u32, placeholder, aarch64.Instruction.bl(@intCast(i28, displacement)).toU32());
12751275
1276 if (!fixup.exists) {1276 if (!fixup.exists) {
1277 const end = stub_h.addr + self.next_stub_helper_off.? - stub_h.offset;1277 const stub_off = self.stub_helper_stubs_start_off.? + fixup.symbol * 3 * @sizeOf(u32);
1278 const end = stub_h.addr + stub_off - stub_h.offset;
1278 var buf: [@sizeOf(u64)]u8 = undefined;1279 var buf: [@sizeOf(u64)]u8 = undefined;
1279 mem.writeIntLittle(u64, &buf, end);1280 mem.writeIntLittle(u64, &buf, end);
1280 try self.base.file.?.pwriteAll(&buf, la_ptr.offset + fixup.symbol * @sizeOf(u64));1281 try self.base.file.?.pwriteAll(&buf, la_ptr.offset + fixup.symbol * @sizeOf(u64));
...@@ -1295,8 +1296,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {...@@ -1295,8 +1296,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1295 }).toU32());1296 }).toU32());
1296 mem.writeIntLittle(u32, cccode[4..8], aarch64.Instruction.b(@intCast(i28, displacement3)).toU32());1297 mem.writeIntLittle(u32, cccode[4..8], aarch64.Instruction.b(@intCast(i28, displacement3)).toU32());
1297 mem.writeIntLittle(u32, cccode[8..12], fixup.symbol * 0xd);1298 mem.writeIntLittle(u32, cccode[8..12], fixup.symbol * 0xd);
1298 try self.base.file.?.pwriteAll(&cccode, self.next_stub_helper_off.?);1299 try self.base.file.?.pwriteAll(&cccode, stub_off);
1299 self.next_stub_helper_off = self.next_stub_helper_off.? + 3 * @sizeOf(u32);
13001300
1301 try self.rebase_info_table.symbols.append(self.base.allocator, .{1301 try self.rebase_info_table.symbols.append(self.base.allocator, .{
1302 .segment = 3,1302 .segment = 3,
...@@ -2102,7 +2102,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -2102,7 +2102,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
2102 });2102 });
2103 self.binding_info_dirty = true;2103 self.binding_info_dirty = true;
2104 }2104 }
2105 if (self.next_stub_helper_off == null) {2105 if (self.stub_helper_stubs_start_off == null) {
2106 const text = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;2106 const text = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2107 const sh = &text.sections.items[self.stub_helper_section_index.?];2107 const sh = &text.sections.items[self.stub_helper_section_index.?];
2108 const data = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;2108 const data = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
...@@ -2123,7 +2123,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {...@@ -2123,7 +2123,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
2123 .literal = @intCast(u19, displacement2 / 4),2123 .literal = @intCast(u19, displacement2 / 4),
2124 }).toU32());2124 }).toU32());
2125 mem.writeIntLittle(u32, code[12..16], aarch64.Instruction.br(.x16).toU32());2125 mem.writeIntLittle(u32, code[12..16], aarch64.Instruction.br(.x16).toU32());
2126 self.next_stub_helper_off = sh.offset + 4 * @sizeOf(u32);2126 self.stub_helper_stubs_start_off = sh.offset + 4 * @sizeOf(u32);
2127 try self.base.file.?.pwriteAll(&code, sh.offset);2127 try self.base.file.?.pwriteAll(&code, sh.offset);
2128 }2128 }
2129}2129}