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) = .{},
115115offset_table_free_list: std.ArrayListUnmanaged(u32) = .{},
116116
117117dyld_stub_binder_index: ?u16 = null,
118next_stub_helper_off: ?u64 = null,
118stub_helper_stubs_start_off: ?u64 = null,
119119
120120/// Table of symbol names aka the string table.
121121string_table: std.ArrayListUnmanaged(u8) = .{},
......@@ -1274,7 +1274,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
12741274 mem.writeIntSliceLittle(u32, placeholder, aarch64.Instruction.bl(@intCast(i28, displacement)).toU32());
12751275
12761276 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;
12781279 var buf: [@sizeOf(u64)]u8 = undefined;
12791280 mem.writeIntLittle(u64, &buf, end);
12801281 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 {
12951296 }).toU32());
12961297 mem.writeIntLittle(u32, cccode[4..8], aarch64.Instruction.b(@intCast(i28, displacement3)).toU32());
12971298 mem.writeIntLittle(u32, cccode[8..12], fixup.symbol * 0xd);
1298 try self.base.file.?.pwriteAll(&cccode, self.next_stub_helper_off.?);
1299 self.next_stub_helper_off = self.next_stub_helper_off.? + 3 * @sizeOf(u32);
1299 try self.base.file.?.pwriteAll(&cccode, stub_off);
13001300
13011301 try self.rebase_info_table.symbols.append(self.base.allocator, .{
13021302 .segment = 3,
......@@ -2102,7 +2102,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
21022102 });
21032103 self.binding_info_dirty = true;
21042104 }
2105 if (self.next_stub_helper_off == null) {
2105 if (self.stub_helper_stubs_start_off == null) {
21062106 const text = &self.load_commands.items[self.text_segment_cmd_index.?].Segment;
21072107 const sh = &text.sections.items[self.stub_helper_section_index.?];
21082108 const data = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
......@@ -2123,7 +2123,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
21232123 .literal = @intCast(u19, displacement2 / 4),
21242124 }).toU32());
21252125 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);
21272127 try self.base.file.?.pwriteAll(&code, sh.offset);
21282128 }
21292129}