authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-23 23:23:00+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-23 23:23:00+02:00
log876071b50b1d23a59b3d3e5acedf4161029f5f2b
treefc31c108290d7f10942cd1a7978cc7a2e8e7553d
parent9e7b2fb894cf4021ec188fbb64b11d750f4354fa

macho: fix writing stubs (on x86_64 only) and lazy ptrs


1 files changed, 8 insertions(+), 3 deletions(-)

src/link/MachO.zig+8-3
...@@ -816,8 +816,8 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {...@@ -816,8 +816,8 @@ pub fn flush(self: *MachO, comp: *Compilation) !void {
816816
817 const laptr_atom = try self.createLazyPointerAtom(stub_atom.local_sym_index);817 const laptr_atom = try self.createLazyPointerAtom(stub_atom.local_sym_index);
818 try self.allocateAtomStage1(laptr_atom, .{818 try self.allocateAtomStage1(laptr_atom, .{
819 .seg = self.text_segment_cmd_index.?,819 .seg = self.data_segment_cmd_index.?,
820 .sect = self.stub_helper_section_index.?,820 .sect = self.la_symbol_ptr_section_index.?,
821 });821 });
822 }822 }
823 try self.allocateTextSegment();823 try self.allocateTextSegment();
...@@ -2183,6 +2183,11 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {...@@ -2183,6 +2183,11 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {
2183 .aarch64 => 3 * @sizeOf(u32),2183 .aarch64 => 3 * @sizeOf(u32),
2184 else => unreachable,2184 else => unreachable,
2185 };2185 };
2186 const alignment: u2 = switch (arch) {
2187 .x86_64 => 0,
2188 .aarch64 => 2,
2189 else => unreachable,
2190 };
2186 const local_sym_index = @intCast(u32, self.locals.items.len);2191 const local_sym_index = @intCast(u32, self.locals.items.len);
2187 try self.locals.append(self.base.allocator, .{2192 try self.locals.append(self.base.allocator, .{
2188 .n_strx = try self.makeString("stub_in_stub_helper"),2193 .n_strx = try self.makeString("stub_in_stub_helper"),
...@@ -2194,7 +2199,7 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {...@@ -2194,7 +2199,7 @@ fn createStubHelperAtom(self: *MachO) !*TextBlock {
2194 const atom = try self.createEmptyAtom(.{2199 const atom = try self.createEmptyAtom(.{
2195 .seg = self.text_segment_cmd_index.?,2200 .seg = self.text_segment_cmd_index.?,
2196 .sect = self.stub_helper_section_index.?,2201 .sect = self.stub_helper_section_index.?,
2197 }, local_sym_index, stub_size, 2);2202 }, local_sym_index, stub_size, alignment);
2198 try atom.relocs.ensureTotalCapacity(self.base.allocator, 1);2203 try atom.relocs.ensureTotalCapacity(self.base.allocator, 1);
21992204
2200 switch (arch) {2205 switch (arch) {